Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualTournicoti

Posted 20 September 2012 - 06:01 AM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :

#define CSM_MAXSPLITS 8

SamplerState shadowMapSampler
{
	Filter = MIN_MAG_MIP_POINT;
	AddressU = BORDER;
	AddressV = BORDER;
	BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

bool getSplitUV(in float posProjZ,in float3 posWorld,out uint split,out float2 uv,out float posLightZ)
{
split=1;
uv=0;
posLightZ=0;
[unroll (CSM_MAXSPLITS)]
for (;split<=g_CSM_nbSplits;split++)
  if (posProjZ<g_CSM_depths[split].x) break;

split--;
if (split==g_CSM_nbSplits) return false;

float4 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
posLight/=posLight.w;
posLightZ=posLight.z;

uv=(posLight.xy)*float2(0.5f,-0.5f)+0.5f;

return true;
}

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
uint split;
float2 uv;
float posLightZ,factor;
if (getSplitUV(posProjZ,posWorld,split,uv,posLightZ))
{
  factor=saturate(dot(normalWorld,g_vDirectionalLightDirection));
  factor=saturate(sqrt(1.0f-factor*factor)/factor)*g_CSM_depths[split].y;
  factor=(g_CSMMaps.Sample(shadowMapSampler,float3(uv,split)).x+factor<posLightZ) ? 0.0f : 1.0f;
}
else
  factor=1.0f;
return factor*g_ColorCSMMaps.Sample(shadowMapSampler,float3(uv,split)).xyz;
}

PS :
g_CSM_depths[split].x is the minimal depth of the #split map, g_CSM_depths[split+1].x is the maximal depth of the #split map.
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome Posted Image

#3Tournicoti

Posted 20 September 2012 - 05:59 AM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :

#define CSM_MAXSPLITS 8

SamplerState shadowMapSampler
{
	Filter = MIN_MAG_MIP_POINT;
	AddressU = BORDER;
	AddressV = BORDER;
	BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

bool getSplitUV(in float posProjZ,in float3 posWorld,out uint split,out float2 uv,out float posLightZ)
{
split=1;
uv=0;
posLightZ=0;
[unroll (CSM_MAXSPLITS)]
for (;split<=g_CSM_nbSplits;split++)
  if (posProjZ<g_CSM_depths[split].x) break;

split--;
if (split==g_CSM_nbSplits) return false;

float4 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
posLight/=posLight.w;
posLightZ=posLight.z;

uv=(posLight.xy)*float2(0.5f,-0.5f)+0.5f;

return true;
}

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
uint split;
float2 uv;
float posLightZ,factor;
if (getSplitUV(posProjZ,posWorld,split,uv,posLightZ))
{
  factor=saturate(dot(normalWorld,g_vDirectionalLightDirection));
  factor=saturate(sqrt(1.0f-factor*factor)/factor)*g_CSM_depths[split].y;
  factor=(g_CSMMaps.Sample(shadowMapSampler,float3(uv,split)).x+factor<posLightZ) ? 0.0f : 1.0f;
}
else
  factor=1.0f;
return factor*g_ColorCSMMaps.Sample(shadowMapSampler,float3(uv,split)).xyz;
}

PS :
g_CSM_depths[split].x is the minimal depth of the #split map, g_CSM_depths[split+1].x is the maximal depth of the #split map
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome Posted Image

#2Tournicoti

Posted 20 September 2012 - 05:58 AM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :

#define CSM_MAXSPLITS 8

SamplerState shadowMapSampler
{
	Filter = MIN_MAG_MIP_POINT;
	AddressU = BORDER;
	AddressV = BORDER;
	BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

bool getSplitUV(in float posProjZ,in float3 posWorld,out uint split,out float2 uv,out float posLightZ)
{
split=1;
uv=0;
posLightZ=0;
[unroll (CSM_MAXSPLITS)]
for (;split<=g_CSM_nbSplits;split++)
  if (posProjZ<g_CSM_depths[split].x) break;

split--;
if (split==g_CSM_nbSplits) return false;

float4 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
posLight/=posLight.w;
posLightZ=posLight.z;

uv=(posLight.xy)*float2(0.5f,-0.5f)+0.5f;

return true;
}

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
uint split;
float2 uv;
float posLightZ,factor;
if (getSplitUV(posProjZ,posWorld,split,uv,posLightZ))
{
  factor=saturate(dot(normalWorld,g_vDirectionalLightDirection));
  factor=saturate(sqrt(1.0f-factor*factor)/factor)*g_CSM_depths[split].y;
  factor=(g_CSMMaps.Sample(shadowMapSampler,float3(uv,split)).x+factor<posLightZ) ? 0.0f : 1.0f;
}
else
  factor=1.0f;
return factor*g_ColorCSMMaps.Sample(shadowMapSampler,float3(uv,split)).xyz;
}

PS :
g_CSM_depths[split].x is the minimal depth bias of the #split map, g_CSM_depths[split+1].x is the maximal depth bias of the #split map
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome Posted Image

#1Tournicoti

Posted 20 September 2012 - 05:53 AM

Thanks, it solved the problem Posted Image

If you want to have a look on my HLSL colored csm sampling functions that use it :

#define CSM_MAXSPLITS 8

SamplerState shadowMapSampler 
{ 
    Filter = MIN_MAG_MIP_POINT;
    AddressU = BORDER;
    AddressV = BORDER;
    BorderCOLOR = float4(1.0f,1.0f,1.0f,1.0f);
};

bool getSplitUV(in float posProjZ,in float3 posWorld,out uint split,out float2 uv,out float posLightZ)
{
split=1;
uv=0;
posLightZ=0;
[unroll (CSM_MAXSPLITS)]
for (;split<=g_CSM_nbSplits;split++)
  if (posProjZ<g_CSM_depths[split].x) break;
 
split--;
if (split==g_CSM_nbSplits) return false;

float4 posLight=mul(float4(posWorld,1.0f),g_CSM_VP[split]);
posLight/=posLight.w;
posLightZ=posLight.z;

uv=(posLight.xy)*float2(0.5f,-0.5f)+0.5f;

return true;
}

float3 sampleColorCSM(in float posProjZ,in float3 posWorld,in float3 normalWorld)
{
uint split;
float2 uv;
float posLightZ,factor;
if (getSplitUV(posProjZ,posWorld,split,uv,posLightZ))
{
  factor=saturate(dot(normalWorld,g_vDirectionalLightDirection));
  factor=saturate(sqrt(1.0f-factor*factor)/factor)*g_CSM_depths[split].y;
  factor=(g_CSMMaps.Sample(shadowMapSampler,float3(uv,split)).x+factor<posLightZ) ? 0.0f : 1.0f;
}
else
  factor=1.0f;
return factor*g_ColorCSMMaps.Sample(shadowMapSampler,float3(uv,split)).xyz;
}

PS :
g_CSM_depths[split].y is the depth bias of the #split map
Any suggestion or improvement is welcome Posted Image

PARTNERS