Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualWilhelm van Huyssteen

Posted 09 January 2013 - 02:12 PM

Thanks for the reply thats what I needed.

#2Wilhelm van Huyssteen

Posted 09 January 2013 - 02:11 PM

Thanks for the reply thats what I needed.

#1Wilhelm van Huyssteen

Posted 09 January 2013 - 10:05 AM

Thanks for the reply thats what I needed.

 

I have now written the following two shaders that I want to use to "backup" and "restore" the depth buffer but it doesnt seem to work yet. Please take a look.

 

copy_depth_to vertex shader



uniform mat4 completeMatrix;
attribute vec3 a_position;
		
void main()
{
  gl_Position = completeMatrix * vec4(a_position,1.0);
}

 

 

copy_depth_to fragment shader

	vec3 unpackColor(float f) {
	    vec3 color;
	    color.b = floor(f / 256.0 / 256.0);
	    color.g = floor((f - color.b * 256.0 * 256.0) / 256.0);
	    color.r = floor(f - color.b * 256.0 * 256.0 - color.g * 256.0);
	    return color / 256.0;
	}


	void main (void)
	{
		gl_FragColor = vec4(unpackColor(gl_FragCoord.z),1.0);
	}

 

 

copy_depth_from vertex shader

 

uniform mat4 completeMatrix;
varying vec2 textcoord0;

attribute vec2 a_textureCoord0;
attribute vec3 a_position;
		
void main()
{
  textcoord0 = a_textureCoord0;
  gl_Position = completeMatrix * vec4(a_position,1.0);
}

 

 

copy_depth_from fragment shader

 

uniform sampler2D tex;
varying vec2 textcoord0;

	float depth()
	{
	                  vec4 color = texture2D(tex,textcoord0.st);
	                  float r = (color.r + color.g * 256.0 + color.b * 256.0 * 256.0)/1.0;
	   
	                  return r *256.0;
	}



		void main (void)
		{
			gl_FragDepth = depth();
		}

PARTNERS