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) );
相关推荐
Jedi Hongbin16 小时前
Three.js NodeMaterial 节点材质系统文档
前端·javascript·three.js·nodematerial
入秋1 天前
Three.js后期处理实战:噪点 景深 以及色彩调整
前端·javascript·three.js
答案answer1 天前
你不知道的Three.js性能优化和使用小技巧
前端·性能优化·three.js
爱看书的小沐2 天前
【小沐学WebGIS】基于Three.JS绘制飞行轨迹Flight Tracker(Three.JS/ vue / react / WebGL)
javascript·vue·webgl·three.js·航班·航迹·飞行轨迹
小兔崽子去哪了5 天前
Three.js 学习记录
three.js
Demoncode_y5 天前
Vue3 + Three.js 实现 3D 汽车个性化定制及展示
前端·javascript·vue.js·3d·汽车·three.js
Mintopia10 天前
Cesium-kit 又发新玩意儿了:CameraControl 相机控制组件全解析
前端·three.js·cesium
Mintopia12 天前
🌍 cesium-kit —— 快速实现动态标点与交互的 Cesium 工具库
前端·three.js·cesium
答案answer12 天前
历时180多天,浅谈我对自由职业的初次探索
前端·程序员·three.js
YAY_tyy12 天前
Three.js 开发实战教程(四):相机系统全解析与多视角控制
前端·javascript·3d·教程·three.js