[777] | 1 |
|
---|
| 2 | int CUBEMAP_SIZE = 128;
|
---|
| 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;
|
---|
[1519] | 26 | //OUT.Position.y = 1 - OUT.Position.y;
|
---|
[777] | 27 | return OUT;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | float4 ReduceTexturePS(VS_OUTPUT IN,
|
---|
| 31 | uniform samplerCUBE EnvironmentMapSampler : register(s0) ) : COLOR
|
---|
| 32 | {
|
---|
| 33 | RATE = 32;
|
---|
[1519] | 34 | CUBEMAP_SIZE = 128;
|
---|
[777] | 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);
|
---|
[1519] | 51 | if (nFace == 4) dir = float3(pos.x, pos.y, 1);
|
---|
[777] | 52 | if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
|
---|
| 53 |
|
---|
[1519] | 54 | color += texCUBE( EnvironmentMapSampler, dir);
|
---|
[777] | 55 | }
|
---|
[1519] | 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);*/
|
---|
[777] | 65 | //return float4(IN.Position.xy,1,1);
|
---|
| 66 | return color / (RATE*RATE);
|
---|
| 67 |
|
---|
| 68 | } |
---|