diff options
-rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 187 | ||||
-rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 71 | ||||
-rw-r--r-- | indra/llprimitive/lltextureentry.h | 22 | ||||
-rw-r--r-- | indra/newview/app_settings/logcontrol.xml | 1 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl | 4 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 | ||||
-rw-r--r-- | indra/newview/featuretable.txt | 4 | ||||
-rw-r--r-- | indra/newview/lldrawpoolalpha.cpp | 40 | ||||
-rw-r--r-- | indra/newview/lldrawpoolpbropaque.cpp | 55 | ||||
-rw-r--r-- | indra/newview/llfetchedgltfmaterial.cpp | 61 | ||||
-rw-r--r-- | indra/newview/llfetchedgltfmaterial.h | 14 | ||||
-rw-r--r-- | indra/newview/llreflectionmapmanager.h | 2 | ||||
-rw-r--r-- | indra/newview/llspatialpartition.h | 8 | ||||
-rw-r--r-- | indra/newview/llviewerobject.cpp | 57 | ||||
-rw-r--r-- | indra/newview/llviewerobject.h | 13 | ||||
-rw-r--r-- | indra/newview/llvovolume.cpp | 18 | ||||
-rw-r--r-- | indra/newview/pipeline.cpp | 23 |
18 files changed, 378 insertions, 206 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index 951b768678..19081cd76f 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -28,12 +28,44 @@ #include "llgltfmaterial.h" -#include "tiny_gltf.h" +#include "tinygltf/tiny_gltf.h" + +LLGLTFMaterial::LLGLTFMaterial(const LLGLTFMaterial& rhs) +{ + *this = rhs; +} + +LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) +{ + //have to do a manual operator= because of LLRefCount + mBaseColorId = rhs.mBaseColorId; + mNormalId = rhs.mNormalId; + mMetallicRoughnessId = rhs.mMetallicRoughnessId; + mEmissiveId = rhs.mEmissiveId; + + mBaseColor = rhs.mBaseColor; + mEmissiveColor = rhs.mEmissiveColor; + + mMetallicFactor = rhs.mMetallicFactor; + mRoughnessFactor = rhs.mRoughnessFactor; + mAlphaCutoff = rhs.mAlphaCutoff; + + mDoubleSided = rhs.mDoubleSided; + mAlphaMode = rhs.mAlphaMode; + + for (S32 i = 0; i < 3; ++i) + { + mTextureTransform[i] = rhs.mTextureTransform[i]; + } + + return *this; +} bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, std::string& error_msg) { +#if 1 tinygltf::TinyGLTF gltf; - + tinygltf::Model model_in; if (gltf.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, json.c_str(), json.length(), "")) @@ -45,12 +77,13 @@ bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, st return true; } - +#endif return false; } std::string LLGLTFMaterial::asJSON(bool prettyprint) const { +#if 1 tinygltf::TinyGLTF gltf; tinygltf::Model model_out; @@ -61,6 +94,9 @@ std::string LLGLTFMaterial::asJSON(bool prettyprint) const gltf.WriteGltfSceneToStream(&model_out, str, prettyprint, false); return str.str(); +#else + return ""; +#endif } void LLGLTFMaterial::setFromModel(const tinygltf::Model& model, S32 mat_index) @@ -130,7 +166,7 @@ void LLGLTFMaterial::setFromModel(const tinygltf::Model& model, S32 mat_index) void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const { - if (model.materials.size() < mat_index+1) + if (model.materials.size() < mat_index + 1) { model.materials.resize(mat_index + 1); } @@ -143,7 +179,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const U32 idx = model.images.size(); model.images.resize(idx + 1); model.textures.resize(idx + 1); - + material_out.pbrMetallicRoughness.baseColorTexture.index = idx; model.textures[idx].source = idx; model.images[idx].uri = mBaseColorId.asString(); @@ -160,7 +196,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const model.textures[idx].source = idx; model.images[idx].uri = mNormalId.asString(); } - + // set metallic-roughness texture if (mMetallicRoughnessId.notNull()) { @@ -187,7 +223,7 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const material_out.alphaMode = getAlphaMode(); material_out.alphaCutoff = mAlphaCutoff; - + mBaseColor.write(material_out.pbrMetallicRoughness.baseColorFactor); mEmissiveColor.write(material_out.emissiveFactor); @@ -195,11 +231,130 @@ void LLGLTFMaterial::writeToModel(tinygltf::Model& model, S32 mat_index) const material_out.pbrMetallicRoughness.roughnessFactor = mRoughnessFactor; material_out.doubleSided = mDoubleSided; + + model.asset.version = "2.0"; +} + + +void LLGLTFMaterial::setBaseColorId(const LLUUID& id) +{ + mBaseColorId = id; +} + +void LLGLTFMaterial::setNormalId(const LLUUID& id) +{ + mNormalId = id; +} + +void LLGLTFMaterial::setMetallicRoughnessId(const LLUUID& id) +{ + mMetallicRoughnessId = id; +} + +void LLGLTFMaterial::setEmissiveId(const LLUUID& id) +{ + mEmissiveId = id; +} + +void LLGLTFMaterial::setBaseColorFactor(const LLColor3& baseColor, F32 transparency) +{ + mBaseColor.set(baseColor, transparency); + mBaseColor.clamp(); +} + +void LLGLTFMaterial::setAlphaCutoff(F32 cutoff) +{ + mAlphaCutoff = llclamp(cutoff, 0.f, 1.f); +} + +void LLGLTFMaterial::setEmissiveColorFactor(const LLColor3& emissiveColor) +{ + mEmissiveColor = emissiveColor; + mEmissiveColor.clamp(); +} + +void LLGLTFMaterial::setMetallicFactor(F32 metallic) +{ + mMetallicFactor = llclamp(metallic, 0.f, 1.f); +} + +void LLGLTFMaterial::setRoughnessFactor(F32 roughness) +{ + mRoughnessFactor = llclamp(roughness, 0.f, 1.f); +} + +void LLGLTFMaterial::setAlphaMode(S32 mode) +{ + mAlphaMode = (AlphaMode)llclamp(mode, (S32)ALPHA_MODE_OPAQUE, (S32)ALPHA_MODE_MASK); +} + +void LLGLTFMaterial::setDoubleSided(bool double_sided) +{ + // sure, no clamping will ever be needed for a bool, but include the + // setter for consistency with the clamping API + mDoubleSided = double_sided; +} + +// Default value accessors + +LLUUID LLGLTFMaterial::getDefaultBaseColorId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultNormalId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultEmissiveId() +{ + return LLUUID::null; +} + +LLUUID LLGLTFMaterial::getDefaultMetallicRoughnessId() +{ + return LLUUID::null; +} + +F32 LLGLTFMaterial::getDefaultAlphaCutoff() +{ + return 0.f; +} + +S32 LLGLTFMaterial::getDefaultAlphaMode() +{ + return (S32)ALPHA_MODE_OPAQUE; +} + +F32 LLGLTFMaterial::getDefaultMetallicFactor() +{ + return 0.f; +} + +F32 LLGLTFMaterial::getDefaultRoughnessFactor() +{ + return 0.f; +} + +LLColor4 LLGLTFMaterial::getDefaultBaseColor() +{ + return LLColor4::white; +} + +LLColor3 LLGLTFMaterial::getDefaultEmissiveColor() +{ + return LLColor3::black; +} + +bool LLGLTFMaterial::getDefaultDoubleSided() +{ + return false; } -void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model & model, S32 mat_index, LLGLTFMaterial const * base_material) const +void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model& model, S32 mat_index, LLGLTFMaterial const* base_material) const { - if (model.materials.size() < mat_index+1) + if (model.materials.size() < mat_index + 1) { model.materials.resize(mat_index + 1); } @@ -256,37 +411,37 @@ void LLGLTFMaterial::writeOverridesToModel(tinygltf::Model & model, S32 mat_inde model.images[idx].uri = mEmissiveId.asString(); } - if(mAlphaMode != base_material->mAlphaMode) + if (mAlphaMode != base_material->mAlphaMode) { material_out.alphaMode = getAlphaMode(); } - if(mAlphaCutoff != base_material->mAlphaCutoff) + if (mAlphaCutoff != base_material->mAlphaCutoff) { material_out.alphaCutoff = mAlphaCutoff; } - if(mBaseColor != base_material->mBaseColor) + if (mBaseColor != base_material->mBaseColor) { mBaseColor.write(material_out.pbrMetallicRoughness.baseColorFactor); } - if(mEmissiveColor != base_material->mEmissiveColor) + if (mEmissiveColor != base_material->mEmissiveColor) { mEmissiveColor.write(material_out.emissiveFactor); } - if(mMetallicFactor != base_material->mMetallicFactor) + if (mMetallicFactor != base_material->mMetallicFactor) { material_out.pbrMetallicRoughness.metallicFactor = mMetallicFactor; } - if(mRoughnessFactor != base_material->mRoughnessFactor) + if (mRoughnessFactor != base_material->mRoughnessFactor) { material_out.pbrMetallicRoughness.roughnessFactor = mRoughnessFactor; } - if(mDoubleSided != base_material->mDoubleSided) + if (mDoubleSided != base_material->mDoubleSided) { material_out.doubleSided = mDoubleSided; } diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index e8d1d67f1b..9c82f08805 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -27,8 +27,10 @@ #pragma once #include "llrefcount.h" +#include "llmemory.h" #include "v4color.h" #include "v3color.h" +#include "v2math.h" #include "lluuid.h" #include "llmd5.h" @@ -43,6 +45,13 @@ class LLGLTFMaterial : public LLRefCount { public: + struct TextureTransform + { + LLVector2 mOffset = { 0.f, 0.f }; + LLVector2 mScale = { 1.f, 1.f }; + F32 mRotation = 0.f; + }; + enum AlphaMode { ALPHA_MODE_OPAQUE = 0, @@ -50,6 +59,11 @@ public: ALPHA_MODE_MASK }; + LLGLTFMaterial() {} + LLGLTFMaterial(const LLGLTFMaterial& rhs); + + LLGLTFMaterial& operator=(const LLGLTFMaterial& rhs); + LLUUID mBaseColorId; LLUUID mNormalId; LLUUID mMetallicRoughnessId; @@ -65,17 +79,41 @@ public: bool mDoubleSided = false; AlphaMode mAlphaMode = ALPHA_MODE_OPAQUE; - // get a UUID based on a hash of this LLGLTFMaterial - LLUUID getHash() const + enum TextureTransformIdx : U32 { - LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; - LLMD5 md5; - md5.update((unsigned char*)this, sizeof(this)); - md5.finalize(); - LLUUID id; - md5.raw_digest(id.mData); - return id; - } + TEXTURE_TRANSFORM_DIFFUSE_EMISSIVE, + TEXTURE_TRANSFORM_NORMAL, + TEXTURE_TRANSFORM_METALLIC_ROUGHNESS + }; + TextureTransform mTextureTransform[3]; + + //setters for various members (will clamp to acceptable ranges) + + void setBaseColorId(const LLUUID& id); + void setNormalId(const LLUUID& id); + void setMetallicRoughnessId(const LLUUID& id); + void setEmissiveId(const LLUUID& id); + + void setBaseColorFactor(const LLColor3& baseColor, F32 transparency); + void setAlphaCutoff(F32 cutoff); + void setEmissiveColorFactor(const LLColor3& emissiveColor); + void setMetallicFactor(F32 metallic); + void setRoughnessFactor(F32 roughness); + void setAlphaMode(S32 mode); + void setDoubleSided(bool double_sided); + + // Default value accessors + static LLUUID getDefaultBaseColorId(); + static LLUUID getDefaultNormalId(); + static LLUUID getDefaultEmissiveId(); + static LLUUID getDefaultMetallicRoughnessId(); + static F32 getDefaultAlphaCutoff(); + static S32 getDefaultAlphaMode(); + static F32 getDefaultMetallicFactor(); + static F32 getDefaultRoughnessFactor(); + static LLColor4 getDefaultBaseColor(); + static LLColor3 getDefaultEmissiveColor(); + static bool getDefaultDoubleSided(); // set mAlphaMode from string. // Anything otherthan "MASK" or "BLEND" sets mAlphaMode to ALPHA_MODE_OPAQUE @@ -123,7 +161,18 @@ public: // write to given tinygltf::Model void writeToModel(tinygltf::Model& model, S32 mat_index) const; + // get a UUID based on a hash of this LLGLTFMaterial + LLUUID getHash() const + { + LLMD5 md5; + md5.update((unsigned char*)this, sizeof(this)); + md5.finalize(); + LLUUID id; + md5.raw_digest(id.mData); + return id; + } + // calculate the fields in this material that differ from a base material and write them out to a given tinygltf::Model - void writeOverridesToModel(tinygltf::Model & model, S32 mat_index, LLGLTFMaterial const * base_material) const; + void writeOverridesToModel(tinygltf::Model& model, S32 mat_index, LLGLTFMaterial const* base_material) const; }; diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index 24875f0d21..bb74d258fd 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -135,10 +135,6 @@ public: S32 setMaterialID(const LLMaterialID& pMaterialID); S32 setMaterialParams(const LLMaterialPtr pMaterialParams); - void setGLTFMaterial(LLGLTFMaterial* material) { mGLTFMaterial = material; } - LLGLTFMaterial* getGLTFMaterial() { return mGLTFMaterial; } - - virtual const LLUUID &getID() const { return mID; } const LLColor4 &getColor() const { return mColor; } const F32 getAlpha() const { return mColor.mV[VALPHA]; } @@ -200,10 +196,18 @@ public: // Media flags enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 }; + // GLTF asset + void setGLTFMaterial(LLGLTFMaterial* material) { mGLTFMaterial = material; } + LLGLTFMaterial* getGLTFMaterial() { return mGLTFMaterial; } + // GLTF override LLGLTFMaterial* getGLTFMaterialOverride() { return mGLTFMaterialOverrides; } void setGLTFMaterialOverride(LLGLTFMaterial* mat) { mGLTFMaterialOverrides = mat; } + // GLTF render + LLGLTFMaterial* getGLTFRenderMaterial() { return mGLTFRenderMaterial; } + void setGLTFRenderMaterial(LLGLTFMaterial* mat) { mGLTFRenderMaterial = mat; } + public: F32 mScaleS; // S, T offset F32 mScaleT; // S, T offset @@ -230,12 +234,18 @@ protected: bool mMaterialUpdatePending; LLMaterialID mMaterialID; LLMaterialPtr mMaterial; - LLPointer<LLGLTFMaterial> mGLTFMaterial; // if present, ignore mMaterial + + // Reference to GLTF material asset state + // On the viewer, this should be the same LLGLTFMaterial instance that exists in LLGLTFMaterialList + LLPointer<LLGLTFMaterial> mGLTFMaterial; // GLTF material parameter overrides -- the viewer will use this data to override material parameters - // set by the asset + // set by the asset and store the results in mRenderGLTFMaterial LLPointer<LLGLTFMaterial> mGLTFMaterialOverrides; + // GLTF material to use for rendering -- will always be an LLFetchedGLTFMaterial + LLPointer<LLGLTFMaterial> mGLTFRenderMaterial; + // Note the media data is not sent via the same message structure as the rest of the TE LLMediaEntry* mMediaEntry; // The media data for the face diff --git a/indra/newview/app_settings/logcontrol.xml b/indra/newview/app_settings/logcontrol.xml index 482012cdd6..2a26cb9a43 100644 --- a/indra/newview/app_settings/logcontrol.xml +++ b/indra/newview/app_settings/logcontrol.xml @@ -73,6 +73,7 @@ <string>Avatar</string> <string>Voice</string> --> + <string>Capabilities</string> </array> </map> </array> diff --git a/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl index b633813819..feaf562686 100644 --- a/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl @@ -196,7 +196,7 @@ vec4 filterColor(vec3 N) // apply the bias to the lod lod += u_lodBias; - lod = clamp(lod, 0, 7); + lod = clamp(lod, 0, 6); // sample lambertian at a lower resolution to avoid fireflies vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod); diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl index f4879b52de..32f157e9d2 100644 --- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl @@ -127,7 +127,7 @@ vec4 prefilterEnvMap(vec3 R) float envMapDim = 256.0; int numSamples = 4; - float numMips = 7.0; + float numMips = 6.0; float roughness = mipLevel/numMips; @@ -151,7 +151,7 @@ vec4 prefilterEnvMap(vec3 R) // Solid angle of 1 pixel across all cube faces float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim); // Biased (+1.0) mip level for better result - float mip = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); + float mip = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, numMips); //float mip = clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); color += textureLod(reflectionProbes, vec4(L,sourceIdx), mip) * dotNL; totalWeight += dotNL; diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 211e1f5d8d..ca436033f1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -507,7 +507,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods - float reflection_lods = 7; + float reflection_lods = 6; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); diff --git a/indra/newview/featuretable.txt b/indra/newview/featuretable.txt index 2cb48e51d0..efd498183d 100644 --- a/indra/newview/featuretable.txt +++ b/indra/newview/featuretable.txt @@ -286,9 +286,9 @@ RenderFSAASamples 1 0 RenderGLMultiThreaded 1 0 RenderGLContextCoreProfile 1 0 -// HACK: Current AMD drivers have bugged cubemap arrays, limit number of reflection probes to 16 +// HACK: Current AMD drivers have bugged cubemap arrays, limit number of reflection probes to 32 list AMD -RenderReflectionProbeCount 1 16 +RenderReflectionProbeCount 1 32 list GL3 RenderFSAASamples 0 0 diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 01b2647eaa..41e52846b3 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -675,45 +675,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged) gPipeline.bindDeferredShader(*target_shader); } - if (params.mTexture.notNull()) - { - gGL.getTexUnit(0)->bindFast(params.mTexture); // diffuse - } - else - { - gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::sWhiteImagep); - } - - if (params.mNormalMap) - { - target_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - else - { - target_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - } - - if (params.mSpecularMap) - { - target_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); // PBR linear packed Occlusion, Roughness, Metal. - } - else - { - target_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - if (params.mEmissiveMap) - { - target_shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, params.mEmissiveMap); // PBR sRGB Emissive - } - else - { - target_shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - target_shader->uniform1f(LLShaderMgr::ROUGHNESS_FACTOR, params.mGLTFMaterial->mRoughnessFactor); - target_shader->uniform1f(LLShaderMgr::METALLIC_FACTOR, params.mGLTFMaterial->mMetallicFactor); - target_shader->uniform3fv(LLShaderMgr::EMISSIVE_COLOR, 1, params.mGLTFMaterial->mEmissiveColor.mV); + params.mGLTFMaterial->bind(target_shader); } else { diff --git a/indra/newview/lldrawpoolpbropaque.cpp b/indra/newview/lldrawpoolpbropaque.cpp index 71f648a714..2f710e570b 100644 --- a/indra/newview/lldrawpoolpbropaque.cpp +++ b/indra/newview/lldrawpoolpbropaque.cpp @@ -95,57 +95,10 @@ void LLDrawPoolPBROpaque::renderDeferred(S32 pass) for (LLCullResult::drawinfo_iterator i = begin; i != end; ++i) { LLDrawInfo* pparams = *i; - LLGLTFMaterial *mat = pparams->mGLTFMaterial; - - // glTF 2.0 Specification 3.9.4. Alpha Coverage - // mAlphaCutoff is only valid for LLGLTFMaterial::ALPHA_MODE_MASK - F32 min_alpha = -1.0; - if (mat->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK) - { - min_alpha = mat->mAlphaCutoff; - } - shader->uniform1f(LLShaderMgr::MINIMUM_ALPHA, min_alpha); - - if (pparams->mTexture.notNull()) - { - gGL.getTexUnit(0)->bindFast(pparams->mTexture); // diffuse - } - else - { - gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::sWhiteImagep); - } - - if (pparams->mNormalMap) - { - shader->bindTexture(LLShaderMgr::BUMP_MAP, pparams->mNormalMap); - } - else - { - shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - } - - if (pparams->mSpecularMap) - { - shader->bindTexture(LLShaderMgr::SPECULAR_MAP, pparams->mSpecularMap); // PBR linear packed Occlusion, Roughness, Metal. - } - else - { - shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - if (pparams->mEmissiveMap) - { - shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, pparams->mEmissiveMap); // PBR sRGB Emissive - } - else - { - shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - shader->uniform1f(LLShaderMgr::ROUGHNESS_FACTOR, pparams->mGLTFMaterial->mRoughnessFactor); - shader->uniform1f(LLShaderMgr::METALLIC_FACTOR, pparams->mGLTFMaterial->mMetallicFactor); - shader->uniform3fv(LLShaderMgr::EMISSIVE_COLOR, 1, pparams->mGLTFMaterial->mEmissiveColor.mV); - + auto& mat = pparams->mGLTFMaterial; + + mat->bind(shader); + LLGLDisable cull_face(mat->mDoubleSided ? GL_CULL_FACE : 0); bool tex_setup = false; diff --git a/indra/newview/llfetchedgltfmaterial.cpp b/indra/newview/llfetchedgltfmaterial.cpp index a06dd276cd..2d3015635c 100644 --- a/indra/newview/llfetchedgltfmaterial.cpp +++ b/indra/newview/llfetchedgltfmaterial.cpp @@ -27,6 +27,10 @@ #include "llfetchedgltfmaterial.h" +#include "llviewertexturelist.h" +#include "llavatarappearancedefines.h" +#include "llshadermgr.h" + LLFetchedGLTFMaterial::LLFetchedGLTFMaterial() : LLGLTFMaterial() , mExpectedFlusTime(0.f) @@ -38,5 +42,62 @@ LLFetchedGLTFMaterial::LLFetchedGLTFMaterial() LLFetchedGLTFMaterial::~LLFetchedGLTFMaterial() { + +} + +void LLFetchedGLTFMaterial::bind(LLGLSLShader* shader) +{ + // glTF 2.0 Specification 3.9.4. Alpha Coverage + // mAlphaCutoff is only valid for LLGLTFMaterial::ALPHA_MODE_MASK + F32 min_alpha = -1.0; + + if (mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK) + { + min_alpha = mAlphaCutoff; + } + shader->uniform1f(LLShaderMgr::MINIMUM_ALPHA, min_alpha); + + if (mBaseColorTexture.notNull()) + { + gGL.getTexUnit(0)->bindFast(mBaseColorTexture); + } + else + { + gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::sWhiteImagep); + } + + + if (mNormalTexture.notNull()) + { + shader->bindTexture(LLShaderMgr::BUMP_MAP, mNormalTexture); + } + else + { + shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + } + + if (mMetallicRoughnessTexture.notNull()) + { + shader->bindTexture(LLShaderMgr::SPECULAR_MAP, mMetallicRoughnessTexture); // PBR linear packed Occlusion, Roughness, Metal. + } + else + { + shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + + if (mEmissiveTexture.notNull()) + { + shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, mEmissiveTexture); // PBR sRGB Emissive + } + else + { + shader->bindTexture(LLShaderMgr::EMISSIVE_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + + // NOTE: base color factor is baked into vertex stream + + shader->uniform1f(LLShaderMgr::ROUGHNESS_FACTOR, mRoughnessFactor); + shader->uniform1f(LLShaderMgr::METALLIC_FACTOR, mMetallicFactor); + shader->uniform3fv(LLShaderMgr::EMISSIVE_COLOR, 1, mEmissiveColor.mV); } diff --git a/indra/newview/llfetchedgltfmaterial.h b/indra/newview/llfetchedgltfmaterial.h index 4cbe6651c4..3b2801bf77 100644 --- a/indra/newview/llfetchedgltfmaterial.h +++ b/indra/newview/llfetchedgltfmaterial.h @@ -28,14 +28,26 @@ #include "llgltfmaterial.h" #include "llpointer.h" +#include "llviewertexture.h" -class LLFetchedGLTFMaterial : public LLGLTFMaterial +class LLGLSLShader; + +class LLFetchedGLTFMaterial: public LLGLTFMaterial { friend class LLGLTFMaterialList; // for lifetime management public: LLFetchedGLTFMaterial(); virtual ~LLFetchedGLTFMaterial(); + // bind this material for rendering + void bind(LLGLSLShader* shader); + + // Textures used for fetching/rendering + LLPointer<LLViewerFetchedTexture> mBaseColorTexture; + LLPointer<LLViewerFetchedTexture> mNormalTexture; + LLPointer<LLViewerFetchedTexture> mMetallicRoughnessTexture; + LLPointer<LLViewerFetchedTexture> mEmissiveTexture; + protected: //Lifetime management F64 mExpectedFlusTime; // since epoch in seconds diff --git a/indra/newview/llreflectionmapmanager.h b/indra/newview/llreflectionmapmanager.h index 14b762998a..e0a2c00db3 100644 --- a/indra/newview/llreflectionmapmanager.h +++ b/indra/newview/llreflectionmapmanager.h @@ -38,7 +38,7 @@ class LLViewerObject; #define LL_MAX_REFLECTION_PROBE_COUNT 256 // reflection probe resolution -#define LL_REFLECTION_PROBE_RESOLUTION 256 +#define LL_REFLECTION_PROBE_RESOLUTION 128 #define LL_IRRADIANCE_MAP_RESOLUTION 64 // reflection probe mininum scale diff --git a/indra/newview/llspatialpartition.h b/indra/newview/llspatialpartition.h index c3e9d8ceb9..0d16b818f1 100644 --- a/indra/newview/llspatialpartition.h +++ b/indra/newview/llspatialpartition.h @@ -41,6 +41,7 @@ #include "llviewercamera.h" #include "llvector4a.h" #include "llvoavatar.h" +#include "llfetchedgltfmaterial.h" #include <queue> #include <unordered_map> @@ -114,9 +115,11 @@ public: F32 mDistance; U32 mDrawMode; - // Material points here are likely for debugging only and are immaterial (zing!) + // Material pointer here is likely for debugging only and are immaterial (zing!) LLMaterialPtr mMaterial; - LLPointer<LLGLTFMaterial> mGLTFMaterial; + + // PBR material parameters + LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial; LLUUID mMaterialID; // id of LLGLTFMaterial or LLMaterial applied to this draw info @@ -128,7 +131,6 @@ public: const LLMatrix4* mSpecularMapMatrix; LLPointer<LLViewerTexture> mNormalMap; const LLMatrix4* mNormalMapMatrix; - LLPointer<LLViewerTexture> mEmissiveMap; LLVector4 mSpecColor; // XYZ = Specular RGB, W = Specular Exponent F32 mEnvIntensity; diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index a256b770b1..ccc1259c25 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -414,11 +414,6 @@ void LLViewerObject::deleteTEImages() delete[] mTESpecularMaps; mTESpecularMaps = NULL; } - - mGLTFBaseColorMaps.clear(); - mGLTFNormalMaps.clear(); - mGLTFMetallicRoughnessMaps.clear(); - mGLTFEmissiveMaps.clear(); } void LLViewerObject::markDead() @@ -4766,11 +4761,6 @@ void LLViewerObject::setNumTEs(const U8 num_tes) mTEImages = new_images; mTENormalMaps = new_normmaps; mTESpecularMaps = new_specmaps; - - mGLTFBaseColorMaps.resize(num_tes); - mGLTFNormalMaps.resize(num_tes); - mGLTFMetallicRoughnessMaps.resize(num_tes); - mGLTFEmissiveMaps.resize(num_tes); } else { @@ -4930,14 +4920,28 @@ void LLViewerObject::updateTEMaterialTextures(U8 te) mTESpecularMaps[te] = LLViewerTextureManager::getFetchedTexture(spec_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_ALM, LLViewerTexture::LOD_TEXTURE); } - auto fetch_texture = [](const LLUUID& id, LLViewerObject *obj) + LLFetchedGLTFMaterial* mat = (LLFetchedGLTFMaterial*) getTE(te)->getGLTFMaterial(); + LLUUID mat_id = getRenderMaterialID(te); + if (mat == nullptr && mat_id.notNull()) + { + mat = (LLFetchedGLTFMaterial*) gGLTFMaterialList.getMaterial(mat_id); + getTE(te)->setGLTFMaterial(mat); + } + else if (mat_id.isNull() && mat != nullptr) + { + mat = nullptr; + getTE(te)->setGLTFMaterial(nullptr); + } + + auto fetch_texture = [this](const LLUUID& id) { LLViewerFetchedTexture* img = nullptr; if (id.notNull()) { if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id)) { - LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(id); + // TODO -- fall back to LLTextureEntry::mGLTFRenderMaterial when overriding with baked texture + LLViewerTexture* viewerTexture = getBakedTextureForMagicId(id); img = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : nullptr; } else @@ -4950,34 +4954,13 @@ void LLViewerObject::updateTEMaterialTextures(U8 te) return img; }; - LLGLTFMaterial* mat = getTE(te)->getGLTFMaterial(); - LLUUID mat_id = getRenderMaterialID(te); - if (mat == nullptr && mat_id.notNull()) - { - mat = gGLTFMaterialList.getMaterial(mat_id); - getTE(te)->setGLTFMaterial(mat); - } - else if (mat_id.isNull() && mat != nullptr) - { - mat = nullptr; - getTE(te)->setGLTFMaterial(nullptr); - } - if (mat != nullptr) { - mGLTFBaseColorMaps[te] = fetch_texture(mat->mBaseColorId, this); - mGLTFNormalMaps[te] = fetch_texture(mat->mNormalId, this); - mGLTFMetallicRoughnessMaps[te] = fetch_texture(mat->mMetallicRoughnessId, this); - mGLTFEmissiveMaps[te] = fetch_texture(mat->mEmissiveId, this); + mat->mBaseColorTexture = fetch_texture(mat->mBaseColorId); + mat->mNormalTexture = fetch_texture(mat->mNormalId); + mat->mMetallicRoughnessTexture = fetch_texture(mat->mMetallicRoughnessId); + mat->mEmissiveTexture= fetch_texture(mat->mEmissiveId); } - else - { - mGLTFBaseColorMaps[te] = nullptr; - mGLTFNormalMaps[te] = nullptr; - mGLTFMetallicRoughnessMaps[te] = nullptr; - mGLTFEmissiveMaps[te] = nullptr; - } - } void LLViewerObject::refreshBakeTexture() diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index 9d80f095c9..5d72f7f3c3 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -371,12 +371,6 @@ public: LLViewerTexture *getTENormalMap(const U8 te) const; LLViewerTexture *getTESpecularMap(const U8 te) const; - LLViewerTexture* getGLTFBaseColorMap(U8 te) const { return mGLTFBaseColorMaps[te]; } - LLViewerTexture* getGLTFNormalMap(U8 te) const { return mGLTFNormalMaps[te]; } - LLViewerTexture* getGLTFEmissiveMap(U8 te) const { return mGLTFEmissiveMaps[te]; } - LLViewerTexture* getGLTFMetallicRoughnessMap(U8 te) const { return mGLTFMetallicRoughnessMaps[te]; } - - bool isImageAlphaBlended(const U8 te) const; void fitFaceTexture(const U8 face); @@ -693,13 +687,6 @@ public: LLPointer<LLViewerTexture> *mTENormalMaps; LLPointer<LLViewerTexture> *mTESpecularMaps; - std::vector<LLPointer<LLViewerTexture> > mGLTFBaseColorMaps; - std::vector<LLPointer<LLViewerTexture> > mGLTFNormalMaps; - std::vector<LLPointer<LLViewerTexture> > mGLTFMetallicRoughnessMaps; - std::vector<LLPointer<LLViewerTexture> > mGLTFEmissiveMaps; - - - // true if user can select this object by clicking under any circumstances (even if pick_unselectable is true) // can likely be factored out BOOL mbCanSelect; diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 2a06331b63..c1c80d5adc 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5390,7 +5390,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, LLUUID mat_id; - LLGLTFMaterial* gltf_mat = facep->getTextureEntry()->getGLTFMaterial(); + auto* gltf_mat = (LLFetchedGLTFMaterial*) facep->getTextureEntry()->getGLTFMaterial(); if (gltf_mat != nullptr) { mat_id = gltf_mat->getHash(); // TODO: cache this hash @@ -5519,21 +5519,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, if (gltf_mat) { - LLViewerObject* vobj = facep->getViewerObject(); - U8 te = facep->getTEOffset(); - - draw_info->mTexture = vobj->getGLTFBaseColorMap(te); - draw_info->mNormalMap = vobj->getGLTFNormalMap(te); - draw_info->mSpecularMap = vobj->getGLTFMetallicRoughnessMap(te); - draw_info->mEmissiveMap = vobj->getGLTFEmissiveMap(te); - if (draw_info->mGLTFMaterial->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK) - { - draw_info->mAlphaMaskCutoff = gltf_mat->mAlphaCutoff * gltf_mat->mBaseColor.mV[3]; - } - else - { - draw_info->mAlphaMaskCutoff = 1.f; - } + // nothing to do, render pools will reference the GLTF material } else if (mat) { diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 0c27296440..cb54cec165 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -3723,15 +3723,26 @@ void LLPipeline::touchTexture(LLViewerTexture* tex, F32 vsize) void LLPipeline::touchTextures(LLDrawInfo* info) { LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; - for (int i = 0; i < info->mTextureList.size(); ++i) + + auto& mat = info->mGLTFMaterial; + if (mat.notNull()) { - touchTexture(info->mTextureList[i], info->mTextureListVSize[i]); + touchTexture(mat->mBaseColorTexture, info->mVSize); + touchTexture(mat->mNormalTexture, info->mVSize); + touchTexture(mat->mMetallicRoughnessTexture, info->mVSize); + touchTexture(mat->mEmissiveTexture, info->mVSize); } + else + { + for (int i = 0; i < info->mTextureList.size(); ++i) + { + touchTexture(info->mTextureList[i], info->mTextureListVSize[i]); + } - touchTexture(info->mTexture, info->mVSize); - touchTexture(info->mSpecularMap, info->mVSize); - touchTexture(info->mNormalMap, info->mVSize); - touchTexture(info->mEmissiveMap, info->mVSize); + touchTexture(info->mTexture, info->mVSize); + touchTexture(info->mSpecularMap, info->mVSize); + touchTexture(info->mNormalMap, info->mVSize); + } } void LLPipeline::postSort(LLCamera& camera) |