Skip to content

Commit

Permalink
Updated builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed May 21, 2024
1 parent a65fbf7 commit 989e89f
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 23 deletions.
150 changes: 139 additions & 11 deletions build/three.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7891,6 +7891,8 @@ class Object3D extends EventDispatcher {

object.matricesTexture = this._matricesTexture.toJSON( meta );

if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );

if ( this.boundingSphere !== null ) {

object.boundingSphere = {
Expand Down Expand Up @@ -13803,7 +13805,7 @@ var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D(

var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";

var batching_pars_vertex = "#ifdef USE_BATCHING\n\tattribute float batchId;\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif";
var batching_pars_vertex = "#ifdef USE_BATCHING\n\tattribute float batchId;\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec3 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\n\t}\n#endif";

var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( batchId );\n#endif";

Expand All @@ -13829,9 +13831,9 @@ var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\

var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif";

var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif";

var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( batchId );\n\tvColor.xyz *= batchingColor.xyz;\n#endif";

var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat luminance( const in vec3 rgb ) {\n\tconst vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n\treturn dot( weights, rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated";

Expand Down Expand Up @@ -14852,6 +14854,12 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,

if ( renderer.autoClear || forceClear ) {

// buffers might not be writable which is required to ensure a correct clear

state.buffers.depth.setTest( true );
state.buffers.depth.setMask( true );
state.buffers.color.setMask( true );

renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );

}
Expand Down Expand Up @@ -19747,6 +19755,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '',
parameters.batching ? '#define USE_BATCHING' : '',
parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '',
parameters.instancing ? '#define USE_INSTANCING' : '',
parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
parameters.instancingMorph ? '#define USE_INSTANCING_MORPH' : '',
Expand Down Expand Up @@ -19998,7 +20007,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',

parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',
parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? '#define USE_COLOR' : '',
parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
parameters.vertexUv1s ? '#define USE_UV1' : '',
parameters.vertexUv2s ? '#define USE_UV2' : '',
Expand Down Expand Up @@ -20594,6 +20603,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
precision: precision,

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

array.push( _programLayers.mask );
_programLayers.disableAll();
Expand Down Expand Up @@ -28515,6 +28527,8 @@ class WebGLRenderer {

const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };

let _renderBackground = false;

function getTargetPixelRatio() {

return _currentRenderTarget === null ? _pixelRatio : 1;
Expand Down Expand Up @@ -29462,8 +29476,8 @@ class WebGLRenderer {

}

const renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
if ( renderBackground ) {
_renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
if ( _renderBackground ) {

background.addToRenderList( currentRenderList, scene );

Expand Down Expand Up @@ -29508,7 +29522,7 @@ class WebGLRenderer {

}

if ( renderBackground ) background.render( scene );
if ( _renderBackground ) background.render( scene );

for ( let i = 0, l = cameras.length; i < l; i ++ ) {

Expand All @@ -29522,7 +29536,7 @@ class WebGLRenderer {

if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );

if ( renderBackground ) background.render( scene );
if ( _renderBackground ) background.render( scene );

renderScene( currentRenderList, scene, camera );

Expand Down Expand Up @@ -29739,7 +29753,8 @@ class WebGLRenderer {
samples: 4,
stencilBuffer: stencil,
resolveDepthBuffer: false,
resolveStencilBuffer: false
resolveStencilBuffer: false,
colorSpace: ColorManagement.workingColorSpace,
} );

// debug
Expand Down Expand Up @@ -29768,7 +29783,15 @@ class WebGLRenderer {
_currentClearAlpha = _this.getClearAlpha();
if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );

_this.clear();
if ( _renderBackground ) {

background.render( scene );

} else {

_this.clear();

}

// Turn off the features which can affect the frag color for opaque objects pass.
// Otherwise they are applied twice in opaque objects pass and transmission objects pass.
Expand Down Expand Up @@ -30025,6 +30048,7 @@ class WebGLRenderer {

materialProperties.outputColorSpace = parameters.outputColorSpace;
materialProperties.batching = parameters.batching;
materialProperties.batchingColor = parameters.batchingColor;
materialProperties.instancing = parameters.instancing;
materialProperties.instancingColor = parameters.instancingColor;
materialProperties.instancingMorph = parameters.instancingMorph;
Expand Down Expand Up @@ -30114,6 +30138,14 @@ class WebGLRenderer {

needsProgramChange = true;

} else if ( object.isBatchedMesh && materialProperties.batchingColor === true && object.colorTexture === null ) {

needsProgramChange = true;

} else if ( object.isBatchedMesh && materialProperties.batchingColor === false && object.colorTexture !== null ) {

needsProgramChange = true;

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

needsProgramChange = true;
Expand Down Expand Up @@ -30306,6 +30338,13 @@ class WebGLRenderer {
p_uniforms.setOptional( _gl, object, 'batchingTexture' );
p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );

p_uniforms.setOptional( _gl, object, 'batchingColorTexture' );
if ( object._colorsTexture !== null ) {

p_uniforms.setValue( _gl, 'batchingColorTexture', object._colorsTexture, textures );

}

}

const morphAttributes = geometry.morphAttributes;
Expand Down Expand Up @@ -33072,11 +33111,14 @@ const ID_ATTR_NAME = 'batchId';
const _matrix$1 = /*@__PURE__*/ new Matrix4();
const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
const _identityMatrix = /*@__PURE__*/ new Matrix4();
const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
const _projScreenMatrix$2 = /*@__PURE__*/ new Matrix4();
const _frustum = /*@__PURE__*/ new Frustum();
const _box$1 = /*@__PURE__*/ new Box3();
const _sphere$2 = /*@__PURE__*/ new Sphere();
const _vector$5 = /*@__PURE__*/ new Vector3();
const _forward = /*@__PURE__*/ new Vector3();
const _temp = /*@__PURE__*/ new Vector3();
const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
const _mesh = /*@__PURE__*/ new Mesh();
const _batchIntersects = [];
Expand Down Expand Up @@ -33161,6 +33203,9 @@ class BatchedMesh extends Mesh {

this._initMatricesTexture();

// Local color per geometry by using data texture
this._colorsTexture = null;

}

_initMatricesTexture() {
Expand All @@ -33183,6 +33228,20 @@ class BatchedMesh extends Mesh {

}

_initColorsTexture() {

let size = Math.sqrt( this._maxGeometryCount );
size = Math.ceil( size );

// 4 floats per RGBA pixel initialized to white
const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
colorsTexture.colorSpace = ColorManagement.workingColorSpace;

this._colorsTexture = colorsTexture;

}

_initializeGeometry( reference ) {

const geometry = this.geometry;
Expand Down Expand Up @@ -33416,6 +33475,7 @@ class BatchedMesh extends Mesh {
const active = this._active;
const matricesTexture = this._matricesTexture;
const matricesArray = this._matricesTexture.image.data;
const colorsTexture = this._colorsTexture;

// push new visibility states
visibility.push( true );
Expand All @@ -33429,6 +33489,14 @@ class BatchedMesh extends Mesh {
_identityMatrix.toArray( matricesArray, geometryId * 16 );
matricesTexture.needsUpdate = true;

// initialize the color to white
if ( colorsTexture !== null ) {

_whiteColor.toArray( colorsTexture.image.data, geometryId * 4 );
colorsTexture.needsUpdate = true;

}

// add the reserved range and draw range objects
reservedRanges.push( reservedRange );
drawRanges.push( {
Expand Down Expand Up @@ -33747,6 +33815,49 @@ class BatchedMesh extends Mesh {

}

setColorAt( geometryId, color ) {

if ( this._colorsTexture === null ) {

this._initColorsTexture();

}

// @TODO: Map geometryId to index of the arrays because
// optimize() can make geometryId mismatch the index

const active = this._active;
const colorsTexture = this._colorsTexture;
const colorsArray = this._colorsTexture.image.data;
const geometryCount = this._geometryCount;
if ( geometryId >= geometryCount || active[ geometryId ] === false ) {

return this;

}

color.toArray( colorsArray, geometryId * 4 );
colorsTexture.needsUpdate = true;

return this;

}

getColorAt( geometryId, color ) {

const active = this._active;
const colorsArray = this._colorsTexture.image.data;
const geometryCount = this._geometryCount;
if ( geometryId >= geometryCount || active[ geometryId ] === false ) {

return null;

}

return color.fromArray( colorsArray, geometryId * 4 );

}

setVisibleAt( geometryId, value ) {

const visibility = this._visibility;
Expand Down Expand Up @@ -33887,6 +33998,13 @@ class BatchedMesh extends Mesh {
this._matricesTexture = source._matricesTexture.clone();
this._matricesTexture.image.data = this._matricesTexture.image.slice();

if ( this._colorsTexture !== null ) {

this._colorsTexture = source._colorsTexture.clone();
this._colorsTexture.image.data = this._colorsTexture.image.slice();

}

return this;

}
Expand All @@ -33898,6 +34016,14 @@ class BatchedMesh extends Mesh {

this._matricesTexture.dispose();
this._matricesTexture = null;

if ( this._colorsTexture !== null ) {

this._colorsTexture.dispose();
this._colorsTexture = null;

}

return this;

}
Expand Down Expand Up @@ -33943,6 +34069,7 @@ class BatchedMesh extends Mesh {
// get the camera position in the local frame
_invMatrixWorld.copy( this.matrixWorld ).invert();
_vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _invMatrixWorld );
_forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _invMatrixWorld );

for ( let i = 0, l = visibility.length; i < l; i ++ ) {

Expand All @@ -33963,7 +34090,7 @@ class BatchedMesh extends Mesh {
if ( ! culled ) {

// get the distance from camera used for sorting
const z = _vector$5.distanceTo( _sphere$2.center );
const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
_renderList.push( drawRanges[ i ], z );

}
Expand Down Expand Up @@ -46876,6 +47003,7 @@ class ObjectLoader extends Loader {
object._geometryCount = data.geometryCount;

object._matricesTexture = getTexture( data.matricesTexture.uuid );
if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );

break;

Expand Down
Loading

0 comments on commit 989e89f

Please sign in to comment.