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

WebGLRenderer: Refactor creation of transmission render target. #23450

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion docs/api/en/materials/MeshPhysicalMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ <h3>[property:Float transmission]</h3>

The transmission property can be used to model these materials.<br />

When transmission is non-zero, [page:Material.opacity opacity] should be set to *1*.
When transmission is non-zero, [page:Material.opacity opacity] should be set to *1*.<br />

This feature can only be used with a WebGL 2 rendering context.
</p>

<h3>[property:Texture transmissionMap]</h3>
Expand Down
4 changes: 3 additions & 1 deletion docs/api/zh/materials/MeshPhysicalMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ <h3>[property:Float transmission]</h3>

The transmission property can be used to model these materials.<br />

When transmission is non-zero, [page:Material.opacity opacity] should be set to *1*.
When transmission is non-zero, [page:Material.opacity opacity] should be set to *1*.<br />

This feature can only be used with a WebGL 2 rendering context.
</p>

<h3>[property:Texture transmissionMap]</h3>
Expand Down
32 changes: 21 additions & 11 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
UnsignedByteType,
LinearEncoding,
NoToneMapping,
LinearMipmapLinearFilter,
NearestFilter,
ClampToEdgeWrapping
LinearMipmapLinearFilter
} from '../constants.js';
import { Frustum } from '../math/Frustum.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector4 } from '../math/Vector4.js';
import { WebGLAnimation } from './webgl/WebGLAnimation.js';
Expand Down Expand Up @@ -170,6 +169,7 @@ function WebGLRenderer( parameters = {} ) {

const _projScreenMatrix = new Matrix4();

const _vector2 = new Vector2();
const _vector3 = new Vector3();

const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
Expand Down Expand Up @@ -1184,23 +1184,33 @@ function WebGLRenderer( parameters = {} ) {

function renderTransmissionPass( opaqueObjects, scene, camera ) {

if ( capabilities.isWebGL2 === false ) {

console.error( 'THREE.WebGLRenderer: Transmission can only be used with WebGL 2.' );
return;

}

if ( _transmissionRenderTarget === null ) {

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

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

}

// set size of transmission render target to half size of drawing buffer

_this.getDrawingBufferSize( _vector2 ).multiplyScalar( 0.5 ).floor();
_transmissionRenderTarget.setSize( _vector2.x, _vector2.y );

//

const currentRenderTarget = _this.getRenderTarget();
_this.setRenderTarget( _transmissionRenderTarget );
_this.clear();
Expand Down Expand Up @@ -1786,7 +1796,7 @@ function WebGLRenderer( parameters = {} ) {
// are midframe flushes and an external depth buffer. Disable use of the extension.
if ( renderTarget.useRenderToTexture ) {

console.warn( 'render-to-texture extension was disabled because an external texture was provided' );
console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
renderTarget.useRenderToTexture = false;
renderTarget.useRenderbuffer = true;

Expand Down