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

resource_local_to_scene causes emission materials to break visuals of MeshInstance3D half the time #83190

Closed
Wierdox opened this issue Oct 12, 2023 · 4 comments · Fixed by #84303

Comments

@Wierdox
Copy link
Contributor

Wierdox commented Oct 12, 2023

Godot version

v4.0.2.stable.official [7a0977c] v4.1.2.stable.official [399c9dc] v4.2.dev6.official [57a6813]

System information

Godot v4.1.2.stable - Windows 10.0.19044 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 SUPER (NVIDIA; 31.0.15.3640) - AMD Ryzen 5 5600G with Radeon Graphics (12 Threads)

Issue description

Found issue when animating emission materials, primarily tested with StandardMaterial3D and primitive meshes. ORMMaterial3D seems to be similar if not the same, ShaderMaterial doesn't seem to cause the issue. Issue occurs in all 3 renderers.

Every case so far that I know causes the problem(all have emission enabled, referring to a MeshInstance3D):

  • mesh and material is resource_local_to_scene
  • material_override is resource_local_to_scene
  • material is made unique via code material = material.duplicate()

Effects of issue

  • It's pure white if emission_energy_multiplier is set to 1 or greater.
  • emission_energy_multiplier values near 1 approach a white infused version of the emission color, below that its brightness fades, leading to no effect at 0.
Godot_v4.1.2-stable_win64_9S2gmCHcyt.webm

Steps to reproduce

Download repro, start main.tscn to see the problem, and it will animate emission_energy_multiplier to 0 to show what it looks like compared to normal behavior. Output contains some info.

Minimal reproduction project

bug_reproduction.zip

@bitsawer
Copy link
Member

Could be related to #71243 (and its duplicate issue #71406).

I tested PR #71578 on top of current master, but it didn't seem to fix this specific issue, so this issue could be something different.

@wilfredjonathanjames
Copy link

wilfredjonathanjames commented Oct 22, 2023

I think I have the same issue, though what I'm seeing is bright white rather than black.

I've created a reliable reproduction here. Video here.

4.2-beta1
MacOS 12.3

Steps:

  1. Open main.tscn
  2. See that the sphere in main.tscn is yellow
  3. Open mesh.tscn
  4. Update Root/Mesh:mesh:material:emission_energy_multiplier from 0 to 1
  5. Save mesh.tscn - this is necessary
  6. See that the sphere in main.tscn is white

Notes:

  1. The issue does not appear if Mesh is the scene root of mesh.tscn
  2. The issue seems to be the emission value getting multiplied somewhere
  3. This happens even if the emission is black
  4. Color emissions appear white

[Edit] Let me know if this isn't the same and I'll raise a new issue.

@Wierdox
Copy link
Contributor Author

Wierdox commented Oct 22, 2023

though what I'm seeing is bright white rather than black.

The black in my video was only what I chose for the mesh's albedo, maybe a bad idea in hindsight. The white glow is assumedly the same cause as yours, when emission_energy_multiplier is set to 1 plus the resource_local_to_scene stuff. Though it's interesting how it happens in the editor for you, I only saw it in game. Got to sleep right now, I'll look into it more tomorrow.

Also, thanks for sharing another repro + video.

Update:
Tested repro + reenacted in my own game and got the same outcome. I will note that if you save the mesh.tscn while currently viewing main.tscn, the bad glow won't happen until you leave then go back. I think that is standard for updating instanced scenes though(doesn't happen until reload).

It seems the white glow in the editor only happens if the mesh is instanced in another. The bad glow doesn't show in the original scene view though, curiously enough.

@Wierdox
Copy link
Contributor Author

Wierdox commented Oct 26, 2023

It seems that the issue might have to do with emission_texture. I've started looking into the source code a bit, but very little luck so far. Think I'm a little in over my head.

Note: emission_operator is for adding or multiplying the emission color by the optional emission_texture color, or so that's how I currently understand it. Also, all tests assumed with emission_energy_multiplier = 1, and uses the repros listed above.

I've dug around and found out that:

  • emission_operator=EMISSION_OP_ADD and emission_texture = null:
    -- This is default and is the standard issue, bad glow like repros.
  • emission_operator=EMISSION_OP_ADD and emission_texture = pure white:
    -- This will look exactly like the bad glow, a pure white.
  • emission_operator=EMISSION_OP_ADD and emission_texture = pure black:
    -- This will look like what you'd expect: normal glow since it adds nothing. However, it also fixes the bad glow found in the repros!! This probably means emission_texture is being set to white instead of black as default, somewhere. Or some incorrect formulae causing the problem. At least that's the guess.
  • emission_operator=EMISSION_OP_MULTIPLY and emission_texture = null:
    -- When normal: no glow. Makes sense since there's no texture to multiply by.
    -- When bad glow: it will look correct, but only when it's an instance/duplicate. The original scene has no glow.
  • emission_operator=EMISSION_OP_MULTIPLY and emission_texture = pure white:
    -- This will look like what you'd expect: normal glow since it multiplies by 1. Instances/duplicates will be the same. Effectively fixes the issue.
  • emission_operator=EMISSION_OP_MULTIPLY and emission_texture = pure black:
    -- No glow since it multiplies by 0. Instances will be the same.

New Bug Found:

  • emission_operator=EMISSION_OP_ADD
    -- Reverting any texture in emission_texture to null will cause the mesh to get bad glow, in editor only.
  • emission_operator=EMISSION_OP_MULTIPLY
    -- Reverting any texture in emission_texture to null will cause the mesh to maintain its glow like it was EMISSION_OP_ADD, in editor only.
  • Swapping the above, the bug will persist but with the new effects of that option.
  • It won't go back to normal unless Godot is restarted or all scenes including that material are closed then reopened.

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.

4 participants