Changeset 1671 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Timestamp:
- 10/23/06 23:28:16 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl
r1638 r1671 27 27 } 28 28 29 VS_OUT DepthDistVS(float4 position : POSITION, 30 uniform float4x4 worldViewProj, 31 uniform float4x4 worldView) 32 { 33 34 VS_OUT OUT; 35 36 OUT.hPosition = mul(worldViewProj, position); 37 OUT.Position = mul(worldView, position); 38 39 return OUT; 40 } 41 42 float4 DepthDistPS(VS_OUT IN, 43 uniform float farPlane ):COLOR 44 { 45 float dist = length(IN.Position.xyz) / farPlane; 46 return float4(dist, dist * dist, 1, 1); 47 //return farPlane; 48 } 49 29 50 ///////////////Shadow 30 51 … … 34 55 float4 Position : TEXCOORD0; 35 56 float4 lPosition : TEXCOORD1; 57 float4 lVPosition : TEXCOORD2; 36 58 }; 37 59 … … 45 67 float4 wPos = mul(world, position); 46 68 OUT.lPosition = mul(lightViewProj, wPos); 69 OUT.lVPosition = 0; 47 70 OUT.Position = position; 48 71 return OUT; 49 72 } 50 73 51 /* 74 52 75 float4 depthShadowPS(VS_OUT_SHADOW IN, 53 76 uniform float4x4 lightViewProj, … … 72 95 float4 storedDepth = tex2D(depthShadowMap, pos.xy); 73 96 74 if(storedDepth.r + bias < pos.z) 75 { 76 float M1 = storedDepth.r; 77 float M2 = storedDepth.g; 78 float v2 = M2 - M1 * M1; 79 float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); 80 light = saturate(shadow + (1 - shadow) * pmax); 81 } 97 98 float M1 = storedDepth.r; 99 float M2 = storedDepth.g; 100 float v2 = M2 - M1 * M1; 101 float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); 102 light = saturate(shadow + (1 - shadow) * pmax); 103 82 104 } 83 105 … … 88 110 return light; 89 111 } 90 */ 91 92 112 113 114 115 VS_OUT_SHADOW distShadowVS(float4 position : POSITION, 116 uniform float4x4 worldViewProj, 117 uniform float4x4 world, 118 uniform float4x4 lightView, 119 uniform float4x4 lightViewProj) 120 { 121 VS_OUT_SHADOW OUT; 122 OUT.hPosition = mul(worldViewProj, position); 123 float4 wPos = mul(world, position); 124 OUT.lPosition = mul(lightViewProj, wPos); 125 OUT.lVPosition = mul(lightView, wPos); 126 OUT.Position = position; 127 return OUT; 128 } 129 130 131 float4 distShadowPS(VS_OUT_SHADOW IN, 132 uniform float4x4 lightViewProj, 133 uniform float lightFarPlane, 134 uniform sampler2D depthShadowMap : register(s0) 135 ):COLOR 136 { 137 float bias = 0.001; 138 float epsilon = 0.001; 139 float4 light = float4(1,1,1,1); 140 float4 shadow = float4(0.85,0.85,0.85,1); 141 142 if(IN.lPosition.z > 0.0) 143 { 144 float4 pos = (IN.lPosition / IN.lPosition.w); 145 146 float d = length(pos.xy); 147 148 light = saturate((1.0 - d)/0.05); 149 150 if(d <= 1.0) 151 { 152 float dist = length(IN.lVPosition.xyz) / lightFarPlane; 153 pos.xy = (pos.xy + 1.0) / 2.0; 154 pos.y = 1.0 - pos.y; 155 float4 storedDist = tex2D(depthShadowMap, pos.xy); 156 dist -= bias; 157 float lit_factor = light * (dist <= storedDist.r); 158 159 float M1 = storedDist.r; 160 float M2 = storedDist.g; 161 float v2 = min(max(M2 - M1 * M1, 0.0) + epsilon, 1.0); 162 float m_d = M1 - dist; 163 float pmax = v2 / (v2 + m_d * m_d); 164 165 // Adjust the light color based on the shadow attenuation 166 light = max(lit_factor, pmax); 167 168 } 169 170 } 171 else 172 light = 0; 173 174 return shadow + (1 - shadow) * light; 175 } 176 177 178 /* 93 179 float4 depthShadowPS(VS_OUT_SHADOW IN, 94 180 uniform float4x4 lightViewProj, … … 126 212 return light; 127 213 } 214 */ -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl
r1638 r1671 272 272 } 273 273 274 struct vertOUTBump 275 { 276 float4 hPos :POSITION; 277 float3 wPos :TEXCOORD1; 278 float2 texCoord :TEXCOORD0; 279 float3 mNormal :TEXCOORD2; 280 float3 tangent :TEXCOORD3; 281 float3 binormal :TEXCOORD4; 282 }; 283 284 vertOUTBump DiffuseBumpVS(float4 position : POSITION, 285 float3 normal : NORMAL, 286 half3 tangent : TEXCOORD1, 287 float2 texCoord : TEXCOORD0, 288 uniform float4x4 worldViewProj, 289 uniform float4x4 world) 290 { 291 vertOUTBump OUT; 292 OUT.hPos = mul(worldViewProj, position); 293 OUT.wPos = mul(world, position).xyz; 294 OUT.mNormal = normal; 295 OUT.tangent = tangent; 296 OUT.texCoord = texCoord; 297 OUT.binormal = cross(tangent, normal); 298 return OUT; 299 } 300 301 float4 DiffuseBumpPS( vertOUTBump IN, 302 uniform float3 cameraPos, 303 uniform float3 lastCenter, //LI// 304 uniform samplerCUBE SmallEnvMapSampler : register(s0), 305 uniform samplerCUBE DistanceEnvMapSampler : register(s1), 306 uniform sampler2D NormalMap : register(s2), 307 uniform float4x4 worldI 308 ) : COLOR0 309 { 310 float M = 4; 311 312 float3 N = IN.mNormal; 313 N = normalize( N ); 314 float3x3 TangentToModel = float3x3(IN.tangent, IN.binormal, N); 315 316 half3 tNormal = tex2D(NormalMap, IN.texCoord).rgb; 317 318 N = mul(tNormal, TangentToModel ); 319 320 N = normalize( N ); 321 N = mul(N, worldI); 322 323 float3 pos = IN.wPos - lastCenter; 324 325 //return float4(N,1)+ lastCenter.x*0.000001; 326 // return readCubeMap(SmallEnvMapSampler, pos) + lastCenter.x*0.000001; 327 328 float4 I = 0; 329 float3 L1, L2, L3, L4, L; 330 float4 Le; 331 float width = 1.0 / M; 332 float width2 = width * 2; 333 float d; 334 335 for (float x = 0.5; x < M; x++) 336 for (float y = 0.5; y < M; y++) 337 { 338 float2 p, tpos; 339 tpos.x = x * width; 340 tpos.y = y * width; 341 342 p = tpos.xy; 343 p = 2.0 * p - 1.0; //-1..1 344 345 L1 = float3(p.x - width, p.y - width, 1); 346 L2 = float3(p.x + width, p.y - width, 1); 347 L3 = float3(p.x + width, p.y + width, 1); 348 L4 = float3(p.x - width, p.y + width, 1); 349 L = float3(p.x, p.y, 1); 350 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 351 352 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 353 354 } 355 356 for (float x = 0.5; x < M; x++) 357 for (float y = 0.5; y < M; y++) 358 { 359 float2 p, tpos; 360 tpos.x = x * width; // 0..1 361 tpos.y = y * width; // 0..1 362 363 p = tpos.xy; 364 p = 2.0 * p - 1.0; //-1..1 365 366 L4 = float3(p.x - width, p.y - width, -1); 367 L3 = float3(p.x + width, p.y - width, -1); 368 L2 = float3(p.x + width, p.y + width, -1); 369 L1 = float3(p.x - width, p.y + width, -1); 370 L = float3(p.x, p.y, -1); 371 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 372 373 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 374 } 375 376 for (float x = 0.5; x < M; x++) 377 for (float y = 0.5; y < M; y++) 378 { 379 float2 p, tpos; 380 tpos.x = x * width; // 0..1 381 tpos.y = y * width; // 0..1 382 383 p = tpos.xy; 384 p = 2.0 * p - 1.0; //-1..1 385 386 L4 = float3(p.x - width, 1, p.y - width); 387 L3 = float3(p.x + width, 1, p.y - width); 388 L2 = float3(p.x + width, 1, p.y + width); 389 L1 = float3(p.x - width, 1, p.y + width); 390 L = float3(p.x, 1, p.y); 391 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 392 393 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 394 } 395 396 for (float x = 0.5; x < M; x++) 397 for (float y = 0.5; y < M; y++) 398 { 399 float2 p, tpos; 400 tpos.x = x * width; // 0..1 401 tpos.y = y * width; // 0..1 402 403 p = tpos.xy; 404 p = 2.0 * p - 1.0; //-1..1 405 406 L1 = float3(p.x - width, -1, p.y - width); 407 L2 = float3(p.x + width, -1, p.y - width); 408 L3 = float3(p.x + width, -1, p.y + width); 409 L4 = float3(p.x - width, -1, p.y + width); 410 L = float3(p.x, -1, p.y); 411 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 412 413 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 414 } 415 416 for (float x = 0.5; x < M; x++) 417 for (float y = 0.5; y < M; y++) 418 { 419 float2 p, tpos; 420 tpos.x = x * width; // 0..1 421 tpos.y = y * width; // 0..1 422 423 p = tpos.xy; 424 p = 2.0 * p - 1.0; //-1..1 425 426 L1 = float3(1, p.x - width, p.y - width); 427 L2 = float3(1, p.x + width, p.y - width); 428 L3 = float3(1, p.x + width, p.y + width); 429 L4 = float3(1, p.x - width, p.y + width); 430 L = float3(1, p.x, p.y); 431 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 432 433 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 434 } 435 436 for (float x = 0.5; x < M; x++) 437 for (float y = 0.5; y < M; y++) 438 { 439 float2 p, tpos; 440 tpos.x = x * width; // 0..1 441 tpos.y = y * width; // 0..1 442 443 p = tpos.xy; 444 p = 2.0 * p - 1.0; //-1..1 445 446 L4 = float3(-1, p.x - width, p.y - width); 447 L3 = float3(-1, p.x + width, p.y - width); 448 L2 = float3(-1, p.x + width, p.y + width); 449 L1 = float3(-1, p.x - width, p.y + width); 450 L = float3(-1, p.x, p.y); 451 Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1); 452 453 I += 0.5 * Le * GetContibution( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler); 454 } 455 float kd = 0.3; 456 return kd * I; 457 } 458 274 459 float4 P2PContr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap, samplerCUBE distmap) 275 460 { … … 280 465 float3 Lpos = L * d; 281 466 float3 Ldir = Lpos - pos; 282 float dist = dot(Ldir, Ldir);467 float dist = 4 * dot(Ldir, Ldir); 283 468 Ldir = normalize(Ldir); 284 dist /= 10000.0;285 return Le * max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir) / dist;469 470 return Le * (max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir)) / dist; 286 471 } 287 472 … … 293 478 float M = 4.0; 294 479 295 //float3 N = mul( world_IT, float4(IN.mNormal,1)).xyz;296 480 float3 N = IN.mNormal; 297 481 N = normalize( N ); … … 302 486 float4 Le; 303 487 float width = 1.0 / M; 304 float d; 305 306 //float vdir = length(pos); 307 //return (readDistanceCubeMap(DistanceEnvMapSampler, pos) - vdir); 308 //return readCubeMap(SmallEnvMapSampler, pos); 309 //return readDistanceCubeMap(DistanceEnvMapSampler, pos); 488 float d; 489 490 float kd = 0.3; 491 492 //return kd * readCubeMap(SmallEnvMapSampler, N) + lastCenter.x * 0.00000001; 310 493 311 494 for (float x = 0.5; x < M; x++) … … 327 510 } 328 511 329 float kd = 0.8;330 512 return kd * I; 331 513 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Phong.hlsl
r1629 r1671 209 209 float4 I = 0; 210 210 I = texColor * ambientLight * ambient; 211 float maxlightangle = 3.14 / 2.0;211 float maxlightangle = 90.0 / 180.0 * 3.14; 212 212 for(int i=0; i< M; i++) 213 213 {
Note: See TracChangeset
for help on using the changeset viewer.