polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
47 lines (40 loc) • 1.55 kB
text/typescript
/**
* Creates a Mesh Standard Material, which can be extended with GL nodes.
*
* @remarks
* This node can create children, which will be GL nodes. The GLSL code generated by the nodes will extend the Material. This is experimental.
*
*/
import {TypedBuilderMatNode} from './_BaseBuilder';
import {ShaderAssemblerVolume} from '../gl/code/assemblers/materials/Volume';
import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig';
import {VolumeController} from './utils/VolumeController';
import {AssemblerName} from '../../poly/registers/assemblers/_BaseRegister';
import {Poly} from '../../Poly';
class VolumeMatParamsConfig extends NodeParamsConfig {
color = ParamConfig.COLOR([1, 1, 1]);
stepSize = ParamConfig.FLOAT(0.01);
density = ParamConfig.FLOAT(1);
shadowDensity = ParamConfig.FLOAT(1);
lightDir = ParamConfig.VECTOR3([-1, -1, -1]);
}
const ParamsConfig = new VolumeMatParamsConfig();
export class VolumeBuilderMatNode extends TypedBuilderMatNode<ShaderAssemblerVolume, VolumeMatParamsConfig> {
params_config = ParamsConfig;
static type() {
return 'volumeBuilder';
}
public usedAssembler(): Readonly<AssemblerName.GL_VOLUME> {
return AssemblerName.GL_VOLUME;
}
protected _create_assembler_controller() {
return Poly.assemblersRegister.assembler(this, this.usedAssembler());
}
private _volume_controller = new VolumeController(this);
initializeNode() {}
async cook() {
this.compile_if_required();
this._volume_controller.update_uniforms_from_params();
this.set_material(this.material);
}
}