/////////////////////////////////////////////////////////////////////////////// // // ## ###### // ###### ### // ## ############### Shark 3D Engine (www.shark3d.com) // ########## # # # // ######## Copyright (c) 1996-2006 Spinor GmbH. // ######### # # # All rights reserved. // ## ########## // ## // /////////////////////////////////////////////////////////////////////////////// #define Poly2Point 1 struct PS_INPUT { float3 normalWorld : TEXCOORD1; float3 posWorld : TEXCOORD0; }; sampler colorSamp: register(s0); sampler distanceSamp: register(s1); /////////////////////////////////////////////////////////////////////////////// // Pixelshader // Profile: 3x0 #ifdef Poly2Point float4 GetContibution(float3 L, float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, samplerCUBE cubemap) { float d; d = texCUBE(cubemap, L1).r; L1 = d * normalize(L1); d = texCUBE(cubemap, L2).r; L2 = d * normalize(L2); d = texCUBE(cubemap, L3).r; L3 = d * normalize(L3); d = texCUBE(cubemap, L4).r; L4 = d * normalize(L4); float3 r1 = normalize(L1 - pos); float3 r2 = normalize(L2 - pos); float3 r3 = normalize(L3 - pos); float3 r4 = normalize(L4 - pos); float3 crossP = cross(r1, r2); float r = length(crossP); float dd = dot(r1,r2); float tri1 = acos(dd) * dot(crossP/r, N); crossP = cross(r2, r3); r = length(crossP); dd = dot(r1,r2); float tri2 = acos(dd) * dot(crossP/r, N); crossP = cross(r3, r4); r = length(crossP); dd = dot(r1,r2); float tri3 = acos(dd) * dot(crossP/r, N); crossP = cross(r4, r1); r = length(crossP); dd = dot(r1,r2); float tri4= acos(dd) * dot(crossP/r, N); return max(tri1 + tri2 + tri3 + tri4, 0); } float4 main(PS_INPUT input): COLOR0 { float M = 4; float3 N = normalize( input.normalWorld ); float3 pos = input.posWorld; //return texCUBE(colorSamp, N); float4 I = 0; float3 L1, L2, L3, L4, L; float4 Le; float width = 1.0 / M; float width2 = width * 2; float d; for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width; tpos.y = y * width; p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L1 = float3(p.x - width, p.y - width, 1); L2 = float3(p.x + width, p.y - width, 1); L3 = float3(p.x + width, p.y + width, 1); L4 = float3(p.x - width, p.y + width, 1); L = float3(p.x, p.y, 1); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width;// 0..1 tpos.y = y * width;// 0..1 p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L4 = float3(p.x - width, p.y - width, -1); L3 = float3(p.x + width, p.y - width, -1); L2 = float3(p.x + width, p.y + width, -1); L1 = float3(p.x - width, p.y + width, -1); L = float3(p.x, p.y, -1); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width;// 0..1 tpos.y = y * width;// 0..1 p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L4 = float3(p.x - width, 1, p.y - width); L3 = float3(p.x + width, 1, p.y - width); L2 = float3(p.x + width, 1, p.y + width); L1 = float3(p.x - width, 1, p.y + width); L = float3(p.x, 1, p.y); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width;// 0..1 tpos.y = y * width;// 0..1 p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L1 = float3(p.x - width, -1, p.y - width); L2 = float3(p.x + width, -1, p.y - width); L3 = float3(p.x + width, -1, p.y + width); L4 = float3(p.x - width, -1, p.y + width); L = float3(p.x, -1, p.y); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width;// 0..1 tpos.y = y * width;// 0..1 p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L1 = float3(1, p.x - width, p.y - width); L2 = float3(1, p.x + width, p.y - width); L3 = float3(1, p.x + width, p.y + width); L4 = float3(1, p.x - width, p.y + width); L = float3(1, p.x, p.y); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } for (float x = 1; x < M; x++) for (float y = 1; y < M; y++) { float2 p, tpos; tpos.x = x * width;// 0..1 tpos.y = y * width;// 0..1 p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 L4 = float3(-1, p.x - width, p.y - width); L3 = float3(-1, p.x + width, p.y - width); L2 = float3(-1, p.x + width, p.y + width); L1 = float3(-1, p.x - width, p.y + width); L = float3(-1, p.x, p.y); Le = float4(texCUBE(colorSamp, L).rgb, 1); I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp); } float kd = 0.5; return kd * I; } #else float4 P2PContr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap, samplerCUBE distmap) { Nl = normalize(Nl); L = normalize(L); float4 Le = texCUBE(cubemap, L); float d = texCUBE(distmap, L).r; float3 Lpos = L * d; float3 Ldir = Lpos - pos; float dist = 4 * dot(Ldir, Ldir); Ldir = normalize(Ldir); return Le * (max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir)) / dist; } float4 main(PS_INPUT input): COLOR0 { float M = 4.0; float3 N = normalize( input.normalWorld ); float3 pos = input.posWorld; // return texCUBE(distanceSamp, N).r; //return float4(N,1); float4 I = 0; float3 L; float4 Le; float width = 1.0 / M; float d; float kd = 3.0; for (float x = 0.5; x < M; x++) for (float y = 0.5; y < M; y++) { float2 p, tpos; tpos.x = x * width; tpos.y = y * width; p = tpos.xy; p = 2.0 * p - 1.0; //-1..1 I += P2PContr(N, float3(0,0,-1), pos, float3(p.x, p.y, 1), colorSamp, distanceSamp); I += P2PContr(N, float3(0,0,1), pos, float3(-p.x, p.y, -1), colorSamp, distanceSamp); I += P2PContr(N, float3(-1,0,0), pos, float3(1, p.y, -p.x), colorSamp, distanceSamp); I += P2PContr(N, float3(1,0,0), pos, float3(-1, p.y, p.x), colorSamp, distanceSamp); I += P2PContr(N, float3(0,-1,0), pos, float3(p.x, 1, -p.y), colorSamp, distanceSamp); I += P2PContr(N, float3(0,1,0), pos, float3(p.x, -1, p.y), colorSamp, distanceSamp); } return kd * I; } #endif ///////////////////////////////////////////////////////////////////////////////