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

Revision 1519, 1.8 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    //OUT.Position.y = 1 - OUT.Position.y;
27    return OUT;
28}
29
30float4 ReduceTexturePS(VS_OUTPUT IN,
31                                                uniform samplerCUBE EnvironmentMapSampler : register(s0) ) : COLOR
32
33        RATE = 32;
34        CUBEMAP_SIZE = 128;
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.x, pos.y, 1);
52                if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
53
54                color += texCUBE( EnvironmentMapSampler, dir);
55    }
56  /* 
57    if (nFace == 0)     dir = float3(1, 0, 0);
58        if (nFace == 1) dir = float3(-1, 0, 0);
59        if (nFace == 2) dir = float3(0, 1, 0);
60        if (nFace == 3) dir = float3(0, -1, 0);
61        if (nFace == 4) dir = float3(0, 0, 1);
62        if (nFace == 5) dir = float3(0, 0,-1);
63               
64    return texCUBE(EnvironmentMapSampler, dir);*/
65    //return float4(IN.Position.xy,1,1);
66        return color / (RATE*RATE);     
67       
68}
Note: See TracBrowser for help on using the repository browser.