PDA

View Full Version : FBO texture as color rendering target & pass it as as texture input into depth shader



olivieryuyu
12-26-2014, 02:41 PM
Hello :)

I would like to create a texture with one 16bit integer component, attach it to FBO as color rendering target and pass it as texture input into depth shader.

I am aware that it is Sampling and Rendering to the Same Texture is not possible.

Any hints to solved this in the best way?

Thanks a lot

Alfonse Reinheart
12-26-2014, 03:57 PM
I would like to create a texture with one 16bit integer component, attach it to FBO as color rendering target and pass it as texture input into depth shader.

You can't do that directly; you cannot alias color and depth format textures with each other (https://www.opengl.org/wiki/Texture_Storage#View_texture_aliases). You also cannot copy the texel values between color and depth formats (https://www.opengl.org/wiki/Texture_Storage#Texture_copy).


I am aware that it is Sampling and Rendering to the Same Texture is not possible.

That's not the problem. You can read from and render to the same texture. Just not at the same time. And even then, you can render to and read from different parts of it if you have GL 4.5/ARB/NV_texture_barrier. The problem is your desire to treat a color texture as a depth texture.

The only reason I can come up with as to why you need this to be a depth value (besides actually using this for some kind of depth buffering operation in addition to the texture read) is if you're trying to take advantage of shadow samplers (https://www.opengl.org/wiki/Sampler_%28GLSL%29#Shadow_samplers) and depth comparison sampling modes (https://www.opengl.org/wiki/Sampler_Object#Comparison_mode). If that's true, here are your options, from best to worst:

1: Use purely integer textures, then use texture gather functions (https://www.opengl.org/wiki/Sampler_%28GLSL%29#Texture_gather_accesses) and do the shadow comparisons and PCF computations yourself in the shader. If you don't have access to texture gather functions, you'll have to use texelFetch and so forth.

2: Use PBOs (https://www.opengl.org/wiki/Pixel_Buffer_Object) or some similar operation to copy from your integer texture to the depth texture.