threejs 节点材质系统 绑定attribute

新的 节点材质系统 绑定属性及使用 非常方便 不必重复声明

以instances为例

js 复制代码
import {instancedBufferAttribute,instancedDynamicBufferAttribute,} from "three/tsl";

声明一个 InstancedBufferAttribute 使用 instancedBufferAttribute包装后就可以在shader中直接使用

js 复制代码
const instanceCount = 10
// 透明度
const floatOpacity = new Float32Array(instanceCount);

const buffer = new THREE.InstancedBufferAttribute(floatOpacity, 1);
// instancedDynamicBufferAttribute 每次写入buffer
// instancedBufferAttribute 手动更新 buffer.needUpdate = true
instanceMesh.instanceOpacity = instancedBufferAttribute(buffer);

使用

顶点着色器 声明 varying

js 复制代码
varyingProperty( 'float', 'vInstanceOpacity' ).assign( instanceMesh.instanceOpacity );

片元着色器 使用 varying

js 复制代码
const vInstanceOpacity = varyingProperty( 'float', 'vInstanceOpacity' ); 
diffuseColor.a.assign( diffuseColor.a.mul( opacityNode ).mul(vInstanceOpacity) );
相关推荐
叶智辽21 小时前
【ThreeJS实战】从86MB到4MB:复杂模型加载优化黑魔法
性能优化·three.js
Charlie_lll2 天前
学习Three.js–雪花
前端·three.js
Charlie_lll5 天前
学习Three.js–风车星系
前端·three.js
Charlie_lll6 天前
学习Three.js–星环粒子(ShaderMaterial)
前端·three.js
Nan_Shu_61412 天前
学习:threejs案例—大屏3D地图可视化
前端·javascript·学习·three.js
Charlie_lll13 天前
学习Three.js–基于GeoJSON绘制2D矢量地图
前端·three.js
Charlie_lll16 天前
学习Three.js–太阳系星球自转公转
前端·three.js
Charlie_lll18 天前
学习Three.js–纹理贴图(Texture)
前端·three.js
Charlie_lll18 天前
学习Three.js--光源Light+轨道控制器OrbitControls
前端·three.js
Nan_Shu_61418 天前
学习: Threejs (17)
学习·three.js