Jump to content

Recommended Posts

Posted

Is there a texture/buffer which stores the height-data of the scene, or is there any other way of getting the y-position of a pixel in the PostProcess shader?

or is it possible to get all the coords (x/y/z) of a specific point?

Posted

this is how to calculate the pixel position in world coords:

 

//needed uniforms in eg postfilter.frag
uniform vec3 cameraposition;
uniform mat4 cameramatrix;

vec3 screencoord;
vec4 fogcoord;

screencoord = vec3(((gl_FragCoord.x/buffersize.x)-0.5) * 2.0,((-gl_FragCoord.y/buffersize.y)+0.5) * 2.0 / (buffersize.x/buffersize.y),DepthToZPosition( depth ));
screencoord.x *= screencoord.z;
screencoord.y *= -screencoord.z;

vec4 worldpos = vec4(screencoord,1.0) * cameramatrix;

worldpos += vec4(cameraposition,0.0);

 

Needed Shader variables to be set

SetShaderVec3(postfilter,"cameraposition",camera.position);
SetShaderMat4(postfilter , "cameramatrix" , GetEntityMatrix(Camera).Inverse() ) ;

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

Thanks a lot!

works fine!

btw there are built in uniforms as "cameraposition" and "camerainversemat4" where i dont even have to parse the variables to the shader ;)

Posted

yeah, I wasn't sure in which version I have implemented it and so i have added these parameters as i haven't looked if they are provided by the engine.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...