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) );
相关推荐
一马平川的大草原7 天前
基于Vue+Three.js实现三维油藏模型解析与可视化交互切割操作
vue.js·three.js·三维油藏模型
RulerMike8 天前
three 实现简单机械臂逆运动
前端·ai编程·three.js
程序员阿峰10 天前
前端3D·Three.js一学就会系列:第二 画线
前端·three.js
程序员阿峰11 天前
前端3D·Three.js一学就会系列: 第一个3D网站
前端·three.js
烛阴11 天前
Three.js 场景完全入门指南:让你的 3D 场景不在乱成一团
webgl·three.js
ai超级个体14 天前
前端下午茶:这 3 个网页特效建议收藏(送源码)
前端·three.js·threejs·网页设计·vibe coding·网页灵感·网页分享
codingWhat16 天前
用 three.js 实现 3D 地图
three.js
答案answer20 天前
我的Three.js3D场景编辑器免费开源啦🎉🎉🎉
前端·github·three.js
一拳不是超人21 天前
Three.js一起学-如何通过官方例子高效学习 Three.js?手把手带你“抄”出一个3D动画
前端·webgl·three.js