godot icon indicating copy to clipboard operation
godot copied to clipboard

Shader Materials broken when created in C# (Regression from `4.4-beta2` -> `4.4-beta3`)

Open Joy-less opened this issue 10 months ago • 2 comments

Tested versions

  • The regression occurs in 4.4-beta3, 4.4-beta4, 4.4-rc1.
  • The last working version is 4.4-beta2.

System information

Godot v4.4.rc1.mono - Windows 11 (build 26100) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1050 Ti (NVIDIA; 32.0.15.6636) - Intel(R) Core(TM) i3-9100F CPU @ 3.60GHz (4 threads)

Issue description

ShaderMaterial is completely bugged when created with new in C# starting with Godot 4.4-beta3.

Here is the code that works in 4.4-beta2 but not in 4.4-beta3 and beyond:

[Export] Shader EyesShader;

// ...

ShaderMaterial EyesMaterial = new() {
    Shader = EyesShader,
};
FaceMesh.SetSurfaceOverrideMaterial(0, EyesMaterial);

Here is the fix:

[Export] ShaderMaterial EyesMaterial;

// ...

// Create eyes material
ShaderMaterial Material = (ShaderMaterial)EyesMaterial.Duplicate();
FaceMesh.SetSurfaceOverrideMaterial(0, Material);

This is what it looks like in 4.4-beta2:

Image

This is what it looks like in 4.4-rc1 (same as 4.4-beta3 and 4.4-beta4):

Image

The big orange eyes are created in the editor so the ShaderMaterial is not instantiated in C#. The blue eyes on the character are subject to the given C# code.

Steps to reproduce

Shader ExampleShader;
MeshInstance3D ExampleMeshInstance3D;

ExampleMeshInstance3D.SetSurfaceOverrideMaterial(0, new ShaderMaterial() {
    Shader = ExampleShader,
});

Minimal reproduction project (MRP)

shader-material-regression.zip

Godot 4.4-beta2:

Image

Godot 4.4-rc1:

Image

Joy-less avatar Feb 22 '25 21:02 Joy-less

I haven't bisected, but looking at the changelog for 4.4-beta3 and the description of the bug, #95626 sounds like it might be related.

CC @Chaosus @raulsntos

akien-mga avatar Feb 22 '25 22:02 akien-mga

I bisected it to 860a6ab9ac57056a11cb913aef9eff75e85810f6

Also, here's the MRP ported to GDScript: shader-material-regression-gd.zip

raulsntos avatar Feb 23 '25 02:02 raulsntos