static const float3 BumpBasis[3] = { float3( sqrt(2.0) / sqrt(3.0), 0.0, 1.0 / sqrt(3.0)), float3( -1.0 / sqrt(6.0), 1.0 / sqrt(2.0), 1.0 / sqrt(3.0)), float3( -1.0 / sqrt(6.0), -1.0 / sqrt(2.0), 1.0 / sqrt(3.0)) }; float3 CalculateDLMContribution(float3 TangentNormal) { TangentNormal.y = -TangentNormal.y; float3 lightmapContribution = 0; lightmapContribution.x = dot(BumpBasis[0], TangentNormal); lightmapContribution.y = dot(BumpBasis[1], TangentNormal); lightmapContribution.z = dot(BumpBasis[2], TangentNormal); lightmapContribution = saturate(lightmapContribution); lightmapContribution *= lightmapContribution; return lightmapContribution; } float3 CalculateDLMDiff(float3 TangentNormal, float3 DLightmap0, float3 DLightmap1, float3 DLightmap2) { float3 lightmapContribution = CalculateDLMContribution(TangentNormal); float3 light = 0; float sum = dot(lightmapContribution, float3(1.0f, 1.0f, 1.0f)); light += DLightmap0 * lightmapContribution.x; light += DLightmap1 * lightmapContribution.y; light += DLightmap2 * lightmapContribution.z; light /= sum; return light; } float3 CalculateDLMSpec(float3 TangentNormal, float3 EyeVectorTS, float3 DLightmap0, float3 DLightmap1, float3 DLightmap2) { float3 reflectedEye = -reflect(normalize(EyeVectorTS), TangentNormal); float3 lightmapContribution = CalculateDLMContribution(reflectedEye); float3 light = 0; light += DLightmap0 * lightmapContribution.x; light += DLightmap1 * lightmapContribution.y; light += DLightmap2 * lightmapContribution.z; light /= 1.33f; // Arbitrary value :( float luminance = dot(light, float3(0.30f, 0.59f, 0.11f)); luminance = pow(luminance, 6.0f) * 7.0f; // Hardcoded test values return saturate(light * luminance); }