Jump to content
  • Advertisement
Sign in to follow this  

[GLSL]Sampling inside the view volume

This topic is 3798 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

This is a follow up/alternate version of an issue i posted about a few days ago, but hear me out. I am using a noise function to map a certain "attribute" to parts of my world (lets say it's a height value). As my camera moves around in my world, i want to be able to sample that function, as a post processing effect, at specific intervals (or slices) inside the camera volume, since i am trying to create a volumetric effect. That would be easy if i could sample using the clip-space coordinates of each fragment, however i need to be able to sample using "world" coordinates. Source code for my attempt so far follows. I am using a little "trick" to separate the world matrix from the view matrix, in that i am storing both the Projection and Camera matrices in the GL_PROJECTION matrix stack and saving the GL_MODELVIEW stack for world transformations. I have also loaded the Projection and Eye matrices into GL_Texture_matrix[6] and [7] respectively to have access to them individually if i need them. In my application i render a quad in screenspace like this:


And this is my vertex shader

uniform float samplingDepth;
varying vec3 worldCoordinates;

void main()

vec4 oVertex = gl_Vertex;
worldCoordinates = gl_TextureMatrixInverse[6] * gl_TextureMatrixInverse[7] *oVertex; // the vertex is in clip-space, so multiplying by the inverse of the projection and camera matrices brings it to world space

vec3 eye = gl_TextureMatrixInverse[6] * gl_TextureMatrixInverse[7] * vec4(0.0,0.0,0.0,1.0); //same thing for the camera position

vec3 lookAt = lookAt = worldCoordinates - eye;//create the eye->screen vector in world-space
worldCoordinates = worldCoordinates + lookAt * samplingDepth;//extrude along the vector

gl_Position = gl_ModelViewProjectionMatrix * oVertex;

This does not work. I am able to sample right infront of the camera correctly, but if i try to sample further inside the "volume" i get "nothing"... I also tried it in another way, throwing up quads in screen-space at various Z-values. But then the conversion to world-space wasnt correct due to the division by w that happens during the projection transformation. Any ideas?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!