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

MeshInstance shadows sometimes don't show in editor, resetting material temporarily fixes it [GLES2] #44255

Open
snougo opened this issue Dec 10, 2020 · 11 comments

Comments

@snougo
Copy link

snougo commented Dec 10, 2020

Godot version:

3.2.4 beta3

OS/device including version:

屏幕快照 2020-12-10 15 08 29

Issue description:

if your whole scene is imported form outside, the shadow won't be rendered if you switch from GLES3 to GLES2, you have to restart Godot Editor then this problem will be fixed. also if your imported scene use some built-in mesh like cubemesh or spheremesh, then you won't have this problem, shadow will be rendered normally when you switch from GLES3 to GLES2

Steps to reproduce:
find some outside model
import this model to the Godot
open the scene of this model and save it as .tscn
switch from GLES3 to GLES2
屏幕快照 2020-12-10 15 23 29
屏幕快照 2020-12-10 15 23 11

Minimal reproduction project:

bug.report.zip

@Calinou
Copy link
Member

Calinou commented Dec 10, 2020

the shadow won't be rendered if you switch from GLES3 to GLES2, you have to restart Godot Editor then this problem will be fixed.

I don't understand. You always have to restart the editor after switching renderers.

@snougo
Copy link
Author

snougo commented Dec 10, 2020

@Calinou
I tested it again and I found that you just need to close this scene and reopen it or creat a new empty scene then switching back this scene, sorry my bad

oh I forgot to say that in runtime the shadow works fine even you don't do that I mentioned, it's just a Editor issue

@snougo snougo changed the title in some case the shadow of imported scene won't be rendered if switch form GLES3 to GLES2 in some case the shadow of imported scene won't be rendered in Editor if switch form GLES3 to GLES2 Dec 10, 2020
@akien-mga akien-mga added this to the 3.2 milestone Mar 2, 2021
@AlphaVDP2
Copy link

Reposting assets from closed issue for reference.

Issue description:
No shadow is cast from a mesh when material is assigned to the Mesh instead of the Node.
Issue does not appear in GLES 3 mode.
Appears to be a regression as it worked in v3.2.3 in both GLES 2 and 3 modes.

Steps to reproduce:
Assign a material only to the Mesh and not the Node.

shadow_bug

Shadow_Bug.zip

@akien-mga akien-mga modified the milestones: 3.2, 3.3 Mar 17, 2021
@snougo
Copy link
Author

snougo commented Sep 24, 2021

still happend in 3.4 beta5

@lawnjelly
Copy link
Member

lawnjelly commented Sep 24, 2021

This broke somewhere between 3.2.4 beta 1 (it worked) and 3.2.4 beta 2 (didn't work).

Something on this list:
2e073ec...04103db

Going to be a pain to bisect as the artifacts have expired...
Can't immediately see any PR jumping out as the culprit.

@Calinou Calinou added topic:3d and removed topic:3d labels Sep 24, 2021
@akien-mga akien-mga modified the milestones: 3.3, 3.5 Oct 26, 2021
@akien-mga
Copy link
Member

Still reproducible in 3.4 RC 1. I can confirm that the regression happened between 3.2.4 beta 1 and beta 2.

I can try to do a bisect at some point, but if anyone else wants to burn some CPU cycles, feel free!

@JFonS
Copy link
Contributor

JFonS commented Oct 27, 2021

Git bisect points at #43206.

Seems a bit odd, but I tried commenting out all the VisualServer calls from that PR and the issue does go away. It must be doing something that messes up with the state of other instances, or maybe the RIDs get mixed up, needs further investigation.

CC @Calinou @aaronfranke

@akien-mga
Copy link
Member

Is this still reproducible in 3.5 beta 5 or later? I remember other issues caused by #43206 and some invalid RIDs that might have been solved by @lawnjelly and others.

@snougo
Copy link
Author

snougo commented May 6, 2022

@akien-mga
yes it still reproducible in 3.5 beta5 on Mac, but I am not sure if it has be fixed in other Platforms like windows and linux

@akien-mga akien-mga changed the title in some case the shadow of imported scene won't be rendered in Editor if switch form GLES3 to GLES2 MeshInstance shadows sometimes don't show in editor, resetting material temporarily fixes it [GLES2] Jun 10, 2022
@akien-mga
Copy link
Member

akien-mga commented Jun 10, 2022

This is still reproducible in the current 3.x branch (1b6ac2a) on Linux, with both Intel HD Graphics 630 and AMD Radeon RX Vega M. So it's likely not OS nor driver specific since so far it could be reproduced on all systems we tried with.

As #44255 (comment) describes it, assigning a Material to the MeshInstance directly or to the Mesh Surface seems to have an impact on whether the bug happens, though it might be more due to the order in which things are processed. For example in the "Shadow_Bug.zip" project, clearing the material on the "broken" mesh and then undoing it fixes the shadows.

As a reminder, this was bisected to be a regression caused by #43206. There's surely still some invalid RID flakiness in there.

@lawnjelly
Copy link
Member

lawnjelly commented Jun 10, 2022

Curiously, the issue still occurs even after turning off "view grid" in the view menu. 🤔 Maybe we can try manually commenting out the grid code to confirm that it is causing the issue.

There don't seem to be any RID errors reported in the RID handles build.
But I can confirm that if I comment out the line spatial_editor->update_grid(); in SpatialEditorViewport::_update_camera it fixes the bug, so it is something in the PR.

void SpatialEditor::update_grid() {
	_finish_grid();
	_init_grid();
}

Having the grid off disables _init_grid(), and it still happens, so the problem is occurring in _finish_grid() which is confirmed by placing a return at the top of the function.

void SpatialEditor::_finish_grid() {
	for (int i = 0; i < 3; i++) {
		if (grid_instance[i].is_valid()) {
			VisualServer::get_singleton()->free(grid_instance[i]);
			grid_instance[i] = RID();
		}

		if (grid[i].is_valid()) {
			VisualServer::get_singleton()->free(grid[i]);
			grid[i] = RID();
		}
	}
}

What is interesting is that while debugging this appears to be being called in a multithread fashion (because the debugger goes haywire), which is suggestive of a possible race condition. 🤔

Commenting out

			VisualServer::get_singleton()->free(grid_instance[i]);

fixes it.

Putting some more debug output on creating and deleting the RIDs, printing out the RID id (e.g. 12512) and the revision (e.g. 1). It all seems okay, it is deleting both, and creating both on each update, and reusing the same slot (hence only the revision is changing).

This is occurring even with the grid switched off (for the first few frames?) which suggests the grid defaults to on and it takes some time before it reads the editor / project setting for the "view grid" to turn it off, which explains why turning it off didn't fix the bug.

_init_grid()
--- GDScript language server started ---
_finish_grid()
_init_grid()
SpatialEditor::_init_grid create grid 12512 .. 1
SpatialEditor::_init_grid create grid instance 12513 .. 1
_finish_grid()
SpatialEditor::_finish_grid free grid instance 12513 .. 1
SpatialEditor::_finish_grid free grid 12512 .. 1
_init_grid()
SpatialEditor::_init_grid create grid 12512 .. 2
SpatialEditor::_init_grid create grid instance 12513 .. 2
_finish_grid()
SpatialEditor::_finish_grid free grid instance 12513 .. 2
SpatialEditor::_finish_grid free grid 12512 .. 2
_init_grid()
SpatialEditor::_init_grid create grid 12512 .. 3
SpatialEditor::_init_grid create grid instance 12513 .. 3
_finish_grid()
SpatialEditor::_finish_grid free grid instance 12513 .. 3
SpatialEditor::_finish_grid free grid 12512 .. 3
_init_grid()
SpatialEditor::_init_grid create grid 12512 .. 4
SpatialEditor::_init_grid create grid instance 12513 .. 4
Switch Scene Tab
_finish_grid()
SpatialEditor::_finish_grid free grid instance 12513 .. 4
SpatialEditor::_finish_grid free grid 12512 .. 4
_finish_grid()

It is possible that the RIDs is a wild goose chase, and drawing the grid is setting an obscure OpenGL state that isn't being reset when drawing the cubes. This would help explain the GLES2 / GLES3 difference. Maybe we can test this.

Another couple of ideas:

  • Look at the cull result for the shadow map and see if the number of instances tallies up with the number of boxes or is 1 short
  • Try running this in a graphics debugger and examine the GL state / commands to work out whether a drawcall is being issued and / or a state is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Blockers / regressions
Development

No branches or pull requests

7 participants