Reusing the depth buffer across render targets
Reusing the depth buffer across render targets
Hi, how can you force Irrlicht/OpenGL to reuse the same zbuffer for all your rendering, be it the screen or texture(s)? It seems like certain gpu drivers reuse these by default whereas others have different zbuffers at least for the frame buffer and MRTs.
Thanks
Thanks
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
I thought Irrlicht always used the same depth buffer. Isn't this what Nadro is working on at the moment (setting the depth buffer). I'm guessing that you are clearing the depth buffer yourself when you set a render target.
Re: Reusing the depth buffer across render targets
If you check the code, you see the main window's Z buffer is different from the MRT Z buffers. It cannot be easily shared either. The Z buffer of a MRT is shared with other MRTs that have matching resolution (and in my fork, matching stencil).
Re: Reusing the depth buffer across render targets
Unfortunate - talking about deferred rendering here, I suppose that I will have to render the transparent objects into the MRTs as well then... make sure *not* to render into the depth texture this time if I want to read it in the shader for soft particles. Does this make sense? The plus side is that now I'd get lighting for the transparent materials as well... neat
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
@ent1ty
Plase wait a few more days, I'll send big commit related for these things.
Plase wait a few more days, I'll send big commit related for these things.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Reusing the depth buffer across render targets
That's awesome, thanks - I'll wait
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
Patch is already merged with trunk. If you will notice any bug please report it.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Reusing the depth buffer across render targets
Can I do something like this:
I.e. reuse the depth buffer between the MRTs and the screen? I'm only getting black screen, not sure if I'm supposed to be messing with the depth buffer this much I added some getters inside IRenderTarget.h, as you could notice:
Maybe exposing the depth buffer is a bad idea (is it?), but at least the textures should be fine I think.
Another thing - before, you could reset the render target to the screen by calling setRenderTarget(video::ERT_FRAME_BUFFER) but with the current API this isn't possible anymore - is setting the render target to 0 the same thing? The docs seems to suggest that it, in fact, sets the target to the previously used target - so if you're rendering into 2 sets of MRTs, it wouldn't be possible for you to render onto the screen anymore
Code: Select all
video::IRenderTarget *RT = Device->getVideoDriver()->addRenderTarget();
RT->setTexture(0, MRTRenderTarget->getDepthStencil());
Code: Select all
core::array<ITexture*> getTextures() const
{
return Texture;
}
ITexture* getDepthStencil() const
{
return DepthStencil;
}
Another thing - before, you could reset the render target to the screen by calling setRenderTarget(video::ERT_FRAME_BUFFER) but with the current API this isn't possible anymore - is setting the render target to 0 the same thing? The docs seems to suggest that it, in fact, sets the target to the previously used target - so if you're rendering into 2 sets of MRTs, it wouldn't be possible for you to render onto the screen anymore
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
No, you cannot reuse the window's buffer with any RTT. It's special.
Re: Reusing the depth buffer across render targets
setRenderTarget with null pointer will allow you to render on screen again, however D3D9 may have a bug related to this case. I'll check that.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Reusing the depth buffer across render targets
Thanks, but I can't get the MRTs working. Here's how I set the render target:
But I only get output in the first MRT. Any clue what could be wrong? I tried to use the layout syntax (layout(location = 0) out vec3 OutColor; ...) in the fragment shader but this is only supported since OpenGL 3.0. Here's the whole shader:
Code: Select all
core::array<u32> texIndices;
texIndices.push_back(0);
texIndices.push_back(1);
Device->getVideoDriver()->setRenderTarget(RenderTarget, texIndices,
false, true, false,
video::SColor(0, 0, 0, 0));
Code: Select all
varying vec3 Normal;
uniform float Lighting;
uniform sampler2D Tex0;
void main()
{
vec3 vNormal= normalize(Normal);
vNormal*= 0.5;
vNormal+= 0.5;
gl_FragData[0] = texture2D(Tex0, gl_TexCoord[0].xy);
// set normal to 0 for objects that should not receive lighting
gl_FragData[1] = vec4(vNormal * Lighting, 0.0);
}
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
Can you post a full code of IRenderTarget creation process?
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Reusing the depth buffer across render targets
Here goes:
Code: Select all
irr::core::array<irr::video::ITexture*> MRTs;
// [...]
video::IVideoDriver *video = Device->getVideoDriver();
createMRT("deferred-mrt-color", video::ECF_A8R8G8B8);
createMRT("deferred-mrt-normal", video::ECF_A8R8G8B8);
DepthBuffer = video->addRenderTargetTexture(video->getCurrentRenderTargetSize(),
"deferred-depth",
depth);
RenderTarget = video->addRenderTarget();
RenderTarget->setTexture(MRTs, DepthBuffer);
// where createMRT:
void video::CRenderer::createMRT(const c8* name, video::ECOLOR_FORMAT format)
{
if(MRTs.size() <= 4)
{
dimension= Device->getVideoDriver()->getCurrentRenderTargetSize();
MRTs.push_back(Device->getVideoDriver()->addRenderTargetTexture(dimension, name, format));
}
}
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Re: Reusing the depth buffer across render targets
There is a bug in Irrlicht. I should fix it tomorrow.
UPDATE:
Sorry, I'll not have an access to my dev PC for few upcoming days, so I will not be able to fix it until next week. I'll send fix immediately after back to home.
UPDATE:
Sorry, I'll not have an access to my dev PC for few upcoming days, so I will not be able to fix it until next week. I'll send fix immediately after back to home.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Reusing the depth buffer across render targets
Please check the latest revision.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes