No replies to this topic

### #1XVincentX

Valued Member

• Members
• 115 posts

Posted 23 June 2009 - 02:46 PM

Hello!
I have got a scene completely drawn using GBuffers and it's ok, and now it's time to apply shadows.
At first i made the usual ZOnly pass and set it as a texture.

http://img44.imagesh...48/porcesco.jpg

This is a projection of light on the scene, and it is not good, but really (i'm working too much) i do not remember what's going wrong.

I tryed to fill the shadowmap from FillGBufferShader, but it's impossible becouse it was required to output different projected position (GeometryShader and Texture2DArray) and different colors(Multiple Render Target) ,but D3D10 supports one of this for Draw call.

So at first i fill GBuffers (all ok), and after i draw using a ZOnly pass.
This pass is performed in D3D10 using a Texture2D with R32_TYPELESS and bound in 2 pipeline objects (Shader Resource View and DepthStencilView) using D3D10 casts to R32_FLOAT and D32_FLOAT.

So there is no render target bound in ZOnly pass, as this code says.




SRenderTarget is a NULL array.
The Shadow Map has got SAME backbuffer's size, so there is no projection to change.
Now that i have got ShadowMap and ALSO GBuffers, i have to perform rendering on FrameBuffer.

Current code is this:

float4 ps_draw(in float4 Pos:SV_POSITION, in float2 Tex:TEXCOORD)	:	SV_TARGET

{

float4 TexC = BaseColor.Sample(SamplText,Tex);

float3 Norm = 2.0f * Normal.Sample(SamplText,Tex).xyz - 1.0f;

float NdotL = max(0.0f,dot(Norm,normalize(LightPointFrom.xyz-LightPointTo.xyz).xyz));

float4 V = (EyePosition - Position.Sample(SamplText,Tex));

float3 R = reflect(Norm.xyz,normalize(LightPointFrom.xyz-LightPointTo.xyz).xyz);

float Specular = max(0.0f,dot(R,V));

float3 LightToVec = Position.Sample(SamplText,Tex) - LightPointFrom.xyz;

float LightToVecDist = length(LightToVec);

}



It uses a simple Phong Shading.
In return statement i do a mul with shadow to make sense of where shadow was projected (as you can see from first image).

After some hours thinking, i noticed about a my mistake in texture projection. So i modified code in this way but it's still completely wrong.


float4 ps_draw(in float4 Pos:SV_POSITION, in float2 Tex:TEXCOORD)	:	SV_TARGET

{

float4 TexC = BaseColor.Sample(SamplText,Tex);

float3 Norm = 2.0f * Normal.Sample(SamplText,Tex).xyz - 1.0f;

float NdotL = max(0.0f,dot(Norm,normalize(LightPointFrom.xyz-LightPointTo.xyz).xyz));

float4 V = (EyePosition - Position.Sample(SamplText,Tex));

float3 R = reflect(Norm.xyz,normalize(LightPointFrom.xyz-LightPointTo.xyz).xyz);

float Specular = max(0.0f,dot(R,V));

float4 NewPos = mul(mul(Position.Sample(SamplText,Tex),LightView),ProjMatrix);

NewPos /= NewPos.w;

float3 LightToVec = Position.Sample(SamplText,Tex) - LightPointFrom.xyz;

float LightToVecDist = length(LightToVec);

}



For now, please, do not look these problems (/100.0f, or epsilon in step function) becouse the problem is not there.





TexC is BaseColor and Shadow is the sample from shadow map. What i'm doing now (only for test purposes) is to project shadow with the scene to understand where map is placed in comparision to scene.

And, it is not right, so the problem it's above.

Using original texcoords:
http://img44.imagesh...48/porcesco.jpg

with this code:

float4 PSpot2D = mul(mul(Position.Sample(SamplText,Tex),LightView),ProjMatrix);



http://img14.imagesh...21/67551848.jpg

using this other one

float4 PSpot2D = mul(mul(Position.Sample(SamplText,Tex),LightView),ProjMatrix);

float2 VTexC = float2(PSpot2D.x/PSpot2D.w * 0.5f + 0.5f,-PSpot2D.y/PSpot2D.w * 0.5f + 0.5f);



http://img15.imagesh...71/51704351.jpg

Remember: THESE are NOT results of Shadow Lookup and comparision with camera distance. It' JUST a projection of Depth surface on the screen in order to verify it's position in comparision with original scene.
Really going crazy.

Thank you all for help.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users