opengl - GLSL compute world coordinate from eye depth and screen position -



opengl - GLSL compute world coordinate from eye depth and screen position -

i'm trying recover world position of point knowing it's depth in eye space, computed follow (in vertex shader) :

float depth = - umodelview * vec4( inpos , 1.0 ) ;

where inpos point in world space (obviously, don't want recover particular point, point depth expressed in format).

and it's normalized screen position (between 0 , 1), computed follow (in fragment shader ) :

vec2 screen_pos = ( vec2( gl_fragcoord.xy ) - vec2( 0.5 ) ) / uscreensize.xy ;

i can access next info :

uscreensize : it's name suggest, it's screen width , height ucamerapos : photographic camera position in world space

and standard matrices :

umodelview : model view photographic camera matrix umodelviewproj : model view projection matrix uprojmatrix : projection matrix

how can compute position (x,y,z) of point in world space ? (not in eye space)

i can't have access other (i can't utilize near, far, left, right, ...) because projection matrix not restricted perspective or orthogonal.

thanks in advance.

i question right, have x , y window space (and converted normalized device space [-1,1]), z in eye space, , want recosntruct world space position.

i can't have access other (i can't utilize near, far, left, right, ...) because projection matrix not restricted perspective or orthogonal.

well, actually, there not much besides orthogonal or projective mapping can achieved matrix multiplication in homogenous space. however, projection matrix sufficient, long invertible (in theory, projection matrix transform points plane, line or single point. in case, info lost , never able reconstruct original data. untypical case).

so can projection matrix , 2d position ray in eye space. , can intersect z=depth plane point back.

so have calculate 2 points

vec4 p = inverse(uprojmatrix) * vec4 (ndc_x, ndc_y, -1, 1); vec4 q = inverse(uprojmatrix) * vec4 (ndc_x, ndc_y, 1, 1);

which mark 2 points on ray in eye space. not forget split p , q respective w component 3d coordinates. now, need intersect z=depth plane , eye space x , y. finally, can utilize inverse of umodelview matrix project point object space.

however, said want world space. impossible. need view matrix that, have not listed given. have compisition of model , view matrix, , need know @ to the lowest degree 1 of these reconstruct world space position. cameraposition not enoguh. need orientation.

opengl glsl

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -