Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Deferred Rendering: Normal+Depth texture

4: Adsense

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   

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


#2 Hodgman   Moderators   

50632
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   

210
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   Members   

13714
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.


Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log





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.