-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PMREM anisotropic filtering #23556
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,12 +409,6 @@ class PMREMGenerator { | |
|
||
uniforms[ 'envMap' ].value = texture; | ||
|
||
if ( ! isCubeTexture ) { | ||
|
||
uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height ); | ||
|
||
} | ||
|
||
const size = this._cubeSize; | ||
_setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size ); | ||
|
||
|
@@ -672,6 +666,10 @@ function _getBlurShader( lodMax, width, height ) { | |
|
||
name: 'SphericalGaussianBlur', | ||
|
||
extensions: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the shaderMaterial.extensions.shaderTextureLOD = true; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, good call, thanks! |
||
shaderTextureLOD: true | ||
}, | ||
|
||
defines: { | ||
'n': MAX_SAMPLES, | ||
'CUBEUV_TEXEL_WIDTH': 1.0 / width, | ||
|
@@ -765,14 +763,12 @@ function _getBlurShader( lodMax, width, height ) { | |
|
||
function _getEquirectShader() { | ||
|
||
const texelSize = new Vector2( 1, 1 ); | ||
const shaderMaterial = new RawShaderMaterial( { | ||
|
||
name: 'EquirectangularToCubeUV', | ||
|
||
uniforms: { | ||
'envMap': { value: null }, | ||
'texelSize': { value: texelSize } | ||
'envMap': { value: null } | ||
}, | ||
|
||
vertexShader: _getCommonVertexShader(), | ||
|
@@ -785,31 +781,16 @@ function _getEquirectShader() { | |
varying vec3 vOutputDirection; | ||
|
||
uniform sampler2D envMap; | ||
uniform vec2 texelSize; | ||
|
||
#include <common> | ||
|
||
void main() { | ||
|
||
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); | ||
|
||
vec3 outputDirection = normalize( vOutputDirection ); | ||
vec2 uv = equirectUv( outputDirection ); | ||
|
||
vec2 f = fract( uv / texelSize - 0.5 ); | ||
uv -= f * texelSize; | ||
vec3 tl = texture2D ( envMap, uv ).rgb; | ||
uv.x += texelSize.x; | ||
vec3 tr = texture2D ( envMap, uv ).rgb; | ||
uv.y += texelSize.y; | ||
vec3 br = texture2D ( envMap, uv ).rgb; | ||
uv.x -= texelSize.x; | ||
vec3 bl = texture2D ( envMap, uv ).rgb; | ||
|
||
vec3 tm = mix( tl, tr, f.x ); | ||
vec3 bm = mix( bl, br, f.x ); | ||
gl_FragColor.rgb = mix( tm, bm, f.y ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More vestigial code. |
||
|
||
gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); | ||
|
||
} | ||
`, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,15 @@ export default /* glsl */` | |
uv.x *= CUBEUV_TEXEL_WIDTH; | ||
uv.y *= CUBEUV_TEXEL_HEIGHT; | ||
|
||
return texture2D( envMap, uv ).rgb; | ||
#ifdef TEXTURE_LOD_EXT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would doing this instead work? #ifdef texture2DGradEXT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's equivalent, yes, but this was how it was done elsewhere in the code, specifically here: https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js#L60 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see... |
||
|
||
return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; // disable anisotropic filtering | ||
|
||
#else | ||
|
||
return texture2D( envMap, uv ).rgb; | ||
|
||
#endif | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,7 +423,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { | |
prefixFragment = [ | ||
|
||
customExtensions, | ||
customDefines | ||
customDefines, | ||
parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '' | ||
|
||
].filter( filterEmptyLine ).join( '\n' ); | ||
|
||
|
@@ -700,7 +701,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { | |
vertexShader = unrollLoops( vertexShader ); | ||
fragmentShader = unrollLoops( fragmentShader ); | ||
|
||
if ( parameters.isWebGL2 && parameters.isRawShaderMaterial !== true ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably the most controversial part of my change. Feedback welcome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be good to find a solution without changing this line since it affects user code. Just to be clear, you have removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. I also considered using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't these extensions automatically enabled with WebGL 2? So you need the injection only with WebGL 1. I mean all materials are affected by this, not only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, I only removed the check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I'll merge and do another PR reverting some of these things so we can see how it looks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, it's best when The idea of excluding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. I didn't realize a |
||
if ( parameters.isWebGL2 ) { | ||
|
||
// GLSL 3.0 conversion for built-in materials and ShaderMaterial | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized my previous simplification of PMREM had made this vestigial, so I removed it as well.