Sign in to follow this  

world position to pixel

This topic is 3668 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
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

This topic is 3668 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this