|
1 | 1 | import NodeMaterial from '../../../materials/nodes/NodeMaterial.js';
|
2 | 2 | import { getDirection, blur, bilinearCubeUV, getBlurParams } from '../../../nodes/pmrem/PMREMUtils.js';
|
3 | 3 | import { equirectUV } from '../../../nodes/utils/EquirectUVNode.js';
|
4 |
| -import { uniform } from '../../../nodes/core/UniformNode.js'; |
5 |
| -import { uniformArray } from '../../../nodes/accessors/UniformArrayNode.js'; |
| 4 | +import { userData } from '../../../nodes/accessors/UserDataNode.js'; |
6 | 5 | import { texture } from '../../../nodes/accessors/TextureNode.js';
|
7 | 6 | import { cubeTexture } from '../../../nodes/accessors/CubeTextureNode.js';
|
8 |
| -import { float, vec3, Fn } from '../../../nodes/tsl/TSLBase.js'; |
| 7 | +import { float, int, vec3, Fn } from '../../../nodes/tsl/TSLBase.js'; |
9 | 8 | import { uv } from '../../../nodes/accessors/UV.js';
|
10 | 9 | import { attribute } from '../../../nodes/core/AttributeNode.js';
|
11 | 10 |
|
@@ -622,26 +621,20 @@ class PMREMGenerator {
|
622 | 621 | const blurMesh = this._lodMeshes[ lodOut ];
|
623 | 622 | blurMesh.material = blurMaterial;
|
624 | 623 |
|
625 |
| - const blurUniforms = blurMaterial.uniforms; |
626 |
| - |
627 |
| - const {radiansPerPixel, samples, weights}=getBlurParams(sigmaRadians, this._sizeLods[ lodIn ] - 1, MAX_SAMPLES); |
628 |
| - |
629 | 624 | targetIn.texture.frame = ( targetIn.texture.frame || 0 ) + 1;
|
630 |
| - |
631 |
| - blurUniforms.envMap.value = targetIn.texture; |
632 |
| - blurUniforms.samples.value = samples; |
633 |
| - blurUniforms.weights.array = weights; |
634 |
| - blurUniforms.latitudinal.value = direction === 'latitudinal' ? 1 : 0; |
635 |
| - |
636 |
| - if ( poleAxis ) { |
637 |
| - |
638 |
| - blurUniforms.poleAxis.value = poleAxis; |
639 |
| - |
640 |
| - } |
| 625 | + blurMaterial._envMap.value = targetIn.texture |
641 | 626 |
|
642 | 627 | const { _lodMax } = this;
|
643 |
| - blurUniforms.dTheta.value = radiansPerPixel; |
644 |
| - blurUniforms.mipInt.value = _lodMax - lodIn; |
| 628 | + const {radiansPerPixel, samples, weights}=getBlurParams(sigmaRadians, this._sizeLods[ lodIn ] - 1, MAX_SAMPLES); |
| 629 | + |
| 630 | + blurMesh.userData={ |
| 631 | + samples, |
| 632 | + weights, |
| 633 | + poleAxis, |
| 634 | + latitudinal: direction === 'latitudinal' ? 1 : 0, |
| 635 | + dTheta: radiansPerPixel, |
| 636 | + mipInt: _lodMax - lodIn |
| 637 | + }; |
645 | 638 |
|
646 | 639 | const outputSize = this._sizeLods[ lodOut ];
|
647 | 640 | const x = 3 * outputSize * ( lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0 );
|
@@ -771,36 +764,26 @@ function _getMaterial( type ) {
|
771 | 764 |
|
772 | 765 | function _getBlurShader( lodMax, width, height ) {
|
773 | 766 |
|
774 |
| - const weights = uniformArray( new Array( MAX_SAMPLES ).fill( 0 ) ); |
775 |
| - const poleAxis = uniform( new Vector3( 0, 1, 0 ) ); |
776 |
| - const dTheta = uniform( 0 ); |
| 767 | + const weights = userData( 'weights', 'float' ); |
| 768 | + const poleAxis = userData( 'poleAxis', 'vec3' ); |
| 769 | + const dTheta = userData( 'dTheta', 'float' ); |
777 | 770 | const n = float( MAX_SAMPLES );
|
778 |
| - const latitudinal = uniform( 0 ); // false, bool |
779 |
| - const samples = uniform( 1 ); // int |
| 771 | + const latitudinal = userData( 'latitudinal', 'int' ); // bool |
| 772 | + const samples = userData( 'samples', 'int' ); |
| 773 | + const mipInt = userData( 'mipInt', 'int' ); |
| 774 | + |
780 | 775 | const envMap = texture( null );
|
781 |
| - const mipInt = uniform( 0 ); // int |
782 | 776 | const CUBEUV_TEXEL_WIDTH = float( 1 / width );
|
783 | 777 | const CUBEUV_TEXEL_HEIGHT = float( 1 / height );
|
784 | 778 | const CUBEUV_MAX_MIP = float( lodMax );
|
785 | 779 |
|
786 |
| - const materialUniforms = { |
787 |
| - n, |
788 |
| - latitudinal, |
789 |
| - weights, |
790 |
| - poleAxis, |
791 |
| - outputDirection, |
792 |
| - dTheta, |
793 |
| - samples, |
794 |
| - envMap, |
795 |
| - mipInt |
796 |
| - }; |
797 |
| - |
798 | 780 | const material = _getMaterial( 'blur' );
|
799 |
| - material.uniforms = materialUniforms; // TODO: Move to outside of the material |
| 781 | + material._envMap = envMap; |
| 782 | + |
800 | 783 | const cubeUVsampler=Fn(( [ sampleDirection ] )=>{
|
801 | 784 | return bilinearCubeUV( envMap, sampleDirection, mipInt, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP );
|
802 | 785 | });
|
803 |
| - material.fragmentNode = blur( { ...materialUniforms, latitudinal: latitudinal.equal( 1 ), sampler: cubeUVsampler } ); |
| 786 | + material.fragmentNode = blur( { n, latitudinal: latitudinal.equal( int ( 1 ) ), poleAxis, outputDirection, weights, samples, dTheta, sampler: cubeUVsampler } ); |
804 | 787 |
|
805 | 788 | return material;
|
806 | 789 |
|
|
0 commit comments