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

Add new shading model to Filament for specularGlossiness. #1083

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public enum Shading {
UNLIT, // no lighting applied, emissive possible
LIT, // default, standard lighting
SUBSURFACE, // subsurface lighting model
CLOTH // cloth lighting model
CLOTH, // cloth lighting model
SPECULAR_GLOSSINESS // legacy lighting model
}

public enum Interpolation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public enum Shading {
UNLIT,
LIT,
SUBSURFACE,
CLOTH
CLOTH,
SPECULAR_GLOSSINESS
}

public enum Interpolation {
Expand Down
16 changes: 12 additions & 4 deletions docs/Materials.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
# Material models

Filament materials can use one of the following material models:
- Lit (or standard)
- Subsurface
- Cloth
- Unlit
- `lit` (or standard)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of changing the shading model names to the programmatic versions here, you should update the ### shadingModel section to add specularGlossiness to the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

- `subsurface`
- `cloth`
- `unlit`
- `specularGlossiness` (legacy)

## Lit model

Expand Down Expand Up @@ -522,6 +523,13 @@

![Figure [materialUnlit]: The unlit model is used to render debug information](images/screenshot_unlit.jpg)

## Specular glossiness

This alternative lighting model exists to comply with legacy standards.

Similar to cloth, it encompasses all the parameters previously defined for the standard
lit mode except for _metallic_ and _reflectance_, and adds a _sheenColor_ parameter.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the ### Material fragment inputs section too? sheenColor is listed as cloth only. Also add a table to describe the parameter, like this:

       Parameter      |      Definition
---------------------:|:---------------------
**sheenColor**        | Specular tint to create two-tone specular fabrics (defaults to $\sqrt{baseColor}$)

       Property       |   Type   |            Range         |           Note
---------------------:|:--------:|:------------------------:|:-------------------------
**sheenColor**        | float3   |  [0..1]                  | Linear RGB

Except in a way that makes sense :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


# Material definitions

A material definition is a text file that describes all the information required by a material:
Expand Down
1 change: 1 addition & 0 deletions libs/filabridge/include/filament/MaterialEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum class Shading : uint8_t {
LIT, //!< default, standard lighting
SUBSURFACE, //!< subsurface lighting model
CLOTH, //!< cloth lighting model
SPECULAR_GLOSSINESS, //!< legacy lighting model
};

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/filamat/include/filamat/MaterialBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class UTILS_PUBLIC MaterialBuilder : public MaterialBuilderBase {
THICKNESS, // float, subsurface shading model only
SUBSURFACE_POWER, // float, subsurface shading model only
SUBSURFACE_COLOR, // float3, subsurface and cloth shading models only
SHEEN_COLOR, // float3, cloth shading model only
SHEEN_COLOR, // float3, cloth and specular-glossiness shading models only
EMISSIVE, // float4, all shading models
NORMAL, // float3, all shading models only, except unlit
POST_LIGHTING_COLOR, // float4, all shading models
Expand Down
1 change: 1 addition & 0 deletions libs/filamat/src/shaders/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ std::ostream& CodeGenerator::generateShaderLit(std::ostream& out, ShaderType typ
case Shading::UNLIT:
assert("Lit shader generated with unlit shading model");
break;
case Shading::SPECULAR_GLOSSINESS:
case Shading::LIT:
out << SHADERS_SHADING_MODEL_STANDARD_FS_DATA;
break;
Expand Down
9 changes: 5 additions & 4 deletions libs/filamat/src/shaders/ShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ namespace filamat {

static const char* getShadingDefine(filament::Shading shading) noexcept {
switch (shading) {
case filament::Shading::LIT: return "SHADING_MODEL_LIT";
case filament::Shading::UNLIT: return "SHADING_MODEL_UNLIT";
case filament::Shading::SUBSURFACE: return "SHADING_MODEL_SUBSURFACE";
case filament::Shading::CLOTH: return "SHADING_MODEL_CLOTH";
case filament::Shading::LIT: return "SHADING_MODEL_LIT";
case filament::Shading::UNLIT: return "SHADING_MODEL_UNLIT";
case filament::Shading::SUBSURFACE: return "SHADING_MODEL_SUBSURFACE";
case filament::Shading::CLOTH: return "SHADING_MODEL_CLOTH";
case filament::Shading::SPECULAR_GLOSSINESS: return "SHADING_MODEL_SPECULAR_GLOSSINESS";
}
}

Expand Down
2 changes: 1 addition & 1 deletion shaders/src/common_lighting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct PixelParams {
float subsurfacePower;
#endif

#if defined(SHADING_MODEL_CLOTH) && defined(MATERIAL_HAS_SUBSURFACE_COLOR)
#if (defined(SHADING_MODEL_CLOTH) || defined(SHADING_MODEL_SPECULAR_GLOSSINESS)) && defined(MATERIAL_HAS_SUBSURFACE_COLOR)
vec3 subsurfaceColor;
#endif
};
8 changes: 4 additions & 4 deletions shaders/src/common_material.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct MaterialInputs {
vec4 baseColor;
#if !defined(SHADING_MODEL_UNLIT)
float roughness;
#if !defined(SHADING_MODEL_CLOTH)
#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
float metallic;
float reflectance;
#endif
Expand All @@ -81,7 +81,7 @@ struct MaterialInputs {
vec3 subsurfaceColor;
#endif

#if defined(SHADING_MODEL_CLOTH)
#if defined(SHADING_MODEL_CLOTH) || defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
vec3 sheenColor;
#if defined(MATERIAL_HAS_SUBSURFACE_COLOR)
vec3 subsurfaceColor;
Expand All @@ -104,7 +104,7 @@ void initMaterial(out MaterialInputs material) {
material.baseColor = vec4(1.0);
#if !defined(SHADING_MODEL_UNLIT)
material.roughness = 1.0;
#if !defined(SHADING_MODEL_CLOTH)
#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
material.metallic = 0.0;
material.reflectance = 0.5;
#endif
Expand All @@ -128,7 +128,7 @@ void initMaterial(out MaterialInputs material) {
material.subsurfaceColor = vec3(1.0);
#endif

#if defined(SHADING_MODEL_CLOTH)
#if defined(SHADING_MODEL_CLOTH) || defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
material.sheenColor = sqrt(material.baseColor.rgb);
#if defined(MATERIAL_HAS_SUBSURFACE_COLOR)
material.subsurfaceColor = vec3(0.0);
Expand Down
8 changes: 7 additions & 1 deletion shaders/src/shading_lit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ void getPixelParams(const MaterialInputs material, out PixelParams pixel) {
baseColor.rgb /= max(baseColor.a, FLT_EPS);
#endif

#if !defined(SHADING_MODEL_CLOTH)
#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
// This is from KHR_materials_pbrSpecularGlossiness.
vec3 specular = material.sheenColor;
float maxSpecularComponent = max(max(specular.r, specular.g), specular.b);
pixel.diffuseColor = baseColor.rgb * (1.0 - maxSpecularComponent);
pixel.f0 = specular;
#elif !defined(SHADING_MODEL_CLOTH)
float metallic = material.metallic;
float reflectance = material.reflectance;

Expand Down
1 change: 1 addition & 0 deletions tools/matc/src/matc/ParametersProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ ParametersProcessor::ParametersProcessor() {
mStringToShading["lit"] = MaterialBuilder::Shading::LIT;
mStringToShading["subsurface"] = MaterialBuilder::Shading::SUBSURFACE;
mStringToShading["unlit"] = MaterialBuilder::Shading::UNLIT;
mStringToShading["specularGlossiness"] = MaterialBuilder::Shading::SPECULAR_GLOSSINESS;

mStringToVariant["directionalLighting"] = filament::Variant::DIRECTIONAL_LIGHTING;
mStringToVariant["dynamicLighting"] = filament::Variant::DYNAMIC_LIGHTING;
Expand Down
1 change: 1 addition & 0 deletions tools/matinfo/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const char* toString(Shading shadingModel) {
case Shading::LIT: return "lit";
case Shading::SUBSURFACE: return "subsurface";
case Shading::CLOTH: return "cloth";
case Shading::SPECULAR_GLOSSINESS: return "specularGlossiness";
}
}

Expand Down