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) );
相关推荐
用户831348593069841 分钟前
Vue+Threejs实现人物奔跑场景
vue.js·webgl·three.js
云空1 天前
《Three.js 完整版3D魔方:带贴纸+中心固定+自动求解复原》
前端·javascript·3d·three.js
云空1 天前
《Three.js 可操控3D魔方(键盘转动+打乱+复原)》
javascript·学习·游戏·3d·three.js
云空2 天前
《终极版3D数字沙盘:双视角漫游+建筑点击信息+昼夜一键切换》
3d·three.js
云空3 天前
《Three.js 3D实例大全》
开发语言·javascript·3d·three.js
云空3 天前
《Three.js 3D坦克对战【AI单机版】》
javascript·人工智能·3d·three.js
李伟_Li慢慢4 天前
12-mini版WebGLObjects
前端·three.js
李伟_Li慢慢4 天前
17-mini版WebGLBufferRenderer
前端·three.js
李伟_Li慢慢4 天前
16-mini版WebGLBackground
前端·three.js
李伟_Li慢慢4 天前
13-mini版WebGLProgram
前端·three.js