prepareShadowTextures() not working

Problems building or running the engine, queries about how to use features etc.
Post Reply
yeahRIGHT
Halfling
Posts: 74
Joined: Sun Sep 07, 2008 5:09 pm

prepareShadowTextures() not working

Post by yeahRIGHT » Thu Jan 14, 2010 7:14 pm

Hi there,

I am wondering why my shadow textures stay blank (= white, 0 triangles rendered) when I call prepareShadowTextures(). I've written a custom compositor pass, inspired by the Deferred Shading Demo, but greatly simplified, I use only directional lights and they all cast shadows. But I can't get the shadows working.

This is the code:

Code: Select all

void DeferredLightRenderOperation::execute(SceneManager* scene, RenderSystem* rs) {
    Camera* const cam = mViewport->getCamera();

	const LightList& lightList = scene->_getLightsAffectingFrustum();
	for( LightList::const_iterator it = lightList.begin();  it != lightList.end();  ++it ) {
        Light* light = *it;
		if( light->getType() != Light::LT_DIRECTIONAL )
			continue;

		LightList renderedLight;
		renderedLight.push_back(light);


		// update shadow map, it is assumed that all directional lights cast shadows
		ASSERT( light->getCastShadows() );

		SceneManager::RenderContext* context = scene->_pauseRendering();
		scene->prepareShadowTextures(cam, mViewport, &renderedLight);
		scene->_resumeRendering(context);
After that code I draw the fullscreen quad, which is working (so I have a working lighting solution in my deferred renderer). But the shadow texture stays blank. I have a special material that displays the content_type shadow texture, which is white. Also, prepareShadowTextures() renders 0 triangles, when I step through it.

I am working on this for 4 days now, anyone have any idea? Thx.
0 x

andik
Gnoblar
Posts: 15
Joined: Sat May 03, 2008 12:52 pm
Location: .de

Re: prepareShadowTextures() not working

Post by andik » Tue Jan 19, 2010 10:04 am

I'm working on a similar solution for my renderer and I have exactly the same problem. The shadow map will not be filled if I call the prepareShadowTextures() method. I even tried the custom compositor pass and the shadow settings from the demo, but without success. I don't use the material generator but this should not be the problem. Everything except the shadows works fine.

Is there any special scene manager setting in the demo that I didn't get?

Any help is appreciated.
Thanks.
0 x

yeahRIGHT
Halfling
Posts: 74
Joined: Sun Sep 07, 2008 5:09 pm

Re: prepareShadowTextures() not working

Post by yeahRIGHT » Sun Jan 24, 2010 12:09 pm

I now worked around this issue by rendering the shadow map manually: setting up a material scheme for casting shadows, viewport, texture, etc.

It was tricky at times, but I eventually got it working. I still haven't succeeded with prepareTextureShadows(), so I believe I will stay with that approach.
0 x

User avatar
XenoPhoenix
Gnoblar
Posts: 14
Joined: Mon Feb 08, 2010 1:40 am

Re: prepareShadowTextures() not working

Post by XenoPhoenix » Thu Apr 08, 2010 2:49 pm

I am also having the problem, I have, like andik, implemented the deferred shading without using the material generator and everything is working fine, however my shadow maps are always full depth (white, nothing rendered).

What could cause this to happens as other than then lack of material generation mine is like the demo.

I would be really appreciative if we could get some help as this has been driving me mad for days now!
0 x

andik
Gnoblar
Posts: 15
Joined: Sat May 03, 2008 12:52 pm
Location: .de

Re: prepareShadowTextures() not working

Post by andik » Thu Apr 15, 2010 12:45 pm

This point is still open in my implementation. A manual rendering of shadows is no option for me. I will try to implement my compositor script in the deferred shading demo. Maybe it will work this way.
0 x

andik
Gnoblar
Posts: 15
Joined: Sat May 03, 2008 12:52 pm
Location: .de

Re: prepareShadowTextures() not working

Post by andik » Sat Apr 17, 2010 6:20 am

I narrowed the problem down to the shadow settings of the scene manager. If I set the shadow map texture format to PF_R8G8B8A8, the shadow map will be filled. However, a PF_FLOAT32_R texture format produces an empty shadow map. I'm clueless why this is the case, because I use exactly the same shadow settings as the deferred shading demo.

Any help is appreciated.
Thanks
0 x

User avatar
XenoPhoenix
Gnoblar
Posts: 14
Joined: Mon Feb 08, 2010 1:40 am

[SOLVED]

Post by XenoPhoenix » Mon Apr 19, 2010 9:48 am

Hey there, I think I have finally figured out what this was, Basically when I had my SceneManager set to use PF_FLOAT16_R my shadow caster looked something like this:

Code: Select all

// Shadow caster fragment program.
void ShadowCasterFP(
	const float3 iViewPos : TEXCOORD0,
	
	out float4 oColour : COLOR0,

	const uniform float cFarClipDistance
)
{
	const float depth = length( iViewPos ) / cFarClipDistance;
	oColour = float4( depth, depth, depth, 1.0);
}
For whatever reason, shadow maps are using the last parameter (1.0) as the output channel, changing that line to:

Code: Select all

oColour = float4( depth, depth, depth, depth);
Solved the problem for me.

Andik, thanks for the hint on the texture format though, this put me on the right path to solve it :)
0 x

andik
Gnoblar
Posts: 15
Joined: Sat May 03, 2008 12:52 pm
Location: .de

Re: prepareShadowTextures() not working

Post by andik » Mon Apr 19, 2010 1:45 pm

Hi,
I'm glad I could help. However, this does not solve the problem in my implementation :( Did you make further modifications, e.g. in the shadow settings?

My shadow config looks like this:

Code: Select all

mSceneMgr->setShadowTextureCasterMaterial("DeferredLighting/ShadowCaster");
mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
mSceneMgr->setShadowTextureCount(1);
mSceneMgr->setShadowTextureConfig(0,512,512,PF_FLOAT16_R);
mSceneMgr->setShadowFarDistance(1000);
thanks
0 x

User avatar
XenoPhoenix
Gnoblar
Posts: 14
Joined: Mon Feb 08, 2010 1:40 am

Re: prepareShadowTextures() not working

Post by XenoPhoenix » Mon Apr 19, 2010 6:45 pm

Ah sorry to hear that, My scene shadow settings are as follows:

Code: Select all

		viewport_->setShadowsEnabled(true);
		sceneManager_->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
		sceneManager_->setShadowTextureSelfShadow(true);
		sceneManager_->setShadowTextureCasterMaterial("DeferredShader/ShadowCaster");
		sceneManager_->setShadowCasterRenderBackFaces(false);
		sceneManager_->setShadowFarDistance(100);
		sceneManager_->setShadowTextureSize(512);
		sceneManager_->setShadowTextureCount(1);
		sceneManager_->setShadowTexturePixelFormat(PF_FLOAT16_R);
Well actually I've changed mine since this now, but that is what I had when I first got it working. Hope this helps, if you want anything else let me know.
0 x

andik
Gnoblar
Posts: 15
Joined: Sat May 03, 2008 12:52 pm
Location: .de

[Solved]

Post by andik » Wed Apr 21, 2010 7:32 am

Thanks for your help.

By adding this pass to the compositor script, I finally solved the problem!

Code: Select all

//Render the post-GBuffer render queue objects
pass render_scene
{
	//This value is synchronized with the code
	first_render_queue 80
}
However, I don't understand why it works this way. Currently, my scene does not consist of geometry that must be rendered postponed.
0 x

Post Reply