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

How to do the shadow mapping after perspective deformations? #130

Open
Brendon3Tang opened this issue Apr 20, 2023 · 1 comment
Open

How to do the shadow mapping after perspective deformations? #130

Brendon3Tang opened this issue Apr 20, 2023 · 1 comment

Comments

@Brendon3Tang
Copy link

Brendon3Tang commented Apr 20, 2023

Hi, I am having a hard time doing the shadow mapping after changing my code according to the chapter "Technical difficulties: linear interpolation with perspective deformations".

My own thought about this problem is that we used the z-value of the original P, but the index (x+y*width) of the shadowBuffer for that z-value comes from the P', (original P after the MVP transformation). So, the pixel doesn't match the z-value.

Please correct me if I am wrong.

Also, I tried to download the sample code from the master branch and run it. But I didn't see the shadow, either. Does anyone successfully do the shadow mapping? Any hints would be helpful, I would appreciate it!

@Brendon3Tang
Copy link
Author

I fixed this problem by passing both "bc_screen" and "bc_clip" into the fragment shader.

In the triangle() of our_gl.cpp, I store the pts2.z as the fragment_depth instead of pts.z so that I can make sure that the z-value and the x-value & y-value in idx (x+y*width) come from the same point, P'. Now we make the index of the shadowBuffer in this pixel and the z-value of in this pixel consistent.

In the DepthShader, I did almost the same thing as in Lesson 7 (but I tried to save the vertices after MVP into the varying_tri instead of the vertices after VP, while the vertex shader still returned the vertices after VP transformation to the main function).

Then in the Shader, I used "bc_screen" and varying_tri (still, it saved the vertices after MVP) to calculate the (x', y', z') of P'。 And use the (x', y') to get the index to access the shadowBuffer, and compared it with z'。After that, I used "bc_clip" to do whatever we should do to calculate uv, n, and other stuff.

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

No branches or pull requests

1 participant