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) );
相关推荐
幸会同学4 天前
在Cesium中实现飘动的红旗
javascript·three.js·cesium
答案answer4 天前
一个超级真实的Three.js树🌲生成器插件
前端·three.js
CC码码8 天前
重生之我在浏览器里“蹦迪”
前端·javascript·three.js
onthewaying9 天前
在Android平台上使用Three.js优雅的加载3D模型
android·前端·three.js
VcB之殇11 天前
【three.js】实现玻璃材质时,出现黑色/白色像素噪点
前端·three.js
SeanTao12 天前
打造炫酷3D科技地球:Three.js实战指南
three.js
4_0_412 天前
一步一步实现 Shader 水波纹效果(入门到进阶)
前端·three.js
冴羽15 天前
这是一个很酷的金属球,点击它会产生涟漪……
前端·javascript·three.js
胖虎26516 天前
Three.js 工业 3D 可视化:生产线状态监控系统实现方案
three.js
何贤19 天前
🪐 行星科技概念官网!Hero Section 回归!(Three.js ✨)
前端·javascript·three.js