I decided to look directly at the buffer with this new shader
#define FarClip 200
cbuffer cMultiFrame
{
row_major float4x4 WorldMatrix;
bool Lamp;
};
cbuffer cSometime
{
row_major float4x4 ViewMatrix;
row_major float4x4 VSpotMatrix; //Matrice spotlight
float4 LightInfo; //Luce puntiforme del lampione
float4 LightInfo2; //Direzione del fanale
float4 LightInfo3; //Posizione del fanale
float Phi;
float Theta;
};
cbuffer cNeverChange
{
row_major float4x4 ProjMatrix;
row_major float4x4 VMatrix[6];
};
Texture2D Text;
Texture2D SpotText;
TextureCube Cubemap;
SamplerState SamplText;
float Attenuation
(
float distance,
float a,
float b,
float c
)
{
float Atten = 1.0f / ( a + b * distance + c * pow(distance,2) );
return Atten;
}
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Nor : NORMAL;
float2 Tex : TEXCOORD;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 PSpot2D : P2DPOS;
float4 WPos: WORLDPOS;
float3 Nor : NORMAL;
float2 Tex : TEXCOORD;
float3 LPos : PROJPOS;
float Dist: DISTANCE;
float Dist2: DISTANCE2;
};
struct VGS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 WPos: WORLDPOSITION;
uint RTIndex : SV_RenderTargetArrayIndex;
};
struct VPS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 WPos: WORLDPOSITION;
};
PS_INPUT vs_position (VS_INPUT In)
{
PS_INPUT Out = (PS_INPUT)0;
Out.Pos = mul(mul(mul(In.Pos,WorldMatrix),ViewMatrix),ProjMatrix);
Out.PSpot2D = mul(mul(mul(In.Pos,WorldMatrix),VSpotMatrix),ProjMatrix);
Out.WPos = mul(In.Pos,WorldMatrix);
Out.Nor = mul(In.Nor,WorldMatrix);
Out.Tex = In.Tex;
Out.Dist = distance(Out.WPos,LightInfo.xyz);
Out.Dist2 = distance(Out.WPos,LightInfo3.xyz);
Out.LPos = Out.WPos - LightInfo.xyz;
return Out;
}
VS_INPUT vs_void (VS_INPUT In)
{
return In;
}
float4 ps_light (PS_INPUT In) : SV_TARGET
{
float4 BaseColor = (Lamp == true) ? float4(0.25f, 0.21f, 0.20f, 1) : Text.Sample(SamplText,In.Tex);
float3 vLight = normalize(LightInfo.xyz-In.WPos);
float NdotL = dot(In.Nor,vLight);
float Att = Attenuation(distance(LightInfo.xyz,In.WPos),0.003,0.003,0.003);
float4 PointLight = (saturate(NdotL)) * Att;
float3 LightToVecDirection = normalize(LightInfo3.xyz - In.WPos);
float3 LightToSourceDirection = normalize(LightInfo3.xyz - LightInfo2.xyz);
float cosAlpha = dot(LightToVecDirection,LightToSourceDirection);
float2 VTexC;
VTexC[0] = In.PSpot2D.x/In.PSpot2D.w/2.0f +0.5f;
VTexC[1] = -In.PSpot2D.y/In.PSpot2D.w/2.0f +0.5f;
float SpotShadow = SpotText.Sample(SamplText,VTexC);
float Atten = 0.0f;
if( cosAlpha > Theta )
{
Atten = 1.0f;
}
else if( cosAlpha > Phi )
{
Atten = 0.5f;
}
if (Atten != 0)
{
if ((In.Dist2/FarClip) >= SpotShadow)
{
return SpotShadow;
}
}
float4 SpotLight = (Atten * dot( In.Nor, LightToVecDirection ));
return (PointLight + SpotLight) * BaseColor;
}
[maxvertexcount(18)]
void Gs_Cubemap(triangle VS_INPUT input[3], inout TriangleStream<VGS_OUTPUT> Out)
{
VGS_OUTPUT output;
for( int f = 0; f < 6; f++ )
{
output.RTIndex = f;
for( int v = 0; v < 3; v++ )
{
output.Pos = mul(mul(mul( input[v].Pos, WorldMatrix),VMatrix[f]),ProjMatrix );
output.WPos = mul(input[v].Pos,WorldMatrix);
Out.Append( output );
}
Out.RestartStrip();
}
}
float ps_depth (VGS_OUTPUT In) : SV_TARGET
{
return distance(In.WPos,LightInfo.xyz) / FarClip;
}
float ps_spotdepth (VPS_OUTPUT In) : SV_TARGET
{
return distance(In.WPos,LightInfo3.xyz) / FarClip;
}
VPS_OUTPUT vs_spot(VS_INPUT In)
{
VPS_OUTPUT p = (VPS_OUTPUT)0;
p.Pos = mul(mul(mul(In.Pos,WorldMatrix),VSpotMatrix),ProjMatrix);
p.WPos = mul(In.Pos,WorldMatrix);
return p;
}
And i had this new result.

Can this help?


















