UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

90 lines (89 loc) 3.78 kB
"use strict"; import { RAYMARCHING_UNIFORMS } from "./../../../gl/gl/raymarching/uniforms"; import { TypeAssert } from "../../../../poly/Assert"; import { NodeParamsConfig } from "../../../utils/params/ParamsConfig"; import { CustomMaterialName } from "../../../../../core/geometry/Material"; import { ParamConfig } from "../../../utils/params/ParamsConfig"; import { BaseBuilderParamConfig } from "../../_BaseBuilder"; import { TypedMatNode } from "../../_Base"; import { isBooleanTrue } from "../../../../../core/Type"; import { CUSTOM_MAT_PARAM_OPTIONS } from "./_CustomMaterialBase"; export function CustomMaterialRayMarchingParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle on to choose which customMaterials will be generated */ this.overrideCustomMaterials = ParamConfig.BOOLEAN(0, { ...CUSTOM_MAT_PARAM_OPTIONS, separatorBefore: true, separatorAfter: true }); /** @param creates a shadow material for point lights */ this.createCustomMatDistance = ParamConfig.BOOLEAN(1, { visibleIf: { overrideCustomMaterials: 1 }, ...CUSTOM_MAT_PARAM_OPTIONS }); /** @param min shadow depth for point lights */ this.shadowDistanceMin = ParamConfig.FLOAT(RAYMARCHING_UNIFORMS.shadowDistanceMin.value, { range: [0, 100], rangeLocked: [true, false], step: 1, visibleIf: [{ overrideCustomMaterials: 0 }, { overrideCustomMaterials: 1, createCustomMatDistance: 1 }] }); /** @param max shadow depth for point lights */ this.shadowDistanceMax = ParamConfig.FLOAT(RAYMARCHING_UNIFORMS.shadowDistanceMax.value, { range: [0, 100], rangeLocked: [true, false], step: 1, visibleIf: [{ overrideCustomMaterials: 0 }, { overrideCustomMaterials: 1, createCustomMatDistance: 1 }] }); /** @param creates a shadow material for spot lights and directional lights */ this.createCustomMatDepth = ParamConfig.BOOLEAN(1, { visibleIf: { overrideCustomMaterials: 1 }, ...CUSTOM_MAT_PARAM_OPTIONS }); /** @param min shadow depth for spot lights and directional lights */ this.shadowDepthMin = ParamConfig.FLOAT(RAYMARCHING_UNIFORMS.shadowDepthMin.value, { range: [0, 100], rangeLocked: [true, false], step: 1, visibleIf: [{ overrideCustomMaterials: 0 }, { overrideCustomMaterials: 1, createCustomMatDepth: 1 }] }); /** @param max shadow depth for spot lights and directional lights */ this.shadowDepthMax = ParamConfig.FLOAT(RAYMARCHING_UNIFORMS.shadowDepthMax.value, { range: [0, 100], rangeLocked: [true, false], step: 1, visibleIf: [{ overrideCustomMaterials: 0 }, { overrideCustomMaterials: 1, createCustomMatDepth: 1 }] }); } }; } class CustomMaterialRayMarchingParamsConfig extends CustomMaterialRayMarchingParamConfig( BaseBuilderParamConfig(NodeParamsConfig) ) { } class CustomMaterialMatNode extends TypedMatNode { } export function materialRayMarchingAssemblerCustomMaterialRequested(node, customName) { const param = node.p.overrideCustomMaterials; if (!param) { console.warn(`param overrideCustomMaterials not found on ${node.path()}, creating all customMaterials`); return true; } if (!isBooleanTrue(node.pv.overrideCustomMaterials)) { return true; } switch (customName) { case CustomMaterialName.DISTANCE: { return isBooleanTrue(node.pv.createCustomMatDistance); } case CustomMaterialName.DEPTH: { return isBooleanTrue(node.pv.createCustomMatDepth); } case CustomMaterialName.DEPTH_DOF: { return false; } } TypeAssert.unreachable(customName); }