XEffects - Reloaded - New Release (V 1.4)
What do you see if you draw2DImage the depthMap?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Here's the code I use in the loop:
And here's the output:
I made sure the shader wasn't outputing those values. It outputs vec4( 0.0, 1.0, 0.0, 1.0 ).
So as you can see, apparently the depth texture is the same as the backbuffer or something like that. Or I am doing something wrong.
Code: Select all
effect->update();
videoDriver->draw2DImage( effect->getDepthMapTexture(), position2di( 0,0 ) );
I made sure the shader wasn't outputing those values. It outputs vec4( 0.0, 1.0, 0.0, 1.0 ).
So as you can see, apparently the depth texture is the same as the backbuffer or something like that. Or I am doing something wrong.
TheQuestion = 2B || !2B
Well BlindSide, after our talk in IRC, I decided to have a look for myself through the code. Here's the image first, of the working implementation:
I have a vague explanation for the reason this was messing up, but nothing clear. To fix the code, you just swap the section that renders the depth buffer above the section that renders the post processing routines:
In the old code, the depth buffer was the last thing rendered. Thus it was a frame behind the actual framebuffer.
Given that it's the last render target enabled, the only reasoning I can possibly find is that beginScene() must annihilate the depth buffer, thus making it unusable for the post processing routines, because it used to go:
There must be another explanation, because that certainly doesn't explain why the draw2DImage for the depth buffer doesn't work. The only reason I can think for that is because the depth buffer is still bound from setRenderTarget, and trying to use it with draw2DImage isn't possible.
Oh well, it works, and that's the only explanations I could think of.
I have a vague explanation for the reason this was messing up, but nothing clear. To fix the code, you just swap the section that renders the depth buffer above the section that renders the post processing routines:
Code: Select all
if(DepthPass)
{
driver->setRenderTarget(DepthRTT, true, true, SColor(0xffffffff));
// Set max distance constant for depth shader.
depthMC->FarLink = smgr->getActiveCamera()->getFarValue();
for(u32 i = 0;i < DepthPassArray.size();++i)
{
BufferMaterialList.set_used(0);
for(u32 g = 0;g < DepthPassArray[i]->getMaterialCount();++g)
BufferMaterialList.push_back(DepthPassArray[i]->getMaterial(g).MaterialType);
DepthPassArray[i]->setMaterialType((E_MATERIAL_TYPE)Depth);
DepthPassArray[i]->OnAnimate(device->getTimer()->getTime());
DepthPassArray[i]->render();
for(u32 g = 0;g < DepthPassArray[i]->getMaterialCount();++g)
DepthPassArray[i]->getMaterial(g).MaterialType = (E_MATERIAL_TYPE)BufferMaterialList[g];
}
}
if(PostProcessingRoutinesSize)
{
bool Alter = 0;
ScreenQuad.getMaterial().setTexture(1, ScreenRTT);
ScreenQuad.getMaterial().setTexture(2, DepthRTT);
for(u32 i = 0;i < PostProcessingRoutinesSize;++i)
{
ScreenQuad.getMaterial().MaterialType = (E_MATERIAL_TYPE)PostProcessingRoutines[i];
Alter = !Alter;
ScreenQuad.getMaterial().setTexture(0, i == 0 ? ScreenRTT : ScreenQuad.rt[int(!Alter)]);
driver->setRenderTarget(i >= PostProcessingRoutinesSize - 1 ?
outputTarget : ScreenQuad.rt[int(Alter)], true, true, ClearColour);
ScreenQuad.render(driver);
}
}
Given that it's the last render target enabled, the only reasoning I can possibly find is that beginScene() must annihilate the depth buffer, thus making it unusable for the post processing routines, because it used to go:
Code: Select all
beginScene
|
postProcess
|
renderDepth
Oh well, it works, and that's the only explanations I could think of.
TheQuestion = 2B || !2B
Thanks Halifax, that may have taken me a while to track down. I'll try and look more closely at the cause of this.
Cheers, I hope the depth buffer is useful.
Cheers, I hope the depth buffer is useful.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
You have to apply the changes that I spoke of about 3 posts above you or so. If you don't have the time or the know-how, then you could just wait for BlindSide to put it into the main build. To get it working now, replace your two files with these:Nate_D wrote:okay so I am trying to output the depth map texture.
I have enabled the depth pass and added the room node to the depth pass using these lines of code...
effect->enableDepthPass(true);
effect->addNodeToDepthPass(room);
and then in the runloop I am trying to get the depth map texture and set it as the texture for a cube just to see if it works...
irr::video::ITexture* test = effect->getDepthMapTexture();
cube_node->setMaterialTexture(0, test)
so far the cube is completely black, if I don't enable the depthpass however it is completely white. Am I doing this completely the wrong way?
effectWrapper.h (13.5 KB)
effectWrapper.cpp (17.6 KB)
The code you posted above should work fine. Mind you, the depth map texture is encoded in the red and green channels, so you are going to get a crazy looking texture. So the best thing to do would be to output it in a texture by using a fragment shader with the following(OpenGL):
Code: Select all
gl_FragColor = texture2D( DepthMapSampler, gl_TexCoord[0].st );
By the way, BlindSide, addPostProcessingEffectFromFile doesn't return the material identification number. It's an easy fix, but I just wanted to tell you, because without that you can't use removePostProcessingEffect because it requires an identification number.
TheQuestion = 2B || !2B
Ok sorry for the trouble I fixed this.
It turned out I wasn't setting the render target back to 0 after the depth pass, that's why you HAD to have a post processing pass after it to set the rendertarget to something else. Nate Dog's example didn't work because although he swapped the two sections around he didn't actually have a post processing effect applied.
Anyway this means theres no reason to swap the two sections around anymore (Although I'm not sure why I put the depth pass after the post processing path, you may want to experiment and see which arrangement keeps animations up to date, probably Halifax way is better anyway).
Here is the fixed file: http://irrlichtirc.g0dsoft.com/paste/345
(If you find it difficult to copy goto the bottom and there is a text box with the plain text version.)
Cheers
It turned out I wasn't setting the render target back to 0 after the depth pass, that's why you HAD to have a post processing pass after it to set the rendertarget to something else. Nate Dog's example didn't work because although he swapped the two sections around he didn't actually have a post processing effect applied.
Anyway this means theres no reason to swap the two sections around anymore (Although I'm not sure why I put the depth pass after the post processing path, you may want to experiment and see which arrangement keeps animations up to date, probably Halifax way is better anyway).
Here is the fixed file: http://irrlichtirc.g0dsoft.com/paste/345
(If you find it difficult to copy goto the bottom and there is a text box with the plain text version.)
Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Could you upload it somewhere else too? That site's always down for me when I need it most.BlindSide wrote: Here is the fixed file: http://irrlichtirc.g0dsoft.com/paste/345
(If you find it difficult to copy goto the bottom and there is a text box with the plain text version.)
Cheers
Hello,
first - Thank you for this great code. It`s very usefull.
But I have a problem. When I try to compile my application, I get this error:
I have following files in my project (using C++ .net 2005):
CScreenQuad.h
CShaderPre.cpp
CShaderPre.h
effectWrapper.cpp
effectWrapper.h
effectWrapperCB.h
main.cpp
Is there any other file which needs to be included or linked to the project?
Thanks again.
first - Thank you for this great code. It`s very usefull.
But I have a problem. When I try to compile my application, I get this error:
Code: Select all
error LNK2019: unresolved external symbol "public: void __thiscall effectHandler::addPostProcessingEffectFromFile(class irr::core::string<char,class irr::core::irrAllocator<char> > const &)" (?addPostProcessingEffectFromFile@effectHandler@@QAEXABV?$string@DV?$irrAllocator@D@core@irr@@@core@irr@@@Z) referenced in function _main
CScreenQuad.h
CShaderPre.cpp
CShaderPre.h
effectWrapper.cpp
effectWrapper.h
effectWrapperCB.h
main.cpp
Is there any other file which needs to be included or linked to the project?
Thanks again.