diff --git a/src/deprecated/deprecated.js b/src/deprecated/deprecated.js index 3e23a7e519f..173b205868e 100644 --- a/src/deprecated/deprecated.js +++ b/src/deprecated/deprecated.js @@ -71,6 +71,8 @@ import { SkinInstance } from '../scene/skin-instance.js'; import { StandardMaterial } from '../scene/materials/standard-material.js'; import { Batch } from '../scene/batching/batch.js'; import { getDefaultMaterial } from '../scene/materials/default-material.js'; +import { StandardMaterialOptions } from '../scene/materials/standard-material-options.js'; +import { LitOptions } from '../scene/materials/lit-options.js'; import { Animation, Key, Node } from '../scene/animation/animation.js'; import { Skeleton } from '../scene/animation/skeleton.js'; @@ -785,6 +787,28 @@ _defineAlias('glossVertexColor', 'glossMapVertexColor'); _defineAlias('opacityVertexColor', 'opacityMapVertexColor'); _defineAlias('lightVertexColor', 'lightMapVertexColor'); +function _defineOption(name, newName) { + if (name !== 'chunks' && name !== '_pass') { + Object.defineProperty(StandardMaterialOptions.prototype, name, { + get: function () { + Debug.deprecated(`Getting pc.Options#${name} has been deprecated as the property has been moved to pc.Options.LitOptions#${newName || name}.`); + return this.litOptions[newName || name]; + }, + set: function (value) { + Debug.deprecated(`Setting pc.Options#${name} has been deprecated as the property has been moved to pc.Options.LitOptions#${newName || name}.`); + this.litOptions[newName || name] = value; + } + }); + } +} +_defineOption('refraction', 'useRefraction'); + +const tempOptions = new LitOptions(); +const litOptionProperties = Object.getOwnPropertyNames(tempOptions); +for (const litOption in litOptionProperties) { + _defineOption(litOptionProperties[litOption]); +} + // ANIMATION export const anim = { diff --git a/src/index.js b/src/index.js index a8eac9ea019..3772cdebd95 100644 --- a/src/index.js +++ b/src/index.js @@ -115,6 +115,7 @@ export { Layer } from './scene/layer.js'; export { LayerComposition } from './scene/composition/layer-composition.js'; export { Light } from './scene/light.js'; export { LightingParams } from './scene/lighting/lighting-params.js'; +export { LitOptions } from './scene/materials/lit-options.js'; export { Material } from './scene/materials/material.js'; export { Mesh } from './scene/mesh.js'; export { MeshInstance, Command } from './scene/mesh-instance.js'; @@ -128,6 +129,7 @@ export { Skin } from './scene/skin.js'; export { SkinInstance } from './scene/skin-instance.js'; export { Sprite } from './scene/sprite.js'; export { StandardMaterial } from './scene/materials/standard-material.js'; +export { StandardMaterialOptions } from './scene/materials/standard-material-options.js'; export { StencilParameters } from './scene/stencil-parameters.js'; export { TextureAtlas } from './scene/texture-atlas.js'; diff --git a/src/scene/materials/lit-options.js b/src/scene/materials/lit-options.js new file mode 100644 index 00000000000..4f6da1fafcf --- /dev/null +++ b/src/scene/materials/lit-options.js @@ -0,0 +1,155 @@ +import { Debug } from '../../core/debug.js'; +import { + BLEND_NONE, FOG_NONE, GAMMA_NONE +} from '../constants.js'; + +/** + * The lit options determines how the lit-shader gets generated. It specifies a set of + * parameters which triggers different fragment and vertex shader generation in the backend. + * + * @property {object} chunks Object containing custom shader chunks that will replace default ones. + * @property {string} customFragmentShader Replaced the whole fragment shader with this string. + * @property {number} fog The type of fog being applied in the shader. See {@link Scene#fog} for the list of + * possible values. + * @property {number} gamma The type of gamma correction being applied in the shader. See + * {@link Scene#gammaCorrection} for the list of possible values. + * @property {number} toneMap The type of tone mapping being applied in the shader. See {@link Scene#toneMapping} + * for the list of possible values. + * @property {boolean} conserveEnergy The value of {@link StandardMaterial#conserveEnergy}. + * @property {number} occludeSpecular The value of {@link StandardMaterial#occludeSpecular}. + * @property {boolean} occludeDirect The value of {@link StandardMaterial#occludeDirect}. + * @property {number} shadingModel The value of {@link StandardMaterial#shadingModel}. + * @property {number} fresnelModel The value of {@link StandardMaterial#fresnelModel}. + * @property {number} cubeMapProjection The value of {@link StandardMaterial#cubeMapProjection}. + * @property {boolean} useMetalness The value of {@link StandardMaterial#useMetalness}. + * @property {number} blendType The value of {@link Material#blendType}. + * @property {boolean} twoSidedLighting The value of {@link Material#twoSidedLighting}. + * @property {number} occludeSpecularFloat Defines if {@link StandardMaterial#occludeSpecularIntensity} constant + * should affect specular occlusion. + * @property {boolean} alphaTest Enable alpha testing. See {@link Material#alphaTest}. + * @property {boolean} alphaToCoverage Enable alpha to coverage. See {@link Material#alphaToCoverage}. + * @property {boolean} opacityFadesSpecular Enable specular fade. See {@link Material#opacityFadesSpecular}. + * @property {float} ambientSH If ambient spherical harmonics are used. Ambient SH replace prefiltered cubemap + * ambient on certain platform (mostly Android) for performance reasons. + * @property {boolean} useSpecular If any specular or reflections are needed at all. + * @property {boolean} fixSeams If cubemaps require seam fixing (see {@link Texture#options.fixCubemapSeams}). + * @property {string} forceFragmentPrecision Override fragment shader numeric precision. Can be "lowp", "mediump", + * "highp" or null to use default. + * @property {boolean} fastTbn Use slightly cheaper normal mapping code (skip tangent space normalization). Can look + * buggy sometimes. + * @property {boolean} useRefraction If refraction is used. + * @property {number} skyboxIntensity If reflected skybox intensity should be modulated. + * @property {boolean} useCubeMapRotation If cube map rotation is enabled. + * @property {boolean} useInstancing If hardware instancing compatible shader should be generated. Transform is read + * from per-instance {@link VertexBuffer} instead of shader's uniforms. + * @property {boolean} useMorphPosition If morphing code should be generated to morph positions. + * @property {boolean} useMorphNormal If morphing code should be generated to morph normals. + * @property {string} reflectionSource One of "envAtlasHQ", "envAtlas", "cubeMap", "sphereMap". + * @property {boolean} ambientSource One of "ambientSH", "envAtlas", "constant". + */ +class LitOptions { + constructor() { + this.hasTangents = false; + this.chunks = []; + + this._pass = 0; + this.alphaTest = false; + this.forceFragmentPrecision = false; + this.blendType = BLEND_NONE; + this.separateAmbient = false; + this.screenSpace = false; + this.skin = false; + this.useInstancing = false; + this.useMorphPosition = false; + this.useMorphNormal = false; + this.useMorphTextureBased = false; + + this.nineSlicedMode = false; + + this.clusteredLightingEnabled = true; + + this.clusteredLightingCookiesEnabled = false; + this.clusteredLightingShadowsEnabled = false; + this.clusteredLightingShadowType = 0; + this.clusteredLightingAreaLightsEnabled = false; + + this.vertexColors = false; + this.lightMapEnabled = false; + this.useLightMapVertexColors = false; + this.dirLightMapEnabled = false; + this.heightMapEnabled = false; + this.normalMapEnabled = false; + this.clearCoatNormalMapEnabled = false; + this.aoMapEnabled = false; + this.useAoVertexColors = false; + this.diffuseMapEnabled = false; + + this.useAmbientTint = false; + this.customFragmentShader = null; + this.pixelSnap = false; + + this.useClearCoatNormalMap = false; + this.useDiffuseMap = false; + this.useAoMap = false; + + this.detailModes = 0; + this.shadingModel = 0; + this.ambientSH = false; + this.fastTbn = false; + this.twoSidedLighting = false; + this.occludeSpecular = false; + this.occludeSpecularFloat = false; + + this.useMsdf = false; + this.msdfTextAttribute = 0; + + this.alphaToCoverage = false; + this.opacityFadesSpecular = false; + + this.cubeMapProjection = false; + + this.occludeDirect = false; + this.conserveEnergy = false; + this.useSpecular = false; + this.useSpecularityFactor = false; + this.useSpecularColor = false; + this.enableGGXSpecular = false; + this.fresnelModel = 0; + this.useRefraction = false; + this.useClearCoat = false; + this.useSheen = false; + this.useIridescence = false; + this.useMetalness = false; + this.useDynamicRefraction = false; + + this.fog = FOG_NONE; + this.gamma = GAMMA_NONE; + this.toneMap = -1; + this.fixSeams = false; + + this.reflectionSource = null; + this.reflectionEncoding = null; + this.ambientSource = 'constant'; + this.ambientEncoding = null; + + // TODO: add a test for if non skybox cubemaps have rotation (when this is supported) - for now assume no non-skybox cubemap rotation + this.skyboxIntensity = 1.0; + this.useCubeMapRotation = false; + + this.lightMapWithoutAmbient = false; + + this.lights = []; + this.noShadow = false; + this.lightMaskDynamic = 0x0; + } + + set pass(p) { + Debug.warn(`pc.LitOptions#pass should be set by its parent pc.StandardMaterialOptions, setting it directly has no effect.`); + } + + get pass() { + return this._pass; + } +} + +export { LitOptions }; diff --git a/src/scene/materials/standard-material-options-builder.js b/src/scene/materials/standard-material-options-builder.js index d0c19c0b678..5b8b930e67c 100644 --- a/src/scene/materials/standard-material-options-builder.js +++ b/src/scene/materials/standard-material-options-builder.js @@ -44,7 +44,6 @@ class StandardMaterialOptionsBuilder { // Minimal options for Depth and Shadow passes updateMinRef(options, scene, stdMat, objDefs, staticLightList, pass, sortedLights) { - options.litOptions = {}; this._updateSharedOptions(options, scene, stdMat, objDefs, pass); this._updateMinOptions(options, stdMat); this._updateUVOptions(options, stdMat, objDefs, true); @@ -52,13 +51,12 @@ class StandardMaterialOptionsBuilder { } updateRef(options, scene, stdMat, objDefs, staticLightList, pass, sortedLights) { - options.litOptions = {}; this._updateSharedOptions(options, scene, stdMat, objDefs, pass); this._updateEnvOptions(options, stdMat, scene); this._updateMaterialOptions(options, stdMat); if (pass === SHADER_FORWARDHDR) { - if (options.gamma) options.gamma = GAMMA_SRGBHDR; - options.toneMap = TONEMAP_LINEAR; + if (options.litOptions.gamma) options.litOptions.gamma = GAMMA_SRGBHDR; + options.litOptions.toneMap = TONEMAP_LINEAR; } options.litOptions.hasTangents = objDefs && ((objDefs & SHADERDEF_TANGENTS) !== 0); this._updateLightOptions(options, scene, stdMat, objDefs, sortedLights, staticLightList); @@ -70,7 +68,7 @@ class StandardMaterialOptionsBuilder { options.forceUv1 = stdMat.forceUv1; options.chunks = stdMat.chunks || ''; - options.litOptions.pass = pass; + options.pass = pass; options.litOptions.alphaTest = stdMat.alphaTest > 0; options.litOptions.forceFragmentPrecision = stdMat.forceFragmentPrecision || ''; options.litOptions.blendType = stdMat.blendType; @@ -120,13 +118,13 @@ class StandardMaterialOptionsBuilder { // All texture related lit options options.litOptions.lightMapEnabled = options.lightMap; - options.litOptions.lightMapVertexColors = options.lightVertexColors; + options.litOptions.useLightMapVertexColors = options.lightVertexColors; options.litOptions.dirLightMapEnabled = options.dirLightMap; options.litOptions.heightMapEnabled = options.heightMap; options.litOptions.normalMapEnabled = options.normalMap; options.litOptions.clearCoatNormalMapEnabled = options.clearCoatNormalMap; options.litOptions.aoMapEnabled = options.aoMap; - options.litOptions.aoVertexColors = options.aoVertexColors; + options.litOptions.useAoVertexColors = options.aoVertexColors; options.litOptions.diffuseMapEnabled = options.diffuseMap; } @@ -248,7 +246,7 @@ class StandardMaterialOptionsBuilder { options.sheenGlossinessTint = 1; // LIT OPTIONS - options.litOptions.ambientTint = options.ambientTint; + options.litOptions.useAmbientTint = options.ambientTint; options.litOptions.customFragmentShader = stdMat.customFragmentShader; options.litOptions.pixelSnap = stdMat.pixelSnap; @@ -279,7 +277,7 @@ class StandardMaterialOptionsBuilder { options.litOptions.useSpecularColor = useSpecularColor; options.litOptions.enableGGXSpecular = stdMat.enableGGXSpecular; options.litOptions.fresnelModel = stdMat.fresnelModel; - options.litOptions.useRefraction = (stdMat.refraction || !!stdMat.refractionMap) && (stdMat.useDynamicRefraction || !!options.reflectionSource); + options.litOptions.useRefraction = (stdMat.refraction || !!stdMat.refractionMap) && (stdMat.useDynamicRefraction || !!options.litOptions.reflectionSource); options.litOptions.useClearCoat = !!stdMat.clearCoat; options.litOptions.useSheen = stdMat.useSheen; options.litOptions.useIridescence = stdMat.useIridescence && stdMat.iridescence !== 0.0; diff --git a/src/scene/materials/standard-material-options.js b/src/scene/materials/standard-material-options.js new file mode 100644 index 00000000000..6956bae8485 --- /dev/null +++ b/src/scene/materials/standard-material-options.js @@ -0,0 +1,53 @@ +import { LitOptions } from "./lit-options.js"; + +/** + * The standard material options define a set of options used to control the shader frontend shader generation, + * such as textures, tints and multipliers. + * + * @property {number} pass Value of {@link Layer#shaderPass} of the Layer being rendered. Must be set to the + * same in {@link LitOptions#pass}. + * @property {boolean} forceUv1 If UV1 (second set of texture coordinates) is required in the shader. Will be + * declared as "vUv1" and passed to the fragment shader. + * @property {boolean} ambientTint The value of {@link StandardMaterial#ambientTint}. + * @property {boolean} diffuseTint Defines if {@link StandardMaterial#diffuse} constant should affect diffuse color. + * @property {boolean} specularTint Defines if {@link StandardMaterial#specular} constant should affect specular + * color. + * @property {boolean} metalnessTint Defines if {@link StandardMaterial#metalness} constant should affect metalness + * value. + * @property {boolean} glossTint Defines if {@link StandardMaterial#shininess} constant should affect glossiness + * value. + * @property {boolean} emissiveTint Defines if {@link StandardMaterial#emissive} constant should affect emission + * value. + * @property {boolean} opacityTint Defines if {@link StandardMaterial#opacity} constant should affect opacity value. + * @property {boolean} packedNormal If normal map contains X in RGB, Y in Alpha, and Z must be reconstructed. + */ +class StandardMaterialOptions { + constructor() { + this.chunks = []; + this._pass = 0; + this.forceUv1 = false; + this.ambientTint = false; + this.diffuseTint = false; + this.specularTint = false; + this.metalnessTint = false; + this.glossTint = false; + this.emissiveTint = false; + this.opacityTint = false; + this.emissiveEncoding = 'linear'; + this.lightMapEncoding = 'linear'; + this.packedNormal = false; + + this.litOptions = new LitOptions(); + } + + set pass(p) { + this._pass = p; + this.litOptions._pass = p; + } + + get pass() { + return this._pass; + } +} + +export { StandardMaterialOptions }; diff --git a/src/scene/materials/standard-material.js b/src/scene/materials/standard-material.js index c0ece74d070..d02570dbdc2 100644 --- a/src/scene/materials/standard-material.js +++ b/src/scene/materials/standard-material.js @@ -34,10 +34,11 @@ let _params = new Set(); * Callback used by {@link StandardMaterial#onUpdateShader}. * * @callback UpdateShaderCallback - * @param {*} options - An object with shader generator settings (based on current material and - * scene properties), that you can change and then return. Properties of the object passed into - * this function are documented in {@link StandardMaterial#onUpdateShader}. - * @returns {*} Returned settings will be used by the shader. + * @param {import('./standard-material-options.js').StandardMaterialOptions} options - An object with shader generator settings (based on current + * material and scene properties), that you can change and then return. Properties of the object passed + * into this function are documented in {@link StandardMaterial}. Also contains a member named litOptions + * which holds some of the options only used by the lit shader backend {@link LitOptions}. + * @returns {import('./standard-material-options.js').StandardMaterialOptions} Returned settings will be used by the shader. */ /** @@ -498,70 +499,10 @@ let _params = new Set(); * properties), that you can change and then return. Returned value will be used instead. This is * mostly useful when rendering the same set of objects, but with different shader variations based * on the same material. For example, you may wish to render a depth or normal pass using textures - * assigned to the material, a reflection pass with simpler shaders and so on. Properties of the - * object passed into this function are: - * - * - pass: value of {@link Layer#shaderPass} of the Layer being rendered. - * - chunks: Object containing custom shader chunks that will replace default ones. - * - customFragmentShader: Completely replace fragment shader with this code. - * - forceUv1: if UV1 (second set of texture coordinates) is required in the shader. Will be - * declared as "vUv1" and passed to the fragment shader. - * - fog: the type of fog being applied in the shader. See {@link Scene#fog} for the list of - * possible values. - * - gamma: the type of gamma correction being applied in the shader. See - * {@link Scene#gammaCorrection} for the list of possible values. - * - toneMap: the type of tone mapping being applied in the shader. See {@link Scene#toneMapping} - * for the list of possible values. - * - ambientTint: the value of {@link StandardMaterial#ambientTint}. - * - conserveEnergy: the value of {@link StandardMaterial#conserveEnergy}. - * - occludeSpecular: the value of {@link StandardMaterial#occludeSpecular}. - * - occludeDirect: the value of {@link StandardMaterial#occludeDirect}. - * - shadingModel: the value of {@link StandardMaterial#shadingModel}. - * - fresnelModel: the value of {@link StandardMaterial#fresnelModel}. - * - cubeMapProjection: the value of {@link StandardMaterial#cubeMapProjection}. - * - useMetalness: the value of {@link StandardMaterial#useMetalness}. - * - blendType: the value of {@link Material#blendType}. - * - twoSidedLighting: the value of {@link Material#twoSidedLighting}. - * - diffuseTint: defines if {@link StandardMaterial#diffuse} constant should affect diffuse color. - * - specularTint: defines if {@link StandardMaterial#specular} constant should affect specular - * color. - * - metalnessTint: defines if {@link StandardMaterial#metalness} constant should affect metalness - * value. - * - glossTint: defines if {@link StandardMaterial#shininess} constant should affect glossiness - * value. - * - emissiveTint: defines if {@link StandardMaterial#emissive} constant should affect emission - * value. - * - opacityTint: defines if {@link StandardMaterial#opacity} constant should affect opacity value. - * - occludeSpecularFloat: defines if {@link StandardMaterial#occludeSpecularIntensity} constant - * should affect specular occlusion. - * - alphaTest: enable alpha testing. See {@link Material#alphaTest}. - * - alphaToCoverage: enable alpha to coverage. See {@link Material#alphaToCoverage}. - * - opacityFadesSpecular: enable specular fade. See {@link Material#opacityFadesSpecular}. - * - alphaFade: fade value. See {@link Material#alphaFade}. - * - sphereMap: if {@link StandardMaterial#sphereMap} is used. - * - cubeMap: if {@link StandardMaterial#cubeMap} is used. - * - ambientSH: if ambient spherical harmonics are used. Ambient SH replace prefiltered cubemap - * ambient on certain platform (mostly Android) for performance reasons. - * - useSpecular: if any specular or reflections are needed at all. - * - fixSeams: if cubemaps require seam fixing (see {@link Texture#options.fixCubemapSeams}). - * - emissiveEncoding: how emissiveMap is encoded. This value is based on Texture#encoding. - * - lightMapEncoding: how lightMap is encoded. This value is based on on Texture#encoding. - * - packedNormal: if normal map contains X in RGB, Y in Alpha, and Z must be reconstructed. - * - forceFragmentPrecision: Override fragment shader numeric precision. Can be "lowp", "mediump", - * "highp" or null to use default. - * - fastTbn: Use slightly cheaper normal mapping code (skip tangent space normalization). Can look - * buggy sometimes. - * - refraction: if refraction is used. - * - skyboxIntensity: if reflected skybox intensity should be modulated. - * - useCubeMapRotation: if cube map rotation is enabled. - * - useInstancing: if hardware instancing compatible shader should be generated. Transform is read - * from per-instance {@link VertexBuffer} instead of shader's uniforms. - * - useMorphPosition: if morphing code should be generated to morph positions. - * - useMorphNormal: if morphing code should be generated to morph normals. - * - reflectionSource: one of "envAtlasHQ", "envAtlas", "cubeMap", "sphereMap" - * - reflectionEncoding: one of null, "rgbm", "rgbe", "linear", "srgb" - * - ambientSource: one of "ambientSH", "envAtlas", "constant" - * - ambientEncoding: one of null, "rgbm", "rgbe", "linear", "srgb" + * assigned to the material, a reflection pass with simpler shaders and so on. These properties are + * split into two sections, generic standard material options and lit options. Properties of the + * standard material options are {@link StandardMaterialOptions} and the options for the lit options + * are {@link LitOptions}. * @augments Material */ class StandardMaterial extends Material { diff --git a/src/scene/shader-lib/program-library.js b/src/scene/shader-lib/program-library.js index 65703452314..a9c8cdd8336 100644 --- a/src/scene/shader-lib/program-library.js +++ b/src/scene/shader-lib/program-library.js @@ -5,6 +5,7 @@ import { Shader } from '../../platform/graphics/shader.js'; import { SHADER_FORWARD, SHADER_DEPTH, SHADER_PICK, SHADER_SHADOW } from '../constants.js'; import { ShaderPass } from '../shader-pass.js'; +import { StandardMaterialOptions } from '../materials/standard-material-options.js'; /** * A class responsible for creation and caching of required shaders. @@ -37,8 +38,8 @@ class ProgramLibrary { // Unique non-cached programs collection to dump and update game shaders cache this._programsCollection = []; - this._defaultStdMatOption = {}; - this._defaultStdMatOptionMin = {}; + this._defaultStdMatOption = new StandardMaterialOptions(); + this._defaultStdMatOptionMin = new StandardMaterialOptions(); standardMaterial.shaderOptBuilder.updateRef( this._defaultStdMatOption, {}, standardMaterial, null, [], SHADER_FORWARD, null); diff --git a/src/scene/shader-lib/programs/lit-shader.js b/src/scene/shader-lib/programs/lit-shader.js index 0aee2223d53..5a143c1b190 100644 --- a/src/scene/shader-lib/programs/lit-shader.js +++ b/src/scene/shader-lib/programs/lit-shader.js @@ -750,7 +750,7 @@ class LitShader { } } - const useAo = options.aoMapEnabled || options.aoVertexColors; + const useAo = options.aoMapEnabled || options.useAoVertexColors; if (useAo) { code += chunks.aoDiffuseOccPS; @@ -876,11 +876,11 @@ class LitShader { code += chunks.combinePS; // lightmap support - if (options.lightMapEnabled || options.lightMapVertexColors) { + if (options.lightMapEnabled || options.useLightMapVertexColors) { code += (options.useSpecular && options.dirLightMapEnabled) ? chunks.lightmapDirAddPS : chunks.lightmapAddPS; } - const addAmbient = (!options.lightMapEnabled && !options.lightMapVertexColors) || options.lightMapWithoutAmbient; + const addAmbient = (!options.lightMapEnabled && !options.useLightMapVertexColors) || options.lightMapWithoutAmbient; if (addAmbient) { if (options.ambientSource === 'ambientSH') { @@ -895,7 +895,7 @@ class LitShader { } } - if (options.ambientTint && !useOldAmbient) { + if (options.useAmbientTint && !useOldAmbient) { code += "uniform vec3 material_ambient;\n"; } @@ -1017,7 +1017,7 @@ class LitShader { } } - if (options.ambientTint && !useOldAmbient) { + if (options.useAmbientTint && !useOldAmbient) { code += " dDiffuseLight *= material_ambient;\n"; } @@ -1025,7 +1025,7 @@ class LitShader { code += " occludeDiffuse();\n"; } - if (options.lightMapEnabled || options.lightMapVertexColors) { + if (options.lightMapEnabled || options.useLightMapVertexColors) { code += " addLightMap();\n"; } diff --git a/src/scene/shader-lib/programs/standard.js b/src/scene/shader-lib/programs/standard.js index e8ffed4796a..5b4a099eb8a 100644 --- a/src/scene/shader-lib/programs/standard.js +++ b/src/scene/shader-lib/programs/standard.js @@ -10,13 +10,14 @@ import { ShaderPass } from '../../shader-pass.js'; import { LitShader } from './lit-shader.js'; import { ChunkBuilder } from '../chunk-builder.js'; import { ChunkUtils } from '../chunk-utils.js'; +import { StandardMaterialOptions } from '../../materials/standard-material-options.js'; const _matTex2D = []; const standard = { // Shared Standard Material option structures - optionsContext: {}, - optionsContextMin: {}, + optionsContext: new StandardMaterialOptions(), + optionsContextMin: new StandardMaterialOptions(), /** @type { Function } */ generateKey: function (options) { @@ -88,7 +89,7 @@ const standard = { _getUvSourceExpression: function (transformPropName, uVPropName, options) { const transformId = options[transformPropName]; const uvChannel = options[uVPropName]; - const isMainPass = ShaderPass.isForward(options.litOptions.pass); + const isMainPass = ShaderPass.isForward(options.pass); let expression; if (isMainPass && options.litOptions.nineSlicedMode === SPRITE_RENDERMODE_SLICED) { @@ -292,7 +293,7 @@ const standard = { decl.append(`uniform float textureBias;`); } - if (ShaderPass.isForward(options.litOptions.pass)) { + if (ShaderPass.isForward(options.pass)) { // parallax if (options.heightMap) { // if (!options.normalMap) {