Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LitOptions class to hold backend options #4900

Merged
merged 25 commits into from
Dec 9, 2022

Conversation

GSterbrant
Copy link
Contributor

Description

Fixes #4871.

The backend options for the lit shader are now defined in their own class, which makes it possible to know what options are available.

Additionally, this allows us to validate options which might have moved to the backend object, and inform developers if they are still expecting the option to be there. This primarily pertains to options set through the onUpdateShader callback.

…hader.

Also validates that options changed directly through the onUpdateShader so users get some feedback if they set a value moved to the backend options.
Changed the name of ambientTint in the backend to be more explanatory, which coincidentally helps with the validation in this PR as well.
@GSterbrant GSterbrant added the area: graphics Graphics related issue label Nov 30, 2022
@GSterbrant GSterbrant self-assigned this Nov 30, 2022
@mvaligursky
Copy link
Contributor

The docs for these should probably move to appropriate classes too

* @property {UpdateShaderCallback} onUpdateShader A custom function that will be called after all
* shader generator properties are collected and before shader code is generated. This function
* will receive an object with shader generator settings (based on current material and scene
* 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"

@mvaligursky
Copy link
Contributor

mvaligursky commented Nov 30, 2022

And also, if the option has moved to litOptions, we should generate some deprecated properties that warn user the option has moved. Those would ideally be added to deprecated.js

Replacing the options with a class allows for hooking up setters and getters for the parameters that have been moved to the lit options. This allows for a more generic solution for validating option properties having been moved.
@GSterbrant
Copy link
Contributor Author

I added an options class which is used to hookup deprecation callbacks, and replaced the use of an anonymous options object with this new (albeit empty) one.

… StandardMaterialOptions.

Also updated the documentation to use properties annotations (with types) for typescript.
Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please do test it with at least engine examples to make sure all is happy.

@GSterbrant GSterbrant merged commit ae68126 into main Dec 9, 2022
@GSterbrant GSterbrant deleted the gsterbrant_lit_options_object branch December 9, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add LitOptions to Standard Material
2 participants