-
Notifications
You must be signed in to change notification settings - Fork 220
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
Bugs with code in WebGL2 3D Perspective Section #168
Comments
Thanks for the report and sorry it's confusing The first example is manually dividing by Z. The problem with manually dividing by Z is the sign is lost. Example (-6 / -3 = 2). -6 and -3 are negative but after dividing the result is positive. This is one reason why the space the shader returns is called "clip space" because once the sign is lost it's impossible to clip the triangle correctly all the vertices that are So, what really happens is your shader returns vertices in clip space by setting You can see if you take the 2nd example on the page where we let WebGL do the division it shows the correct image Sorry if that was confusing. The point of the first example it to show that dividing by Z will give you the illusion of perspective. The point of the second example it to show that WebGL does
It divides by Z for you so you don't do the division yourself like the first example, you let WebGL do it. I should probably put more details to show why you let WebGL do it. |
as for
You might be right. For me, it didn't really matter. What mattered was that the image looks like it has perspective (things further away are smaller than things that are near). Once we've established that dividing by Z gives the illusion of perspective we can go to step 3 and show we can achieve this division using matrices And step 4 is that there is magic math (math that is unexplained) that will compute a matrix that will give us perspective based on field of view, aspect, near, and far inputs. |
Describe the bug
It seems some codes are wrong in the first example of 3D Perspective Section.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Then in the result figure, the model seems to be worn, just like below
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Also, the code in that example also gets wrong. In this code "float zToDivideBy = 1.0 + position.z * u_fudgeFactor;" it should be "float zToDivideBy = (1.0 + position.z) * u_fudgeFactor;".
The text was updated successfully, but these errors were encountered: