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) );
相关推荐
爱看书的小沐2 小时前
【小沐杂货铺】基于Three.js渲染三维无人机Drone(WebGL / vue / react )
javascript·vue.js·react.js·无人机·webgl·three.js·drone
叶智辽8 天前
【ThreeJS实战】5个让我帧率翻倍的小技巧,不用改模型
性能优化·three.js
Charlie_lll8 天前
学习Three.js–柱状图
前端·3d·three.js
初次攀爬者9 天前
学习Three.js--柱状图
前端·html·three.js
叶智辽13 天前
【ThreeJS实战】从86MB到4MB:复杂模型加载优化黑魔法
性能优化·three.js
Charlie_lll14 天前
学习Three.js–雪花
前端·three.js
Charlie_lll17 天前
学习Three.js–风车星系
前端·three.js
Charlie_lll18 天前
学习Three.js–星环粒子(ShaderMaterial)
前端·three.js
Nan_Shu_61424 天前
学习:threejs案例—大屏3D地图可视化
前端·javascript·学习·three.js
Charlie_lll25 天前
学习Three.js–基于GeoJSON绘制2D矢量地图
前端·three.js