提交 8dfd933f 编写于 作者: M mkkellogg

Added checks for definition of POINT_LIGHT_SHADOWS in shaders for including...

Added checks for definition of POINT_LIGHT_SHADOWS in shaders for including point light shadow mapping code.
上级 0f9a9226
......@@ -44,209 +44,238 @@
shadowCoord.z += shadowBias[ i ];
#if defined( SHADOWMAP_TYPE_PCF )
if( isPointLight ){
initGridSamplingDisk();
#if defined(POINT_LIGHT_SHADOWS)
float diskRadius = 1.5;
float numSamples = 1.0;
shadow = 0.0;
if( isPointLight ) {
vec3 baseDirection = normalize( lightToPosition );
float curDistance = length( lightToPosition );
initGridSamplingDisk();
float dist = unpack1K( textureCube( shadowCube[ i ], baseDirection ) );
if ( curDistance >= dist )
shadow += 1.0;
// evaluate each sampling direction
for( int s = 0; s < 20; s++ ){
vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;
dist = unpack1K( textureCube( shadowCube[ i ], vec3( baseDirection + offset ) ) );
float diskRadius = 1.5;
float numSamples = 1.0;
shadow = 0.0;
vec3 baseDirection = normalize( lightToPosition );
float curDistance = length( lightToPosition );
float dist = unpack1K( textureCube( shadowCube[ i ], baseDirection ) );
if ( curDistance >= dist )
shadow += 1.0;
numSamples += 1.0;
}
// evaluate each sampling direction
for( int s = 0; s < 20; s++ ) {
vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;
dist = unpack1K( textureCube( shadowCube[ i ], vec3( baseDirection + offset ) ) );
if ( curDistance >= dist )
shadow += 1.0;
numSamples += 1.0;
}
shadow /= numSamples;
} else {
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
/*
// nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
// must enroll loop manually
shadow /= numSamples;
} else {
for ( float y = -1.25; y <= 1.25; y += 1.25 )
for ( float x = -1.25; x <= 1.25; x += 1.25 ) {
#endif
vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
/*
// nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
// must enroll loop manually
// doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup
//vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );
for ( float y = -1.25; y <= 1.25; y += 1.25 )
for ( float x = -1.25; x <= 1.25; x += 1.25 ) {
float fDepth = unpackDepth( rgbaDepth );
vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );
if ( fDepth < shadowCoord.z )
shadow += 1.0;
// doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup
//vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );
}
float fDepth = unpackDepth( rgbaDepth );
if ( fDepth < shadowCoord.z )
shadow += 1.0;
}
shadow /= 9.0;
shadow /= 9.0;
*/
*/
const float shadowDelta = 1.0 / 9.0;
const float shadowDelta = 1.0 / 9.0;
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
float dx0 = -1.25 * xPixelOffset;
float dy0 = -1.25 * yPixelOffset;
float dx1 = 1.25 * xPixelOffset;
float dy1 = 1.25 * yPixelOffset;
float dx0 = -1.25 * xPixelOffset;
float dy0 = -1.25 * yPixelOffset;
float dx1 = 1.25 * xPixelOffset;
float dy1 = 1.25 * yPixelOffset;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
#if defined(POINT_LIGHT_SHADOWS)
}
#endif
}
shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
if( isPointLight ){
#if defined(POINT_LIGHT_SHADOWS)
initGridSamplingDisk();
if( isPointLight ) {
float diskRadius = 2.5;
float numSamples = 1.0;
shadow = 0.0;
initGridSamplingDisk();
vec3 baseDirection = normalize( lightToPosition );
float curDistance = length( lightToPosition );
float diskRadius = 2.5;
float numSamples = 1.0;
shadow = 0.0;
float dist = unpack1K( textureCube( shadowCube[ i ], baseDirection ) );
if ( curDistance >= dist )
shadow += 1.0;
// evaluate each sampling direction
for( int s = 0; s < 20; s++ ){
vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;
dist = unpack1K( textureCube( shadowCube[ i ], vec3( baseDirection + offset ) ) );
vec3 baseDirection = normalize( lightToPosition );
float curDistance = length( lightToPosition );
float dist = unpack1K( textureCube( shadowCube[ i ], baseDirection ) );
if ( curDistance >= dist )
shadow += 1.0;
numSamples += 1.0;
}
// evaluate each sampling direction
for( int s = 0; s < 20; s++ ) {
vec3 offset = gridSamplingDisk[ s ] * diskRadius * cubeTexelSize;
dist = unpack1K( textureCube( shadowCube[ i ], vec3( baseDirection + offset ) ) );
if ( curDistance >= dist )
shadow += 1.0;
numSamples += 1.0;
}
shadow /= numSamples;
shadow /= numSamples;
} else {
} else {
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
#endif
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
float dx0 = -1.0 * xPixelOffset;
float dy0 = -1.0 * yPixelOffset;
float dx1 = 1.0 * xPixelOffset;
float dy1 = 1.0 * yPixelOffset;
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
mat3 shadowKernel;
mat3 depthKernel;
float dx0 = -1.0 * xPixelOffset;
float dy0 = -1.0 * yPixelOffset;
float dx1 = 1.0 * xPixelOffset;
float dy1 = 1.0 * yPixelOffset;
depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
mat3 shadowKernel;
mat3 depthKernel;
vec3 shadowZ = vec3( shadowCoord.z );
shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));
shadowKernel[0] *= vec3(0.25);
depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));
shadowKernel[1] *= vec3(0.25);
vec3 shadowZ = vec3( shadowCoord.z );
shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));
shadowKernel[0] *= vec3(0.25);
shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));
shadowKernel[2] *= vec3(0.25);
shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));
shadowKernel[1] *= vec3(0.25);
vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );
shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));
shadowKernel[2] *= vec3(0.25);
shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );
vec4 shadowValues;
shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
shadow = dot( shadowValues, vec4( 1.0 ) );
}
vec4 shadowValues;
shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
shadow = dot( shadowValues, vec4( 1.0 ) );
#if defined(POINT_LIGHT_SHADOWS)
}
#endif
shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );
#else
if( isPointLight ){
#if defined(POINT_LIGHT_SHADOWS)
if( isPointLight ) {
vec4 data = textureCube( shadowCube[ i ], normalize( lightToPosition ) );
float dist = unpack1K( data );
if ( length( lightToPosition ) >= dist)
shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness );
} else {
#endif
vec4 data = textureCube( shadowCube[ i ], normalize( lightToPosition ) );
float dist = unpack1K( data );
if ( length( lightToPosition ) >= dist)
vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );
float fDepth = unpackDepth( rgbaDepth );
if ( fDepth < shadowCoord.z )
// spot with multiple shadows is darker
shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness );
} else {
vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );
float fDepth = unpackDepth( rgbaDepth );
if ( fDepth < shadowCoord.z )
// spot with multiple shadows has the same color as single shadow spot
// spot with multiple shadows is darker
// shadowColor = min( shadowColor, vec3( realShadowDarkness ) );
shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness );
#if defined(POINT_LIGHT_SHADOWS)
// spot with multiple shadows has the same color as single shadow spot
}
// shadowColor = min( shadowColor, vec3( realShadowDarkness ) );
}
#endif
#endif
......
#ifdef USE_SHADOWMAP
uniform samplerCube shadowCube[ MAX_SHADOWS ];
uniform sampler2D shadowMap[ MAX_SHADOWS ];
uniform vec2 shadowMapSize[ MAX_SHADOWS ];
......@@ -17,58 +16,64 @@
}
vec4 pack1K ( float depth ) {
depth /= 1000.0;
const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
vec4 res = fract( depth * bitSh );
res -= res.xxyz * bitMsk;
return res;
#if defined(POINT_LIGHT_SHADOWS)
uniform samplerCube shadowCube[ MAX_SHADOWS ];
vec4 pack1K ( float depth ) {
}
depth /= 1000.0;
const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
vec4 res = fract( depth * bitSh );
res -= res.xxyz * bitMsk;
return res;
}
float unpack1K ( vec4 color ) {
const vec4 bitSh = vec4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );
return dot( color, bitSh ) * 1000.0;
float unpack1K ( vec4 color ) {
}
const vec4 bitSh = vec4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );
return dot( color, bitSh ) * 1000.0;
}
vec3 gridSamplingDisk[ 20 ];
bool gridSamplingInitialized = false;
vec3 gridSamplingDisk[ 20 ];
bool gridSamplingInitialized = false;
void initGridSamplingDisk(){
void initGridSamplingDisk(){
if( gridSamplingInitialized ){
if( gridSamplingInitialized ){
return;
return;
}
gridSamplingDisk[0] = vec3(1, 1, 1);
gridSamplingDisk[1] = vec3(1, -1, 1);
gridSamplingDisk[2] = vec3(-1, -1, 1);
gridSamplingDisk[3] = vec3(-1, 1, 1);
gridSamplingDisk[4] = vec3(1, 1, -1);
gridSamplingDisk[5] = vec3(1, -1, -1);
gridSamplingDisk[6] = vec3(-1, -1, -1);
gridSamplingDisk[7] = vec3(-1, 1, -1);
gridSamplingDisk[8] = vec3(1, 1, 0);
gridSamplingDisk[9] = vec3(1, -1, 0);
gridSamplingDisk[10] = vec3(-1, -1, 0);
gridSamplingDisk[11] = vec3(-1, 1, 0);
gridSamplingDisk[12] = vec3(1, 0, 1);
gridSamplingDisk[13] = vec3(-1, 0, 1);
gridSamplingDisk[14] = vec3(1, 0, -1);
gridSamplingDisk[15] = vec3(-1, 0, -1);
gridSamplingDisk[16] = vec3(0, 1, 1);
gridSamplingDisk[17] = vec3(0, -1, 1);
gridSamplingDisk[18] = vec3(0, -1, -1);
gridSamplingDisk[19] = vec3(0, 1, -1);
gridSamplingInitialized = true;
}
gridSamplingDisk[0] = vec3(1, 1, 1);
gridSamplingDisk[1] = vec3(1, -1, 1);
gridSamplingDisk[2] = vec3(-1, -1, 1);
gridSamplingDisk[3] = vec3(-1, 1, 1);
gridSamplingDisk[4] = vec3(1, 1, -1);
gridSamplingDisk[5] = vec3(1, -1, -1);
gridSamplingDisk[6] = vec3(-1, -1, -1);
gridSamplingDisk[7] = vec3(-1, 1, -1);
gridSamplingDisk[8] = vec3(1, 1, 0);
gridSamplingDisk[9] = vec3(1, -1, 0);
gridSamplingDisk[10] = vec3(-1, -1, 0);
gridSamplingDisk[11] = vec3(-1, 1, 0);
gridSamplingDisk[12] = vec3(1, 0, 1);
gridSamplingDisk[13] = vec3(-1, 0, 1);
gridSamplingDisk[14] = vec3(1, 0, -1);
gridSamplingDisk[15] = vec3(-1, 0, -1);
gridSamplingDisk[16] = vec3(0, 1, 1);
gridSamplingDisk[17] = vec3(0, -1, 1);
gridSamplingDisk[18] = vec3(0, -1, -1);
gridSamplingDisk[19] = vec3(0, 1, -1);
gridSamplingInitialized = true;
}
#endif
#endif
\ No newline at end of file
#ifdef USE_SHADOWMAP for( int i = 0; i < MAX_SHADOWS; i ++ ) { #if MAX_POINT_LIGHTS > 0 // if shadowDarkness[ i ] < 0.0, that means we have a point light with a cube // shadow map if( shadowDarkness[ i ] < 0.0 ){ // When we have a point light, the @shadowMatrix uniform is used to store // the inverse of the view matrix, so that we can get the world-space // position of the light. vec4 lightPositionWorld = ( shadowMatrix[ i ] * vec4( pointLightPosition[ i ], 1.0 )); vec4 distanceToLight = worldPosition - lightPositionWorld; distanceToLight.w = 1.0; // We also repurpose vShadowCoord to hold the distance in world space from the // light to the vertex. This value will be interpolated correctly in the fragment shader. vShadowCoord[ i ] = distanceToLight; } else { vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition; } #else vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition; #endif } #endif
\ No newline at end of file
#ifdef USE_SHADOWMAP for( int i = 0; i < MAX_SHADOWS; i ++ ) { #if defined(POINT_LIGHT_SHADOWS) // if shadowDarkness[ i ] < 0.0, that means we have a point light with a cube // shadow map if( shadowDarkness[ i ] < 0.0 ){ // When we have a point light, the @shadowMatrix uniform is used to store // the inverse of the view matrix, so that we can get the world-space // position of the light. vec4 lightPositionWorld = ( shadowMatrix[ i ] * vec4( pointLightPosition[ i ], 1.0 )); vec4 distanceToLight = worldPosition - lightPositionWorld; distanceToLight.w = 1.0; // We also repurpose vShadowCoord to hold the distance in world space from the // light to the vertex. This value will be interpolated correctly in the fragment shader. vShadowCoord[ i ] = distanceToLight; } else { vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition; } #else vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition; #endif } #endif
\ No newline at end of file
......
......@@ -219,6 +219,7 @@ THREE.WebGLProgram = ( function () {
parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
......@@ -330,6 +331,7 @@ THREE.WebGLProgram = ( function () {
parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
......
......@@ -20,7 +20,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
"flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
"maxBones", "useVertexTexture", "morphTargets", "morphNormals",
"maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
"maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled",
"maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
"shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
"flipSided"
];
......@@ -91,6 +91,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
function allocateShadows( lights ) {
var maxShadows = 0;
var pointLightShadows = 0;
for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
......@@ -98,12 +99,17 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
if ( ! light.castShadow ) continue;
if ( light instanceof THREE.SpotLight || light instanceof THREE.PointLight ) maxShadows ++;
if ( light instanceof THREE.DirectionalLight ) maxShadows ++;
if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
if ( light instanceof THREE.PointLight ) {
maxShadows ++;
pointLightShadows ++;
}
}
return maxShadows;
return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
}
......@@ -114,7 +120,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
// (not to blow over maxLights budget)
var maxLightCount = allocateLights( lights );
var maxShadows = allocateShadows( lights );
var allocatedShadows = allocateShadows( lights );
var maxBones = allocateBones( object );
var precision = renderer.getPrecision();
......@@ -176,8 +182,9 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
maxSpotLights: maxLightCount.spot,
maxHemiLights: maxLightCount.hemi,
maxShadows: maxShadows,
shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && maxShadows > 0,
maxShadows: allocatedShadows.maxShadows,
pointLightShadows: allocatedShadows.pointLightShadows,
shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
shadowMapType: renderer.shadowMap.type,
shadowMapDebug: renderer.shadowMap.debug,
......
......@@ -238,6 +238,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
_lookTarget.add( cubeDirections[face] );
shadowCamera.up.copy( cubeUps[face] );
shadowCamera.lookAt( _lookTarget );
shadowMap.activeCubeFace = face;
} else {
......@@ -269,13 +270,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
// render shadow map
if( isCube ){
shadowMap.activeCubeFace = face;
}
// render shadow map
_renderer.setRenderTarget( shadowMap );
_renderer.clear();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册