Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a material unique with emission enabled will result in incorrect editor colors #60849

Closed
stryker313 opened this issue May 7, 2022 · 11 comments · Fixed by #84303
Closed

Comments

@stryker313
Copy link

Godot version

4.0 Alpha 7

System information

Windows 10 Nvidia GTX 1060 Intel i5 4690k

Issue description

If you make a unique material on a material with emission enabled, it will glitch out in the editor

Untitled3.mp4

When making a copy of the material, pasting to another object, then making unique, the red will turn to white.

In the game, it is fine.

However, the colors are inaccurate in the editor

When you exit the editor and return, the colors will be fine again.

The editor issue only exists when you make a copy of a material, then make that material unique.

Steps to reproduce

Create 2 meshes
Create a material3d on 1 mesh
Set emission to true
Set albedo and emission color to color other than white
Copy material from mesh 1 to mesh 2
Make material on mesh 2 unique
Editor will glitch the colors out

Again, this does not affect the game. The colors are correct in game. However, the editor is inaccurate.

Minimal reproduction project

MaterialBug (2).zip

@codespren
Copy link

codespren commented Oct 15, 2022

Bug happens here too but not only in the editor but in game also when making material unique from the code. macOS, AMD Radeon Pro 5500M, Godot 4 Beta 1.

Code:

scene = (PackedScene)ResourceLoader.Load("res://data/scenes/scene.tscn");
meshInstance = (MeshInstance3D)scene.Instantiate();
SphereMesh mesh = (SphereMesh)meshInstance.Mesh.Duplicate();
meshInstance.Mesh = mesh;
StandardMaterial3D material = (StandardMaterial3D)mesh.SurfaceGetMaterial(0).Duplicate(); // X
mesh.SurfaceSetMaterial(0, material);
AddChild(meshInstance);
StandardMaterial3D material = (StandardMaterial3D)meshInstance.Mesh.SurfaceGetMaterial(0);
material.EmissionEnabled = true;

After that the emission is very bright, basically white. If I remove Duplicate() from the line marked with X it works correctly.

@BlueMoonJune
Copy link

anyone found a work around for the runtime example?

@elvisish
Copy link

elvisish commented May 20, 2023

This still seems to be an issue, duplicating a material from the mesh at runtime and setting it as a material override, then turning emission on just shows solid white.

Setting the emission_energy_multiplier to much less than it should be (ie: use 0.3 instead of 7.5) makes it not pure white, but it isn't anywhere near as vibrant and is too muted.

EDIT: it seems to happen with material overrides, geometry overrides and surface overrides, I think if the material is duplicated it breaks emissions.

@clayjohn
Copy link
Member

I wonder if #77326 helps this at all. It turns out we weren't properly freeing materials when geometry was duplicated

@solitaryurt
Copy link

Experiencing this same bug.

@elvisish
Copy link

I wonder if #77326 helps this at all. It turns out we weren't properly freeing materials when geometry was duplicated

Is this available for testing? I gave up trying to get emissions to show as non-white unless it was set to 0.03, and then it looks really weak and not emissive at all. It definitely sounds like having two of the same material simultaneously would cause something like this.

@Calinou
Copy link
Member

Calinou commented May 24, 2023

Is this available for testing?

It's not in 4.0.3, but you can build the master branch or use the artifacts linked in that PR: https://docs.godotengine.org/en/latest/contributing/workflow/testing_pull_requests.html

@Cammymoop
Copy link
Contributor

Aha! I've narrowed down what causes this I think.
I got the exact same broken state on a new material that I manually copied all properties on, so I tired not setting some emission related properties and found out it was emission_texture that makes it happen.

And yup, you can reproduce the bug in the editor too by simply setting a material's emission texture and then clearing it.
So I guess something is going wrong when it's being set to null

@Cammymoop
Copy link
Contributor

So yeah a workaround for this is to create a new material and copy all the properties into it except not the emission texture unless you have one.

@spacehare
Copy link

i was able to get this working by setting a full-black emission texture.
image

@elvisish
Copy link

elvisish commented Oct 2, 2023

i was able to get this working by setting a full-black emission texture. image

Afraid this didn't work for me:
image
(how it should look)
How it looks in game:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.