Jump to content
  • Advertisement
Sign in to follow this  
ThomasM

Unprojecting with Fragment Shader

This topic is 4797 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 want to unproject the pixels rendered with the use of a fragment shader to reconstruct the points in 3D and return them by the fragment color (r = x, g = y, b = z). Thus reconstructing the world coordinates from the screen coordinates with the use of the fragment shader. I thought it would work with the following (GLSL Shader language used):
vec4 P2d = gl_FragCoord;
P2d.w = 1 / P2d.w;
gl_FragColor = vec4(gl_ModelViewMatrixInverse * P2d);

But that doesn't work correct at all... The computed values are totally weird. Any idea?

Share this post


Link to post
Share on other sites
Advertisement
check correct syntax

--vertex shader --
glColor = gl_Vertex.xyz;

-- fragment_shader --
gl_FragColor = glColor

u might wanna use gl_FragColor = glColor * (inv scenescale) eg 0.01 or something else its only really gonna work with vertices between 0->1

Share this post


Link to post
Share on other sites
I've read the GLSL specification and it says .xyz can be equally used like .rgb.

My values are not only between 0 and 1 because I use the framebuffer_object extension with a renderbuffer of type GL_RGB32F_ARB.

So that should be no problem...

Share this post


Link to post
Share on other sites
Quote:
I've read the GLSL specification and it says .xyz can be equally used like .rgb.

yeah i mostly just use xyzw for everything even colors/texturecoords

Quote:
My values are not only between 0 and 1 because I use the framebuffer_object extension with a renderbuffer of type GL_RGB32F_ARB.
So that should be no problem...

that doesnt help, i was talking about
glColor = gl_Vertex.xyz; (which btw doesnt have to be color it could be some other varying eg varying vec3 ws_vert = gl_Vertex.xyz;
say u have a pixel at (100,50,10) now if u draw the color (100,50,10) its gonna be white no matter what u do.
if u first scale the values by a hundrenth (100,50,10)*0.01 then u get (1,0.5,0.1) some orange color

Share this post


Link to post
Share on other sites
Okay, I think I now understand you, but I don't want to display the returned color (which in fact is the coordinate in 3D / world coordinate). I want to use it for a vertex buffer object to draw objects with these world coordinates.

So it doesn't matter that the values aren't between 0 and 1, quite the contrary. The values should be the right world coordinates, which normally are NOT between 0 and 1.
Anyway, they are not correct either...

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!