source: GTP/trunk/App/Demos/Illum/Shark3D/version164x12u/IllumDemo/bin/res/levelutil/shader/prog/d3d9_hlsl/gtp_diffuse_d3d9_hlsl_ps3x0.s3d_shadercode_run @ 2196

Revision 2196, 6.9 KB checked in by szirmay, 17 years ago (diff)
Line 
1///////////////////////////////////////////////////////////////////////////////
2//
3//      ##  ######
4//       ######  ###
5//  ## ###############        Shark 3D Engine (www.shark3d.com)
6//   ########## # # #
7//    ########                Copyright (c) 1996-2006 Spinor GmbH.
8//   ######### # # #          All rights reserved.
9//  ##   ##########
10//      ##
11//
12///////////////////////////////////////////////////////////////////////////////
13
14
15#define Poly2Point 1
16
17struct PS_INPUT
18{
19float3 normalWorld  : TEXCOORD1;
20float3 posWorld : TEXCOORD0;
21};
22
23sampler colorSamp: register(s0);
24sampler distanceSamp: register(s1);
25
26///////////////////////////////////////////////////////////////////////////////
27// Pixelshader
28// Profile: 3x0
29
30#ifdef Poly2Point
31
32float4 GetContibution(float3 L, float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, samplerCUBE cubemap)
33{
34float d;
35d = texCUBE(cubemap, L1).r;
36L1 = d * normalize(L1);
37d = texCUBE(cubemap, L2).r;
38L2 = d * normalize(L2);
39d = texCUBE(cubemap, L3).r;
40L3 = d * normalize(L3);
41d = texCUBE(cubemap, L4).r;
42L4 = d * normalize(L4);
43
44
45    float3 r1 = normalize(L1 - pos);   
46    float3 r2 = normalize(L2 - pos);
47    float3 r3 = normalize(L3 - pos);
48    float3 r4 = normalize(L4 - pos);
49 
50  float3 crossP = cross(r1, r2);
51  float r = length(crossP);
52  float dd = dot(r1,r2);
53  float tri1 = acos(dd) * dot(crossP/r, N);
54 
55  crossP = cross(r2, r3);
56  r = length(crossP);
57  dd = dot(r1,r2);
58  float tri2 = acos(dd) * dot(crossP/r, N);
59 
60  crossP = cross(r3, r4);
61  r = length(crossP);
62  dd = dot(r1,r2);
63  float tri3 = acos(dd) * dot(crossP/r, N);
64 
65  crossP = cross(r4, r1);
66  r = length(crossP);
67  dd = dot(r1,r2);
68  float tri4= acos(dd) * dot(crossP/r, N);
69 
70 
71   return max(tri1 + tri2 + tri3 + tri4, 0);
72}
73
74float4 main(PS_INPUT input): COLOR0
75{
76    float M = 4;
77
78    float3 N = normalize( input.normalWorld );
79    float3 pos = input.posWorld;
80   
81    //return texCUBE(colorSamp, N);
82     
83    float4 I = 0;
84    float3 L1, L2, L3, L4, L;
85    float4 Le;
86    float width = 1.0 / M;
87    float width2 = width * 2;
88    float d;
89
90    for (float x = 1; x < M; x++)
91 for (float y = 1; y < M; y++)
92 {
93    float2 p, tpos;
94    tpos.x = x * width;
95    tpos.y = y * width;
96   
97    p = tpos.xy;   
98    p = 2.0 * p - 1.0; //-1..1
99           
100L1 = float3(p.x - width, p.y - width, 1);
101L2 = float3(p.x + width, p.y - width, 1);
102L3 = float3(p.x + width, p.y + width, 1);
103L4 = float3(p.x - width, p.y + width, 1);
104L = float3(p.x, p.y, 1);
105Le = float4(texCUBE(colorSamp, L).rgb, 1);
106
107I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
108
109}
110
111for (float x = 1; x < M; x++)
112 for (float y = 1; y < M; y++)
113 {
114float2 p, tpos;
115    tpos.x = x * width;// 0..1
116    tpos.y = y * width;// 0..1
117   
118    p = tpos.xy;   
119    p = 2.0 * p - 1.0; //-1..1
120           
121L4 = float3(p.x - width, p.y - width, -1);
122L3 = float3(p.x + width, p.y - width, -1);
123L2 = float3(p.x + width, p.y + width, -1);
124L1 = float3(p.x - width, p.y + width, -1);
125L = float3(p.x, p.y, -1);
126Le = float4(texCUBE(colorSamp, L).rgb, 1);
127
128I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
129 }
130 
131for (float x = 1; x < M; x++)
132 for (float y = 1; y < M; y++)
133 {
134float2 p, tpos;
135    tpos.x = x * width;// 0..1
136    tpos.y = y * width;// 0..1
137   
138    p = tpos.xy;   
139    p = 2.0 * p - 1.0; //-1..1
140           
141L4 = float3(p.x - width, 1, p.y - width);
142L3 = float3(p.x + width, 1, p.y - width);
143L2 = float3(p.x + width, 1, p.y + width);
144L1 = float3(p.x - width, 1, p.y + width);
145L = float3(p.x, 1, p.y);
146Le = float4(texCUBE(colorSamp, L).rgb, 1);
147
148I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
149 }
150 
151for (float x = 1; x < M; x++)
152 for (float y = 1; y < M; y++)
153 {
154float2 p, tpos;
155    tpos.x = x * width;// 0..1
156    tpos.y = y * width;// 0..1
157   
158    p = tpos.xy;   
159    p = 2.0 * p - 1.0; //-1..1
160           
161L1 = float3(p.x - width, -1, p.y - width);
162L2 = float3(p.x + width, -1, p.y - width);
163L3 = float3(p.x + width, -1, p.y + width);
164L4 = float3(p.x - width, -1, p.y + width);
165L = float3(p.x, -1, p.y);
166Le = float4(texCUBE(colorSamp, L).rgb, 1);
167
168I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
169 }
170 
171 for (float x = 1; x < M; x++)
172 for (float y = 1; y < M; y++)
173{
174float2 p, tpos;
175    tpos.x = x * width;// 0..1
176    tpos.y = y * width;// 0..1
177   
178    p = tpos.xy;   
179    p = 2.0 * p - 1.0; //-1..1
180           
181L1 = float3(1, p.x - width, p.y - width);
182L2 = float3(1, p.x + width, p.y - width);
183L3 = float3(1, p.x + width, p.y + width);
184L4 = float3(1, p.x - width, p.y + width);
185L = float3(1, p.x, p.y);
186Le = float4(texCUBE(colorSamp, L).rgb, 1);
187
188I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
189}
190 
191for (float x = 1; x < M; x++)
192 for (float y = 1; y < M; y++)
193 {
194float2 p, tpos;
195    tpos.x = x * width;// 0..1
196    tpos.y = y * width;// 0..1
197   
198    p = tpos.xy;   
199    p = 2.0 * p - 1.0; //-1..1
200           
201L4 = float3(-1, p.x - width, p.y - width);
202L3 = float3(-1, p.x + width, p.y - width);
203L2 = float3(-1, p.x + width, p.y + width);
204L1 = float3(-1, p.x - width, p.y + width);
205L = float3(-1, p.x, p.y);
206Le = float4(texCUBE(colorSamp, L).rgb, 1);
207
208I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, distanceSamp);
209 }
210 float kd = 0.5;
211return kd * I;
212}
213
214
215
216#else
217
218float4 P2PContr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap, samplerCUBE distmap)
219{
220Nl = normalize(Nl);
221L = normalize(L);
222float4 Le = texCUBE(cubemap, L);
223float d = texCUBE(distmap, L).r;
224float3 Lpos = L * d;
225float3 Ldir = Lpos - pos;
226float dist = 4 * dot(Ldir, Ldir);
227Ldir = normalize(Ldir);
228
229return Le * (max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir)) / dist;
230}
231
232float4 main(PS_INPUT input): COLOR0
233{
234    float M = 4.0;
235
236    float3 N = normalize( input.normalWorld );
237    float3 pos = input.posWorld;
238
239  //  return texCUBE(distanceSamp, N).r;
240   
241//return float4(N,1);
242
243    float4 I = 0;
244    float3 L;
245    float4 Le;
246    float width = 1.0 / M;
247    float d;
248
249    float kd = 3.0;
250
251    for (float x = 0.5; x < M; x++)
252 for (float y = 0.5; y < M; y++)
253 {
254    float2 p, tpos;
255    tpos.x = x * width;
256    tpos.y = y * width;
257   
258    p = tpos.xy;   
259    p = 2.0 * p - 1.0; //-1..1
260           
261I += P2PContr(N, float3(0,0,-1), pos, float3(p.x, p.y, 1), colorSamp, distanceSamp);
262I += P2PContr(N, float3(0,0,1), pos, float3(-p.x, p.y, -1), colorSamp, distanceSamp);
263I += P2PContr(N, float3(-1,0,0), pos, float3(1, p.y, -p.x), colorSamp, distanceSamp);
264I += P2PContr(N, float3(1,0,0), pos, float3(-1, p.y, p.x), colorSamp, distanceSamp);
265I += P2PContr(N, float3(0,-1,0), pos, float3(p.x, 1, -p.y), colorSamp, distanceSamp);
266I += P2PContr(N, float3(0,1,0), pos, float3(p.x, -1, p.y), colorSamp, distanceSamp);
267}
268
269return kd * I;
270
271}
272#endif
273///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.