
Thanks for the great work!
Code: Select all
CompositorManager &compMan = CompositorManager::getSingleton();
MaterialManager::getSingleton().addListener(new GBufferSchemeHandler, "GBuffer");
MaterialManager::getSingleton().addListener(new NullSchemeHandler, "NoGBuffer");
compMan.registerCustomCompositionPass("DeferredLight", new DeferredLightCompositionPass);
CompositorInstance* DSInstance;
DSInstance = compMan.addCompositor(myVp, "DeferredShading/GBuffer");
DSInstance->setEnabled(true);
DSInstance = compMan.addCompositor(myVp, "DeferredShading/ShowLit");
DSInstance->setEnabled(true);
It works very well. I rise the spotlights number up to 20, and I obtain 40/35 FPS (with/without SSAO) on my laptop (2.53GHz Intel Core 2 Duo, nVidia GeForce 9600M GT 512MB) using D3D. Here it is a couple of screenshots.Noman wrote: First of all, just to make sure - the deferred shading demo works correctly on your system (to rule out hardware issues etc) ?
Code: Select all
//[geom_ps shader in diffuse.cg, original ssao code by nullsquared]:
//float4 OUT.c contains this values: (linear depth value, normal.x, normal.y, normal.z)
//instead of this..
//OUT.c = float4(length(vp.xyz) / far, normalize(vn.xyz).xyz);
//..I use this
float COEF = 0.1;
OUT.c = float4(length(vp.xyz) * COEF / far, normalize(vn.xyz).xyz);
Code: Select all
//change this..
#ifdef WRITE_LINEAR_DEPTH
ss << " oColor1.a = length(iViewPos) / cFarDistance;" << std::endl;
//..into this
#ifdef WRITE_LINEAR_DEPTH
ss << " oColor1.a = length(iViewPos) * 0.1 / cFarDistance;" << std::endl;
Code: Select all
//[ssao_ps shader in ssao.cg, deferred ssao code]
//I try to change this..
float depth = geom.w * COEF;
//..into this
#define COEF 0.1
float depth = geom.w * COEF;
Yes, your work is excellent: I'm currently using up to 25 spotlight with shadows in my project, and I still obtain 20 FPS..Noman wrote: Good to hear that you're understanding the workings of the framework and making progress! The screenshot from the modified demo is actually quite impressive! We would need ~20 shadow textures at the same time to get the same result without deferred shading. Cool stuff!
I'm using 1 unit = 1 meter scale in my scene, and SSAO works indeed quite well. The problem is that since my scene use one only texture, I need to rise up SSAO strenght output to better highlight scene geometry. But if I do that, circle artifacts become visible. With the trick I explained in the previous post for depth value writing, I could decrease that kind of artifacts. But if it is not possible.. then I'll use SSAO in his original state.Noman wrote: All in all, the SSAO works well when the scale system is 1 unit = 1 meter. I don't know why they are not having the same effect on your SSAO results... You can debug the SSAO compositor by commenting out the "input 0 scene" line in the SSAO compositor in the target_output pass, and then enabling SSAO will give you the SSAO buffer. Can you post screenshots of it and maybe that will help us debug the problem?
Code: Select all
float checkShadow_PCF(
float2 offset //added: it is inverse_texture_size.xy
sampler2D shadowMap,
float3 viewPos,
float4x4 invView,
float4x4 shadowViewProj,
float shadowFarClip,
#if LIGHT_TYPE == LIGHT_DIRECTIONAL
float3 shadowCamPos
#else
float distanceFromLight
#endif
)
{
float3 worldPos = mul(invView, float4(viewPos, 1)).xyz;
#if LIGHT_TYPE == LIGHT_DIRECTIONAL
float distanceFromLight = length(shadowCamPos-worldPos);
#endif
float4 shadowProjPos = mul(shadowViewProj, float4(worldPos,1));
shadowProjPos /= shadowProjPos.w;
float2 shadowSampleTexCoord = shadowProjPos.xy;
float2 uv = shadowSampleTexCoord.xy;
float3 o = float3(offset, -offset.x) * 0.3f;
// Note: We using 2x2 PCF. Good enough and is alot faster.
float c = (distanceFromLight <= tex2D(shadowMap, uv.xy - o.xy).r) ? 1 : 0; // top left
c += (distanceFromLight <= tex2D(shadowMap, uv.xy + o.xy).r) ? 1 : 0; // bottom right
c += (distanceFromLight <= tex2D(shadowMap, uv.xy + o.zy).r) ? 1 : 0; // bottom left
c += (distanceFromLight <= tex2D(shadowMap, uv.xy - o.zy).r) ? 1 : 0; // top right
return c / 4;
}
Now we can continue our step-by-step road to the pixel shaderNoman wrote: the pixels marked by A do get passed to the pixel shader, but the calculations there lead to having no effect. This code is at the end of the function :
Code: Select all
#if LIGHT_TYPE == LIGHT_SPOT float spotlightAngle = saturate(dot(lightDir.xyz, -objToLightDir)); float spotFalloff = saturate((spotlightAngle - spotParams.x) / (spotParams.y - spotParams.x)); total_light_contrib *= (1-spotFalloff); #endif
In the case of a pixel being outside the spotlight's range, spotFalloff will be 1, causing total_light_contrib to be zeroed out. Since we are doing additive lighting, this means that the colour will not change.