source: GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/illum.hlsl @ 2398

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