Jump to content
  • Advertisement
DividedByZero

DX11 Depth shadow mapping question

Recommended Posts

Hi @pcmaster, had a decent nights sleep and am all ready to drop another twelve hour effort in to this - LOL.

Yep, defininetly sampling from squareMapDepth (t1).

I'll do some refactoring of the shader this morning to get rid of unnecessary bit that have crept in over the last few days, in an effort to make things more readable.

With the depth map, does it need any special processing in advance? I am feeding it as is from the light pass, directly as an SRV to the shader. Just thought I'd mention this in case that is the issue.

Many thanks one again.

Share this post


Link to post
Share on other sites
Advertisement

I have added the non working shadow pass from the debugger, just in case something stands out that I am not seeing.

Thanks again.

1GEFbBc.png

Share this post


Link to post
Share on other sites

You're confusing yourself. Either sample a depth target, or a render target that rendered depth earlier. Its two different things: Before shadowing, you render the scene which results in a render target with the scene and a depth target with the scene (as a depth value). These can both be sampled as a texture during shadowing. If you rendered the target with a depth manually as an earlier poster suggested then the depth target has nothing to do with the shadowing and you are sampling the render target. Otherwise you need to sample the depth target as a shader resource.

Either way, be aware you cant sample it if it is still loaded as the depth or render target, you would have two depth targets or two render targets etc

The most straight forward DX11 example I know is http://www.rastertek.com/dx11tut40.html 

Share this post


Link to post
Share on other sites

Hi @TeaTreeTim.

Yes I most certainly am confusing myself, I've tried all manner of combinations.

So as of right now, I am using the pure untouched depth buffer from the light view, which is assigned to texture slot 1 (T1). And the rocky looking texture is on T0.

2m9wady.png

At this point there is still no shadowing. I'll continue to chip away.

 

[edit]

Just to verify from the graphical debugger, this is the point where I set the depth map to the srv on T1

dXIW7gl.png

Thanks for your help on this.

Edited by DividedByZero
Additional information

Share this post


Link to post
Share on other sites

I have done quite a bit of refactoring, and referring to the rastertek tutorial closely.

The shaders I have now are

cbuffer MatrixBuffer : register(b0)
{
	matrix matWorld;
	matrix matView;
	matrix matProjection;
	matrix matLightView;
	matrix matLightProjection;
}

cbuffer LightBuffer : register(b1)
{
	float4 lightPosition;
	float4 lightAmbient;
}

struct VS_INPUT
{
	float4 position : POSITION;
	float3 normal : NORMAL;
	float2 textureCoord : TEXCOORD0;
};

struct VS_OUTPUT
{
	float4 position : SV_POSITION;
	float3 normal : NORMAL;
	float2 textureCoord : TEXCOORD0;

	float3 lightPosition : COLOR1;
	float4 lightAmbient : COLOR2;
	float4 fragmentPosition : COLOR3;

	float4 lightViewPosition : COLOR4;
};

VS_OUTPUT vs_main(VS_INPUT input)
{
	VS_OUTPUT output;
	
	// Position
	input.position.w = 1.0f;
	output.position = mul(input.position, matWorld);
	output.position = mul(output.position, matView);
	output.position = mul(output.position, matProjection);

	// Normal
	output.normal = input.normal;
	output.normal = mul(input.normal, matWorld);
	output.fragmentPosition = mul(input.position, matWorld);

	// Text co-ord
	output.textureCoord = input.textureCoord;

	// Light
	output.lightPosition = lightPosition;
	output.lightAmbient = lightAmbient;

	// Shadow position
	output.lightViewPosition = mul(input.position, matWorld);
	output.lightViewPosition = mul(output.position, matLightView);
	output.lightViewPosition = mul(output.position, matLightProjection);


	// Calculate the position of the vertex in the world.
	float4 worldPosition;
	worldPosition = mul(input.position, matWorld);
	output.lightPosition = lightPosition.xyz - worldPosition.xyz;
	output.lightPosition = normalize(output.lightPosition);

	return output;
}

and

SamplerState SampleTypeClamp : register(s0);
SamplerState SampleTypeWrap : register(s1);

Texture2D shaderTexture : register(t0);
Texture2D depthMapTexture : register(t1);

struct VS_OUTPUT
{
	float4 position : SV_POSITION;
	float3 normal : NORMAL;
	float2 textureCoord : TEXCOORD0;

	float3 lightPosition : COLOR1;
	float4 lightAmbient : COLOR2;
	float4 fragmentPosition : COLOR3;

	float4 lightViewPosition : COLOR4;
};

float4 ps_main(VS_OUTPUT input) : SV_TARGET
{
	float bias;
	float4 color;
	float2 projectTexCoord;
	float depthValue;
	float lightDepthValue;
	float lightIntensity;
	float4 textureColor;

	bias = 0.001f;

	projectTexCoord.x = input.lightViewPosition.x / input.lightViewPosition.w / 2.0f + 0.5f;
	projectTexCoord.y = -input.lightViewPosition.y / input.lightViewPosition.w / 2.0f + 0.5f;

	if ((saturate(projectTexCoord.x) == projectTexCoord.x) && (saturate(projectTexCoord.y) == projectTexCoord.y))
	{
		depthValue = depthMapTexture.Sample(SampleTypeClamp, projectTexCoord).r;
		lightDepthValue = input.lightViewPosition.z / input.lightViewPosition.w;
		lightDepthValue = lightDepthValue - bias;


		if (lightDepthValue < depthValue)
		{
			color.r = 0.0f;
			color.g = 0.0f;
			color.b = 0.0f;
			color.a = 1.0f;
			return color;
		}
	}

	return shaderTexture.Sample(SampleTypeClamp, input.textureCoord);	
}

Presently the image I get is

KxTv2YV.png

But oddly enough, the result is this whether or not I send the depth buffer to slot 1 of the SRV.

Is this indicative of the total shadow volume area as per the shadow matrices?

Seems like I am still having trouble getting the depth values from the shadow depth SRV.

Hopefully I am getting close, but could really use a helping hand.

Thanks again.

Edited by DividedByZero

Share this post


Link to post
Share on other sites

Try this instead.

{
  .... //CODE omitted
	float4 textureColor = shaderTexture.Sample(SampleTypeClamp, input.textureCoord);
	float3 FinalColor = 0, AmbientColor, mAmb = float3(.48f,.77f,.46f), lAmb = float3(.2f,.2f,.2f);

	depthValue = depthMapTexture.Sample(SampleTypeClamp, projectTexCoord).r;
	lightDepthValue = input.lightViewPosition.z / input.lightViewPosition.w;
	lightDepthValue = lightDepthValue - bias;

	AmbientColor = mAmb*lAmb;

   if(lightDepthValue <= depthValue)
   {
		float LCL = saturate(dot(LightDir, input.normal));//light dir is the direction of light
		FinalColor = depthValue*LCL;
		FinalColor = textureColor.rgb*(AmbientColor + FinalColor);
	}
	else
		FinalColor =  textureColor.rgb*AmbientColor;
	
	return float4(FinalColor.rgb, 1);
}









}

 

Share this post


Link to post
Share on other sites

I have re-written a standalone project completely from scratch and for some reason the end result it still the same.

I have omitted all lighting calculations and jut focusing on whether the scene is either shadowed or fully lit.

GYQhFKO.png

I have noticed however, the generated shadow map doesn't have much contrast to it.

OTYaf2k.png

This is the vertex shader for the map creation

cbuffer WVPCB : register(b0)
{
	float4x4 matWorld;
	float4x4 matView;
	float4x4 matProjection;
}

struct VS_INPUT
{
	float4 position : POSITION;
	float3 normal : NORMAL;
	float2 textureCoord : TEXCOORD0;
};

struct SHADOW_PS_INPUT
{
	float4 position : SV_POSITION;
};

SHADOW_PS_INPUT vs_main_depth_map(VS_INPUT input)
{
	SHADOW_PS_INPUT output;

	output.position = mul(input.position, matWorld);
	output.position = mul(output.position, matView);
	output.position = mul(output.position, matProjection);

	return output;
}

And this is the pixel shader.

struct SHADOW_PS_INPUT
{
	float4 position : SV_POSITION;
};

float4 ps_main_depth_map(SHADOW_PS_INPUT input) : SV_TARGET
{
	float z = input.position.z;
	return float4(z, z, z, 1);
}

Does this look ok for the shadow map creation pass?

Many thanks once again.

 

 

Share this post


Link to post
Share on other sites

I might have to admit defeat on this one and throw in the towel.

I have read maybe a dozen tutorials on this and keep getting the same result, even when I completely re-code the whole project from scratch.

Obviously something I am not correctly interpreting along the way.

Here is a dropbox link for the current exe if anyone feels like analyzing anything with the VS Graphical Debugger.

https://www.dropbox.com/s/qdd2ojy80x3w658/shadow.zip?dl=0

There are many leaks though, as I haven't cleaned up all of the interfaces on exit.

Thanks again.

Edited by DividedByZero

Share this post


Link to post
Share on other sites

Following along the RasterTek tutorial, my shaders are now the same as what are in the tutorial. I also found that my texture formats for the depth buffer creation were wrong. (I was using R8G8B8A8 and have now expanded these to R32G32B32A32 etc...)

Stepping through the graphical debugger, all of my formats for DSV, SRV, and RTV's are the same as the tutorial for each target.

So as of now this is what I am getting

hFX8Mqn.png

The above is using a perspective view for the light, but still no shadows if I use an orthographic generated depth map.

Edited by DividedByZero

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!