Albert85

01-09-2015, 09:02 AM

Hello everybody

this is what I would like to do:

starting from 3D points in world coordinates, using the geometry shader I would like to:

1) move each point for example 5 pixels on the left

2) reconvert each point in world coordinates

3) extract the points using the trasformfeedbackbuffer

I have a problem with the reconversion of the points (from screen coordinates to world coordinates). Although I don't move the points (step (1)) their position is not the same.

This is the geometry shader:

#version 330 compatibility

#extension GL_ARB_geometry_shader4: enable

#define MAX_VERTICES 2

layout(points) in;

layout(points) out;

in vec3 my_Position[]; // Position

out vec3 movedPosition; // Position

vec3 fromWorldCoordsToScreenCoords(in vec3 wc)

{

vec4 pos0 = gl_ModelViewProjectionMatrix * vec4(wc, 1.0);

pos0 /= pos0.w;

return pos0.xyz;

}

vec3 fromScreenCoordsToWorldCoords(in vec3 sc)

{

vec4 wc = gl_ModelViewProjectionMatrixInverse * vec4(sc,1.0) ;

wc /= wc.w;

return (wc.xyz);

}

void main(void)

{

vec3 inputPos_ScreenCoord = fromWorldCoordsToScreenCoords(my_Position[0]);

vec3 movedPosition = fromScreenCoordsToWorldCoords(inputPos_ScreenCoord );

gl_Position = vec4(movedPosition,1.0);

gl_PointSize = 5;

EmitVertex();

// my_Position[0] is slightly different from gl_Position!!! WHY??

}

Can you help me?

Thanks!

this is what I would like to do:

starting from 3D points in world coordinates, using the geometry shader I would like to:

1) move each point for example 5 pixels on the left

2) reconvert each point in world coordinates

3) extract the points using the trasformfeedbackbuffer

I have a problem with the reconversion of the points (from screen coordinates to world coordinates). Although I don't move the points (step (1)) their position is not the same.

This is the geometry shader:

#version 330 compatibility

#extension GL_ARB_geometry_shader4: enable

#define MAX_VERTICES 2

layout(points) in;

layout(points) out;

in vec3 my_Position[]; // Position

out vec3 movedPosition; // Position

vec3 fromWorldCoordsToScreenCoords(in vec3 wc)

{

vec4 pos0 = gl_ModelViewProjectionMatrix * vec4(wc, 1.0);

pos0 /= pos0.w;

return pos0.xyz;

}

vec3 fromScreenCoordsToWorldCoords(in vec3 sc)

{

vec4 wc = gl_ModelViewProjectionMatrixInverse * vec4(sc,1.0) ;

wc /= wc.w;

return (wc.xyz);

}

void main(void)

{

vec3 inputPos_ScreenCoord = fromWorldCoordsToScreenCoords(my_Position[0]);

vec3 movedPosition = fromScreenCoordsToWorldCoords(inputPos_ScreenCoord );

gl_Position = vec4(movedPosition,1.0);

gl_PointSize = 5;

EmitVertex();

// my_Position[0] is slightly different from gl_Position!!! WHY??

}

Can you help me?

Thanks!