您的位置:首页 > 教育 > 锐评 > 律师事务所网站模板_洛阳疫情最新政策措施_如何做网站 新手 个人 教程_什么是网络营销

律师事务所网站模板_洛阳疫情最新政策措施_如何做网站 新手 个人 教程_什么是网络营销

2024/10/5 22:49:06 来源:https://blog.csdn.net/printf_hello/article/details/142681464  浏览:    关键词:律师事务所网站模板_洛阳疫情最新政策措施_如何做网站 新手 个人 教程_什么是网络营销
律师事务所网站模板_洛阳疫情最新政策措施_如何做网站 新手 个人 教程_什么是网络营销

文章目录

        • setup
        • setupView (每次渲染scene都会执行) * viewMatrix

取自 WebGlLights.js r168

setup
for ( let i = 0, l = lights.length; i < l; i ++ ) {const light = lights[ i ];const color = light.color;
const intensity = light.intensity;
const distance = light.distance;const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;if ( light.isAmbientLight ) {r += color.r * intensity;g += color.g * intensity;b += color.b * intensity;} else if ( light.isLightProbe ) {for ( let j = 0; j < 9; j ++ ) {state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );}numLightProbes ++;} else if ( light.isDirectionalLight ) {const uniforms = cache.get( light );uniforms.color.copy( light.color ).multiplyScalar( light.intensity );if ( light.castShadow ) {const shadow = light.shadow;const shadowUniforms = shadowCache.get( light );shadowUniforms.shadowIntensity = shadow.intensity;shadowUniforms.shadowBias = shadow.bias;shadowUniforms.shadowNormalBias = shadow.normalBias;shadowUniforms.shadowRadius = shadow.radius;shadowUniforms.shadowMapSize = shadow.mapSize;state.directionalShadow[ directionalLength ] = shadowUniforms;state.directionalShadowMap[ directionalLength ] = shadowMap;state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;numDirectionalShadows ++;}state.directional[ directionalLength ] = uniforms;directionalLength ++;} else if ( light.isSpotLight ) {const uniforms = cache.get( light );uniforms.position.setFromMatrixPosition( light.matrixWorld );uniforms.color.copy( color ).multiplyScalar( intensity );uniforms.distance = distance;uniforms.coneCos = Math.cos( light.angle );uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );uniforms.decay = light.decay;state.spot[ spotLength ] = uniforms;const shadow = light.shadow;if ( light.map ) {state.spotLightMap[ numSpotMaps ] = light.map;numSpotMaps ++;// make sure the lightMatrix is up to date// TODO : do it if required onlyshadow.updateMatrices( light );if ( light.castShadow ) numSpotShadowsWithMaps ++;}state.spotLightMatrix[ spotLength ] = shadow.matrix;if ( light.castShadow ) {const shadowUniforms = shadowCache.get( light );shadowUniforms.shadowIntensity = shadow.intensity;shadowUniforms.shadowBias = shadow.bias;shadowUniforms.shadowNormalBias = shadow.normalBias;shadowUniforms.shadowRadius = shadow.radius;shadowUniforms.shadowMapSize = shadow.mapSize;state.spotShadow[ spotLength ] = shadowUniforms;state.spotShadowMap[ spotLength ] = shadowMap;numSpotShadows ++;}spotLength ++;} else if ( light.isRectAreaLight ) {const uniforms = cache.get( light );uniforms.color.copy( color ).multiplyScalar( intensity );uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );state.rectArea[ rectAreaLength ] = uniforms;rectAreaLength ++;} else if ( light.isPointLight ) {const uniforms = cache.get( light );uniforms.color.copy( light.color ).multiplyScalar( light.intensity );uniforms.distance = light.distance;uniforms.decay = light.decay;if ( light.castShadow ) {const shadow = light.shadow;const shadowUniforms = shadowCache.get( light );shadowUniforms.shadowIntensity = shadow.intensity;shadowUniforms.shadowBias = shadow.bias;shadowUniforms.shadowNormalBias = shadow.normalBias;shadowUniforms.shadowRadius = shadow.radius;shadowUniforms.shadowMapSize = shadow.mapSize;shadowUniforms.shadowCameraNear = shadow.camera.near;shadowUniforms.shadowCameraFar = shadow.camera.far;state.pointShadow[ pointLength ] = shadowUniforms;state.pointShadowMap[ pointLength ] = shadowMap;state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;numPointShadows ++;}state.point[ pointLength ] = uniforms;pointLength ++;} else if ( light.isHemisphereLight ) {const uniforms = cache.get( light );uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );state.hemi[ hemiLength ] = uniforms;hemiLength ++;}
setupView (每次渲染scene都会执行) * viewMatrix
function setupView( lights, camera ) {let directionalLength = 0;let pointLength = 0;let spotLength = 0;let rectAreaLength = 0;let hemiLength = 0;const viewMatrix = camera.matrixWorldInverse;for ( let i = 0, l = lights.length; i < l; i ++ ) {const light = lights[ i ];if ( light.isDirectionalLight ) {const uniforms = state.directional[ directionalLength ];uniforms.direction.setFromMatrixPosition( light.matrixWorld );vector3.setFromMatrixPosition( light.target.matrixWorld );uniforms.direction.sub( vector3 );uniforms.direction.transformDirection( viewMatrix );directionalLength ++;} else if ( light.isSpotLight ) {const uniforms = state.spot[ spotLength ];uniforms.position.setFromMatrixPosition( light.matrixWorld );uniforms.position.applyMatrix4( viewMatrix );uniforms.direction.setFromMatrixPosition( light.matrixWorld );vector3.setFromMatrixPosition( light.target.matrixWorld );uniforms.direction.sub( vector3 );uniforms.direction.transformDirection( viewMatrix );spotLength ++;} else if ( light.isRectAreaLight ) {const uniforms = state.rectArea[ rectAreaLength ];uniforms.position.setFromMatrixPosition( light.matrixWorld );uniforms.position.applyMatrix4( viewMatrix );// extract local rotation of light to derive width/height half vectorsmatrix42.identity();matrix4.copy( light.matrixWorld );matrix4.premultiply( viewMatrix );matrix42.extractRotation( matrix4 );uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );uniforms.halfWidth.applyMatrix4( matrix42 );uniforms.halfHeight.applyMatrix4( matrix42 );rectAreaLength ++;} else if ( light.isPointLight ) {const uniforms = state.point[ pointLength ];uniforms.position.setFromMatrixPosition( light.matrixWorld );uniforms.position.applyMatrix4( viewMatrix );pointLength ++;} else if ( light.isHemisphereLight ) {const uniforms = state.hemi[ hemiLength ];uniforms.direction.setFromMatrixPosition( light.matrixWorld );uniforms.direction.transformDirection( viewMatrix );hemiLength ++;}}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com