float3 combinedNormal; combinedNormal = tex2D(animatedNormalMapSampler, IN.normalMapCoords1.xy); //convert the normal from 0 to 1 into -1 to 1 combinedNormal = normalize(2 * combinedNormal - 1); //IN.reflectCoords.z is the distance from the viewer to the pixel float distScaledDistortion = IN.reflectCoords.z; //setup a distortion fadeout with distance distScaledDistortion = clamp(3 / (distScaledDistortion + 2), .3, 1); //scale the normal by this distortion and a user-supplied constant - reflectDistortion float3 scaledNormal = normalize(combinedNormal * float3(reflectDistortion * distScaledDistortion, 1, reflectDistortion * distScaledDistortion)); //project the coordinates and offset them by the normal //note that up in this normal map is y not z IN.reflectCoords.xy = IN.reflectCoords.xy / IN.reflectCoords.w + scaledNormal.xz; float4 reflectiveColor = tex2D(reflectionSampler, IN.reflectCoords);
Hope that helps.