source: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_ReduceCubeMap.hlsl @ 777

Revision 777, 1.5 KB checked in by szirmay, 18 years ago (diff)
Line 
1
2int CUBEMAP_SIZE = 128;
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    float4 color = 0;
34    // color += texCUBE( EnvironmentMapSampler, Tex );
35    float3 dir;
36 
37   for (int i = 0; i < RATE; i++)
38     for (int j = 0; j < RATE; j++)
39    {
40                float2 pos;
41                pos.x = IN.Position.x + (2*i + 1)/(float)CUBEMAP_SIZE;
42                pos.y = IN.Position.y - (2*j + 1)/(float)CUBEMAP_SIZE;  // y=-u
43
44                // "scrambling"
45                if (nFace == 0) dir = float3(1, pos.y, -pos.x);
46                if (nFace == 1) dir = float3(-1, pos.y, pos.x);
47                if (nFace == 2) dir = float3(pos.x, 1, -pos.y);
48                if (nFace == 3) dir = float3(pos.x, -1, pos.y);
49                if (nFace == 4) dir = float3(pos.xy, 1);
50                if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
51
52                color += readCubeMap( EnvironmentMapSampler, dir);
53    }
54    //return float4(IN.Position.xy,1,1);
55        return color / (RATE*RATE);     
56       
57}
Note: See TracBrowser for help on using the repository browser.