[3255] | 1 | #define SPOT_ANGLE 2.093
|
---|
| 2 | #define SPOT_FALLOFF 1
|
---|
| 3 | #define SHADOW_COLOR float4(0.2,0.2,0.2,1.0)
|
---|
| 4 | #define SHADOW_BIAS_POINT 0.0025
|
---|
| 5 | #define SHADOW_EPSILON_POINT 0.000001
|
---|
| 6 |
|
---|
| 7 | float4 Illumination(float3 N, float3 L, float3 V, float4 lightColor, float4 lightRange, float4 diffuseColor, float specularity, float4 specularColor)
|
---|
| 8 | {
|
---|
| 9 | // Blinn lighting
|
---|
| 10 | float d = length(L);
|
---|
| 11 | L = normalize(L);
|
---|
| 12 | float3 H = normalize(L + V);
|
---|
| 13 | float4 Lighting = lit(dot(N, L), dot(N, H), specularity);
|
---|
| 14 | Lighting = saturate(Lighting);
|
---|
| 15 |
|
---|
| 16 | return lightColor * (Lighting.y * diffuseColor + Lighting.z * specularColor) //color
|
---|
| 17 | / (lightRange.y + d * lightRange.z + d * d * lightRange.w) //attenuation
|
---|
| 18 | ;
|
---|
| 19 |
|
---|
| 20 | //return lightColor * (Lighting.y * diffuseColor);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | float3 NormalMap(float3 tangent, float3 binormal, float3 normal, float2 texCoord, sampler2D normalMap)
|
---|
| 24 | {
|
---|
| 25 | normal = normalize(normal);
|
---|
| 26 | //return normal;
|
---|
| 27 | float3 mNormal;
|
---|
| 28 | float3 tNormal = tex2D(normalMap, texCoord).rgb;
|
---|
| 29 | //tNormal = float3(0.5,0.5,1.0);
|
---|
| 30 |
|
---|
| 31 | tangent = normalize(tangent);
|
---|
| 32 | binormal = normalize(binormal);
|
---|
| 33 | float3x3 TangentToModel = float3x3(tangent, binormal, normal );
|
---|
| 34 |
|
---|
| 35 | tNormal.xy = (tNormal.xy *2.0) - 1.0;
|
---|
| 36 | mNormal = normalize( mul( tNormal, TangentToModel ) );
|
---|
| 37 |
|
---|
| 38 | return mNormal;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | float shadowPoint(samplerCUBE shadowMap, float3 lightCPos, float lightFarPlane)
|
---|
| 43 | {
|
---|
| 44 | float light = 1;
|
---|
| 45 |
|
---|
| 46 | float dist = length(lightCPos) / lightFarPlane;
|
---|
| 47 | float4 storedDist = texCUBE(shadowMap, float3(lightCPos.xy, -lightCPos.z));
|
---|
| 48 | dist -= SHADOW_BIAS_POINT;
|
---|
| 49 | float lit_factor = (dist <= storedDist.r);
|
---|
| 50 |
|
---|
| 51 | float M1 = storedDist.r;
|
---|
| 52 | float M2 = storedDist.g;
|
---|
| 53 | float v2 = min(max(M2 - M1 * M1, 0.0) + SHADOW_EPSILON_POINT, 1.0);
|
---|
| 54 | float m_d = M1 - dist;
|
---|
| 55 | float pmax = v2 / (v2 + m_d * m_d);
|
---|
| 56 |
|
---|
| 57 | light = max(lit_factor, pmax);
|
---|
| 58 |
|
---|
| 59 | return (SHADOW_COLOR + (1 - SHADOW_COLOR) * light);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | uniform float4 prmAtlasTilesHalfPixel;
|
---|
| 63 | uniform float allClusterCount;
|
---|
| 64 | uniform float clusterCount;
|
---|
| 65 |
|
---|
| 66 | float4 PathMapIndirect(sampler2D PMTex, sampler2D weightIndexTex, sampler2D weightTex, float2 texAtlas)
|
---|
| 67 | {
|
---|
| 68 | int2 prmAtlasTiles = prmAtlasTilesHalfPixel.xy;
|
---|
| 69 | float2 atlasHalfPixel = prmAtlasTilesHalfPixel.zw;
|
---|
| 70 |
|
---|
| 71 | float3 col = 0;
|
---|
| 72 | for(int iCluster = 0; iCluster < 8; iCluster++)
|
---|
| 73 | {
|
---|
| 74 | float2 prmTexPos = float2(
|
---|
| 75 | (texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
|
---|
| 76 | 1.0 - (texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y);// + atlasHalfPixel;
|
---|
| 77 |
|
---|
| 78 | float weightIndex = tex2D(weightIndexTex, float2(((float)iCluster + 0.5) / clusterCount, 0.5)).r;
|
---|
| 79 | float3 weight = tex2D(weightTex, float2((weightIndex + 0.5)/allClusterCount, 0.5)).rgb;
|
---|
| 80 | float3 val = tex2D(PMTex, prmTexPos).xyz;
|
---|
| 81 | // if(length(val - float3(1,1,1))== 0)
|
---|
| 82 | // val = 0;
|
---|
| 83 | col += val.xyz * weight;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | return float4(col,1);
|
---|
| 87 | } |
---|