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) );
相关推荐
独立开发之道20 分钟前
【three.js教程】安装指南:从零搭建你的第一个 3D Web 项目
three.js
xiaominlaopodaren1 天前
three.js最小地图运行时(一):视图状态
javascript·gis·three.js
xiaominlaopodaren3 天前
three.js地图数学基础(八):浮点精度
javascript·gis·three.js
xiaominlaopodaren4 天前
three.js地图数学基础(七):地图相机
javascript·gis·three.js
xiaominlaopodaren5 天前
three.js地图数学基础(六):齐次坐标与矩阵
javascript·gis·three.js
答案answer6 天前
VibeCoding 能做到什么程度?我用它做了一座 3D 数字博物馆
ai编程·three.js·vibecoding
xiaominlaopodaren7 天前
three.js地图数学基础(四):瓦片金字塔
javascript·gis·three.js
xiaominlaopodaren8 天前
three.js地图数学基础(三):实战墨卡托
javascript·gis·three.js
xiaominlaopodaren9 天前
three.js地图数学基础(二):Web Mercator
javascript·gis·three.js
其美杰布-富贵-李10 天前
第 8 篇:Three.js 材质系统
javascript·three.js·js