source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreGames/CarGame/Media/materials/programs/GameTools_ReduceCubeMap.hlsl @ 3255

Revision 3255, 1.5 KB checked in by szirmay, 15 years ago (diff)
Line 
1
2int CUBEMAP_SIZE = 256;
3int RATE = 32;
4int nFace;
5
6float4 readCubeMap(samplerCUBE cm, float3 coord)               
7{
8        float4 color = texCUBE( cm, float3(coord.xy, coord.z) );
9        return color;
10}
11
12
13struct VS_INPUT {           // vertex shader input
14    float4 Position : POSITION;
15};
16
17struct VS_OUTPUT {          // vertex shader output, pixel shader input
18    float4 hPosition : POSITION;
19    float2 Position  : TEXCOORD0;
20};
21
22VS_OUTPUT ReduceTextureVS(VS_INPUT IN) {
23        VS_OUTPUT OUT;
24    OUT.hPosition = IN.Position;
25    OUT.Position = IN.Position.xy;
26    return OUT;
27}
28
29float4 ReduceTexturePS(VS_OUTPUT IN,
30                                                uniform samplerCUBE EnvironmentMapSampler : register(s0) ) : COLOR
31
32        RATE = 32;
33        CUBEMAP_SIZE = 256;
34       
35    float4 color = 0;
36    // color += texCUBE( EnvironmentMapSampler, Tex );
37    float3 dir;
38 
39   for (int i = 0; i < RATE; i++)
40     for (int j = 0; j < RATE; j++)
41    {
42                float2 pos;
43                pos.x = IN.Position.x + (2*i + 1)/(float)CUBEMAP_SIZE;
44                pos.y = IN.Position.y - (2*j + 1)/(float)CUBEMAP_SIZE;  // y=-u
45
46                // "scrambling"
47                if (nFace == 0) dir = float3(1, pos.y, -pos.x);
48                if (nFace == 1) dir = float3(-1, pos.y, pos.x);
49                if (nFace == 2) dir = float3(pos.x, 1, -pos.y);
50                if (nFace == 3) dir = float3(pos.x, -1, pos.y);
51                if (nFace == 4) dir = float3(pos.xy, 1);
52                if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
53
54                color += readCubeMap( EnvironmentMapSampler, dir);
55    }
56    //return float4(IN.Position.xy,1,1);
57        return color / (RATE*RATE);     
58       
59}
Note: See TracBrowser for help on using the repository browser.