// set to zero to disable effect
#define ANGLE_SURFACE_DARKEN 0.25 // less number - less darken
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewPos;
float4 vecFog;
float4 vecFogColor;
float4 vecLight;
float4 vecColor;
float4 vecSkill41; // used to controll wireframe color
texture entSkin1;
sampler ColorSampler = sampler_state
{
Texture = <entSkin1>;
Mipfilter = None;
Minfilter = None;
Magfilter = None;
};
void VS(
in float4 inposition : POSITION,
in float3 innormal : NORMAL,
in float4 intex1 : TEXCOORD0,
in float4 intex2 : TEXCOORD1,
out float4 outposition : POSITION,
out float4 outcolor : COLOR0,
out float3 outnormal : TEXCOORD0,
out float4 outtex : TEXCOORD1,
out float4 outworldPos : TEXCOORD2)
{
inposition.w = 1.0f;
outposition = mul(inposition, matWorldViewProj);
outnormal = normalize(mul(innormal, (float3x3)matWorld));
outtex.xy = intex1.xy;
outtex.zw = intex2.xy;
outworldPos = mul(inposition, matWorld);
// no lightning
outcolor = float4(vecColor.xyz, vecLight.w);
}
float4 PS(
float4 color : COLOR0,
float3 normal : TEXCOORD0,
float4 tex : TEXCOORD1,
float4 worldPos : TEXCOORD2) : COLOR0
{
// hard edges (if needed)
float3 dpdx = ddx(worldPos);
float3 dpdy = ddy(worldPos);
normal.xyz = normalize(cross(dpdy, dpdx));
float4 textureColor = tex2D(ColorSampler, tex.xy);
// darken surface on angle
if(ANGLE_SURFACE_DARKEN > 0)
{
float3 vPixelToViewDir = normalize(vecViewPos.xyz - worldPos.xyz); // *** direction vector from the surface to the camera
float dot_result = dot(vPixelToViewDir, normal.xyz); // *** get the angle ( cos(angle) ) between these vectors; both vectors in the dot product have to be normalized (length = 1)
color.rgb *= saturate(1.0 - (1.0 - dot_result) * ANGLE_SURFACE_DARKEN); // *** apply the darkening factor with adjustable intensity; saturate() to prevent negative numbers (and numbers > 1)
}
// add texture to the color
color.rgb *= textureColor.rgb;
// fog part
// just remove this 3 lines to remove the fog
float fDepth = distance ( vecViewPos.xyz, worldPos.xyz );
float Fog = saturate ( ( fDepth - vecFog.x ) * vecFog.z );
color.rgb = lerp ( color.rgb, vecFogColor, Fog );
color.a = 1;
return color;
}
void WR_VS(
in float4 inposition : POSITION,
out float4 outposition : POSITION)
{
// dirty trick to draw wiraframes
// above the actual solid polygons
inposition.w = 0.998f;
outposition = mul(inposition, matWorldViewProj);
}
float4 WR_PS(
float4 color : COLOR0,
float4 worldPos : TEXCOORD2) : COLOR0
{
// change wireframe color with vecSkill41...43
color.rgb = vecSkill41.xyz;
// fog for wireframes
// just remove this 3 lines to remove the fog
float fDepth = distance ( vecViewPos.xyz, worldPos.xyz );
float Fog = saturate ( ( fDepth - vecFog.x ) * vecFog.z );
color.rgb = lerp ( color.rgb, vecFogColor, Fog );
color.a = vecSkill41.w; // alpha value of the wireframe
return color;
}
technique
{
pass pass0 // first draw the solid model with hard edges
{
ZWriteEnable = True;
AlphaBlendEnable = False;
AlphaTestEnable = False;
AlphaFunc = ALWAYS;
Fillmode = SOLID;
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
pass pass1 // then draw wireframes
{
ZWriteEnable = True;
AlphaBlendEnable = True;
AlphaTestEnable = False;
AlphaFunc = Greater;
Fillmode = Wireframe;
VertexShader = compile vs_2_0 WR_VS();
PixelShader = compile ps_2_0 WR_PS();
}
}
technique fallback { pass one { } }