Original Post
Hi, can anyone post here some shader code with explanation, how to implement slope scaled depth-bias on shadow mapping using shaders? Thanks, Filousov
Quote:
1. Dont use slope-scale depth bias.
float4 ps_renderMidpointDepthShader(VS_OUTPUT input) : COLOR{ // Get depth value of first surface and second closest surfaces to light. float z1 = tex2D(g_depthSampler, input.shadowTexCoord).r; float z2 = tex2D(g_secondDepthSampler, input.shadowTexCoord).r; const float fac = 1.5; float slopeOffset;#ifdef OPTIMIZE_MIDPOINT_DEPTH_SHADER // (10t,27a) instructions... float4 t1 = input.shadowTexCoord + g_shadowTexelAdj[0]; float4 t2 = input.shadowTexCoord + g_shadowTexelAdj[1]; float4 t3 = input.shadowTexCoord + g_shadowTexelAdj[2]; float4 t4 = input.shadowTexCoord + g_shadowTexelAdj[3]; float4 dz1; dz1.x = tex2D(g_depthSampler, t1.xy).r; dz1.y = tex2D(g_depthSampler, t1.wz).r; dz1.z = tex2D(g_depthSampler, t2.xy).r; dz1.w = tex2D(g_depthSampler, t2.wz).r; float4 slopeOffset4 = max(fac*(dz1-z1),g_zMinOffset); float4 dz2; dz2.x = tex2D(g_depthSampler, t3.xy).r; dz2.y = tex2D(g_depthSampler, t3.wz).r; dz2.z = tex2D(g_depthSampler, t4.xy).r; dz2.w = tex2D(g_depthSampler, t4.wz).r; slopeOffset4 = max(fac*(dz2-z1),slopeOffset4); float2 slopeOffset2 = max(slopeOffset4.xy, slopeOffset4.wz); slopeOffset = max(slopeOffset2.x, slopeOffset2.y);#else // (10t,44a) instructions... // Get max neighbour difference in first depth. float dz00 = tex2D(g_depthSampler, input.shadowTexCoord + float2(-g_shadowTexelWidth,-g_shadowTexelWidth)).r; float dz01 = tex2D(g_depthSampler, input.shadowTexCoord + float2(0,-g_shadowTexelWidth)).r; float dz02 = tex2D(g_depthSampler, input.shadowTexCoord + float2(g_shadowTexelWidth,-g_shadowTexelWidth)).r; float dz10 = tex2D(g_depthSampler, input.shadowTexCoord + float2(-g_shadowTexelWidth,0)).r; float dz12 = tex2D(g_depthSampler, input.shadowTexCoord + float2(g_shadowTexelWidth,0)).r; float dz20 = tex2D(g_depthSampler, input.shadowTexCoord + float2(-g_shadowTexelWidth,g_shadowTexelWidth)).r; float dz21 = tex2D(g_depthSampler, input.shadowTexCoord + float2(0,g_shadowTexelWidth)).r; float dz22 = tex2D(g_depthSampler, input.shadowTexCoord + float2(g_shadowTexelWidth,g_shadowTexelWidth)).r; slopeOffset = max(fac*(dz00-z1),g_zMinOffset); slopeOffset = max(fac*(dz01-z1),slopeOffset); slopeOffset = max(fac*(dz02-z1),slopeOffset); slopeOffset = max(fac*(dz10-z1),slopeOffset); slopeOffset = max(fac*(dz12-z1),slopeOffset); slopeOffset = max(fac*(dz20-z1),slopeOffset); slopeOffset = max(fac*(dz21-z1),slopeOffset); slopeOffset = max(fac*(dz22-z1),slopeOffset);#endif // From "Shadow mapping based on dual depth layers". float zbias = min(slopeOffset,(z2-z1)/2); return z1 + zbias;}Quote:
The problem is:
There is a lot of artifacts on the faces, which are near parallel with light direction.
Quote:
I'd also like not to spend another pass on rendering. So I prefer some method,
which will not add another rendering pass.
Quote:
I also tried normal comparison, 3x3 jitter PCF, but with no real success of getting better
appearance.
Quote:
Also when looking with camera in the direction of the light the shadows has a bad quality, which is of course expected.
But what trick, would you suggest me to use, in order to get better quality of shadows, when looking same direction as light?
Quote:
Slopescaledepthbias only affects the z value itself, not any color value you output from the shader. Therefore, it may help prevent z fighting when creating your shadow map, but not when you perform shadow testing.
Quote:
2) Rendering back faces. Yes, this I have of course tried.
While it almost entirely removes artifact from the side of car nearer to lamp.
It introduces incorrect shadowing on the side of car further from lamp.
I have taken some new screen shots in order to show you:
Quote:
www.celba.cz/car3.jpg - the car from the side nearer to lamp - I think not so bad, only problem with door-handle. (Compare with www.celba.cz/car1.jpg)
Quote:
4) I'm satisfied with TSM, but the problem is that with small focus region as I stated in post before. I think, this is something with triangle interpolation being different in depth and camera render, but don't know, how to get rid of it.
Quote:
1) To TSM triangle interpolation problem:
I solved the problem with TSM. Now it works as expected. The problem was in shaders. Once I send coords to pixel shader in 4D and secondly in 3D with w = 1.
Quote:
2) I tried to use average of first and second depth from the light and it still produces artifacts on the car. Soiled, how important is that third pass?
Quote:
3) What method do you think is best for getting better edges of shadows?
Quote:
4) Is matrix stated in NVidia Hardware shadow mapping correct way to handle pixel and texel mapping problem?
Quote:
Original post by Filousov
1) To TSM interpolation problem:
In depth shader I sent (xT/wT, yT/wT, zT/wT, 1) into pixel shader but in
second pass I sent (xT, yT, zT, wT) into pixel shader so I fixed it to (xT/wT, yT/wT, zT/wT, 1) and triangle interpolation problem disappeared.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more