Skip to content
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

Expose transmission texture creation to enable improved quality #22731

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
LinearEncoding,
NoToneMapping,
LinearMipmapLinearFilter,
NearestFilter,
LinearFilter,
ClampToEdgeWrapping
} from '../constants.js';
import { Frustum } from '../math/Frustum.js';
Expand Down Expand Up @@ -556,6 +556,28 @@ function WebGLRenderer( parameters = {} ) {

};

this.getTransmissionRenderTarget = function () {

if ( _transmissionRenderTarget === null ) {

const needsAntialias = _antialias === true && capabilities.isWebGL2 === true;
const renderTargetType = needsAntialias ? WebGLMultisampleRenderTarget : WebGLRenderTarget;

_transmissionRenderTarget = new renderTargetType( 1024, 1024, {
generateMipmaps: true,
type: utils.convert( HalfFloatType ) !== null ? HalfFloatType : UnsignedByteType,
minFilter: LinearMipmapLinearFilter,
magFilter: LinearFilter,
wrapS: ClampToEdgeWrapping,
wrapT: ClampToEdgeWrapping
} );

}

return _transmissionRenderTarget;

};

//

this.dispose = function () {
Expand Down Expand Up @@ -1181,24 +1203,10 @@ function WebGLRenderer( parameters = {} ) {

function renderTransmissionPass( opaqueObjects, scene, camera ) {

if ( _transmissionRenderTarget === null ) {

const needsAntialias = _antialias === true && capabilities.isWebGL2 === true;
const renderTargetType = needsAntialias ? WebGLMultisampleRenderTarget : WebGLRenderTarget;

_transmissionRenderTarget = new renderTargetType( 1024, 1024, {
generateMipmaps: true,
type: utils.convert( HalfFloatType ) !== null ? HalfFloatType : UnsignedByteType,
minFilter: LinearMipmapLinearFilter,
magFilter: NearestFilter,
wrapS: ClampToEdgeWrapping,
wrapT: ClampToEdgeWrapping
} );

}
const transmissionRenderTarget = _this.getTransmissionRenderTarget();

const currentRenderTarget = _this.getRenderTarget();
_this.setRenderTarget( _transmissionRenderTarget );
_this.setRenderTarget( transmissionRenderTarget );
_this.clear();

// Turn off the features which can affect the frag color for opaque objects pass.
Expand All @@ -1210,8 +1218,8 @@ function WebGLRenderer( parameters = {} ) {

_this.toneMapping = currentToneMapping;

textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
textures.updateRenderTargetMipmap( _transmissionRenderTarget );
textures.updateMultisampleRenderTarget( transmissionRenderTarget );
textures.updateRenderTargetMipmap( transmissionRenderTarget );

_this.setRenderTarget( currentRenderTarget );

Expand Down Expand Up @@ -1685,7 +1693,7 @@ function WebGLRenderer( parameters = {} ) {

}

materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget );
materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _this.getTransmissionRenderTarget() );

WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );

Expand Down