Changeset 1671 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials
- Timestamp:
- 10/23/06 23:28:16 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials
- Files:
-
- 4 added
- 8 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 { -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/Diffuse.material
r1638 r1671 157 157 texture_unit 158 158 { 159 cubic_texture cubemap.jpg combinedUVW 160 tex_address_mode clamp 161 colour_op replace 159 162 160 } 163 161 … … 165 163 texture_unit 166 164 { 167 cubic_texture cubemap.jpg combinedUVW 168 tex_address_mode clamp 169 colour_op replace 165 170 166 } 171 167 } … … 173 169 } 174 170 171 vertex_program DiffuseBumpVS hlsl 172 { 173 source GameTools_Diffuse.hlsl 174 entry_point DiffuseBumpVS 175 target vs_3_0 176 } 177 178 fragment_program DiffuseBumpPS hlsl 179 { 180 source GameTools_Diffuse.hlsl 181 entry_point DiffuseBumpPS 182 target ps_3_0 183 } 184 185 186 187 material GameTools/DiffuseBump 188 { 189 technique 190 { 191 pass 192 { 193 194 IllumTechniques 195 { 196 RenderTechnique DistanceCubeMap 197 { 198 update_interval 1 199 update_all_face true 200 distance_calc false 201 face_angle_calc false 202 resolution 128 203 } 204 RenderTechnique ReducedColorCubeMap 205 { 206 update_interval 1 207 reduced_resolution 4 208 resolution 128 209 distance_calc false 210 face_angle_calc false 211 update_all_face true 212 } 213 } 214 215 216 vertex_program_ref DiffuseBumpVS 217 { 218 param_named_auto worldViewProj worldviewproj_matrix 219 param_named_auto world world_matrix 220 221 } 222 fragment_program_ref DiffuseBumpPS 223 { 224 param_named_auto worldI inverse_world_matrix 225 param_named lastCenter float3 0 0 0 226 } 227 228 //Cube map for reflections and refractions 229 texture_unit 230 { 231 } 232 233 //Cube map of distances 234 texture_unit 235 { 236 237 } 238 texture_unit 239 { 240 texture atheneNormalMapNew.dds 241 } 242 } 243 } 244 } 175 245 176 246 fragment_program DiffuseP2PPS hlsl … … 181 251 } 182 252 183 material GameTools/Diffuse /use1253 material GameTools/DiffuseP2P 184 254 { 185 255 technique … … 193 263 { 194 264 update_interval 1 265 resolution 128 195 266 distance_calc false 196 267 face_angle_calc false … … 211 282 vertex_program_ref Diffuse2VS 212 283 { 213 214 param_named_auto world 215 284 param_named_auto worldViewProj worldviewproj_matrix 285 param_named_auto worldI inverse_world_matrix 286 param_named_auto world world_matrix 216 287 } 217 288 fragment_program_ref DiffuseP2PPS 218 289 { 219 param_named REDUCED_CUBEMAP_SIZE int 4220 290 param_named lastCenter float3 0 0 0 221 291 } … … 224 294 texture_unit 225 295 { 226 cubic_texture cubemap.jpg combinedUVW 227 tex_address_mode clamp 228 colour_op replace 296 229 297 } 230 298 … … 232 300 texture_unit 233 301 { 234 cubic_texture cubemap.jpg combinedUVW 235 tex_address_mode clamp 236 colour_op replace 302 237 303 } 238 304 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.material
r1629 r1671 221 221 { 222 222 223 } 224 225 } 226 } 227 } 228 229 material GameTools/ShadowMapDistance 230 { 231 232 technique 233 { 234 scene_blend none 235 236 pass 237 { 238 cull_hardware anticlockwise 239 //cull_hardware none 240 241 vertex_program_ref GameTools/ShadowMap/DistVS 242 { 243 param_named_auto worldViewProj worldviewproj_matrix 244 param_named_auto worldView worldview_matrix 245 } 246 fragment_program_ref GameTools/ShadowMap/DistPS 247 { 248 param_named_auto farPlane far_clip_distance 223 249 } 224 250 -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.program
r1131 r1671 252 252 target ps_3_0 253 253 254 } 255 256 vertex_program GameTools/ShadowMap/DistVS hlsl 257 { 258 source GameTools_DepthShadow.hlsl 259 entry_point DepthDistVS 260 target vs_3_0 261 } 262 263 fragment_program GameTools/ShadowMap/DistPS hlsl 264 { 265 source GameTools_DepthShadow.hlsl 266 entry_point DepthDistPS 267 target ps_3_0 268 254 269 } 255 270 … … 269 284 } 270 285 286 vertex_program GameTools/ShadowMap/ShadowDistVS hlsl 287 { 288 source GameTools_DepthShadow.hlsl 289 entry_point distShadowVS 290 target vs_1_1 291 } 292 293 fragment_program GameTools/ShadowMap/ShadowDistPS hlsl 294 { 295 source GameTools_DepthShadow.hlsl 296 entry_point distShadowPS 297 target ps_2_0 298 299 } 300 271 301 vertex_program GameTools/UV_VS hlsl 272 302 { -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material
r1638 r1671 115 115 { 116 116 max_light_count 3 117 vertex_program_name GameTools/ShadowMap/ShadowDistVS 118 fragment_program_name GameTools/ShadowMap/ShadowDistPS 119 set_light_view true 120 set_light_farplane true 117 121 } 118 122 } … … 136 140 { 137 141 max_light_count 3 142 vertex_program_name GameTools/ShadowMap/ShadowDistVS 143 fragment_program_name GameTools/ShadowMap/ShadowDistPS 144 set_light_view true 145 set_light_farplane true 138 146 } 139 147 } … … 179 187 { 180 188 max_light_count 3 189 vertex_program_name GameTools/ShadowMap/ShadowDistVS 190 fragment_program_name GameTools/ShadowMap/ShadowDistPS 191 set_light_view true 192 set_light_farplane true 181 193 } 182 194 } … … 249 261 { 250 262 max_light_count 3 263 vertex_program_name GameTools/ShadowMap/ShadowDistVS 264 fragment_program_name GameTools/ShadowMap/ShadowDistPS 265 set_light_view true 266 set_light_farplane true 251 267 } 252 268 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/hangar.material
r1085 r1671 9 9 RenderTechnique DepthShadowReciever 10 10 { 11 max_light_count 3 12 vertex_program_name GameTools/ShadowMap/ShadowDistVS 13 fragment_program_name GameTools/ShadowMap/ShadowDistPS 14 set_light_view true 15 set_light_farplane true 11 16 12 17 }
Note: See TracChangeset
for help on using the changeset viewer.