Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 05 Feb 2013
Offline Last Active Apr 05 2013 06:05 AM

Posts I've Made

In Topic: G-Buffer rendered texture missing values

11 March 2013 - 10:44 AM

My guess is that you don't use floating-point textures to store the position in, so the value will be clamped to [0..1] for every component in the shader.

Try to define the texture-format in application-code with glTexImage2D( .., .., RGB_32F, .., .., .., .., GL_FLOAT, .. );


That's the trick ... I used GL_RGBA before instead of GL_RGBA32F. Thank you very much, that helped :)

In Topic: Screen space reflections: Issues

18 February 2013 - 05:55 AM

Sorry for the late response, but here your are.

I split the algorithm into two functions and remove some debugging stuff, I had there (e.g. a counter in the raytracing while loop for manually breaking the loop):

vec4 SSR()
	vec3 reflectedColor = vec3(0.0f);

	vec3 normal = normalize( texture(deferredNormalTex, vert_UV) ).xyz;

	// Depth at current fragment
	float currDepth = linearizeDepth( texture(deferredDepthTex, vert_UV).z );

	// Eye position, camera is at (0, 0, 0), we look along negative z, add near plane to correct parallax
	vec3 eyePosition = normalize( vec3(0, 0, Camera.NearPlane) );
	vec4 reflectionVector = ProjectionMatrix * reflect( vec4(-eyePosition, 0), vec4(normal, 0) ) ;

        // Call raytrace to get reflected color
	reflectedColor = raytrace(reflectionVector.xyz, currDepth);	

	return vec4(reflectedColor, 1.0f);
 * Raytracing to get reflected color
vec3 raytrace(in vec3 reflectionVector, in float startDepth)
	vec3 color = vec3(0.0f);
	float stepSize = rayStepSize; 

	float size = length(reflectionVector.xy);
	reflectionVector = normalize(reflectionVector/size);
	reflectionVector = reflectionVector * stepSize;
        // Current sampling position is at current fragment
	vec2 sampledPosition = vert_UV;
        // Current depth at current fragment
	float currentDepth = startDepth;
        // The sampled depth at the current sampling position
	float sampledDepth = linearizeDepth( texture(deferredDepthTex, sampledPosition).z );

        // Raytrace as long as in texture space of depth buffer (between 0 and 1)
	while(sampledPosition.x <= 1.0 && sampledPosition.x >= 0.0 &&
	      sampledPosition.y <= 1.0 && sampledPosition.y >= 0.0)
                // Update sampling position by adding reflection vector's xy and y components
		sampledPosition = sampledPosition + reflectionVector.xy;
                // Updating depth values
		currentDepth = currentDepth + reflectionVector.z * startDepth;
		float sampledDepth = linearizeDepth( texture(deferredDepthTex, sampledPosition).z );
                // If current depth is greater than sampled depth of depth buffer, intersection is found
		if(currentDepth > sampledDepth)
                        // Delta is for stop the raytracing after the first intersection is found
                        // Not using delta will create "repeating artifacts"
			float delta = (currentDepth - sampledDepth);
			if(delta < 0.003f )
				color = texture(deferredDiffuseTex, sampledPosition).rgb;

	return color;


If you have some questions or comments, give it to me :). I'd like to get more into that whole screen space stuff and understand it more.


In Topic: Screen space reflections: Issues

07 February 2013 - 08:48 PM

Okay, I got it working smile.png , had' some space conversion problems. And adding the camera's near-plane value to the view vector helped very much:




In Topic: Screen space reflections: Issues

07 February 2013 - 02:45 PM

I recently changed my code. I now calculate the reflected ray in the fragment shader of the g-Buffer using:


vec4 ReflectVec = normalize( reflect(vert_EyePosition, Normal) );


Where vert_EyePosition is the negative vertex position, which is multiplied with the model-view-matrix before in the vertex shader and

Normal is the interpolated normal from the vertex shader.

My resulting image of the reflected vector looks like this:




But acctually my tracing doesn't work now, so obviously my reflection vector wasn't correct before. Now I just have to get the tracing right...