GLSL: How to get pixel x,y,z world position?

后端 未结 4 1718
情深已故
情深已故 2020-12-24 02:29

I want to adjust the colors depending on which xyz position they are in the world.

I tried this in my fragment shader:

varying vec4 verpos;

void mai         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 03:00

    Or you could just divide the z coordinate by the w coordinate, which essentially un-does the perspective projection; giving you your original world coordinates.

    ie.

    depth = gl_FragCoord.z / gl_FragCoord.w;
    

    Of course, this will only work for non-clipped coordinates..

    But who cares about clipped ones anyway?

提交回复
热议问题