-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Wondering if I can put in some work here to buff out a three.js flavored export. For re-usable ShaderMaterials, I usually have them as their own little factory function like so:
// File named - ShaderNameHere.js
import * as THREE from 'three';
export function ShaderNameHere() {
this.uniforms = {
iTime: { value: 70.0 },
iMouse: { value: [0, 0] },
iResolution: { value: [2000.0, 1000.0] },
}
this.render = (delta) => { this.uniforms.iTime.value += delta}
this.material = new THREE.ShaderMaterial({
uniforms: this.uniforms,
side: THREE.BackSide,
vertexShader:`...`,
fragmentShader:`...`
})
}Then to use the custom shader material, you can:
import * as THREE from 'three';
import { ShaderNameHere } from './ShaderNameHere.js'
const shaderController = new ShaderNameHere();
const geometry = new THREE.SphereGeometry()
const mesh = new THREE.Mesh(geometry, shaderController.material)
/*
... Then somewhere in your render loop
*/
shaderController.render(delta) Wanted to see how you feel about the three.js flavored export to be a .js file similar to the first snippet?
Think I could bang out a PR for the exporter and have some good ideas for handling stuff like textures etc... Also happy to throw together a more robust export usage explanation page as part of the PR.
Metadata
Metadata
Assignees
Labels
No labels