- Timestamp:
- 02/05/07 17:43:39 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl
r2054 r2095 11 11 } 12 12 13 #define MAX_LIN_ITERATIONCOUNT 30 //8014 #define MIN_LIN_ITERATIONCOUNT 20//6013 #define MAX_LIN_ITERATIONCOUNT 50 //80 14 #define MIN_LIN_ITERATIONCOUNT 15 //60 15 15 #define SECANT_ITERATIONCOUNT 1 16 #define MAX_RAY_DEPTH 216 #define MAX_RAY_DEPTH 4 17 17 18 18 void linearSearch( float3 x, float3 R, float3 N, samplerCUBE mp, … … 219 219 V = normalize(V); 220 220 221 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 222 223 float3 l; 224 float4 Irefl; 221 float F; 225 222 int depth = 0; 226 227 while(depth < MAX_RAY_DEPTH) 228 { 229 float3 R; 230 R = normalize(reflect( V, N)); 231 232 float3 Nl; 233 float4 Il; 234 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 235 if(Il.a == 0) 236 { 237 depth += 1; 238 } 239 else 240 { 241 I = Il; 242 depth = MAX_RAY_DEPTH; 243 } 244 x = l; 245 N = Nl; 246 V = R; 247 248 } 249 if(I.a == 0) 250 I = readCubeMap(CubeMap, l); 251 Irefl = I; 252 253 { 254 float4 Irefr; 255 N = normalize(IN.wNormal.xyz); 256 x = IN.wPos.xyz - lastCenter; 257 V = (IN.wPos.xyz - cameraPos); 258 depth = 0; 223 F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 259 224 260 225 while(depth < MAX_RAY_DEPTH) 261 226 { 262 227 float3 R; 263 264 float ri = refIndex; 265 228 229 float ri = refIndex; 266 230 if(dot(V,N) > 0) 267 231 { … … 270 234 } 271 235 R = refract( V, N, ri); 272 if(dot(R,R) == 0) R = reflect( V, N); 273 236 if(dot(R,R) == 0) R = reflect( V, N); 237 238 float3 Nl; 239 float4 Il; 240 float3 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 241 if(Il.a == 0) 242 { 243 //I = readCubeMap(CubeMap, l); 244 depth += 1; 245 } 246 else 247 { 248 I = Il; 249 depth = MAX_RAY_DEPTH; 250 } 251 x = l; 252 N = normalize(Nl); 253 V = R; 254 } 255 256 I *= (1.0 - F); 257 258 return I; 259 } 260 261 float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN, 262 uniform samplerCUBE DistanceMap : register(s0), 263 uniform samplerCUBE NormDistMap1 : register(s1), 264 uniform samplerCUBE NormDistMap2 : register(s2), 265 uniform samplerCUBE CubeMap : register(s3), //NOT USED 266 uniform float3 cameraPos, 267 uniform float3 lastCenter, 268 uniform float refIndex) : COLOR0 269 { 270 float4 I = 0; 271 float3 N = normalize(IN.wNormal.xyz); 272 float3 x = IN.wPos.xyz - lastCenter; 273 float3 V = (IN.wPos.xyz - cameraPos); 274 V = normalize(V); 275 276 int depth = 0; 277 float3 l; 278 279 while(depth < MAX_RAY_DEPTH) 280 { 281 float3 R; 282 283 float ri = refIndex; 284 if(dot(V,N) > 0) 285 { 286 ri = 1.0 / ri; 287 N = -N; 288 } 289 R = refract( V, N, ri); 290 if(dot(R,R) == 0) R = reflect( V, N); 291 274 292 float3 Nl; 275 293 float4 Il; … … 277 295 if(Il.a == 0) 278 296 { 279 297 depth += 1; 280 298 } 281 299 else 282 300 { 283 284 301 I = Il; 302 depth = MAX_RAY_DEPTH; 285 303 } 286 304 x = l; 287 305 N = normalize(Nl); 288 306 V = R; 289 } 290 307 } 291 308 if(I.a == 0) 292 I = readCubeMap(CubeMap, l); 293 Irefr = I; 294 295 I = Irefl * F + (1.0 - F) * Irefr; 296 } 297 return I; 298 } 299 300 float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN, 301 uniform samplerCUBE DistanceMap : register(s0), 302 uniform samplerCUBE NormDistMap1 : register(s1), 303 uniform samplerCUBE NormDistMap2 : register(s2), 304 uniform float3 cameraPos, 305 uniform float3 lastCenter, 306 uniform float refIndex) : COLOR0 307 { 308 float4 I = float4(0,0,0,0); 309 310 float3 N = normalize(IN.wNormal.xyz); 311 float3 x = IN.wPos.xyz - lastCenter; 312 float3 V = (IN.wPos.xyz - cameraPos); 313 V = normalize(V); 314 float3 l; 315 int depth = 0; 316 317 while(depth < MAX_RAY_DEPTH) 318 { 319 float3 R; 320 321 float ri = refIndex; 322 323 if(dot(V,N) > 0) 324 { 325 ri = 1.0 / ri; 326 N = -N; 327 } 328 R = refract( V, N, ri); 329 if(dot(R,R) == 0) R = reflect( V, N); 330 331 float3 Nl; 332 float4 Il; 333 l = Hit(x, R, N, NormDistMap1, NormDistMap2, DistanceMap, DistanceMap, Il, Nl); 334 if(Il.a == 0) 335 { 336 depth += 1; 337 } 338 else 339 { 340 I = Il; 341 depth = MAX_RAY_DEPTH; 342 } 343 x = l; 344 N = normalize(Nl); 345 V = R; 346 } 347 348 return float4(l,1); 349 } 309 I = 0; 310 else 311 I = float4(l,1); 312 313 return I; 314 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection_MinMax.hlsl
r2054 r2095 11 11 } 12 12 13 #define MAX_LIN_ITERATIONCOUNT 30 //8014 #define MIN_LIN_ITERATIONCOUNT 25//6013 #define MAX_LIN_ITERATIONCOUNT 80 //80 14 #define MIN_LIN_ITERATIONCOUNT 60 //60 15 15 #define SECANT_ITERATIONCOUNT 1 16 #define MAX_RAY_DEPTH 2 16 #define MAX_RAY_DEPTH 4 17 18 //#define METHOD1 17 19 18 20 void linearSearch( float3 x, float3 R, float3 N, samplerCUBE mp, … … 24 26 out float ppp) 25 27 { 28 float3 Ra = abs(R), xa = abs(x); 29 float xm = max(max(xa.x,xa.y),xa.z); 30 float Rm = max(max(Ra.x,Ra.y),Ra.z); 31 float a = xm / Rm; 26 32 27 33 int shootL = 0, shootP = 0; … … 29 35 30 36 float min = minMax.x; 31 float max = minMax.y;32 33 float min T= 0;34 float max T= 0;37 float maximum = minMax.y; 38 39 float minD = 0; 40 float maxD = 0; 35 41 { 36 42 float a = dot(R,R); 37 43 float b = 2 * dot(R, x); 38 44 float c = dot(x,x) - min * min; 39 float c2 = dot(x,x) - max * max;45 float c2 = dot(x,x) - maximum * maximum; 40 46 41 47 float dis = b*b - 4*a*c; … … 51 57 { 52 58 numvalids++; 53 if(t1 > max T)maxT= t1;54 if(t1 < min T || minT == 0)minT= t1;59 if(t1 > maxD)maxD = t1; 60 if(t1 < minD || minD == 0)minD = t1; 55 61 } 56 62 if(t2 > 0) 57 63 { 58 64 numvalids++; 59 if(t2 > max T)maxT= t2;60 if(t2 < min T || minT == 0)minT= t2;65 if(t2 > maxD)maxD = t2; 66 if(t2 < minD || minD == 0)minD = t2; 61 67 } 62 68 if(t3 > 0) 63 69 { 64 70 numvalids++; 65 if(t3 > max T)maxT= t3;66 if(t3 < min T || minT == 0)minT= t3;71 if(t3 > maxD)maxD = t3; 72 if(t3 < minD || minD == 0)minD = t3; 67 73 } 68 74 if(t4 > 0) 69 75 { 70 76 numvalids++; 71 if(t4 > max T)maxT= t4;72 if(t4 < min T || minT == 0)minT= t4;77 if(t4 > maxD)maxD = t4; 78 if(t4 < minD || minD == 0)minD = t4; 73 79 } 74 80 75 81 if(numvalids % 2 == 1) 76 min T= 0.01;82 minD = 0.01; 77 83 if(numvalids == 0) 78 min T = maxT+ 1.0;84 minD = maxD + 1.0; 79 85 } 80 86 87 #ifdef METHOD1 81 88 int iterationNeeded = MAX_LIN_ITERATIONCOUNT;// + (dot(normalize(x), R) + 1.0) / 2.0 * (MAX_LIN_ITERATIONCOUNT - MIN_LIN_ITERATIONCOUNT); 82 89 float pa; 83 float dt = (maxT - minT) / (float) iterationNeeded ; 84 dp = minT; 90 float dD = (maxD - minD) / (float) iterationNeeded ; 91 dp = minD; 92 85 93 //Linear iteration 86 while(dp <= max T&& !found)94 while(dp <= maxD && !found) 87 95 { 96 97 #else 98 float dt = length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT; 99 dt = max(dt, MIN_LIN_ITERATIONCOUNT); 100 dt = 1.0 / dt; 101 102 float minT = max(minD / (a + minD) - dt, dt); 103 float maxT = maxD / (a + maxD) + dt; 104 105 float t = minT;//dt; 106 float pa; 107 108 while(t <= maxT && !found) 109 { 110 dp = a * t / (1 - t); 111 #endif 112 88 113 p = x + R * dp; 89 114 pa = readDistanceCubeMap(mp, p); … … 107 132 else 108 133 shootL = 0; 109 110 dp += dt; 134 135 #ifdef METHOD1 136 dp += dD; 137 #else 138 t += dt; 139 #endif 111 140 } 112 141 … … 214 243 uniform float4 min1, 215 244 uniform float4 min2, 216 uniform float4 max,245 uniform float4 Max, 217 246 uniform float4 max1, 218 247 uniform float4 max2) : COLOR0 … … 220 249 float2 miniMaxi1; 221 250 miniMaxi1.x = min.a; 222 miniMaxi1.y = max.a;251 miniMaxi1.y = Max.a; 223 252 224 253 float2 miniMaxi2; … … 258 287 x = l; 259 288 N = Nl; 260 V = R; 261 289 V = R; 262 290 } 263 291 if(I.a == 0) 264 292 I = readCubeMap(CubeMap, l); 265 293 266 294 return I; … … 275 303 uniform float3 lastCenter, 276 304 uniform float refIndex, 277 //uniform float sFresnel, //0.04305 uniform float sFresnel, //0.04 278 306 uniform float4 min, 279 307 uniform float4 min1, 280 308 uniform float4 min2, 281 uniform float4 max,309 uniform float4 Max, 282 310 uniform float4 max1, 283 311 uniform float4 max2) : COLOR0 … … 285 313 float2 miniMaxi1; 286 314 miniMaxi1.x = min.a; 287 miniMaxi1.y = max.a;315 miniMaxi1.y = Max.a; 288 316 289 317 float2 miniMaxi2; … … 295 323 miniMaxi3.y = max2.a; 296 324 297 325 float4 I = float4(0,0,0,0); 298 326 299 327 float3 N = normalize(IN.wNormal.xyz); 300 328 float3 x = IN.wPos.xyz - lastCenter; 301 329 float3 V = (IN.wPos.xyz - cameraPos); 330 V = normalize(V); 302 331 303 float sFresnel = 0.04; 304 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 305 306 V = normalize(V); 307 float3 l; 308 float4 Irefl; 332 float F; 309 333 int depth = 0; 310 311 while(depth < MAX_RAY_DEPTH) 312 { 313 float3 R; 314 R = normalize(reflect( V, N)); 315 316 float3 Nl; 317 float4 Il; 318 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl); 319 if(Il.a == 0) 320 { 321 depth += 1; 322 } 323 else 324 { 325 I = Il; 326 depth = MAX_RAY_DEPTH; 327 } 328 x = l; 329 N = Nl; 330 V = R; 331 332 } 333 if(I.a == 0) 334 I = readCubeMap(CubeMap, l); 335 Irefl = I; 336 337 { 338 float4 Irefr; 339 N = normalize(IN.wNormal.xyz); 340 x = IN.wPos.xyz - lastCenter; 341 V = (IN.wPos.xyz - cameraPos); 342 V = normalize(V); 343 depth = 0; 334 F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 344 335 345 336 while(depth < MAX_RAY_DEPTH) 346 337 { 347 338 float3 R; 348 349 float ri = refIndex; 350 339 340 float ri = refIndex; 351 341 if(dot(V,N) > 0) 352 342 { … … 355 345 } 356 346 R = refract( V, N, ri); 357 if(dot(R,R) == 0) R = reflect( V, N); 358 347 if(dot(R,R) == 0) R = reflect( V, N); 348 359 349 float3 Nl; 360 350 float4 Il; 361 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl);351 float3 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl); 362 352 if(Il.a == 0) 363 353 { 354 //I = readCubeMap(CubeMap, l); 364 355 depth += 1; 365 356 } … … 372 363 N = normalize(Nl); 373 364 V = R; 374 } 375 376 if(I.a == 0) 377 I = readCubeMap(CubeMap, l); 378 Irefr = I; 365 } 379 366 380 I = Irefl * F + (1.0 - F) * Irefr;381 }382 367 I *= (1.0 - F); 368 369 return I; 383 370 } 384 371 -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflectionMinMax/GTPMultipleReflectionMinMax.material
r2054 r2095 35 35 get_minmax true 36 36 min_var_name min 37 max_var_name max37 max_var_name Max 38 38 } 39 39 RenderTechnique ColorCubeMap
Note: See TracChangeset
for help on using the changeset viewer.