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

BatchedMesh: Make the transform matrix / texture optional #29084

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
38 changes: 29 additions & 9 deletions build/three.cjs

Large diffs are not rendered by default.

38 changes: 29 additions & 9 deletions build/three.module.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion build/three.module.min.js

Large diffs are not rendered by default.

259 changes: 238 additions & 21 deletions build/three.webgpu.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion build/three.webgpu.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "three",
"version": "0.167.0",
"name": "@plastic-software/three",
"version": "0.167.4",
"description": "JavaScript 3D library",
"type": "module",
"main": "./build/three.cjs",
Expand Down
20 changes: 18 additions & 2 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,14 @@ class WebGLRenderer {

needsProgramChange = true;

} else if (object.isBatchedMesh && materialProperties.batchingMatrix === false && object._matricesTexture !== null) {

needsProgramChange = true;

} else if (object.isBatchedMesh && materialProperties.batchingMatrix === true && object._matricesTexture === null) {

needsProgramChange = true;

} else if ( object.isInstancedMesh && materialProperties.instancing === false ) {

needsProgramChange = true;
Expand Down Expand Up @@ -2035,10 +2043,18 @@ class WebGLRenderer {
if ( object.isBatchedMesh ) {

p_uniforms.setOptional( _gl, object, 'batchingTexture' );
p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );
if ( objects._matricesTexture !== null ) {

p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );

}

p_uniforms.setOptional( _gl, object, 'batchingIdTexture' );
p_uniforms.setValue( _gl, 'batchingIdTexture', object._indirectTexture, textures );
if ( object._indirectTexture !== null ) {

p_uniforms.setValue( _gl, 'batchingIdTexture', object._indirectTexture, textures );

}

p_uniforms.setOptional( _gl, object, 'batchingColorTexture' );
if ( object._colorsTexture !== null ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export default /* glsl */`
#ifdef USE_BATCHING
#ifdef USE_BATCHING_MATRIX
#if ! defined( GL_ANGLE_multi_draw )
#define gl_DrawID _gl_DrawID
uniform int _gl_DrawID;
#endif

uniform highp sampler2D batchingTexture;
uniform highp usampler2D batchingIdTexture;
mat4 getBatchingMatrix( const in float i ) {
mat4 getBatchingMatrix( const in int i ) {

int size = textureSize( batchingTexture, 0 ).x;
int j = int( i ) * 4;
Expand Down
6 changes: 4 additions & 2 deletions src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default /* glsl */`
#ifdef USE_BATCHING
mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
#ifdef USE_BATCHING_MATRIX
mat4 batchingMatrix = getBatchingMatrix( gl_DrawID );
#elif defined ( USE_BATCHING )
mat4 batchingMatrix = mat4( 1.0 );
#endif
`;
2 changes: 2 additions & 0 deletions src/renderers/shaders/ShaderLib/points.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uniform float size;
uniform float scale;

#include <common>
#include <batching_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
Expand All @@ -27,6 +28,7 @@ void main() {
#include <color_vertex>
#include <morphinstance_vertex>
#include <morphcolor_vertex>
#include <batching_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <project_vertex>
Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '',
parameters.batching ? '#define USE_BATCHING' : '',
parameters.batchingMatrix ? '#define USE_BATCHING_MATRIX' : '',
parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '',
parameters.instancing ? '#define USE_INSTANCING' : '',
parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
Expand Down
4 changes: 3 additions & 1 deletion src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
}

function getParameters( material, lights, shadows, scene, object ) {

const fog = scene.fog;
const geometry = object.geometry;
const environment = material.isMeshStandardMaterial ? scene.environment : null;
Expand Down Expand Up @@ -192,6 +191,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
precision: precision,

batching: IS_BATCHEDMESH,
batchingMatrix: IS_BATCHEDMESH && object._matricesTexture !== null,
batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null,
instancing: IS_INSTANCEDMESH,
instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
Expand Down Expand Up @@ -512,6 +512,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
_programLayers.enable( 20 );
if ( parameters.batchingColor )
_programLayers.enable( 21 );
if ( parameters.batchingMatrix )
_programLayers.enable( 22 );

array.push( _programLayers.mask );
_programLayers.disableAll();
Expand Down