Deferred Rendering: Normal+Depth texture

Started by
2 comments, last by Ashaman73 9 years, 9 months ago

Hello, Is it wise to keep normals+depth (x,y,z,depth) in a texture or does depth require much more precision that requires more than one component?

This is the way normal+depth texture is stored:


	glBindTexture(GL_TEXTURE_2D, textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH, GL_TEXTURE_2D, textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH], 0);

And this is my depth attachment:


	glGenRenderbuffers(1, &depthTexture);
	glBindRenderbuffer(GL_RENDERBUFFER, depthTexture);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthTexture);
Advertisement

You can store normals in 24-32 bits total (for the x+y+z values) with decent quality. You can store depth in about 16-32 bits (or you can just use the existing depth attachment).

So, GL_RGBA32F will work, but it means that you're using 96 bits to store your normals, which is unnecessarily large.

I am storing the depth to recreate position from texture coords, camera and depth. So depth attachment and storing depth in a float are totally independent? The precision is determined by the format of the attachment, right?

What do you recommend instead of GL_RGBA32F ?


What do you recommend instead of GL_RGBA32F ?

I use 16f RGBA to store depth (encoding in two channels ) and normal ( encoded and compressed in two channels).

For depth encoding/decoding use


encoding
float scaled_depth = depth*1024;
vec2 result = vec2(floor(scaled_depth),fract(scaled_depth));

decoding:
float result = dot(encoded_depth,vec2(1/1024,1));


For normal compression (xyz encoding in just two channels) take a look here.

This topic is closed to new replies.

Advertisement