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

## 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 on other sites
check correct syntax

glColor = gl_Vertex.xyz;

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 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 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 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...

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007628
• ### Who's Online (See full list)

There are no registered users currently online

×