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

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