11import WebGPUUniformsGroup from './WebGPUUniformsGroup.js' ;
2+ import { FloatUniform , Matrix4Uniform } from './WebGPUUniform.js' ;
23import WebGPUSampler from './WebGPUSampler.js' ;
34import WebGPUSampledTexture from './WebGPUSampledTexture.js' ;
4- import { Matrix4 } from '../../../../build/three.module.js' ;
55
66class WebGPUBindings {
77
@@ -97,7 +97,9 @@ class WebGPUBindings {
9797 const array = binding . array ;
9898 const bufferGPU = binding . bufferGPU ;
9999
100- const needsBufferWrite = binding . update ( object , camera ) ;
100+ binding . onBeforeUpdate ( object , camera ) ;
101+
102+ const needsBufferWrite = binding . update ( ) ;
101103
102104 if ( needsBufferWrite === true ) {
103105
@@ -242,33 +244,36 @@ class WebGPUBindings {
242244
243245 // ubos
244246
247+ const modelViewUniform = new Matrix4Uniform ( 'modelMatrix' ) ;
248+ const modelViewMatrixUniform = new Matrix4Uniform ( 'modelViewMatrix' ) ;
249+
245250 const modelGroup = new WebGPUUniformsGroup ( ) ;
246251 modelGroup . setName ( 'modelUniforms' ) ;
247- modelGroup . setUniform ( 'modelMatrix' , new Matrix4 ( ) ) ;
248- modelGroup . setUniform ( 'modelViewMatrix' , new Matrix4 ( ) ) ;
249- modelGroup . setUpdateCallback ( function ( object /*, camera */ ) {
252+ modelGroup . addUniform ( modelViewUniform ) ;
253+ modelGroup . addUniform ( modelViewMatrixUniform ) ;
254+ modelGroup . setOnBeforeUpdate ( function ( object /*, camera */ ) {
250255
251- let updated = false ;
256+ modelViewUniform . setValue ( object . matrixWorld ) ;
257+ modelViewMatrixUniform . setValue ( object . modelViewMatrix ) ;
252258
253- if ( modelGroup . updateMatrix4 ( object . matrixWorld , 0 ) ) updated = true ;
254- if ( modelGroup . updateMatrix4 ( object . modelViewMatrix , 16 ) ) updated = true ;
259+ } ) ;
255260
256- return updated ;
261+ // opacity
257262
258- } ) ;
263+ const opacityUniform = new FloatUniform ( 'opacity' , 1 ) ;
259264
260265 const cameraGroup = this . sharedUniformsGroups . get ( 'cameraUniforms' ) ;
261266
262267 const opacityGroup = new WebGPUUniformsGroup ( ) ;
263268 opacityGroup . setName ( 'opacityUniforms' ) ;
264- opacityGroup . setUniform ( 'opacity' , 1.0 ) ;
269+ opacityGroup . addUniform ( opacityUniform ) ;
265270 opacityGroup . visibility = GPUShaderStage . FRAGMENT ;
266- opacityGroup . setUpdateCallback ( function ( object /*, camera */ ) {
271+ opacityGroup . setOnBeforeUpdate ( function ( object /*, camera */ ) {
267272
268273 const material = object . material ;
269274 const opacity = ( material . transparent === true ) ? material . opacity : 1.0 ;
270275
271- return opacityGroup . updateNumber ( opacity , 0 ) ;
276+ opacityUniform . setValue ( opacity ) ;
272277
273278 } ) ;
274279
@@ -300,18 +305,17 @@ class WebGPUBindings {
300305
301306 // ubos
302307
308+ const modelViewUniform = new Matrix4Uniform ( 'modelMatrix' ) ;
309+ const modelViewMatrixUniform = new Matrix4Uniform ( 'modelViewMatrix' ) ;
310+
303311 const modelGroup = new WebGPUUniformsGroup ( ) ;
304312 modelGroup . setName ( 'modelUniforms' ) ;
305- modelGroup . setUniform ( 'modelMatrix' , new Matrix4 ( ) ) ;
306- modelGroup . setUniform ( 'modelViewMatrix' , new Matrix4 ( ) ) ;
307- modelGroup . setUpdateCallback ( function ( object /*, camera */ ) {
308-
309- let updated = false ;
310-
311- if ( modelGroup . updateMatrix4 ( object . matrixWorld , 0 ) ) updated = true ;
312- if ( modelGroup . updateMatrix4 ( object . modelViewMatrix , 16 ) ) updated = true ;
313+ modelGroup . addUniform ( modelViewUniform ) ;
314+ modelGroup . addUniform ( modelViewMatrixUniform ) ;
315+ modelGroup . setOnBeforeUpdate ( function ( object /*, camera */ ) {
313316
314- return updated ;
317+ modelViewUniform . setValue ( object . matrixWorld ) ;
318+ modelViewMatrixUniform . setValue ( object . modelViewMatrix ) ;
315319
316320 } ) ;
317321
@@ -332,18 +336,17 @@ class WebGPUBindings {
332336
333337 // ubos
334338
339+ const modelViewUniform = new Matrix4Uniform ( 'modelMatrix' ) ;
340+ const modelViewMatrixUniform = new Matrix4Uniform ( 'modelViewMatrix' ) ;
341+
335342 const modelGroup = new WebGPUUniformsGroup ( ) ;
336343 modelGroup . setName ( 'modelUniforms' ) ;
337- modelGroup . setUniform ( 'modelMatrix' , new Matrix4 ( ) ) ;
338- modelGroup . setUniform ( 'modelViewMatrix' , new Matrix4 ( ) ) ;
339- modelGroup . setUpdateCallback ( function ( object /*, camera */ ) {
340-
341- let updated = false ;
342-
343- if ( modelGroup . updateMatrix4 ( object . matrixWorld , 0 ) ) updated = true ;
344- if ( modelGroup . updateMatrix4 ( object . modelViewMatrix , 16 ) ) updated = true ;
344+ modelGroup . addUniform ( modelViewUniform ) ;
345+ modelGroup . addUniform ( modelViewMatrixUniform ) ;
346+ modelGroup . setOnBeforeUpdate ( function ( object /*, camera */ ) {
345347
346- return updated ;
348+ modelViewUniform . setValue ( object . matrixWorld ) ;
349+ modelViewMatrixUniform . setValue ( object . modelViewMatrix ) ;
347350
348351 } ) ;
349352
@@ -360,18 +363,17 @@ class WebGPUBindings {
360363
361364 _setupSharedUniformsGroups ( ) {
362365
366+ const projectionMatrixUniform = new Matrix4Uniform ( 'projectionMatrix' ) ;
367+ const viewMatrixUniform = new Matrix4Uniform ( 'viewMatrix' ) ;
368+
363369 const cameraGroup = new WebGPUUniformsGroup ( ) ;
364370 cameraGroup . setName ( 'cameraUniforms' ) ;
365- cameraGroup . setUniform ( 'projectionMatrix' , new Matrix4 ( ) ) ;
366- cameraGroup . setUniform ( 'viewMatrix' , new Matrix4 ( ) ) ;
367- cameraGroup . setUpdateCallback ( function ( object , camera ) {
368-
369- let updated = false ;
370-
371- if ( cameraGroup . updateMatrix4 ( camera . projectionMatrix , 0 ) ) updated = true ;
372- if ( cameraGroup . updateMatrix4 ( camera . matrixWorldInverse , 16 ) ) updated = true ;
371+ cameraGroup . addUniform ( projectionMatrixUniform ) ;
372+ cameraGroup . addUniform ( viewMatrixUniform ) ;
373+ cameraGroup . setOnBeforeUpdate ( function ( object , camera ) {
373374
374- return updated ;
375+ projectionMatrixUniform . setValue ( camera . projectionMatrix ) ;
376+ viewMatrixUniform . setValue ( camera . matrixWorldInverse ) ;
375377
376378 } ) ;
377379
0 commit comments