0 votes

I want to create a new ShaderMaterial in C#. For now I'm trying out something very basic like constant blue. However, it fails. The same shader works fine when I create it over the editor, but I need the assignment to happen in code, of course once I get this toy example running I will extend the shader.

var mesh = new MeshInstance3D() {
    Mesh = new BoxMesh(),
    Position = new Vector3(x, -z, y)

mesh.MaterialOverlay = new ShaderMaterial {
  Shader = new Shader {
    Code = @"{
      shader_type spatial;
      void fragment() { ALBEDO = vec3(0., 0., 1.); }

The mesh stays grey. I am missing something? Even when I make the shader syntax wrong I get no compilation error, so I suspect some compilation of linking call is missing somewhere, but I didn't find anything in the docs. So how to approach this?

Godot version Godot 4 beta 10
in Engine by (19 points)

1 Answer

0 votes
Best answer

So it turned out that the shader code was wrong. The very first character { is a mistake. It's a pity that Godot does not report such errors.

by (19 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.