|
| 1 | +import { Debug } from '../../core/debug.js'; |
| 2 | +import { |
| 3 | + BLEND_NONE, FOG_NONE, GAMMA_NONE |
| 4 | +} from '../constants.js'; |
| 5 | + |
| 6 | +/** |
| 7 | + * The lit options determines how the lit-shader gets generated. It specifies a set of |
| 8 | + * parameters which triggers different fragment and vertex shader generation in the backend. |
| 9 | + * |
| 10 | + * @property {object} chunks Object containing custom shader chunks that will replace default ones. |
| 11 | + * @property {string} customFragmentShader Replaced the whole fragment shader with this string. |
| 12 | + * @property {number} fog The type of fog being applied in the shader. See {@link Scene#fog} for the list of |
| 13 | + * possible values. |
| 14 | + * @property {number} gamma The type of gamma correction being applied in the shader. See |
| 15 | + * {@link Scene#gammaCorrection} for the list of possible values. |
| 16 | + * @property {number} toneMap The type of tone mapping being applied in the shader. See {@link Scene#toneMapping} |
| 17 | + * for the list of possible values. |
| 18 | + * @property {boolean} conserveEnergy The value of {@link StandardMaterial#conserveEnergy}. |
| 19 | + * @property {number} occludeSpecular The value of {@link StandardMaterial#occludeSpecular}. |
| 20 | + * @property {boolean} occludeDirect The value of {@link StandardMaterial#occludeDirect}. |
| 21 | + * @property {number} shadingModel The value of {@link StandardMaterial#shadingModel}. |
| 22 | + * @property {number} fresnelModel The value of {@link StandardMaterial#fresnelModel}. |
| 23 | + * @property {number} cubeMapProjection The value of {@link StandardMaterial#cubeMapProjection}. |
| 24 | + * @property {boolean} useMetalness The value of {@link StandardMaterial#useMetalness}. |
| 25 | + * @property {number} blendType The value of {@link Material#blendType}. |
| 26 | + * @property {boolean} twoSidedLighting The value of {@link Material#twoSidedLighting}. |
| 27 | + * @property {number} occludeSpecularFloat Defines if {@link StandardMaterial#occludeSpecularIntensity} constant |
| 28 | + * should affect specular occlusion. |
| 29 | + * @property {boolean} alphaTest Enable alpha testing. See {@link Material#alphaTest}. |
| 30 | + * @property {boolean} alphaToCoverage Enable alpha to coverage. See {@link Material#alphaToCoverage}. |
| 31 | + * @property {boolean} opacityFadesSpecular Enable specular fade. See {@link Material#opacityFadesSpecular}. |
| 32 | + * @property {float} ambientSH If ambient spherical harmonics are used. Ambient SH replace prefiltered cubemap |
| 33 | + * ambient on certain platform (mostly Android) for performance reasons. |
| 34 | + * @property {boolean} useSpecular If any specular or reflections are needed at all. |
| 35 | + * @property {boolean} fixSeams If cubemaps require seam fixing (see {@link Texture#options.fixCubemapSeams}). |
| 36 | + * @property {string} forceFragmentPrecision Override fragment shader numeric precision. Can be "lowp", "mediump", |
| 37 | + * "highp" or null to use default. |
| 38 | + * @property {boolean} fastTbn Use slightly cheaper normal mapping code (skip tangent space normalization). Can look |
| 39 | + * buggy sometimes. |
| 40 | + * @property {boolean} useRefraction If refraction is used. |
| 41 | + * @property {number} skyboxIntensity If reflected skybox intensity should be modulated. |
| 42 | + * @property {boolean} useCubeMapRotation If cube map rotation is enabled. |
| 43 | + * @property {boolean} useInstancing If hardware instancing compatible shader should be generated. Transform is read |
| 44 | + * from per-instance {@link VertexBuffer} instead of shader's uniforms. |
| 45 | + * @property {boolean} useMorphPosition If morphing code should be generated to morph positions. |
| 46 | + * @property {boolean} useMorphNormal If morphing code should be generated to morph normals. |
| 47 | + * @property {string} reflectionSource One of "envAtlasHQ", "envAtlas", "cubeMap", "sphereMap". |
| 48 | + * @property {boolean} ambientSource One of "ambientSH", "envAtlas", "constant". |
| 49 | + */ |
| 50 | +class LitOptions { |
| 51 | + constructor() { |
| 52 | + this.hasTangents = false; |
| 53 | + this.chunks = []; |
| 54 | + |
| 55 | + this._pass = 0; |
| 56 | + this.alphaTest = false; |
| 57 | + this.forceFragmentPrecision = false; |
| 58 | + this.blendType = BLEND_NONE; |
| 59 | + this.separateAmbient = false; |
| 60 | + this.screenSpace = false; |
| 61 | + this.skin = false; |
| 62 | + this.useInstancing = false; |
| 63 | + this.useMorphPosition = false; |
| 64 | + this.useMorphNormal = false; |
| 65 | + this.useMorphTextureBased = false; |
| 66 | + |
| 67 | + this.nineSlicedMode = false; |
| 68 | + |
| 69 | + this.clusteredLightingEnabled = true; |
| 70 | + |
| 71 | + this.clusteredLightingCookiesEnabled = false; |
| 72 | + this.clusteredLightingShadowsEnabled = false; |
| 73 | + this.clusteredLightingShadowType = 0; |
| 74 | + this.clusteredLightingAreaLightsEnabled = false; |
| 75 | + |
| 76 | + this.vertexColors = false; |
| 77 | + this.lightMapEnabled = false; |
| 78 | + this.useLightMapVertexColors = false; |
| 79 | + this.dirLightMapEnabled = false; |
| 80 | + this.heightMapEnabled = false; |
| 81 | + this.normalMapEnabled = false; |
| 82 | + this.clearCoatNormalMapEnabled = false; |
| 83 | + this.aoMapEnabled = false; |
| 84 | + this.useAoVertexColors = false; |
| 85 | + this.diffuseMapEnabled = false; |
| 86 | + |
| 87 | + this.useAmbientTint = false; |
| 88 | + this.customFragmentShader = null; |
| 89 | + this.pixelSnap = false; |
| 90 | + |
| 91 | + this.useClearCoatNormalMap = false; |
| 92 | + this.useDiffuseMap = false; |
| 93 | + this.useAoMap = false; |
| 94 | + |
| 95 | + this.detailModes = 0; |
| 96 | + this.shadingModel = 0; |
| 97 | + this.ambientSH = false; |
| 98 | + this.fastTbn = false; |
| 99 | + this.twoSidedLighting = false; |
| 100 | + this.occludeSpecular = false; |
| 101 | + this.occludeSpecularFloat = false; |
| 102 | + |
| 103 | + this.useMsdf = false; |
| 104 | + this.msdfTextAttribute = 0; |
| 105 | + |
| 106 | + this.alphaToCoverage = false; |
| 107 | + this.opacityFadesSpecular = false; |
| 108 | + |
| 109 | + this.cubeMapProjection = false; |
| 110 | + |
| 111 | + this.occludeDirect = false; |
| 112 | + this.conserveEnergy = false; |
| 113 | + this.useSpecular = false; |
| 114 | + this.useSpecularityFactor = false; |
| 115 | + this.useSpecularColor = false; |
| 116 | + this.enableGGXSpecular = false; |
| 117 | + this.fresnelModel = 0; |
| 118 | + this.useRefraction = false; |
| 119 | + this.useClearCoat = false; |
| 120 | + this.useSheen = false; |
| 121 | + this.useIridescence = false; |
| 122 | + this.useMetalness = false; |
| 123 | + this.useDynamicRefraction = false; |
| 124 | + |
| 125 | + this.fog = FOG_NONE; |
| 126 | + this.gamma = GAMMA_NONE; |
| 127 | + this.toneMap = -1; |
| 128 | + this.fixSeams = false; |
| 129 | + |
| 130 | + this.reflectionSource = null; |
| 131 | + this.reflectionEncoding = null; |
| 132 | + this.ambientSource = 'constant'; |
| 133 | + this.ambientEncoding = null; |
| 134 | + |
| 135 | + // TODO: add a test for if non skybox cubemaps have rotation (when this is supported) - for now assume no non-skybox cubemap rotation |
| 136 | + this.skyboxIntensity = 1.0; |
| 137 | + this.useCubeMapRotation = false; |
| 138 | + |
| 139 | + this.lightMapWithoutAmbient = false; |
| 140 | + |
| 141 | + this.lights = []; |
| 142 | + this.noShadow = false; |
| 143 | + this.lightMaskDynamic = 0x0; |
| 144 | + } |
| 145 | + |
| 146 | + set pass(p) { |
| 147 | + Debug.warn(`pc.LitOptions#pass should be set by its parent pc.StandardMaterialOptions, setting it directly has no effect.`); |
| 148 | + } |
| 149 | + |
| 150 | + get pass() { |
| 151 | + return this._pass; |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +export { LitOptions }; |
0 commit comments