diff --git a/android/filament-android/src/main/cpp/Material.cpp b/android/filament-android/src/main/cpp/Material.cpp index be16c7f420..6331520d46 100644 --- a/android/filament-android/src/main/cpp/Material.cpp +++ b/android/filament-android/src/main/cpp/Material.cpp @@ -90,7 +90,7 @@ JNIEXPORT jint JNICALL Java_com_google_android_filament_Material_nGetRefraction(JNIEnv*, jclass, jlong nativeMaterial) { Material* material = (Material*) nativeMaterial; - return (jint) material->getRefraction(); + return (jint)material->getRefractionMode(); } extern "C" diff --git a/android/filament-android/src/main/java/com/google/android/filament/Material.java b/android/filament-android/src/main/java/com/google/android/filament/Material.java index 1571446ff9..6c677a904b 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/Material.java +++ b/android/filament-android/src/main/java/com/google/android/filament/Material.java @@ -146,9 +146,9 @@ public class Material { * * @see * - * Blending and transparency: refraction + * Blending and transparency: refractionMode */ - public enum Refraction { + public enum RefractionMode { NONE, CUBEMAP, SCREEN_SPACE @@ -383,8 +383,8 @@ public class Material { * * Blending and transparency: refraction */ - public Refraction getRefraction() { - return Refraction.values()[nGetRefraction(getNativeObject())]; + public RefractionMode getRefractionMode() { + return RefractionMode.values()[nGetRefractionMode(getNativeObject())]; } /** @@ -895,7 +895,7 @@ public class Material { private static native float nGetMaskThreshold(long nativeMaterial); private static native float nGetSpecularAntiAliasingVariance(long nativeMaterial); private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterial); - private static native int nGetRefraction(long nativeMaterial); + private static native int nGetRefractionMode(long nativeMaterial); private static native int nGetRefractionType(long nativeMaterial); diff --git a/docs/Materials.md.html b/docs/Materials.md.html index 46130972df..111aa6988c 100644 --- a/docs/Materials.md.html +++ b/docs/Materials.md.html @@ -90,7 +90,7 @@ in table [standardProperties]. **emissive** | Additional diffuse albedo to simulate emissive surfaces (such as neons, etc.) This property is mostly useful in an HDR pipeline with a bloom pass **postLightingColor** | Additional color that can be blended with the result of the lighting computations. See `postLightingBlending` **transmission** | Defines how much of the diffuse light of a dielectric is transmitted through the object, in other words this defines how transparent an object is -**absoption** | Absorption factor for refractive objects +**absorption** | Absorption factor for refractive objects **ior** | Index of refraction for refracive objects [Table [standardProperties]: Properties of the standard model] @@ -113,7 +113,7 @@ The type and range of each property is described in table [standardPropertiesTyp **postLightingColor** | float4 | [0..1] | Pre-multiplied linear RGB **transmission** | float | [0..1] | **absorption** | float3 | [0..n] | -**ior** | float | [0..n] | Optional, usually deduced from the reflectance +**ior** | float | [1..n] | Optional, usually deduced from the reflectance [Table [standardPropertiesTypes]: Range and type of the standard model's properties] @@ -1114,7 +1114,7 @@ material { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -### Blending and transparency: refraction +### Blending and transparency: refractionMode Type : `string` @@ -1135,7 +1135,7 @@ Description ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JSON material { - refraction : cubemap, + refractionMode : cubemap, } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1148,7 +1148,7 @@ Value : Any of `solid`, `thin`. Defaults to `solid`. Description -: This is only meaningful when `refraction` is set to anything but `none`. `refractionType` +: This is only meaningful when `refractionMode` is set to anything but `none`. `refractionType` defines the refraction model used. `solid` is used for thick objects such as a crystal ball, an ice cube or as sculpture. `thin` is used for thin objects such as a window, an ornament ball or a soap bubble. In `solid` mode all refracive objects are assumed to be a sphere @@ -1157,7 +1157,7 @@ Description ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ JSON material { - refraction : cubemap, + refractionMode : cubemap, refractionType : thin, } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/filament/include/filament/Material.h b/filament/include/filament/Material.h index 0c4af59e02..f26643a828 100644 --- a/filament/include/filament/Material.h +++ b/filament/include/filament/Material.h @@ -180,7 +180,7 @@ public: AttributeBitset getRequiredAttributes() const noexcept; //! Returns the refraction mode used by this material. - Refraction getRefraction() const noexcept; + RefractionMode getRefractionMode() const noexcept; // Return the refraction type used by this material. RefractionType getRefractionType() const noexcept; diff --git a/filament/src/Material.cpp b/filament/src/Material.cpp index 555b8a9e90..584a818e0d 100644 --- a/filament/src/Material.cpp +++ b/filament/src/Material.cpp @@ -160,7 +160,7 @@ FMaterial::FMaterial(FEngine& engine, const Material::Builder& builder) parser->getVertexDomain(&mVertexDomain); parser->getMaterialDomain(&mMaterialDomain); parser->getRequiredAttributes(&mRequiredAttributes); - parser->getRefraction(&mRefraction); + parser->getRefractionMode(&mRefractionMode); parser->getRefractionType(&mRefractionType); if (mBlendingMode == BlendingMode::MASKED) { @@ -603,8 +603,8 @@ AttributeBitset Material::getRequiredAttributes() const noexcept { return upcast(this)->getRequiredAttributes(); } -Refraction Material::getRefraction() const noexcept { - return upcast(this)->getRefraction(); +RefractionMode Material::getRefractionMode() const noexcept { + return upcast(this)->getRefractionMode(); } RefractionType Material::getRefractionType() const noexcept { diff --git a/filament/src/MaterialParser.cpp b/filament/src/MaterialParser.cpp index 8ecbcc773c..17e4fdfb5b 100644 --- a/filament/src/MaterialParser.cpp +++ b/filament/src/MaterialParser.cpp @@ -246,8 +246,8 @@ bool MaterialParser::getRequiredAttributes(AttributeBitset* value) const noexcep return true; } -bool MaterialParser::getRefraction(Refraction* value) const noexcept { - static_assert(sizeof(Refraction) == sizeof(uint8_t), +bool MaterialParser::getRefractionMode(RefractionMode* value) const noexcept { + static_assert(sizeof(RefractionMode) == sizeof(uint8_t), "Refraction expected size is wrong"); return mImpl.getFromSimpleChunk(ChunkType::MaterialRefraction, (uint8_t*)value); } diff --git a/filament/src/MaterialParser.h b/filament/src/MaterialParser.h index 8ba077897c..d81c4741c2 100644 --- a/filament/src/MaterialParser.h +++ b/filament/src/MaterialParser.h @@ -75,7 +75,7 @@ public: bool getMaskThreshold(float*) const noexcept; bool hasShadowMultiplier(bool*) const noexcept; bool getRequiredAttributes(AttributeBitset*) const noexcept; - bool getRefraction(Refraction* value) const noexcept; + bool getRefractionMode(RefractionMode* value) const noexcept; bool getRefractionType(RefractionType* value) const noexcept; bool hasCustomDepthShader(bool* value) const noexcept; bool hasSpecularAntiAliasing(bool* value) const noexcept; diff --git a/filament/src/details/Material.h b/filament/src/details/Material.h index 30afe2996d..ba847aaaa7 100644 --- a/filament/src/details/Material.h +++ b/filament/src/details/Material.h @@ -115,7 +115,7 @@ public: float getMaskThreshold() const noexcept { return mMaskThreshold; } bool hasShadowMultiplier() const noexcept { return mHasShadowMultiplier; } AttributeBitset getRequiredAttributes() const noexcept { return mRequiredAttributes; } - Refraction getRefraction() const noexcept { return mRefraction; } + RefractionMode getRefractionMode() const noexcept { return mRefractionMode; } RefractionType getRefractionType() const noexcept { return mRefractionType; } bool hasSpecularAntiAliasing() const noexcept { return mSpecularAntiAliasing; } @@ -172,7 +172,7 @@ private: MaterialDomain mMaterialDomain = MaterialDomain::SURFACE; CullingMode mCullingMode = CullingMode::NONE; AttributeBitset mRequiredAttributes; - Refraction mRefraction = Refraction::NONE; + RefractionMode mRefractionMode = RefractionMode::NONE; RefractionType mRefractionType = RefractionType::SOLID; uint64_t mMaterialProperties = 0; diff --git a/libs/filabridge/include/filament/MaterialEnums.h b/libs/filabridge/include/filament/MaterialEnums.h index 444ef53538..1a72f5a3c1 100644 --- a/libs/filabridge/include/filament/MaterialEnums.h +++ b/libs/filabridge/include/filament/MaterialEnums.h @@ -153,7 +153,7 @@ enum MaterialDomain : uint8_t { /** * Refraction */ -enum Refraction : uint8_t { +enum RefractionMode : uint8_t { NONE = 0, //!< no refraction CUBEMAP = 1, //!< refracted rays go to the ibl cubemap SCREEN_SPACE = 2, //!< refracted rays go to screen space diff --git a/libs/filamat/include/filamat/MaterialBuilder.h b/libs/filamat/include/filamat/MaterialBuilder.h index 6d0a8f58c3..fda8d86f7e 100644 --- a/libs/filamat/include/filamat/MaterialBuilder.h +++ b/libs/filamat/include/filamat/MaterialBuilder.h @@ -176,7 +176,7 @@ public: }; using MaterialDomain = filament::MaterialDomain; - using Refraction = filament::Refraction; + using RefractionMode = filament::RefractionMode; using RefractionType = filament::RefractionType; using BlendingMode = filament::BlendingMode; @@ -236,7 +236,7 @@ public: MaterialBuilder& materialDomain(MaterialDomain materialDomain) noexcept; //! Specify the refraction - MaterialBuilder& materialRefraction(Refraction refraction) noexcept; + MaterialBuilder& materialRefraction(RefractionMode refraction) noexcept; //! Specify the refraction type MaterialBuilder& materialRefractionType(RefractionType refractionType) noexcept; @@ -543,7 +543,7 @@ private: CullingMode mCullingMode = CullingMode::BACK; Shading mShading = Shading::LIT; MaterialDomain mMaterialDomain = MaterialDomain::SURFACE; - Refraction mRefraction = Refraction::CUBEMAP; + RefractionMode mRefractionMode = RefractionMode::NONE; RefractionType mRefractionType = RefractionType::SOLID; Interpolation mInterpolation = Interpolation::SMOOTH; VertexDomain mVertexDomain = VertexDomain::OBJECT; diff --git a/libs/filamat/src/MaterialBuilder.cpp b/libs/filamat/src/MaterialBuilder.cpp index 8fc3fbb690..d3502733e1 100644 --- a/libs/filamat/src/MaterialBuilder.cpp +++ b/libs/filamat/src/MaterialBuilder.cpp @@ -210,8 +210,8 @@ MaterialBuilder& MaterialBuilder::materialDomain(MaterialDomain materialDomain) return *this; } -MaterialBuilder& MaterialBuilder::materialRefraction(Refraction refraction) noexcept { - mRefraction = refraction; +MaterialBuilder& MaterialBuilder::materialRefraction(RefractionMode refraction) noexcept { + mRefractionMode = refraction; return *this; } @@ -405,7 +405,7 @@ void MaterialBuilder::prepareToBuild(MaterialInfo& info) noexcept { info.multiBounceAOSet = mMultiBounceAOSet; info.specularAO = mSpecularAO; info.specularAOSet = mSpecularAOSet; - info.refraction = mRefraction; + info.refractionMode = mRefractionMode; info.refractionType = mRefractionType; } @@ -750,7 +750,7 @@ void MaterialBuilder::writeCommonChunks(ChunkContainer& container, MaterialInfo& container.addSimpleChild(ChunkType::MaterialName, mMaterialName.c_str_safe()); container.addSimpleChild(ChunkType::MaterialShaderModels, mShaderModels.getValue()); container.addSimpleChild(ChunkType::MaterialDomain, static_cast(mMaterialDomain)); - container.addSimpleChild(ChunkType::MaterialRefraction, static_cast(mRefraction)); + container.addSimpleChild(ChunkType::MaterialRefraction, static_cast(mRefractionMode)); container.addSimpleChild(ChunkType::MaterialRefractionType, static_cast(mRefractionType)); // UIB diff --git a/libs/filamat/src/shaders/MaterialInfo.h b/libs/filamat/src/shaders/MaterialInfo.h index 6218df4a66..c5fa3a80a2 100644 --- a/libs/filamat/src/shaders/MaterialInfo.h +++ b/libs/filamat/src/shaders/MaterialInfo.h @@ -43,7 +43,7 @@ struct UTILS_PUBLIC MaterialInfo { bool multiBounceAOSet; bool specularAO; bool specularAOSet; - filament::Refraction refraction; + filament::RefractionMode refractionMode; filament::RefractionType refractionType; filament::AttributeBitset requiredAttributes; filament::BlendingMode blendingMode; diff --git a/libs/filamat/src/shaders/ShaderGenerator.cpp b/libs/filamat/src/shaders/ShaderGenerator.cpp index 3fe0d6333a..332ce7cbb0 100644 --- a/libs/filamat/src/shaders/ShaderGenerator.cpp +++ b/libs/filamat/src/shaders/ShaderGenerator.cpp @@ -284,11 +284,11 @@ const std::string ShaderGenerator::createFragmentProgram(filament::backend::Shad material.specularAO : !isMobileTarget(shaderModel); cg.generateDefine(fs, "SPECULAR_AMBIENT_OCCLUSION", specularAO ? 1u : 0u); - cg.generateDefine(fs, "HAS_REFRACTION", material.refraction != Refraction::NONE); - if (material.refraction != Refraction::NONE) { - cg.generateDefine(fs, "REFRACTION_MODE_CUBEMAP", uint32_t(Refraction::CUBEMAP)); - cg.generateDefine(fs, "REFRACTION_MODE_SCREEN_SPACE", uint32_t(Refraction::SCREEN_SPACE)); - switch (material.refraction) { + cg.generateDefine(fs, "HAS_REFRACTION", material.refractionMode != RefractionMode::NONE); + if (material.refractionMode != RefractionMode::NONE) { + cg.generateDefine(fs, "REFRACTION_MODE_CUBEMAP", uint32_t(RefractionMode::CUBEMAP)); + cg.generateDefine(fs, "REFRACTION_MODE_SCREEN_SPACE", uint32_t(RefractionMode::SCREEN_SPACE)); + switch (material.refractionMode) { case NONE: // can't be here break; diff --git a/samples/materials/sandboxLit.mat b/samples/materials/sandboxLit.mat index 200bbd71fc..45c8428de2 100644 --- a/samples/materials/sandboxLit.mat +++ b/samples/materials/sandboxLit.mat @@ -1,7 +1,7 @@ material { name : Lit, shadingModel : lit, - refraction : cubemap, + refractionMode : cubemap, refractionType : solid, parameters : [ { diff --git a/shaders/src/light_indirect.fs b/shaders/src/light_indirect.fs index 5f90de0f9d..5271dcb407 100644 --- a/shaders/src/light_indirect.fs +++ b/shaders/src/light_indirect.fs @@ -348,7 +348,7 @@ void applyRefraction(const PixelParams pixel, r = refract(r, n0, eta0); float N0oR = dot(n0, r); #elif REFRACTION_TYPE == REFRACTION_TYPE_THIN - // Disney roughness remaping for thin layers + // Roughness remaping for thin layers, see Burley 2012, "Physically-Based Shading at Disney" perceptualRoughness = saturate((0.65 * eta0 - 0.35) * perceptualRoughness); #else #error "invalid REFRACTION_TYPE" @@ -385,7 +385,7 @@ void applyRefraction(const PixelParams pixel, #endif vec3 Ft = prefilteredRadiance(r, perceptualRoughness) * frameUniforms.iblLuminance; #else - // compute the point where the ray exists the medium, if needed + // compute the point where the ray exits the medium, if needed vec4 p = vec4(shading_position + r * d, 1.0); vec3 Ft; p = frameUniforms.clipFromWorldMatrix * p; @@ -396,7 +396,7 @@ void applyRefraction(const PixelParams pixel, /* fresnel from the first interface */ Ft *= 1.0 - E; - /* apply absoption */ + /* apply absorption */ #if defined(MATERIAL_HAS_ABSORPTION) Ft *= T; #endif diff --git a/shaders/src/shading_lit.fs b/shaders/src/shading_lit.fs index 0e9ee291b4..cc0c7dc683 100644 --- a/shaders/src/shading_lit.fs +++ b/shaders/src/shading_lit.fs @@ -99,7 +99,7 @@ void getCommonPixelParams(const MaterialInputs material, inout PixelParams pixel float materialIOR = f0ToIor(pixel.f0.g); #else // if ior is set in the material, use it (can lead to unrealistic materials) - float materialIOR = max(0.0, material.ior); + float materialIOR = max(1.0, material.ior); #endif pixel.etaOutIn = airIOR / materialIOR; // air -> material pixel.etaInOut = materialIOR / airIOR; // material -> air diff --git a/tools/matc/src/matc/ParametersProcessor.cpp b/tools/matc/src/matc/ParametersProcessor.cpp index 102fe7ff85..b28352479a 100644 --- a/tools/matc/src/matc/ParametersProcessor.cpp +++ b/tools/matc/src/matc/ParametersProcessor.cpp @@ -464,11 +464,11 @@ static bool processDomain(MaterialBuilder& builder, const JsonishValue& value) { return true; } -static bool processRefraction(MaterialBuilder& builder, const JsonishValue& value) { - static const std::unordered_map strToEnum{ - { "none", MaterialBuilder::Refraction::NONE }, - { "cubemap", MaterialBuilder::Refraction::CUBEMAP }, - { "screenspace", MaterialBuilder::Refraction::SCREEN_SPACE }, +static bool processRefractionMode(MaterialBuilder& builder, const JsonishValue& value) { + static const std::unordered_map strToEnum{ + { "none", MaterialBuilder::RefractionMode::NONE }, + { "cubemap", MaterialBuilder::RefractionMode::CUBEMAP }, + { "screenspace", MaterialBuilder::RefractionMode::SCREEN_SPACE }, }; auto jsonString = value.toJsonString(); if (!isStringValidEnum(strToEnum, jsonString->getString())) { @@ -558,7 +558,7 @@ ParametersProcessor::ParametersProcessor() { mParameters["multiBounceAmbientOcclusion"] = { &processMultiBounceAO, Type::BOOL }; mParameters["specularAmbientOcclusion"] = { &processSpecularAmbientOcclusion, Type::BOOL }; mParameters["domain"] = { &processDomain, Type::STRING }; - mParameters["refraction"] = { &processRefraction, Type::STRING }; + mParameters["refractionMode"] = { &processRefractionMode, Type::STRING }; mParameters["refractionType"] = { &processRefractionType, Type::STRING }; }