Changeset 2271 for GTP/trunk/App
- Timestamp:
- 03/20/07 19:10:47 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials
- Files:
-
- 1 added
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl
r2241 r2271 11 11 } 12 12 13 14 15 #define MAX_LIN_ITERATIONCOUNT 50 //80 16 #define MIN_LIN_ITERATIONCOUNT 30 //60 13 #define MAX_LIN_ITERATIONCOUNT 100 //80 14 #define MIN_LIN_ITERATIONCOUNT 80 //60 17 15 #define SECANT_ITERATIONCOUNT 1 18 #define MAX_RAY_DEPTH 4 19 20 uniform samplerCUBE mp3Color : register(s0); 21 uniform samplerCUBE mp3Dist : register(s1); 22 uniform samplerCUBE mp1 : register(s2); 23 uniform samplerCUBE mp2 : register(s3); 24 25 26 void linearSearch( float3 x, float3 R, samplerCUBE mp, 16 #define MAX_RAY_DEPTH 2 17 18 void linearSearch( float3 x, float3 R, float3 N, samplerCUBE mp, 27 19 out float3 p, 28 20 out float dl, … … 30 22 out float llp, 31 23 out float ppp) 32 { 33 p = 1; 34 35 float3 Ra = abs(R), xa = abs(x); 36 float a = max(max(xa.x, xa.y), xa.z) / max(max(Ra.x, Ra.y), Ra.z); 37 bool undershoot = false, overshoot = false; 38 39 float dt = length(x / max(max(xa.x, xa.y), xa.z) - R / max(max(Ra.x, Ra.y), Ra.z)) * MAX_LIN_ITERATIONCOUNT; 40 dt = max(dt, MIN_LIN_ITERATIONCOUNT); 41 dt = 1.0 / dt; 42 43 float t = 0.01; 44 while( t < 1 && !(overshoot && undershoot) ) { // iteration 45 float dr = a * t / (1 - t); // ray parameter corresponding to t 46 float3 r = x + R * dr; // point on the ray 47 float ra = readDistanceCubeMap(mp, r); // |p'|: distance direction of p 48 49 50 if (ra > 0) { // valid texel, i.e. anything is visible 51 float rrp = length(r)/ra; //|r|/|r'| 52 if (rrp < 1) { // undershooting 53 dl = dr; // store last undershooting as l 54 llp = rrp; 55 undershoot = true; 56 } else { 57 dp = dr; // store last overshooting as p 58 ppp = rrp; 59 overshoot = true;} 60 } else { // nothing is visible: restart search 61 undershoot = false; 62 overshoot = false; 63 } 64 t += dt; // next texel 65 } 66 67 68 if(!(overshoot && undershoot)) 69 p = float3(0,0,0); 24 { 25 float3 Ra = abs(R), xa = abs(x); 26 float xm = max(max(xa.x,xa.y),xa.z); 27 float Rm = max(max(Ra.x,Ra.y),Ra.z); 28 float a = xm / Rm; 29 30 int shootL = 0, shootP = 0; 31 bool found = false; 32 33 float dt = length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT; 34 dt = max(dt, MIN_LIN_ITERATIONCOUNT); 35 dt = 1.0 / dt; 36 37 float t = 0.01;//dt; 38 float pa; 39 40 //Linear iteration 41 while(t <= 1.0 && !found) 42 { 43 dp = a * t / (1 - t); 44 p = x + R * dp; 45 pa = readDistanceCubeMap(mp, p); 46 47 if(pa > 0) 48 { 49 ppp = length(p) / pa; 50 if(ppp < 1) 51 shootP = -1; 52 else 53 shootP = 1; 54 if(shootL * shootP == -1) 55 found = true; 56 else 57 { 58 shootL = shootP; 59 dl = dp; 60 llp = ppp; 61 } 62 } 63 else 64 shootL = 0; 65 66 t += dt; 67 } 68 69 if(!found) 70 p = float3(0,0,0); 70 71 } 71 72 … … 76 77 float llp, 77 78 float ppp, 78 inout float3 p)79 out float3 p) 79 80 { 80 81 for(int i= 0; i < SECANT_ITERATIONCOUNT; i++) … … 97 98 } 98 99 99 float3 Hit(float3 x, float3 R, out float4 Il, out float3 Nl) 100 float3 Hit(float3 x, float3 R, float3 N, 101 samplerCUBE mp1, 102 samplerCUBE mp2, 103 samplerCUBE mp3Color, 104 samplerCUBE mp3Dist, 105 out float4 Il, out float3 Nl) 100 106 { 101 107 float dl1 = 0, dp1, llp1, ppp1; 102 108 float3 p1; 103 linearSearch(x, R, mp1, p1, dl1, dp1, llp1, ppp1);109 linearSearch(x, R, N, mp1, p1, dl1, dp1, llp1, ppp1); 104 110 float dl2 = 0, dp2, llp2, ppp2; 105 111 float3 p2; 106 linearSearch(x, R, mp2, p2, dl2, dp2, llp2, ppp2);112 linearSearch(x, R, N, mp2, p2, dl2, dp2, llp2, ppp2); 107 113 108 114 bool valid1 = dot(p1,p1) != 0; … … 114 120 if(!valid1 && ! valid2) 115 121 { 116 linearSearch(x, R, mp3Dist, p, dl, dp, llp, ppp);122 linearSearch(x, R, N, mp3Dist, p, dl, dp, llp, ppp); 117 123 Il.a = 1; 118 124 secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p); … … 139 145 } 140 146 141 142 143 void SpecularReflectionVS(144 in float4 Pos : POSITION, // modeling space145 in float4 Norm : NORMAL, // normal vector146 out float4 hPos : POSITION, // clipping space147 out float3 x : TEXCOORD1, // cube map space148 out float3 N : TEXCOORD2, // normal149 out float3 V : TEXCOORD3, // view150 uniform float4x4 WorldViewProj,151 uniform float4x4 World,152 uniform float4x4 WorldIT,153 uniform float3 eyePos // eye position154 ) {155 hPos = mul(Pos, WorldViewProj);156 x = mul(Pos, World).xyz;157 N = mul(Norm, WorldIT).xyz;158 V = x - eyePos;159 }160 161 float4 SingleReflectionPS(162 float3 x : TEXCOORD1, // cube map space163 float3 N : TEXCOORD2, // normal164 float3 V : TEXCOORD3, // view165 uniform float Fp0,166 uniform float3 lastCenter // cube map center position167 ) : COLOR168 {169 x -= lastCenter;170 V = normalize(V); N = normalize(N);171 float3 R = reflect(V, N); // reflection dir.172 float3 Nl; // normal vector at the hit point173 float3 Il; // radiance at the hit point174 // ray hit l, radiance Il, normal Nl175 float3 l = Hit(x, R, Il, Nl);176 177 // Fresnel reflection178 float3 F = Fp0 + pow(1-dot(N, -V), 5) * (1 - Fp0);179 return float4(F * Il, 1);180 }181 182 float4 MultipleReflectionPS(183 float3 x : TEXCOORD1, // shaded point in Cube map space184 float3 N : TEXCOORD2, // normal vector185 float3 V : TEXCOORD3, // view direction186 uniform float3 Fp0, // Fresnel at perpendicular direction187 uniform float3 refIndex, // index of refraction188 uniform float3 lastCenter189 ) : COLOR190 {191 x-= lastCenter;192 V = normalize(V); N = normalize(N);193 194 float3 I = float3(1, 1, 1);// radiance of the path195 float3 Fp = Fp0; // Fresnel at 90 degrees at first hit196 float n = refIndex; // index of refraction of the first hit197 int depth = 0; // length of the path198 while (depth < MAX_RAY_DEPTH) {199 float3 R; // reflection or refraction dir200 float3 F = Fp + pow(1-abs(dot(N, -V)), 5) * (1-Fp); // Fresnel201 if (n <= 0) {202 R = reflect(V, N); // reflection203 I *= F; // Fresnel reflection204 }205 else{ // refraction206 if (dot(V,N) > 0) { // coming from inside207 n = 1.0 / n;208 N = -N;209 }210 R = refract(V, N, n);211 if (dot(R, R) == 0) // no refraction direction exits212 R = reflect(V, N); // total reflection213 else214 I *= (1-F); // Fresnel refraction215 }216 217 float3 Nl; // normal vector at the hit point218 float4 Il; // radiance at the hit point219 // Trace ray x+R*d and obtain hit l, radiance Il, normal Nl220 float3 l = Hit(x, R, Il, Nl);221 if (Il.a == 0) { // hit point is on specular surface222 depth += 1;223 } else { // hit point is on diffuse surface224 I *= Il.rgb; // multiply with the radiance225 depth = MAX_RAY_DEPTH; // terminate226 }227 N = Nl; V = R; x = l; // hit point is the next shaded point228 }229 return float4(I, 1);230 }231 232 233 147 struct Shaded_OUT 234 148 { … … 238 152 }; 239 153 240 float4 MultipleReflectionPS_o(Shaded_OUT IN, 154 float4 MultipleReflectionPS(Shaded_OUT IN, 155 uniform samplerCUBE CubeMap : register(s0), 156 uniform samplerCUBE DistanceMap : register(s1), 157 uniform samplerCUBE NormDistMap1 : register(s2), 158 uniform samplerCUBE NormDistMap2 : register(s3), 241 159 uniform float3 cameraPos, 242 160 uniform float3 lastCenter) : COLOR0 243 161 { 244 return 1;245 162 float4 I = float4(0,0,0,0); 246 163 … … 264 181 float3 Nl; 265 182 float4 Il = 0; 266 l = Hit(x, R, Il, Nl);183 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 267 184 if(Il.a == 0) 268 185 { … … 280 197 } 281 198 if(I.a == 0) 282 I = readCubeMap( mp3Color, l);199 I = readCubeMap(CubeMap, l); 283 200 284 201 return I; … … 286 203 287 204 float4 MultipleRefractionPS(Shaded_OUT IN, 205 uniform samplerCUBE CubeMap : register(s0), 206 uniform samplerCUBE DistanceMap : register(s1), 207 uniform samplerCUBE NormDistMap1 : register(s2), 208 uniform samplerCUBE NormDistMap2 : register(s3), 288 209 uniform float3 cameraPos, 289 uniform float3 lastCenter, 210 uniform float3 lastCenter, 290 211 uniform float sFresnel, 291 212 uniform float refIndex ) : COLOR0 … … 298 219 V = normalize(V); 299 220 300 float F; 221 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 222 223 float3 l; 224 float4 Irefl; 301 225 int depth = 0; 302 F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel); 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 if(I.a == 0) 249 I = readCubeMap(CubeMap, l); 250 Irefl = I; 251 252 { 253 float4 Irefr; 254 N = normalize(IN.wNormal.xyz); 255 x = IN.wPos.xyz - lastCenter; 256 V = (IN.wPos.xyz - cameraPos); 257 depth = 0; 303 258 304 259 while(depth < MAX_RAY_DEPTH) 305 260 { 306 261 float3 R; 307 308 float ri = refIndex; 262 263 float ri = refIndex; 264 309 265 if(dot(V,N) > 0) 310 266 { … … 313 269 } 314 270 R = refract( V, N, ri); 315 if(dot(R,R) == 0) R = reflect( V, N); 316 271 if(dot(R,R) == 0) R = reflect( V, N); 272 317 273 float3 Nl; 318 274 float4 Il; 319 float3 l = Hit(x, R, Il, Nl);275 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 320 276 if(Il.a == 0) 321 { 277 { 322 278 depth += 1; 323 279 } … … 330 286 N = normalize(Nl); 331 287 V = R; 332 } 333 /*288 } 289 334 290 if(I.a == 0) 335 { 336 float ri = refIndex; 337 if(dot(V,N) > 0) 338 { 339 ri = 1.0 / ri; 340 N = -N; 341 } 342 float3 R = refract( V, N, ri); 343 if(dot(R,R) == 0) R = reflect( V, N); 344 I = readCubeMap(mp3Color, R); 345 } 346 */ 347 I *= (1.0 - F); 348 349 return I; 291 I = readCubeMap(CubeMap, l); 292 Irefr = I; 293 294 I = Irefl * F + (1.0 - F) * Irefr; 295 } 296 return I; 350 297 } 351 298 352 299 float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN, 300 uniform samplerCUBE DistanceMap : register(s0), 301 uniform samplerCUBE NormDistMap1 : register(s1), 302 uniform samplerCUBE NormDistMap2 : register(s2), 353 303 uniform float3 cameraPos, 354 304 uniform float3 lastCenter, 355 305 uniform float refIndex) : COLOR0 356 306 { 357 float4 I = 0; 358 float3 N = normalize(IN.wNormal.xyz); 359 float3 x = IN.wPos.xyz - lastCenter; 360 float3 V = (IN.wPos.xyz - cameraPos); 361 V = normalize(V); 362 307 float4 I = float4(0,0,0,0); 308 309 float3 N = normalize(IN.wNormal.xyz); 310 float3 x = IN.wPos.xyz - lastCenter; 311 float3 V = (IN.wPos.xyz - cameraPos); 312 V = normalize(V); 313 float3 l; 363 314 int depth = 0; 364 float3 l; 365 315 366 316 while(depth < MAX_RAY_DEPTH) 367 317 { 368 318 float3 R; 369 370 float ri = refIndex; 319 320 float ri = refIndex; 321 371 322 if(dot(V,N) > 0) 372 323 { … … 375 326 } 376 327 R = refract( V, N, ri); 377 if(dot(R,R) == 0) R = reflect( V, N); 378 328 if(dot(R,R) == 0) R = reflect( V, N); 329 379 330 float3 Nl; 380 331 float4 Il; 381 l = Hit(x, R, Il, Nl);332 l = Hit(x, R, N, NormDistMap1, NormDistMap2, DistanceMap, DistanceMap, Il, Nl); 382 333 if(Il.a == 0) 383 334 { 384 depth += 1;335 depth += 1; 385 336 } 386 337 else 387 338 { 388 I = Il;389 depth = MAX_RAY_DEPTH;339 I = Il; 340 depth = MAX_RAY_DEPTH; 390 341 } 391 342 x = l; 392 343 N = normalize(Nl); 393 344 V = R; 394 } 395 if(I.a == 0) 396 I = float4(V,1); 397 else 398 I = float4(l,1); 399 400 return I; 401 } 345 } 346 347 return float4(l,1); 348 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflection/GTPMultipleReflection.material
r2131 r2271 3 3 4 4 source GTPMultipleReflection.hlsl 5 entry_point MultipleReflectionPS5 entry_point MultipleReflectionPS 6 6 target ps_3_0 7 7 flow_control prefer … … 20 20 { 21 21 resolution 1024 22 update_interval 022 update_interval 1 23 23 distance_calc false 24 24 face_angle_calc false … … 29 29 { 30 30 resolution 1024 31 update_interval 031 update_interval 1 32 32 distance_calc false 33 33 face_angle_calc false -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.material
r2266 r2271 141 141 pass mainpass 142 142 { 143 cull_hardware clockwise143 cull_hardware none 144 144 vertex_program_ref GTP/Basic/CPos_VS 145 145 { -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl
r2217 r2271 14 14 #define DEPTH_BIAS 0.001 15 15 #define DEPTH_BIAS_VSM 0.001 16 #define DEPTH_EPSILON 0.000 0516 #define DEPTH_EPSILON 0.0005 17 17 #define DIST_BIAS 0.005 18 #define DIST_BIAS_VSM 0.0 0519 #define DIST_EPSILON 0.0 0118 #define DIST_BIAS_VSM 0.05 19 #define DIST_EPSILON 0.01 20 20 21 #define shadowColor float4(0. 5,0.5,0.5,1)21 #define shadowColor float4(0.9,0.9,0.9,1) 22 22 23 23 float4 shadowMapDepth(LightVPos_OUT IN, -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material
r2179 r2271 143 143 } 144 144 } 145 146 material lambert1 : Difflab/TexturedPhong 147 { 148 technique 0 149 { 150 pass 0 151 { 152 IllumTechniques 153 { 154 155 //RenderTechnique CausticReciever 156 //{ 157 // max_caster_count 1 158 //} 159 RenderTechnique DepthShadowReciever 160 { 161 max_light_count 3 162 vertex_program_name GTP/Basic/LightCPos_VS 163 fragment_program_name GTP/Basic/SM/Dist_VSM_PS 164 set_light_view true 165 set_light_farplane true 166 light_viewproj_param_name LightViewProj 167 light_view_param_name LightView 168 light_farplane_param_name lightFarPlane 169 world_view_proj_param_name WorldViewProj 170 world_param_name World 171 } 172 } 173 fragment_program_ref 174 { 175 param_named shininess float 0 176 param_named ambient float4 1.0 1.0 1.0 1 177 param_named diffuse float4 1.0 1.0 1.0 1 178 param_named specular float4 0 0 0 0 179 } 180 181 texture_unit 0 182 { 183 texture grey.tga 184 } 185 } 186 } 187 } 188 145 189 material whitebackground : Difflab/TexturedPhong 146 190 { -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/hangar.material
r2152 r2271 1 material lambert11 material hangarlambert1 2 2 { 3 3 technique
Note: See TracChangeset
for help on using the changeset viewer.