Jump to content
  • Advertisement
Sign in to follow this  
glPetter3f

world position to pixel

This topic is 3881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am making a shader to draw water and I want the water to be refracted. I am wondering if anyone knows any way to transform world coordinates to screen coordinate in the fragment shader the same way ftransform() does in my vertex shader.

Share this post


Link to post
Share on other sites
Advertisement
ftransform() is really just:

gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;

So you can just replicate that in the pixel shader.

Regards
elFarto

Share this post


Link to post
Share on other sites
Hi i tried doing this but the result isn't correct:

vec4 newgl_FragCoord =gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(eyepos+dir*dist,1);


dir is the direction from camera to fragment and eyepos is the cameras position and dist is the distance from the camera to the fragment.

then i use newgl_FragCoord.xy/resolution.xy for texture lookup.

Share this post


Link to post
Share on other sites
I'm not sure what your trying to do here, but you already have the co-ordinates in screen-space in gl_FragCoord.

Are you trying to do this while drawing a full-screen quad?

Regards
elFarto

Share this post


Link to post
Share on other sites
Yes i have those coordinates but i want the light to be refracted a bit so i have calculated the directiion of the light in vertexshader and then refracted it using refract(I,N,eta) then i want it back to screen coordinates. But I just solved it, I did kind of what you said but it looked strange so i used texture2dProj() just to test what it did and it worked perfectly!

thanx, Petter

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!