Giter Club home page Giter Club logo

Comments (2)

greggman avatar greggman commented on August 29, 2024

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 z < 0 get flipped to a positive value.

So, what really happens is your shader returns vertices in clip space by setting gl_Position. Every 3 vertices make a triangle in clip space, that triangle is clipped in clip space, and after that step the vertices are divided by W.

You can see if you take the 2nd example on the page where we let WebGL do the division it shows the correct image

Screen Shot 2022-06-01 at 6 23 59 PM

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

vertex = gl_Position.xyz / gl_Position.z

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.

from webgl2-fundamentals.

greggman avatar greggman commented on August 29, 2024

as for

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_fudge

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.

from webgl2-fundamentals.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.