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) );
相关推荐
xiaominlaopodaren1 天前
three.js地图数学基础(三):实战墨卡托
javascript·gis·three.js
xiaominlaopodaren2 天前
three.js地图数学基础(二):Web Mercator
javascript·gis·three.js
其美杰布-富贵-李3 天前
第 8 篇:Three.js 材质系统
javascript·three.js·js
Necis3 天前
半天,AI 重写了我的五年前的娃娃机
ai编程·three.js
xiaominlaopodaren3 天前
three.js地图数学基础(一)
前端·three.js
因_崔斯汀6 天前
Three.js 3D 热力云图效果实现
前端·three.js
其美杰布-富贵-李6 天前
第 10 篇:灯光与阴影
javascript·three.js
其美杰布-富贵-李6 天前
第 6 篇:相机与 OrbitControls
前端·javascript·three.js
因_崔斯汀7 天前
Three.js扩散波纹动画实现
前端·three.js
其美杰布-富贵-李8 天前
第 5 篇:Object3D、Group 与场景树
javascript·three.js