playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
67 lines (66 loc) • 3.38 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { ShaderProcessorOptions } from "../../platform/graphics/shader-processor-options.js";
import { DITHER_NONE, FRESNEL_SCHLICK, SPECOCC_AO } from "../constants.js";
import { Material } from "./material.js";
import { LitMaterialOptions } from "./lit-material-options.js";
import { LitMaterialOptionsBuilder } from "./lit-material-options-builder.js";
import { getProgramLibrary } from "../shader-lib/get-program-library.js";
import { lit } from "../shader-lib/programs/lit.js";
import { ShaderUtils } from "../shader-lib/shader-utils.js";
const options = new LitMaterialOptions();
class LitMaterial extends Material {
constructor() {
super(...arguments);
__publicField(this, "usedUvs", [true]);
__publicField(this, "shaderChunkGLSL", null);
__publicField(this, "shaderChunkWGSL", null);
__publicField(this, "useLighting", true);
__publicField(this, "useFog", true);
__publicField(this, "useTonemap", true);
__publicField(this, "useSkybox", true);
__publicField(this, "ambientSH", null);
__publicField(this, "pixelSnap", false);
__publicField(this, "nineSlicedMode", null);
__publicField(this, "twoSidedLighting", false);
__publicField(this, "occludeDirect", false);
__publicField(this, "occludeSpecular", SPECOCC_AO);
__publicField(this, "occludeSpecularIntensity", 1);
__publicField(this, "opacityFadesSpecular", true);
__publicField(this, "opacityDither", DITHER_NONE);
__publicField(this, "opacityShadowDither", DITHER_NONE);
__publicField(this, "shadowCatcher", false);
__publicField(this, "ggxSpecular", false);
__publicField(this, "fresnelModel", FRESNEL_SCHLICK);
__publicField(this, "dynamicRefraction", false);
// has members
__publicField(this, "hasAo", false);
__publicField(this, "hasSpecular", false);
__publicField(this, "hasSpecularityFactor", false);
__publicField(this, "hasLighting", false);
__publicField(this, "hasHeights", false);
__publicField(this, "hasNormals", false);
__publicField(this, "hasSheen", false);
__publicField(this, "hasRefraction", false);
__publicField(this, "hasIrridescence", false);
__publicField(this, "hasMetalness", false);
__publicField(this, "hasClearCoat", false);
__publicField(this, "hasClearCoatNormals", false);
}
getShaderVariant(params) {
options.usedUvs = this.usedUvs.slice();
options.shaderChunkGLSL = this.shaderChunkGLSL;
options.shaderChunkWGSL = this.shaderChunkWGSL;
options.defines = ShaderUtils.getCoreDefines(this, params);
LitMaterialOptionsBuilder.update(options.litOptions, this, params.scene, params.cameraShaderParams, params.objDefs, params.pass, params.sortedLights);
const processingOptions = new ShaderProcessorOptions(params.viewUniformFormat, params.viewBindGroupFormat, params.vertexFormat);
const library = getProgramLibrary(params.device);
library.register("lit", lit);
const shader = library.getProgram("lit", options, processingOptions, this.userId);
return shader;
}
}
export {
LitMaterial
};