UNPKG

@polygonjs/polygonjs

Version:

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

60 lines (59 loc) 2.13 kB
"use strict"; import { UniformsUtils } from "three"; import { ShaderMaterial } from "three"; import { ShaderLib } from "three"; import { RGBADepthPacking } from "three"; import { BasicDepthPacking } from "three"; import { ShaderAssemblerMaterial } from "../../_BaseMaterial"; import TemplateVertex from "../../../../templates/custom/line/CustomLineDistance.vert.glsl"; import TemplateFragment from "../../../../templates/custom/mesh/CustomMeshDistance.frag.glsl"; import { ShaderName } from "../../../../../../utils/shaders/ShaderName"; const INSERT_DEFINE_AFTER_MAP = /* @__PURE__ */ new Map([ [ShaderName.VERTEX, "// INSERT DEFINES"], [ShaderName.FRAGMENT, "// INSERT DEFINES"] ]); const INSERT_BODY_AFTER_MAP = /* @__PURE__ */ new Map([ [ShaderName.VERTEX, "// INSERT BODY"], [ShaderName.FRAGMENT, "// INSERT BODY"] ]); const LINES_TO_REMOVE_MAP = /* @__PURE__ */ new Map([ [ShaderName.VERTEX, ["#include <begin_vertex>", "#include <project_vertex>"]], [ShaderName.FRAGMENT, []] ]); export class ShaderAssemblerCustomLineDistance extends ShaderAssemblerMaterial { templateShader() { const template = ShaderLib.distanceRGBA; const uniforms = UniformsUtils.clone(template.uniforms); return { vertexShader: TemplateVertex, fragmentShader: TemplateFragment, uniforms }; } insertDefineAfter(shader_name) { return INSERT_DEFINE_AFTER_MAP.get(shader_name); } insertBodyAfter(shader_name) { return INSERT_BODY_AFTER_MAP.get(shader_name); } linesToRemove(shader_name) { return LINES_TO_REMOVE_MAP.get(shader_name); } createMaterial() { const template_shader = this.templateShader(); return new ShaderMaterial({ // vertexColors: VertexColors, // side: FrontSide, // transparent: true, // fog: true, // lights: true, defines: { USE_SIZEATTENUATION: 1, DEPTH_PACKING: [RGBADepthPacking, BasicDepthPacking][0] }, uniforms: UniformsUtils.clone(template_shader.uniforms), vertexShader: template_shader.vertexShader, fragmentShader: template_shader.fragmentShader }); } }