1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| struct Connect{
float4 positionCS: POSITION;
float2 texCoord: TEXCOORD0;
float2 texCoordl: TEXCOORD6;
float3 positionWS: TEXCOORD1;
float3 normalWS: TEXCOORD2;
float3 binormalWS: TEXCOORD3;
float3 tangentWS: TEXCOORD4;
float3 lightposWS: TEXCOORD5;
};
struct Fragment{
float4 color: COLOR;
};
Fragment main(Connect data,
uniform sampler2D diffuseMap: register(S0),
uniform sampler2D diffuseMap2: register(S1),
uniform sampler2D normalMap: register(S2),
uniform sampler2D lightMap: register(S3),
uniform sampler2D envMap: register(S4),
uniform float blight: register(C0),
uniform float alpha: register(C1))
{
Fragment result;
float3x3 tangentToWorldMatrix = float3x3( normalize(data.tangentWS),
normalize(data.binormalWS),
normalize(data.normalWS) );
float3 normalTS = float3(0,0,1);
float3 normalWS = mul(normalTS, tangentToWorldMatrix);
float km=tex2D(lightMap, data.texCoordl).y;
float4 diffuseColor = tex2D(diffuseMap, data.texCoord)*km+tex2D(diffuseMap2, data.texCoord)*(1-km);
float refract=0.5f+0.5f*clamp(dot(data.lightposWS,normalWS),0,1);
if (blight==0) //pas de lumiere (tout a fond)
result.color=float4(tex2D(diffuseMap, data.texCoord).xyz, tex2D(diffuseMap, data.texCoord).w*alpha);
else
result.color=float4(refract*diffuseColor.xyz*tex2D(lightMap, data.texCoordl).x , diffuseColor.w);
return result;
} |
Partager