HAL.. no... Retail device doesn't like my shadowmapping

Started by
2 comments, last by S1CA 17 years, 5 months ago
Hi. I am in the murky world of shadow maps. When I run the routine with a REF device, I get this ( shadows are not turned on ): When I turn to HAL, heres the result! This is exactly the same scene. All objects in the scene are drawn using the same shader, my Parallel split shadow mapping one:
float4x4 ViewProj : VIEWPROJECTION;
float4x4 World	 : WORLD;
float DepthBias	= 0.01f;
float SlopeScaleBias = 2.5f;

float3 lightDir;
float3 lightCol;
float3 ambient;
float ShadowMapSize;
float4x4 ShadowMapMatrix;

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

// no filtering in floating point texture
sampler2D ShadowMapSampler  =
sampler_state
{
  MinFilter = Point;
  MagFilter = Point;
  MipFilter = None;
  AddressU = Border;
  AddressV = Border;
  BorderColor = 0xFFFFFFFF;
};

texture shadowMapTex;
texture skinTex;

// hardware sampler has filtering
sampler2D shadowSampler = sampler_state
{
	Texture   = <shadowMapTex>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = None;
	AddressU = Border;
	AddressV = Border;
	BorderColor = 0xFFFFFFFF;
};

sampler2D skinSampler = sampler_state
{
	Texture   = <skinTex>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = None;
	AddressU = Border;
	AddressV = Border;
	BorderColor = 0xFFFFFFFF;
};

void VS_Shadowed(
  in float4 Pos : POSITION,
  in float3 Normal : NORMAL,
  in float2 TexIn: TEXCOORD0,
  out float4 PosOut : POSITION,
  out float2 TexOut : TEXCOORD0,
  out float4 ShadowTex : TEXCOORD1,
  out float3 Diffuse : COLOR0)
{
 	// pass vertex position through as usual
	float4 posWorld = mul( Pos, World );			// obj to world
	PosOut = mul(posWorld, ViewProj);				// world to clip 

	 
  // per vertex lighting
  Diffuse = saturate(dot(-lightDir, Normal));

  // coordinates for shadowmap
 ShadowTex = mul(posWorld, ShadowMapMatrix);			// <<----------- using world space position i think?

TexOut = TexIn;
	
}


//////////////////////////////////////////////////////////////////////////////

float4 PS_Shadowed(
   float2 Tex : TEXCOORD0,
 float4 ShadowTex : TEXCOORD1,
  float4 Diffuse : COLOR0) : COLOR
{

  float TexelSize=1.0f/ShadowMapSize;

  // project texture coordinates
  ShadowTex.xy/=ShadowTex.w;
  
  // 2x2 PCF Filtering
  // 
  float fShadow[4];
  fShadow[0] = (ShadowTex.z < tex2D(ShadowMapSampler, ShadowTex));
  fShadow[1] = (ShadowTex.z < tex2D(ShadowMapSampler, ShadowTex + float2(TexelSize,0)));
  fShadow[2] = (ShadowTex.z < tex2D(ShadowMapSampler, ShadowTex + float2(0,TexelSize)));
  fShadow[3] = (ShadowTex.z < tex2D(ShadowMapSampler, ShadowTex + float2(TexelSize,TexelSize)));
  
  float2 LerpFactor = frac(ShadowMapSize * ShadowTex);
  float LightingFactor = lerp(lerp( fShadow[0], fShadow[1], LerpFactor.x ),
                               lerp( fShadow[2], fShadow[3], LerpFactor.x ),
                               LerpFactor.y);

  // multiply diffuse with shadowmap lookup value
 // Diffuse*=LightingFactor;
  Diffuse*= tex2D(skinSampler, Tex);
  
  // final color
  float4 color=1;
  color.rgb = Diffuse.rgb;
  return color;
}
///////////////////////////////////////////////////////////////////////////////////////////
// This technique is used to render the final shadowed meshes
//
technique Shadowed
{
  pass p0
  {
    CullMode = CCW;
    ZWriteEnable = TRUE;
    ZEnable = TRUE;
    ZFunc = LESS;
	  VertexShader = compile vs_2_0 VS_Shadowed();
	  PixelShader = compile ps_2_0 PS_Shadowed();
  }
 }
 
 
 
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
 
 void VS_RenderToShadowMap2(
  in float4 Pos : POSITION,
  in float3 Normal : NORMAL,
  in float2 TexIn: TEXCOORD0,
  out float4 PosOut : POSITION,
  out float2 TexOut : TEXCOORD0,
  out float4 ShadowTex : TEXCOORD1,
  out float3 Diffuse : COLOR0,
  out float PixelOut : TEXCOORD2
)
{
 	// pass vertex position through as usual
	float4 posWorld = mul( Pos, World );			// obj to world
	PosOut = mul(posWorld, ViewProj);				// world to clip 

	PixelOut = PosOut.z;
	 
  // calculate per vertex lighting
  Diffuse = saturate(dot(-lightDir, Normal));

  // coordinates for shadowmap
 ShadowTex = mul(posWorld, ShadowMapMatrix);			// <<----------- using world space position i think?

	TexOut = TexIn;
	
}


//////////////////////////////////////////////////////////////////////////////

float4 PS_RenderToShadowMap2(
   float2 Tex : TEXCOORD0,
 float4 ShadowTex : TEXCOORD1,
  float4 Diffuse : COLOR0,
  float PixelPos : TEXCOORD2) : COLOR
{

   return PixelPos;
}
///////////////////////////////////////////////////////////////////////////////////////////
// This technique is used to render the final shadowed meshes
//
technique RenderToShadowMap2
{
  pass p0
  {
    CullMode = CCW;
    ZWriteEnable = TRUE;
    ZEnable = TRUE;
    ZFunc = LESS;
	  VertexShader = compile vs_2_0 VS_RenderToShadowMap2();
	  PixelShader = compile ps_2_0 PS_RenderToShadowMap2();
	//  VertexShader = compile vs_1_1 VS_RenderToShadowMap2();
	//  PixelShader = compile ps_1_1 PS_RenderToShadowMap2();
  }
 }


Sorry for the messy code :) I thought at first I was not setting the world/view/proj right for the objects, but its strange the big flat plane draws and not the others. Obviously the REF device is more forgiving in some respect, can anyone suggest what that might be? Many thanks Simon EDIT: its actually the retail d3d9 which doesnt work! not the HAL side of things. I've heard that debug d3d9 is a lot more forgiving but still puzzled as to why this occurs? [Edited by - sipickles on October 20, 2006 1:28:23 PM]
Advertisement
Quote:Original post by sipickles
EDIT: its actually the retail d3d9 which doesnt work! not the HAL side of things. I've heard that debug d3d9 is a lot more forgiving but still puzzled as to why this occurs?

There is an easy way to find out: just check for debug output from the debug runtimes. Hopefully this will tell you what is going on and why it isn't working in retail.

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
What is this? beginners forum??????!!! <joke>

Unfortunately there is no debug output, even on max, apart from the odd redundant call.

So there is obviously something friendly about HAL debug mode and REF retail mode. They overlook some minor problem I've got. unfortunately HAL retail doesn't!

1. Are you using a D3DCREATE_PUREDEVICE device? If so, try it without (pure means "I'm confident that everything I'm doing is supported in hardware, so don't help out" and could be a reason for not seeing any debug spew and a difference between Debug and Retail).

2. Immediately before your draw call, call IDirect3DDevice9::ValidateDevice() to ask the driver if it's unhappy with anything in your pipeline.

3. Be wary that some drivers/hardware don't like certain texture filter modes with particular texture formats - floating point texture formats in particular. I'd check through the device caps and see if your code does anything your hardware doesn't officially support.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement