Changeset 2095 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl
- Timestamp:
- 02/05/07 17:43:39 (17 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.