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: Fix texture unit allocation of morph textures. #22624

Merged
merged 1 commit into from
Oct 4, 2021
Merged
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
WebGLRenderer: Fix texture unit allocation.
Mugen87 committed Oct 1, 2021
commit 6c6b0e29bc2cce013aaaaf43bc488ee04aeaf633
Binary file modified examples/screenshots/webgl_animation_multiple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 18 additions & 17 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
@@ -737,7 +737,7 @@ function WebGLRenderer( parameters = {} ) {

const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );

const program = setProgram( camera, scene, material, object );
const program = setProgram( camera, scene, geometry, material, object );

state.setMaterial( material, frontFaceCW );

@@ -769,12 +769,6 @@ function WebGLRenderer( parameters = {} ) {

}

if ( geometry.morphAttributes.position !== undefined || geometry.morphAttributes.normal !== undefined ) {

morphtargets.update( object, geometry, material, program );

}

bindingStates.setup( object, material, program, geometry, index );

let attribute;
@@ -1339,7 +1333,7 @@ function WebGLRenderer( parameters = {} ) {

if ( object.isImmediateRenderObject ) {

const program = setProgram( camera, scene, material, object );
const program = setProgram( camera, scene, geometry, material, object );

state.setMaterial( material );

@@ -1504,7 +1498,7 @@ function WebGLRenderer( parameters = {} ) {

}

function setProgram( camera, scene, material, object ) {
function setProgram( camera, scene, geometry, material, object ) {

if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...

@@ -1514,11 +1508,11 @@ function WebGLRenderer( parameters = {} ) {
const environment = material.isMeshStandardMaterial ? scene.environment : null;
const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
const vertexAlphas = material.vertexColors === true && !! object.geometry && !! object.geometry.attributes.color && object.geometry.attributes.color.itemSize === 4;
Copy link
Collaborator Author

@Mugen87 Mugen87 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the !! object.geometry statements make sense. Render items always have a geometry, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, we need this for ImmediateRenderObject.

Copy link
Collaborator Author

@Mugen87 Mugen87 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could remove ImmediateRenderObject 🤔. This would noticeably simplify the renderer. And in that way,WebGPURenderer does not have to support ImmediateRenderObject.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me 👍

const vertexTangents = !! material.normalMap && !! object.geometry && !! object.geometry.attributes.tangent;
const morphTargets = !! object.geometry && !! object.geometry.morphAttributes.position;
const morphNormals = !! object.geometry && !! object.geometry.morphAttributes.normal;
const morphTargetsCount = ( !! object.geometry && !! object.geometry.morphAttributes.position ) ? object.geometry.morphAttributes.position.length : 0;
const vertexAlphas = material.vertexColors === true && !! geometry && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
const vertexTangents = !! material.normalMap && !! geometry && !! geometry.attributes.tangent;
const morphTargets = !! geometry && !! geometry.morphAttributes.position;
const morphNormals = !! geometry && !! geometry.morphAttributes.normal;
const morphTargetsCount = ( !! geometry && !! geometry.morphAttributes.position ) ? geometry.morphAttributes.position.length : 0;

const materialProperties = properties.get( material );
const lights = currentRenderState.state.lights;
@@ -1716,9 +1710,9 @@ function WebGLRenderer( parameters = {} ) {

}

// skinning uniforms must be set even if material didn't change
// auto-setting of texture unit for bone texture must go before other textures
// otherwise textures used for skinning can take over texture units reserved for other material textures
// skinning and morph target uniforms must be set even if material didn't change
// auto-setting of texture unit for bone and morph texture must go before other textures
// otherwise textures used for skinning and morphing can take over texture units reserved for other material textures

if ( object.isSkinnedMesh ) {

@@ -1746,6 +1740,13 @@ function WebGLRenderer( parameters = {} ) {

}

if ( !! geometry && ( geometry.morphAttributes.position !== undefined || geometry.morphAttributes.normal !== undefined ) ) {

morphtargets.update( object, geometry, material, program );

}


if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {

materialProperties.receiveShadow = object.receiveShadow;