1 |
|
---|
2 | int CUBEMAP_SIZE = 256;
|
---|
3 | int RATE = 32;
|
---|
4 | int nFace;
|
---|
5 |
|
---|
6 | float4 readCubeMap(samplerCUBE cm, float3 coord)
|
---|
7 | {
|
---|
8 | float4 color = texCUBE( cm, float3(coord.xy, coord.z) );
|
---|
9 | return color;
|
---|
10 | }
|
---|
11 |
|
---|
12 |
|
---|
13 | struct VS_INPUT { // vertex shader input
|
---|
14 | float4 Position : POSITION;
|
---|
15 | };
|
---|
16 |
|
---|
17 | struct VS_OUTPUT { // vertex shader output, pixel shader input
|
---|
18 | float4 hPosition : POSITION;
|
---|
19 | float2 Position : TEXCOORD0;
|
---|
20 | };
|
---|
21 |
|
---|
22 | VS_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 |
|
---|
29 | float4 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 | } |
---|