| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2009, Google Inc. | 2 Copyright 2009, Google Inc. |
| 3 All rights reserved. | 3 All rights reserved. |
| 4 | 4 |
| 5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
| 6 modification, are permitted provided that the following conditions are | 6 modification, are permitted provided that the following conditions are |
| 7 met: | 7 met: |
| 8 | 8 |
| 9 * Redistributions of source code must retain the above copyright | 9 * Redistributions of source code must retain the above copyright |
| 10 notice, this list of conditions and the following disclaimer. | 10 notice, this list of conditions and the following disclaimer. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 var depthSurface = g_pack.createDepthStencilSurface(SHADOW_MAP_WIDTH, | 190 var depthSurface = g_pack.createDepthStencilSurface(SHADOW_MAP_WIDTH, |
| 191 SHADOW_MAP_HEIGHT); | 191 SHADOW_MAP_HEIGHT); |
| 192 | 192 |
| 193 shadowPassRenderRoot.parent = g_client.renderGraphRoot; | 193 shadowPassRenderRoot.parent = g_client.renderGraphRoot; |
| 194 | 194 |
| 195 g_renderSurfaceSet = g_pack.createObject('RenderSurfaceSet'); | 195 g_renderSurfaceSet = g_pack.createObject('RenderSurfaceSet'); |
| 196 g_renderSurfaceSet.renderSurface = renderSurface; | 196 g_renderSurfaceSet.renderSurface = renderSurface; |
| 197 g_renderSurfaceSet.renderDepthStencilSurface = depthSurface; | 197 g_renderSurfaceSet.renderDepthStencilSurface = depthSurface; |
| 198 | 198 |
| 199 g_renderSurfaceSet.parent = shadowPassRenderRoot; | 199 g_renderSurfaceSet.parent = shadowPassRenderRoot; |
| 200 | 200 |
| 201 // Create a render sub-graph for the shadow map generation. | 201 // Create a render sub-graph for the shadow map generation. |
| 202 g_shadowViewInfo = o3djs.rendergraph.createBasicView( | 202 g_shadowViewInfo = o3djs.rendergraph.createBasicView( |
| 203 g_pack, | 203 g_pack, |
| 204 g_client.root, | 204 g_client.root, |
| 205 g_renderSurfaceSet, | 205 g_renderSurfaceSet, |
| 206 [1, 1, 1, 1]); | 206 [1, 1, 1, 1]); |
| 207 | 207 |
| 208 // Create a render sub-graph for the regular pass. | 208 // Create a render sub-graph for the regular pass. |
| 209 g_colorViewInfo = o3djs.rendergraph.createBasicView( | 209 g_colorViewInfo = o3djs.rendergraph.createBasicView( |
| 210 g_pack, | 210 g_pack, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 shadowEffect.createUniformParameters(g_shadowMaterial); | 256 shadowEffect.createUniformParameters(g_shadowMaterial); |
| 257 | 257 |
| 258 g_shadowSampler = g_pack.createObject('Sampler'); | 258 g_shadowSampler = g_pack.createObject('Sampler'); |
| 259 g_shadowSampler.texture = g_shadowTexture; | 259 g_shadowSampler.texture = g_shadowTexture; |
| 260 g_shadowSampler.minFilter = g_o3d.Sampler.POINT; | 260 g_shadowSampler.minFilter = g_o3d.Sampler.POINT; |
| 261 g_shadowSampler.magFilter = g_o3d.Sampler.POINT; | 261 g_shadowSampler.magFilter = g_o3d.Sampler.POINT; |
| 262 g_shadowSampler.mipFilter = g_o3d.Sampler.POINT; | 262 g_shadowSampler.mipFilter = g_o3d.Sampler.POINT; |
| 263 g_shadowSampler.addressModeU = g_o3d.Sampler.BORDER; | 263 g_shadowSampler.addressModeU = g_o3d.Sampler.BORDER; |
| 264 g_shadowSampler.addressModeV = g_o3d.Sampler.BORDER; | 264 g_shadowSampler.addressModeV = g_o3d.Sampler.BORDER; |
| 265 g_shadowSampler.borderColor = [1, 1, 1, 1]; | 265 g_shadowSampler.borderColor = [1, 1, 1, 1]; |
| 266 | |
| 267 } | 266 } |
| 268 | 267 |
| 269 | 268 |
| 270 /** | 269 /** |
| 271 * Sets up reasonable view and projection matrices. | 270 * Sets up reasonable view and projection matrices. |
| 272 */ | 271 */ |
| 273 function updateCamera() { | 272 function updateCamera() { |
| 274 // Set up a perspective transformation for the projection. | 273 // Set up a perspective transformation for the projection. |
| 275 g_colorViewInfo.drawContext.projection = g_math.matrix4.perspective( | 274 g_colorViewInfo.drawContext.projection = g_math.matrix4.perspective( |
| 276 g_math.degToRad(30), // 30 degree frustum. | 275 g_math.degToRad(30), // 30 degree frustum. |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 return clamp(dot(n,l), 0.0, 1.0) * diffuse.rgb + | 579 return clamp(dot(n,l), 0.0, 1.0) * diffuse.rgb + |
| 581 0.2 * specular.rgb * pow(max(dot(l, r), 0.0), shininess); | 580 0.2 * specular.rgb * pow(max(dot(l, r), 0.0), shininess); |
| 582 } | 581 } |
| 583 | 582 |
| 584 void main() { | 583 void main() { |
| 585 vec3 outColor = ambient.rgb; | 584 vec3 outColor = ambient.rgb; |
| 586 vec4 projCoords = vprojTextureCoords; | 585 vec4 projCoords = vprojTextureCoords; |
| 587 | 586 |
| 588 // Convert texture coords to [0, 1] range. | 587 // Convert texture coords to [0, 1] range. |
| 589 projCoords /= projCoords.w; | 588 projCoords /= projCoords.w; |
| 590 projCoords.x = 0.5 * projCoords.x + 0.5; | 589 projCoords = 0.5 * projCoords + 0.5; |
| 591 projCoords.y = 0.5 * projCoords.y + 0.5; | |
| 592 projCoords.z = 0.5 * projCoords.z + 0.5; | |
| 593 | 590 |
| 594 float depth = projCoords.z; | 591 float depth = projCoords.z; |
| 595 | |
| 596 float light; | 592 float light; |
| 597 | 593 |
| 598 // If the rednered point is farther from the light than the distance encoded | 594 // If the rednered point is farther from the light than the distance encoded |
| 599 // in the shadow map, we give it a light coefficient of 0. | 595 // in the shadow map, we give it a light coefficient of 0. |
| 600 vec4 color = texture2D(shadowMapSampler, projCoords.xy); | 596 vec4 color = texture2D(shadowMapSampler, projCoords.xy); |
| 601 | 597 |
| 602 light = (color.a + | 598 light = (color.a + |
| 603 color.b / 256.0 + | 599 color.b / 256.0 + |
| 604 color.g / 65536.0 + | 600 color.g / 65536.0 + |
| 605 color.r / 16777216.0) + 0.008 > depth ? 1.0 : 0.0; | 601 color.r / 16777216.0) + 0.008 > depth ? 1.0 : 0.0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 627 <h1>Shadow Maps</h1> | 623 <h1>Shadow Maps</h1> |
| 628 This sample implements a basic shadow map. | 624 This sample implements a basic shadow map. |
| 629 <br/> | 625 <br/> |
| 630 <!-- Start of O3D plugin --> | 626 <!-- Start of O3D plugin --> |
| 631 <div id="o3d" width="800px" height="600px"></div> | 627 <div id="o3d" width="800px" height="600px"></div> |
| 632 <!-- End of O3D plugin --> | 628 <!-- End of O3D plugin --> |
| 633 Use A, S, D, W, I and O to move the light. | 629 Use A, S, D, W, I and O to move the light. |
| 634 Press spacebar to see the shadow map. | 630 Press spacebar to see the shadow map. |
| 635 </body> | 631 </body> |
| 636 </html> | 632 </html> |
| OLD | NEW |