#define SPOT_ANGLE 2.093 #define SPOT_FALLOFF 1 #define SHADOW_COLOR float4(0.3,0.3,0.3,1.0) #define SHADOW_BIAS_POINT 0.0001 #define SHADOW_EPSILON_POINT 0.0001 float4 Illumination(float3 N, float3 L, float3 V, float4 lightColor, float4 lightRange, float4 diffuseColor, float specularity, float4 specularColor) { // Blinn lighting float d = length(L); L = normalize(L); float3 H = normalize(L + V); float4 Lighting = lit(dot(N, L), dot(N, H), specularity); Lighting = saturate(Lighting); return lightColor * (Lighting.y * diffuseColor + Lighting.z * specularColor) //color / (lightRange.y + d * lightRange.z + d * d * lightRange.w) //attenuation ; //return lightColor * (Lighting.y * diffuseColor); } float3 NormalMap(float3 tangent, float3 binormal, float3 normal, float2 texCoord, sampler2D normalMap) { normal = normalize(normal); //return normal; float3 mNormal; float3 tNormal = tex2D(normalMap, texCoord).rgb; //tNormal = float3(0.5,0.5,1.0); tangent = normalize(tangent); binormal = normalize(binormal); float3x3 TangentToModel = float3x3(tangent, binormal, normal ); tNormal.xy = (tNormal.xy *2.0) - 1.0; mNormal = normalize( mul( tNormal, TangentToModel ) ); return mNormal; } float shadowPoint(samplerCUBE shadowMap, float3 lightCPos, float lightFarPlane) { float light = 1; float dist = length(lightCPos) / lightFarPlane; float4 storedDist = texCUBE(shadowMap, float3(lightCPos.xy, -lightCPos.z)); dist -= SHADOW_BIAS_POINT; float lit_factor = (dist <= storedDist.r); float M1 = storedDist.r; float M2 = storedDist.g; float v2 = min(max(M2 - M1 * M1, 0.0) + SHADOW_EPSILON_POINT, 1.0); float m_d = M1 - dist; float pmax = v2 / (v2 + m_d * m_d); light = max(lit_factor, pmax); return (SHADOW_COLOR + (1 - SHADOW_COLOR) * light); } uniform float4 prmAtlasTilesHalfPixel; uniform float allClusterCount; uniform float clusterCount; float4 PathMapIndirect(sampler2D PMTex, sampler2D weightIndexTex, sampler2D weightTex, float2 texAtlas) { int2 prmAtlasTiles = prmAtlasTilesHalfPixel.xy; float2 atlasHalfPixel = prmAtlasTilesHalfPixel.zw; float3 col = 0; for(int iCluster = 0; iCluster < 8; iCluster++) { float2 prmTexPos = float2( (texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x, 1.0 - (texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y);// + atlasHalfPixel; float weightIndex = tex2D(weightIndexTex, float2(((float)iCluster + 0.5) / clusterCount, 0.5)).r; float3 weight = tex2D(weightTex, float2((weightIndex + 0.5)/allClusterCount, 0.5)).rgb; float3 val = tex2D(PMTex, prmTexPos).xyz; // if(length(val - float3(1,1,1))== 0) // val = 0; col += val.xyz * weight; } return float4(col,1); }