#define IN_HLSL #include "shdrConsts.h" struct v2f { float4 hpos : POSITION; float3 eye : TEXCOORD0; float3 light : TEXCOORD1; float2 texcoord : TEXCOORD2; float3 cubespace0 : TEXCOORD3; float3 cubespace1 : TEXCOORD4; float3 cubespace2 : TEXCOORD5; }; float4 main( v2f IN, uniform sampler2D texmap : register(S0), uniform sampler2D reliefmap : register(S1), uniform sampler2D specmap : register(S2), uniform samplerCUBE cubemap : register(S3), uniform float4 ambient : register(PC_AMBIENT_COLOR), uniform float4 specular : register(PC_MAT_SPECCOLOR), uniform float shine : register(PC_MAT_SPECPOWER) ) : COLOR { const float3 diffuse = {1,1,1}; float2 uv=IN.texcoord; // normal map float4 normal=tex2D(reliefmap, uv); normal.xyz=normalize(normal.xyz-0.5); normal.y=-normal.y; // color map float4 color=tex2D(texmap, uv); // view and light directions float3 eye = normalize(IN.eye); float3 light = normalize(IN.light); // compute diffuse and specular terms float diff=saturate(dot(light,normal.xyz)); float spec=saturate(dot(normalize(light+eye),normal.xyz)); float3 speccolor = specular.xyz*tex2D(specmap, uv).xyz; float invfresnel = dot(eye, normal.xyz); float3 reflectdir = 2.0*invfresnel*normal.xyz - eye; float3x3 cubespace = float3x3(IN.cubespace0, IN.cubespace1, IN.cubespace2); float3 cubedir = mul(cubespace, reflectdir); float envscale = lerp(0.4, 0.2, max(invfresnel, 0.0)); float3 envcolor = texCUBE(cubemap, cubedir).xyz; // compute final color float4 finalcolor; finalcolor.xyz = lerp(ambient*color.xyz + color.xyz*diffuse*diff, envcolor, speccolor*envscale) + speccolor*pow(spec,shine); finalcolor.w=1.0; return finalcolor; }