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

Shadow glitches #5

Open
arakis opened this issue Jul 9, 2020 · 15 comments
Open

Shadow glitches #5

arakis opened this issue Jul 9, 2020 · 15 comments
Labels
bug Something isn't working

Comments

@arakis
Copy link
Collaborator

arakis commented Jul 9, 2020

@LevYas wrote in #3:

There are some glitches with shadows though
image
But this could be because of OpenGL ver 3.3. Even the freshest Nvidia drivers did not bring me 4.

Originally posted by @LevYas in #3 (comment)

@arakis arakis changed the title Yeaah, it has started successfully :) Shadow glitches Jul 9, 2020
@arakis
Copy link
Collaborator Author

arakis commented Jul 9, 2020

This is a known issue and is regardless of the OpenGL version. There's a bug in the shadow calculation. Some brainstorming:
There could be a problem in the source of

I've spent lots of time in shadow debugging in the past. Any help would be great.

Nut sure, but as I remind this occurs only in DirectionLightning (shadow Map). Try PointLight (shadow Cube) here:
https://github.com/AximoGames/AxEngine/blob/master/Demo/DemoApplication.cs#L189

@arakis
Copy link
Collaborator Author

arakis commented Jul 9, 2020

Just a notice: in Marbles ( https://github.com/AximoGames/AxMarbles ) and in this Sample ( https://www.aximo.games/samples/shadows/ ) only PointLight is used and there are no shadow glitches. So, it seems it happens only with DirectionalLight. Any help in fixing the shadow bug would be great.

@arakis arakis added the bug Something isn't working label Jul 9, 2020
@LevYas
Copy link

LevYas commented Jul 9, 2020

I'm afraid I will not be able to help. I've just started to learn OpenGL and OpenTK as a hobby and came across your engine as a real-word usage example :)
BTW, I'm very disappointed there is no TDD practice for shaders. I think they're ideal for unit testing - a specific set of arguments (coordinates, uniforms, ...), a specific set of output (color for pixel, ...), but I failed to find any testing framework for this, only 1.5 proof of concepts several years old and that's all.
I have no idea how people making shaders like this without a decent debugger and tests https://www.shadertoy.com/view/Ms2SD1

@arakis
Copy link
Collaborator Author

arakis commented Jul 9, 2020

There are no isolated shader tests, but some render tests: https://github.com/AximoGames/AxEngine/tree/master/Tests/RenderTests

They work in the following way:

Generally, even the render tests are a life and time saver :-)

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

So I tested a bit and found the following:

  • The Reason, that the OpenGL Version is 3.3, is because OpenTK default initializes the Context with Version 3.3
    You can change the Version by Adding APIVersion = new Version(4, 1) in the NativeWindowSettings in the RenderWindow.cs
  • The Bug presists in Version 4.1 with Intel
    IntelIGPU
    and Nvidia.
    NvidiaGPU

Both were tested with the Context set to Version 4.1

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

I disabled the moving Light and looked with Renderdoc to check how the shadowmaps are and noticed, that the directional light Shadowmap ist just white.
image
And the Problem seems to be in DeferredRendering Part of the Engine, since the only shadows I see in Renderdoc are in the DeferredRenderPipeline
image
If the Renderdoc Capture is interessting, I can upload it to dropbox or something similar, since Github doesn't allow for files bigger than 10MB.

@arakis
Copy link
Collaborator Author

arakis commented Aug 1, 2020

Interesting. But if the shadow map (used for direction light shadows) is "empty", there should not be any shadow? Did you checked the shadow map "Index" (=Slice)?

image

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

Yes, with index 1 there is a shadow map.
Is it normal, that there is an white image as output in the first render pass?
image
And the Issue with the shadow is caused by the shadow map
image

So the next step now is to find out why the shadow map has this problem.

@arakis
Copy link
Collaborator Author

arakis commented Aug 1, 2020

Greate work! Just some ideas:

  • Near-Plane is crossing the sphere?
  • Shadows are renderend with normal cull mode = back, like normal rendering.

I know for shadows, cull mode = front shuld be used. But with that cull mode, the shadows seems to be less accurate. You can test it here: https://github.com/AximoGames/AxEngine/blob/master/Render/Objects/SimpleVertexObject.cs#L266

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

It was the near plane intersecting with the sphere, that caused the issue.
image

I changed in the LightObject.cs the nearplane to 0.1f

But the shadow of rotating directional still disappears and reappears.
I thing there might be a problem, that the shadow map doesnt catch the complete map.

@arakis
Copy link
Collaborator Author

arakis commented Aug 1, 2020

amazing! thx very much for tracking down the problem. Regarding the missing shadows that are far away: I have no idea how to solve this in a perfect manner. One idea is to move the directional shadow light with the player. But even in this case, the map needs to be bigger: More memory, more computing time or shadow have more artifacts. So, what do you think is a good/acceptable way to render shadows that are far away?

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

Sadly no :/

@arakis
Copy link
Collaborator Author

arakis commented Aug 1, 2020

Did you found out why the shadows are not correctly rendered if cull mode is changed?

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

I did not check that, but I can look later

@kbitGit
Copy link
Collaborator

kbitGit commented Aug 1, 2020

Hm it's really weird. This is the shadows when I enable Cullmode Front:
image
I used the following code to enable it in SimpleVertexObject.cs :

GraphicsDevice.Default.CullFaceMode = CullFaceMode.Front;
//GL.CullFace(CullFaceMode.Front);
//GL.Disable(EnableCap.CullFace);
mat.Vao.Draw();
//GL.Enable(EnableCap.CullFace);
//GL.CullFace(CullFaceMode.Back);}
GraphicsDevice.Default.CullFaceMode = CullFaceMode.Back;

The weird part, is that the shadowmaps seem to be fine
Slice 0
image

Slice 1
image

I have currently no clue, where the problem can be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants