Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Deferred Rendering: Normal+Depth texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 xantier   Members   -  Reputation: 168

Like
0Likes
Like

Posted 20 July 2014 - 11:03 PM

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);


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31920

Like
0Likes
Like

Posted 20 July 2014 - 11:11 PM

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.



#3 xantier   Members   -  Reputation: 168

Like
0Likes
Like

Posted 20 July 2014 - 11:14 PM

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 ?



#4 Ashaman73   Crossbones+   -  Reputation: 8001

Like
0Likes
Like

Posted 20 July 2014 - 11:57 PM


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS