• Create Account

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1michaelmk86  Members   -  Reputation: 189

Like
0Likes
Like

Posted 30 June 2012 - 04:09 PM

hi guys,
does any one can provide any clues on why i get horizontal lines on my shadowed scene?

and the shadow map, as seen by the light

and the HLSL file:
float4x4 xWorldViewProjection;
float4x4 xLightsWorldViewProjection;
float4x4 xWorld;
float3 xLightPos;
float xLightPower;
float xAmbient;
float4 xColor = float4(1, 0.8, 0.8, 0);
float xMaxDepth;

Texture xTexture;

sampler TextureSampler = sampler_state { texture = <xTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = Wrap; AddressV = Wrap;};

float DotProduct(float3 lightPos, float3 pos3D, float3 normal)
{
float3 lightDir = normalize(pos3D - lightPos);
return dot(-lightDir, normal);
}

struct SMapVertexToPixel
{
float4 Position	 : POSITION;
float4 Position2D	: TEXCOORD0;
};

struct SMapPixelToFrame
{
float4 Color : COLOR0;
};

{
SMapVertexToPixel Output = (SMapVertexToPixel)0;

Output.Position = mul(inPos, xLightsWorldViewProjection);
Output.Position2D = Output.Position;

return Output;
}

{
SMapPixelToFrame Output = (SMapPixelToFrame)0;

Output.Color = PSIn.Position2D.z/xMaxDepth;  //Output.Color = PSIn.Position2D.z/PSIn.Position2D.w;

return Output;
}

{
pass Pass0
{
}
}

struct SSceneVertexToPixel
{
float4 Position			 : POSITION;
float4 Pos2DAsSeenByLight	: TEXCOORD0;

float2 TexCoords			: TEXCOORD1;
float3 Normal				: TEXCOORD2;
float4 Position3D			: TEXCOORD3;

};

struct SScenePixelToFrame
{
float4 Color : COLOR0;
};

SSceneVertexToPixel ShadowedSceneVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal : NORMAL)
{
SSceneVertexToPixel Output = (SSceneVertexToPixel)0;

Output.Position = mul(inPos, xWorldViewProjection);
Output.Pos2DAsSeenByLight = mul(inPos, xLightsWorldViewProjection);
Output.Normal = normalize(mul(inNormal, (float3x3)xWorld));
Output.Position3D = mul(inPos, xWorld);
Output.TexCoords = inTexCoords;

return Output;
}

{
SScenePixelToFrame Output = (SScenePixelToFrame)0;

float2 ProjectedTexCoords;
ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight.x/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;
ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight.y/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;

float diffuseLightingFactor = 0;
if ((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y))
{
//float realDistance = PSIn.Pos2DAsSeenByLight.z/PSIn.Pos2DAsSeenByLight.w;
float realDistance = PSIn.Pos2DAsSeenByLight.z/xMaxDepth;
if ((realDistance - 1.0f/100.0f) <= depthStoredInShadowMap)
{
diffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);
diffuseLightingFactor = saturate(diffuseLightingFactor);
diffuseLightingFactor *= xLightPower;
}
}

float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
Output.Color = baseColor*(diffuseLightingFactor + xAmbient)*xColor;

return Output;
}

technique Lighting
{
pass Pass0
{
}
}


### #2Jason Z  Crossbones+   -  Reputation: 6169

Like
0Likes
Like

Posted 01 July 2012 - 05:55 AM

That looks like a typical case of shadow map acne - where the resolution of your shadow map isn't sufficiently high for your scene. If you change the resolution of the map, does it get better with higher res?

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3L. Spiro  Crossbones+   -  Reputation: 21892

Like
0Likes
Like

Posted 01 July 2012 - 06:08 AM

What is the format and bit depth of the shadow texture?
The gradient in the dark area near the light is easily visible in the image, and that is causing your artifacts. A large gap between shades of grey.

L. Spiro

### #4michaelmk86  Members   -  Reputation: 189

Like
0Likes
Like

Posted 01 July 2012 - 01:29 PM

What is the format and bit depth of the shadow texture?
The gradient in the dark area near the light is easily visible in the image, and that is causing your artifacts. A large gap between shades of grey.

L. Spiro

Thanks,
changing the format from D3DFMT_R5G6B5 to D3DFMT_X8R8G8B8 completely fix my problem.

I just have one more question, I require the light source to be very far away (to look like it come from the sky), but the problem is that objects that are far away get very pixelate(and not very accurate) shadows. the first thing that came to my mind is to blur the shadow(to look like soft shadows?) not sure what approach need to follow in order to get good quality shadows with the light source being far away.

### #5MJP  Moderators   -  Reputation: 15007

Like
0Likes
Like

Posted 01 July 2012 - 02:15 PM

Neither of those formats have enough precision for a shadow map. At the very least you want to use something like D3DFMT_R16F, although D3DFMT_R32F would be even better. Ideally you don't want to use a render target texture at all and just sample the depth buffer, but doing that requires "driver hacks" so you can worry about that later.

For filtering shadows you can look into Percentage Closer Filtering, often abbreviated as PCF. There are also more advanced techniques like Variance Shadow Maps which open up new possibilities for filtering.

Either way, at a certain point no amount of filtering is going to make up for really low resolution shadows and all you will do is blur the shadow detail out of existence. You appear to be using a spot light with a perspective projection, which means at a certain distance you will have inadequate resolution to capture the details of your scene. Usually this isn't a problem, since typically your spotlights have a range attenuation which means they only have a limited area of effect to begin with. Directional lights are different since they are global light sources, and techniques like cascaded shadow maps are typically used to get adequate resolution across the entire viewable range.

### #6michaelmk86  Members   -  Reputation: 189

Like
0Likes
Like

Posted 02 July 2012 - 03:06 PM

Neither of those formats have enough precision for a shadow map. At the very least you want to use something like D3DFMT_R16F, although D3DFMT_R32F would be even better. Ideally you don't want to use a render target texture at all and just sample the depth buffer, but doing that requires "driver hacks" so you can worry about that later.

For filtering shadows you can look into Percentage Closer Filtering, often abbreviated as PCF. There are also more advanced techniques like Variance Shadow Maps which open up new possibilities for filtering.

Either way, at a certain point no amount of filtering is going to make up for really low resolution shadows and all you will do is blur the shadow detail out of existence. You appear to be using a spot light with a perspective projection, which means at a certain distance you will have inadequate resolution to capture the details of your scene. Usually this isn't a problem, since typically your spotlights have a range attenuation which means they only have a limited area of effect to begin with. Directional lights are different since they are global light sources, and techniques like cascaded shadow maps are typically used to get adequate resolution across the entire viewable range.

As far Percentage Closer Filtering I try the Brute-Force Implementation as seen in (11.3 http://http.develope...ugems_ch11.html) but i didn't manege to get it right.

SScenePixelToFrame ShadowedScenePixelShader(SSceneVertexToPixel PSIn)
{
SScenePixelToFrame Output = (SScenePixelToFrame)0;

float2 ProjectedTexCoords;
ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight.x/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;
ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight.y/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;

float diffuseLightingFactor = 0;
if ((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y))
{
float realDistance = PSIn.Pos2DAsSeenByLight.z/xMaxDepth;
if ((realDistance - 1.0f/100.0f) <= depthStoredInShadowMap)
{
diffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);
diffuseLightingFactor = saturate(diffuseLightingFactor);
diffuseLightingFactor *= xLightPower;
}
}else{
float sum = 0;
float x, y;
for (y = -1.5; y <= 1.5; y += 1.0)
for (x = -1.5; x <= 1.5; x += 1.0)
sum += offset_lookup(ShadowMapSampler, PSIn.Position3D, float2(x, y));
}

float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
Output.Color = baseColor*(diffuseLightingFactor + shadowCoeff + xAmbient)*xColor;

return Output;
}


will be nice if you point out some hints on how to use "offset lookup" method.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS