提交 f8600068 编写于 作者: T Takahiro

Replace 8 with real maxMipLevel in lights_fragment_maps.glsl

上级 faa51af9
...@@ -1975,6 +1975,8 @@ function WebGLRenderer( parameters ) { ...@@ -1975,6 +1975,8 @@ function WebGLRenderer( parameters ) {
uniforms.reflectivity.value = material.reflectivity; uniforms.reflectivity.value = material.reflectivity;
uniforms.refractionRatio.value = material.refractionRatio; uniforms.refractionRatio.value = material.refractionRatio;
uniforms.maxMipLevel.value = material.envMap.maxMipLevel;
} }
if ( material.lightMap ) { if ( material.lightMap ) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
uniform sampler2D envMap; uniform sampler2D envMap;
#endif #endif
uniform float flipEnvMap; uniform float flipEnvMap;
uniform int maxMipLevel;
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL ) #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )
uniform float refractionRatio; uniform float refractionRatio;
......
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
// TODO, replace 8 with the real maxMIPLevel radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_BlinnShininessExponent( material ), maxMipLevel );
radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_BlinnShininessExponent( material ), 8 );
#ifndef STANDARD #ifndef STANDARD
clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 ); clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLeven );
#endif #endif
#endif #endif
...@@ -31,7 +31,8 @@ var UniformsLib = { ...@@ -31,7 +31,8 @@ var UniformsLib = {
envMap: { value: null }, envMap: { value: null },
flipEnvMap: { value: - 1 }, flipEnvMap: { value: - 1 },
reflectivity: { value: 1.0 }, reflectivity: { value: 1.0 },
refractionRatio: { value: 0.98 } refractionRatio: { value: 0.98 },
maxMipLevel: { value: 0 }
}, },
......
...@@ -81,6 +81,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -81,6 +81,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
function generateMipmap( texture, target ) {
_gl.generateMipmap( target );
var image = Array.isArray( texture.image ) ? texture.image[ 0 ] : texture.image;
texture.maxMipLevel = Math.max( Math.log2( Math.max( image.width, image.height ) ), texture.maxMipLevel );
}
// Fallback filters for non-power-of-2 textures // Fallback filters for non-power-of-2 textures
function filterFallback( f ) { function filterFallback( f ) {
...@@ -325,9 +334,19 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -325,9 +334,19 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
if ( ! isCompressed ) {
texture.maxMipLevel = 0;
} else {
texture.maxMipLevel = mipmaps.length - 1;
}
if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) { if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
_gl.generateMipmap( _gl.TEXTURE_CUBE_MAP ); generateMipmap( texture, _gl.TEXTURE_CUBE_MAP );
} }
...@@ -514,10 +533,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -514,10 +533,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
texture.generateMipmaps = false; texture.generateMipmaps = false;
texture.maxMipLevel = mipmaps.length - 1;
} else { } else {
state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data ); state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
texture.maxMipLevel = 0;
} }
...@@ -547,6 +568,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -547,6 +568,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
texture.maxMipLevel = mipmaps.length - 1;
} else { } else {
// regular Texture (image, video, canvas) // regular Texture (image, video, canvas)
...@@ -565,16 +588,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -565,16 +588,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
texture.generateMipmaps = false; texture.generateMipmaps = false;
texture.maxMipLevel = mipmaps.length - 1;
} else { } else {
state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image ); state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
texture.maxMipLevel = 0;
} }
} }
if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D ); if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
generateMipmap( texture, _gl.TEXTURE_2D );
}
textureProperties.__version = texture.version; textureProperties.__version = texture.version;
...@@ -754,7 +783,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -754,7 +783,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP ); if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
generateMipmap( renderTarget.texture, _gl.TEXTURE_CUBE_MAP );
}
state.bindTexture( _gl.TEXTURE_CUBE_MAP, null ); state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
} else { } else {
...@@ -763,7 +797,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -763,7 +797,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo ); setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D ); setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D ); if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
generateMipmap( renderTarget.texture, _gl.TEXTURE_2D );
}
state.bindTexture( _gl.TEXTURE_2D, null ); state.bindTexture( _gl.TEXTURE_2D, null );
} }
...@@ -789,7 +828,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -789,7 +828,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var webglTexture = properties.get( texture ).__webglTexture; var webglTexture = properties.get( texture ).__webglTexture;
state.bindTexture( target, webglTexture ); state.bindTexture( target, webglTexture );
_gl.generateMipmap( target ); generateMipmap( texture, target );
state.bindTexture( target, null ); state.bindTexture( target, null );
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册