//Input variables |
float4x4 world; |
float4x4 inverseWorld; |
float4x4 worldViewProjection; |
float4 viewPosition; |
|
float4 Ambient; |
float4 DirectionalDirection; |
float4 DirectionalColor; |
float4 PointPosition; |
float4 PointColor; |
float PointFactor; |
|
float4 Material; |
|
texture SkinTexture; |
sampler Skin = sampler_state |
{ |
Texture = (SkinTexture); |
ADDRESSU = CLAMP; |
ADDRESSV = CLAMP; |
MAGFILTER = LINEAR; |
MINFILTER = LINEAR; |
MIPFILTER = LINEAR; |
}; |
|
texture NormalMapTexture; |
sampler NormalMap = sampler_state |
{ |
Texture = (NormalMapTexture); |
ADDRESSU = CLAMP; |
ADDRESSV = CLAMP; |
MAGFILTER = LINEAR; |
MINFILTER = LINEAR; |
MIPFILTER = LINEAR; |
}; |
|
texture ReflectionTexture; |
sampler Reflection = sampler_state |
{ |
Texture = (ReflectionTexture); |
ADDRESSU = CLAMP; |
ADDRESSV = CLAMP; |
MAGFILTER = LINEAR; |
MINFILTER = LINEAR; |
MIPFILTER = LINEAR; |
}; |
|
|
struct VS_INPUT |
{ |
float4 ObjectPos: POSITION; |
float2 Tex : TEXCOORD0; |
float3 ObjectNormal : NORMAL; |
}; |
|
struct VS_OUTPUT |
{ |
float4 ScreenPos: POSITION; |
float2 Tex: TEXCOORD0; |
float3 WorldNormal: TEXCOORD1; |
float4 PointDirection: TEXCOORD2; |
}; |
|
|
VS_OUTPUT AircraftVS(VS_INPUT In) |
{ |
VS_OUTPUT Out; |
|
//Move to screen space |
Out.ScreenPos = mul(In.ObjectPos, worldViewProjection); |
|
float4 WorldPos = mul(In.ObjectPos, world); |
float4 WorldNormal = mul(In.ObjectNormal, world); |
|
//Pass on texture coordinates and normal |
Out.Tex = In.Tex; |
Out.WorldNormal = WorldNormal; |
|
//Direction of point light to this vertex |
float4 lightDir; |
lightDir= PointPosition - WorldPos; |
float dist = length(lightDir); |
lightDir = lightDir/dist; |
|
//Store attenuation in w |
lightDir.w = saturate(1/(PointFactor * dist)); |
|
Out.PointDirection = lightDir; |
|
return Out; |
} |
|
float4 DirectionalLight(float3 WorldNormal) |
{ |
return DirectionalColor * saturate(dot(WorldNormal, normalize(DirectionalDirection))); |
} |
|
float4 PointLight(float3 Normal, float4 PointDirection) |
{ |
return PointColor * saturate(PointDirection.w * dot(Normal, normalize(PointDirection.xyz))); |
} |
|
float4 AircraftPS( float2 tex: TEXCOORD0, float3 WorldNormal : TEXCOORD1, float4 PointDirection : TEXCOORD2) : COLOR |
{ |
WorldNormal = normalize(WorldNormal); |
|
float4 Directional = DirectionalLight(WorldNormal); |
float4 Point = PointLight(WorldNormal, PointDirection); |
|
//Specular map is in alpha of diffusemap and material |
float MattFactor = Material.a * tex2D(Skin, tex).a; |
|
//Add it all up |
float4 retval; |
|
retval= saturate( |
Material * |
( //Remove alpha channel from texture |
((Ambient + Directional + Point) * float4(tex2D(Skin, tex).rgb, 1)) + |
(1-MattFactor) * texCUBE(Reflection, WorldNormal) |
) |
); |
|
|
|
return retval; |
} |
|
|
|
//--------------------------------------------------------------// |
// Technique Section for Aircraft Effects |
//--------------------------------------------------------------// |
technique Aircraft |
{ |
pass Single_Pass |
{ |
ZENABLE = TRUE; |
ZWRITEENABLE = TRUE; |
|
CULLMODE = CW; |
|
VertexShader = compile vs_1_1 AircraftVS(); |
PixelShader = compile ps_2_0 AircraftPS(); |
} |
|
} |
|