diff options
author | Ptolemy <ptolemy@lindenlab.com> | 2022-09-09 03:28:12 -0700 |
---|---|---|
committer | Ptolemy <ptolemy@lindenlab.com> | 2022-09-09 03:28:12 -0700 |
commit | 049fc419d1d1f41ac05e424d599a89366cee7ca7 (patch) | |
tree | ea2f275d9f35346cac4e14f9e11ff954d6a9ce58 /indra/newview | |
parent | a3dff0db26c5faa1613b29721498baf530f12fed (diff) |
SL-17701: PBR: WIP Alpha Blending
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/lldrawpoolalpha.cpp | 161 | ||||
-rw-r--r-- | indra/newview/llviewershadermgr.cpp | 77 | ||||
-rw-r--r-- | indra/newview/llviewershadermgr.h | 3 | ||||
-rw-r--r-- | indra/newview/llvovolume.cpp | 11 | ||||
-rw-r--r-- | indra/newview/pipeline.cpp | 4 |
5 files changed, 199 insertions, 57 deletions
diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 89b8ec1ba2..883ba72c3c 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -50,6 +50,8 @@ #include "llglcommonfunc.h" #include "llvoavatar.h" +#include "llenvironment.h" + BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; #define current_shader (LLGLSLShader::sCurBoundShaderPtr) @@ -602,65 +604,74 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged) } } - LLRenderPass::applyModelMatrix(params); + LLRenderPass::applyModelMatrix(params); - LLMaterial* mat = NULL; + LLMaterial* mat = NULL; + LLGLTFMaterial *gltf_mat = params.mGLTFMaterial; // Also see: LLPipeline::getPoolTypeFromTE() + bool is_pbr = LLPipeline::sRenderPBR && gltf_mat; - if (deferred_render) - { - mat = params.mMaterial; - } - - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - target_shader = fullbright_shader; + if (is_pbr && gltf_mat->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND) + { + target_shader = &gDeferredPBRAlphaProgram[rigged]; + } + else + { + if (deferred_render) + { + mat = params.mMaterial; + } - light_enabled = FALSE; - } - } - // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - target_shader = simple_shader; - light_enabled = TRUE; - } + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + target_shader = fullbright_shader; - if (deferred_render && mat) - { - U32 mask = params.mShaderMask; + light_enabled = FALSE; + } + } + // Turn on lighting if it isn't already. + else if (!light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + target_shader = simple_shader; + light_enabled = TRUE; + } - llassert(mask < LLMaterial::SHADER_COUNT); - target_shader = &(gDeferredMaterialProgram[mask]); + if (deferred_render && mat) + { + U32 mask = params.mShaderMask; - if (LLPipeline::sUnderWaterRender) - { - target_shader = &(gDeferredMaterialWaterProgram[mask]); - } + llassert(mask < LLMaterial::SHADER_COUNT); + target_shader = &(gDeferredMaterialProgram[mask]); - if (params.mAvatar != nullptr) + if (LLPipeline::sUnderWaterRender) + { + target_shader = &(gDeferredMaterialWaterProgram[mask]); + } + + if (params.mAvatar != nullptr) + { + llassert(target_shader->mRiggedVariant != nullptr); + target_shader = target_shader->mRiggedVariant; + } + + if (current_shader != target_shader) + { + gPipeline.bindDeferredShader(*target_shader); + } + } + else if (!params.mFullbright) { - llassert(target_shader->mRiggedVariant != nullptr); - target_shader = target_shader->mRiggedVariant; + target_shader = simple_shader; } - - if (current_shader != target_shader) - { - gPipeline.bindDeferredShader(*target_shader); - } - } - else if (!params.mFullbright) - { - target_shader = simple_shader; - } - else - { - target_shader = fullbright_shader; - } + else + { + target_shader = fullbright_shader; + } + } if (params.mAvatar != nullptr) { @@ -673,6 +684,56 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged) target_shader->bind(); } + if (is_pbr) + { + 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); + + LLEnvironment& environment = LLEnvironment::instance(); + target_shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0); + + // TODO? prepare_alpha_shader( target_shader, false, true ); + target_shader->uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, gPipeline.mTransformedSunDir.mV); + target_shader->uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, gPipeline.mTransformedMoonDir.mV); + } + LLVector4 spec_color(1, 1, 1, 1); F32 env_intensity = 0.0f; F32 brightness = 1.0f; diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 0d9670d9ca..8ec51b3856 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -265,6 +265,7 @@ LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2]; LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2]; LLGLSLShader gDeferredPBROpaqueProgram; LLGLSLShader gDeferredSkinnedPBROpaqueProgram; +LLGLSLShader gDeferredPBRAlphaProgram[2]; // not skinned, skinned //helper for making a rigged variant of a given shader bool make_rigged_variant(LLGLSLShader& shader, LLGLSLShader& riggedShader) @@ -1283,6 +1284,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredPBROpaqueProgram.unload(); gDeferredSkinnedPBROpaqueProgram.unload(); + gDeferredPBRAlphaProgram[0].unload(); + gDeferredPBRAlphaProgram[1].unload(); return TRUE; } @@ -1616,6 +1619,80 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() } llassert(success); } + + if (success) + { + for (int rigged = 0; rigged < 2 && success; ++rigged) + { + LLGLSLShader* shader = &gDeferredPBRAlphaProgram[rigged]; + shader->mName = rigged + ? "Skinned Deferred PBR Alpha Shader" + : "Deferred PBR Alpha Shader"; + shader->mRiggedVariant = rigged + ? &gDeferredPBRAlphaProgram[1] + : nullptr; + shader->mFeatures.hasObjectSkinning = (bool)rigged; + shader->mFeatures.calculatesLighting = false; + shader->mFeatures.hasLighting = false; + shader->mFeatures.isAlphaLighting = true; + shader->mFeatures.hasSrgb = true; + shader->mFeatures.encodesNormal = true; + shader->mFeatures.calculatesAtmospherics = true; + shader->mFeatures.hasAtmospherics = true; + shader->mFeatures.hasGamma = true; + shader->mFeatures.hasTransport = true; + shader->mFeatures.hasShadows = use_sun_shadow; + shader->mFeatures.isDeferred = true; // include deferredUtils + shader->mFeatures.hasReflectionProbes = mShaderLevel[SHADER_DEFERRED]; + + shader->mShaderFiles.clear(); + shader->mShaderFiles.push_back(make_pair("deferred/pbralphaV.glsl", GL_VERTEX_SHADER_ARB)); + shader->mShaderFiles.push_back(make_pair("deferred/pbralphaF.glsl", GL_FRAGMENT_SHADER_ARB)); + + shader->clearPermutations(); + + U32 alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND; + shader->addPermutation("DIFFUSE_ALPHA_MODE", llformat("%d", alpha_mode)); + shader->addPermutation("HAS_NORMAL_MAP", "1"); + shader->addPermutation("HAS_SPECULAR_MAP", "1"); // PBR: Packed: Occlusion, Metal, Roughness + shader->addPermutation("HAS_EMISSIVE_MAP", "1"); + shader->addPermutation("USE_VERTEX_COLOR", "1"); + if (use_sun_shadow) + { + shader->addPermutation("HAS_SHADOW", "1"); + } + + if (ambient_kill) + { + shader->addPermutation("AMBIENT_KILL", "1"); + } + + if (sunlight_kill) + { + shader->addPermutation("SUNLIGHT_KILL", "1"); + } + + if (local_light_kill) + { + shader->addPermutation("LOCAL_LIGHT_KILL", "1"); + } + + if (rigged) + { + shader->addPermutation("HAS_SKIN", "1"); + } + + shader->mShaderLevel = mShaderLevel[SHADER_DEFERRED]; + + success = shader->createShader(NULL, NULL); + llassert(success); + + // Alpha Shader Hack + shader->mFeatures.calculatesLighting = true; + shader->mFeatures.hasLighting = true; + } + } + if (success) { diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index ef49074959..38f67cd23c 100644 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -321,5 +321,6 @@ extern LLGLSLShader gNormalMapGenProgram; extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2]; extern LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2]; -extern LLGLSLShader gDeferredPBROpaqueProgram; +extern LLGLSLShader gDeferredPBROpaqueProgram; +extern LLGLSLShader gDeferredPBRAlphaProgram[2]; // not skinned, skinned #endif diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index ad11fb3908..f1e3d27d7c 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5892,7 +5892,8 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) bool is_pbr = false; #endif #else - bool is_pbr = facep->getTextureEntry()->getGLTFMaterial() != nullptr; + LLGLTFMaterial *gltf_mat = facep->getTextureEntry()->getGLTFMaterial(); + bool is_pbr = gltf_mat != nullptr; #endif //ALWAYS null out vertex buffer on rebuild -- if the face lands in a render @@ -5960,8 +5961,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) BOOL force_simple = (facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA); U32 type = gPipeline.getPoolTypeFromTE(te, tex); - - if (is_pbr) + if (is_pbr && gltf_mat && gltf_mat->mAlphaMode != LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) { type = LLDrawPool::POOL_PBR_OPAQUE; } @@ -6781,7 +6781,10 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace if (gltf_mat) { // all other parameters ignored if gltf material is present - registerFace(group, facep, LLRenderPass::PASS_PBR_OPAQUE); + if (gltf_mat->mAlphaMode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) + registerFace(group, facep, LLRenderPass::PASS_ALPHA); + else + registerFace(group, facep, LLRenderPass::PASS_PBR_OPAQUE); } else // do NOT use 'fullbright' for this logic or you risk sending diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 67f0ea68c1..abf0d457e2 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1684,7 +1684,7 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima } } - if (alpha) + if (alpha || (gltf_mat && gltf_mat->mAlphaMode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)) { return LLDrawPool::POOL_ALPHA; } @@ -1692,7 +1692,7 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima { return LLDrawPool::POOL_BUMP; } - else if (gltf_mat && !alpha) + else if (gltf_mat) { return LLDrawPool::POOL_PBR_OPAQUE; } |