diff --git a/indra/llprimitive/llmaterial.cpp b/indra/llprimitive/llmaterial.cpp index a219ac14501a9fee140e004bbbfb132ba6aca9d5..533c81dca970d666adcc5c06a436abd4272eb4ce 100644 --- a/indra/llprimitive/llmaterial.cpp +++ b/indra/llprimitive/llmaterial.cpp @@ -51,7 +51,9 @@ #define MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD "AlphaMaskCutoff" #define MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD "DiffuseAlphaMode" -const LLColor4U LLMaterial::DEFAULT_SPECULAR_LIGHT_COLOR(255,255,255,255); +constexpr F32 DEFAULT_SPECULAR_LIGHT_EXPONENT = 0.2f; +constexpr F32 DEFAULT_ENV_INTENSITY = 0.f; +const LLColor4 DEFAULT_SPECULAR_LIGHT_COLOR(1.f, 1.f, 1.f, 1.f); /** * Materials constants @@ -101,11 +103,11 @@ LLMaterial::LLMaterial() , mSpecularRepeatX(1.0f) , mSpecularRepeatY(1.0f) , mSpecularRotation(0.0f) - , mSpecularLightColor(LLMaterial::DEFAULT_SPECULAR_LIGHT_COLOR) - , mSpecularLightExponent(LLMaterial::DEFAULT_SPECULAR_LIGHT_EXPONENT) - , mEnvironmentIntensity(LLMaterial::DEFAULT_ENV_INTENSITY) + , mSpecularLightColor(DEFAULT_SPECULAR_LIGHT_COLOR) + , mSpecularLightExponent(DEFAULT_SPECULAR_LIGHT_EXPONENT) + , mEnvironmentIntensity(DEFAULT_ENV_INTENSITY) , mDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) - , mAlphaMaskCutoff(0) + , mAlphaMaskCutoff(0.0f) { } @@ -281,32 +283,32 @@ void LLMaterial::setSpecularRotation(F32 rot) mSpecularRotation = rot; } -const LLColor4U LLMaterial::getSpecularLightColor() const +const LLColor4& LLMaterial::getSpecularLightColor() const { return mSpecularLightColor; } -void LLMaterial::setSpecularLightColor(const LLColor4U& color) +void LLMaterial::setSpecularLightColor(const LLColor4& color) { mSpecularLightColor = color; } -U8 LLMaterial::getSpecularLightExponent() const +F32 LLMaterial::getSpecularLightExponent() const { return mSpecularLightExponent; } -void LLMaterial::setSpecularLightExponent(U8 exponent) +void LLMaterial::setSpecularLightExponent(F32 exponent) { mSpecularLightExponent = exponent; } -U8 LLMaterial::getEnvironmentIntensity() const +F32 LLMaterial::getEnvironmentIntensity() const { return mEnvironmentIntensity; } -void LLMaterial::setEnvironmentIntensity(U8 intensity) +void LLMaterial::setEnvironmentIntensity(F32 intensity) { mEnvironmentIntensity = intensity; } @@ -321,12 +323,12 @@ void LLMaterial::setDiffuseAlphaMode(U8 alpha_mode) mDiffuseAlphaMode = alpha_mode; } -U8 LLMaterial::getAlphaMaskCutoff() const +F32 LLMaterial::getAlphaMaskCutoff() const { return mAlphaMaskCutoff; } -void LLMaterial::setAlphaMaskCutoff(U8 cutoff) +void LLMaterial::setAlphaMaskCutoff(F32 cutoff) { mAlphaMaskCutoff = cutoff; } @@ -358,11 +360,11 @@ LLSD LLMaterial::asLLSD() const material_data[MATERIALS_CAP_SPECULAR_MAP_REPEAT_Y_FIELD] = ll_round(mSpecularRepeatY * MATERIALS_MULTIPLIER); material_data[MATERIALS_CAP_SPECULAR_MAP_ROTATION_FIELD] = specularRotInt; - material_data[MATERIALS_CAP_SPECULAR_COLOR_FIELD] = mSpecularLightColor.getValue(); - material_data[MATERIALS_CAP_SPECULAR_EXP_FIELD] = mSpecularLightExponent; - material_data[MATERIALS_CAP_ENV_INTENSITY_FIELD] = mEnvironmentIntensity; + material_data[MATERIALS_CAP_SPECULAR_COLOR_FIELD] = LLColor4U(mSpecularLightColor).getValue(); + material_data[MATERIALS_CAP_SPECULAR_EXP_FIELD] = llclampb(ll_round(mSpecularLightExponent * 255.f)); + material_data[MATERIALS_CAP_ENV_INTENSITY_FIELD] = llclampb(ll_round(mEnvironmentIntensity * 255.f)); material_data[MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD] = mDiffuseAlphaMode; - material_data[MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD] = mAlphaMaskCutoff; + material_data[MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD] = llclampb(ll_round(mAlphaMaskCutoff * 255.f)); return material_data; } @@ -397,11 +399,16 @@ void LLMaterial::fromLLSD(const LLSD& material_data) mSpecularRepeatX = F32(specularRepeatXInt) / MATERIALS_MULTIPLIER; mSpecularRepeatY = F32(specularRepeatYInt) / MATERIALS_MULTIPLIER; - mSpecularLightColor.setValue(getMaterialField<LLSD>(material_data, MATERIALS_CAP_SPECULAR_COLOR_FIELD, LLSD::TypeArray)); - mSpecularLightExponent = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_EXP_FIELD, LLSD::TypeInteger); - mEnvironmentIntensity = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ENV_INTENSITY_FIELD, LLSD::TypeInteger); + LLColor4U specularLightColorInt(getMaterialField<LLSD>(material_data, MATERIALS_CAP_SPECULAR_COLOR_FIELD, LLSD::TypeArray)); + U8 specularLightExponentInt = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_EXP_FIELD, LLSD::TypeInteger); + U8 environmentIntensityInt = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ENV_INTENSITY_FIELD, LLSD::TypeInteger); + U8 alphaMaskCutoffInt = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD, LLSD::TypeInteger); + + mSpecularLightColor = specularLightColorInt; + mSpecularLightExponent = specularLightExponentInt * (1.f / 255.f); + mEnvironmentIntensity = environmentIntensityInt * (1.f / 255.f); mDiffuseAlphaMode = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD, LLSD::TypeInteger); - mAlphaMaskCutoff = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD, LLSD::TypeInteger); + mAlphaMaskCutoff = alphaMaskCutoffInt * (1.f / 255.f); } bool LLMaterial::isNull() const diff --git a/indra/llprimitive/llmaterial.h b/indra/llprimitive/llmaterial.h index 7f00152a35bbd6cd947b33f8474b7d2cc54e49fe..3d98ac4b9e73d958ddf75580f5642c31acb51972 100644 --- a/indra/llprimitive/llmaterial.h +++ b/indra/llprimitive/llmaterial.h @@ -52,12 +52,6 @@ public: ALPHA_SHADER_COUNT = 4 } eShaderCount; - - - static const U8 DEFAULT_SPECULAR_LIGHT_EXPONENT = ((U8)(0.2f * 255)); - static const LLColor4U DEFAULT_SPECULAR_LIGHT_COLOR; - static const U8 DEFAULT_ENV_INTENSITY = 0; - LLMaterial(); LLMaterial(const LLSD& material_data); @@ -107,16 +101,16 @@ public: F32 getSpecularRotation() const; void setSpecularRotation(F32 rot); - const LLColor4U getSpecularLightColor() const; - void setSpecularLightColor(const LLColor4U& color); - U8 getSpecularLightExponent() const; - void setSpecularLightExponent(U8 exponent); - U8 getEnvironmentIntensity() const; - void setEnvironmentIntensity(U8 intensity); + const LLColor4& getSpecularLightColor() const; + void setSpecularLightColor(const LLColor4& color); + F32 getSpecularLightExponent() const; + void setSpecularLightExponent(F32 exponent); + F32 getEnvironmentIntensity() const; + void setEnvironmentIntensity(F32 intensity); U8 getDiffuseAlphaMode() const; void setDiffuseAlphaMode(U8 alpha_mode); - U8 getAlphaMaskCutoff() const; - void setAlphaMaskCutoff(U8 cutoff); + F32 getAlphaMaskCutoff() const; + void setAlphaMaskCutoff(F32 cutoff); bool isNull() const; static const LLMaterial null; @@ -141,11 +135,11 @@ protected: F32 mSpecularRepeatY; F32 mSpecularRotation; - LLColor4U mSpecularLightColor; - U8 mSpecularLightExponent; - U8 mEnvironmentIntensity; + LLColor4 mSpecularLightColor; + F32 mSpecularLightExponent; + F32 mEnvironmentIntensity; U8 mDiffuseAlphaMode; - U8 mAlphaMaskCutoff; + F32 mAlphaMaskCutoff; }; typedef LLPointer<LLMaterial> LLMaterialPtr; diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index c9cb756c9fe2becd218b4ef5417dbe33434bbfd0..d6b3cd03afb47b7480b4baad6d9558eac988f467 100644 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -2027,24 +2027,25 @@ void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow) gGL.getTexUnit(normal_channel)->bind(face->getViewerObject()->getTENormalMap(face->getTEOffset())); gGL.getTexUnit(sDiffuseChannel)->bind(face->getTexture(), false, true); - static const float alpha[4] = + static const LLColor4 alpha[4] = { - 0.00f, - 0.25f, - 0.5f, - 0.75f + {0.00f,0.00f,0.00f,0.00f}, + {0.25f,0.25f,0.25f,0.25f}, + {0.50f,0.50f,0.50f,0.50f}, + {0.75f,0.75f,0.75f,0.75f}, }; - float spec = alpha[tex_entry->getShiny() & TEM_SHINY_MASK]; - LLColor4 specColor(spec, spec, spec, spec); - F32 env = spec; + + LLColor4 specColor = alpha[tex_entry->getShiny() & TEM_SHINY_MASK]; + F32 env = specColor.mV[0]; if (!mat->getSpecularID().isNull()) { - specColor.mV[0] = mat->getSpecularLightColor().mV[0] * (1.f / 255.f); - specColor.mV[1] = mat->getSpecularLightColor().mV[1] * (1.f / 255.f); - specColor.mV[2] = mat->getSpecularLightColor().mV[2] * (1.f / 255.f); - specColor.mV[3] = mat->getSpecularLightExponent() * (1.f / 255.f); - env = mat->getEnvironmentIntensity() * (1.f / 255.f); + const auto& spec_light_col = mat->getSpecularLightColor(); + specColor.mV[0] = spec_light_col.mV[0]; + specColor.mV[1] = spec_light_col.mV[1]; + specColor.mV[2] = spec_light_col.mV[2]; + specColor.mV[3] = mat->getSpecularLightExponent(); + env = mat->getEnvironmentIntensity(); } BOOL fullbright = tex_entry->getFullbright(); @@ -2055,7 +2056,7 @@ void LLDrawPoolAvatar::renderRigged(LLVOAvatar* avatar, U32 type, bool glow) if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK) { - sVertexProgram->setMinimumAlpha(mat->getAlphaMaskCutoff() * (1.f / 255.f)); + sVertexProgram->setMinimumAlpha(mat->getAlphaMaskCutoff()); } else { diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index 8cbe0b5b908d84ccc2959a8726b8b20976ba52cb..6c24edca73a18961f9fc0b69eba0b7b6a946dd39 100644 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -1290,7 +1290,7 @@ void LLPanelFace::refresh() mComboAlphaMode->selectNthItem(alpha_mode); - getChild<LLUICtrl>("maskcutoff")->setValue(material->getAlphaMaskCutoff()); + getChild<LLUICtrl>("maskcutoff")->setValue(llclampb(ll_round(material->getAlphaMaskCutoff() * 255.f))); updateAlphaControls(); identical_planar_texgen = isIdenticalPlanarTexgen(); @@ -1316,8 +1316,8 @@ void LLPanelFace::refresh() getChild<LLUICtrl>("shinyRot")->setValue(rot*RAD_TO_DEG); getChild<LLUICtrl>("shinyOffsetU")->setValue(offset_x); getChild<LLUICtrl>("shinyOffsetV")->setValue(offset_y); - getChild<LLUICtrl>("glossiness")->setValue(material->getSpecularLightExponent()); - getChild<LLUICtrl>("environment")->setValue(material->getEnvironmentIntensity()); + getChild<LLUICtrl>("glossiness")->setValue(llclampb(ll_round(material->getSpecularLightExponent() * 255.f))); + getChild<LLUICtrl>("environment")->setValue(llclampb(ll_round(material->getEnvironmentIntensity() * 255.f))); updateShinyControls(!material->getSpecularID().isNull(), true); } @@ -1327,8 +1327,8 @@ void LLPanelFace::refresh() // if (!material->getSpecularID().isNull()) { - LLColor4 new_color = material->getSpecularLightColor(); - LLColor4 old_color = mShinyColorSwatch->get(); + const LLColor4& new_color = material->getSpecularLightColor(); + const LLColor4& old_color = mShinyColorSwatch->get(); mShinyColorSwatch->setOriginal(new_color); mShinyColorSwatch->set(new_color, old_color != new_color || !editable); @@ -1867,7 +1867,7 @@ void LLPanelFace::onCommitMaterialGloss(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; llassert_always(self); - LLSelectedTEMaterial::setSpecularLightExponent(self,self->getCurrentGlossiness()); + LLSelectedTEMaterial::setSpecularLightExponent(self,self->getCurrentGlossiness() * (1.f / 255.f)); } //static @@ -1875,14 +1875,14 @@ void LLPanelFace::onCommitMaterialEnv(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; llassert_always(self); - LLSelectedTEMaterial::setEnvironmentIntensity(self,self->getCurrentEnvIntensity()); + LLSelectedTEMaterial::setEnvironmentIntensity(self,self->getCurrentEnvIntensity() * (1.f / 255.f)); } //static void LLPanelFace::onCommitMaterialMaskCutoff(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; - LLSelectedTEMaterial::setAlphaMaskCutoff(self,self->getCurrentAlphaMaskCutoff()); + LLSelectedTEMaterial::setAlphaMaskCutoff(self,self->getCurrentAlphaMaskCutoff() * (1.f / 255.f)); } // Commit the number of repeats per meter diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index e16d34015d59b901c0fc5e2c9d5530c723c12d65..598adf5874bef7fbdb7a1ed0c17b6c184de90927 100644 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -474,7 +474,7 @@ public: DEF_GET_MAT_STATE(F32,F32,getNormalRotation,0.0f, true, 0.001f) DEF_EDIT_MAT_STATE(U8,U8,setDiffuseAlphaMode); - DEF_EDIT_MAT_STATE(U8,U8,setAlphaMaskCutoff); + DEF_EDIT_MAT_STATE(F32,F32,setAlphaMaskCutoff); DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetX); DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetY); @@ -488,12 +488,12 @@ public: DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatY); DEF_EDIT_MAT_STATE(F32,F32,setSpecularRotation); - DEF_EDIT_MAT_STATE(U8,U8,setEnvironmentIntensity); - DEF_EDIT_MAT_STATE(U8,U8,setSpecularLightExponent); + DEF_EDIT_MAT_STATE(F32,F32,setEnvironmentIntensity); + DEF_EDIT_MAT_STATE(F32,F32,setSpecularLightExponent); DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setNormalID); DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setSpecularID); - DEF_EDIT_MAT_STATE(LLColor4U, const LLColor4U&,setSpecularLightColor); + DEF_EDIT_MAT_STATE(LLColor4, const LLColor4&,setSpecularLightColor); }; class LLSelectedTE diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index ae04e5ebde3a481b404357023a176c027d14884b..0028bf2e715d021d7d56b7c5535ec4b17b3300dc 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5238,16 +5238,16 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, if (!mat->getSpecularID().isNull()) { LLVector4 specColor; - specColor.mV[0] = mat->getSpecularLightColor().mV[0] * (1.f / 255.f); - specColor.mV[1] = mat->getSpecularLightColor().mV[1] * (1.f / 255.f); - specColor.mV[2] = mat->getSpecularLightColor().mV[2] * (1.f / 255.f); - specColor.mV[3] = mat->getSpecularLightExponent() * (1.f / 255.f); + specColor.mV[0] = mat->getSpecularLightColor().mV[0]; + specColor.mV[1] = mat->getSpecularLightColor().mV[1]; + specColor.mV[2] = mat->getSpecularLightColor().mV[2]; + specColor.mV[3] = mat->getSpecularLightExponent(); draw_info->mSpecColor = specColor; - draw_info->mEnvIntensity = mat->getEnvironmentIntensity() * (1.f / 255.f); + draw_info->mEnvIntensity = mat->getEnvironmentIntensity(); draw_info->mSpecularMap = facep->getViewerObject()->getTESpecularMap(facep->getTEOffset()); } - draw_info->mAlphaMaskCutoff = mat->getAlphaMaskCutoff() * (1.f / 255.f); + draw_info->mAlphaMaskCutoff = mat->getAlphaMaskCutoff(); draw_info->mDiffuseAlphaMode = mat->getDiffuseAlphaMode(); draw_info->mNormalMap = facep->getViewerObject()->getTENormalMap(facep->getTEOffset()); } @@ -6934,7 +6934,7 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace } else { - if (mat->getEnvironmentIntensity() > 0 || + if (mat->getEnvironmentIntensity() > F_ALMOST_ZERO || te->getShiny() > 0) { material_pass = true; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 62b163acd080e8454b95bf554e779766dbb4ac85..9441086399f62cfb7a85fd1ba1cf50d0a629f102 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1692,7 +1692,7 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima { return te->getFullbright() ? LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK : LLDrawPool::POOL_ALPHA_MASK; } - else if (te->getFullbright() && !mat->getEnvironmentIntensity() && !te->getShiny()) + else if (te->getFullbright() && mat->getEnvironmentIntensity() == 0.f && !te->getShiny()) { return LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK; } @@ -1704,7 +1704,7 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima } else if (LLPipeline::sRenderDeferred && mat) { - if (te->getFullbright() && !mat->getEnvironmentIntensity() && !te->getShiny()) + if (te->getFullbright() && mat->getEnvironmentIntensity() == 0.f && !te->getShiny()) { return RenderDeferredFullbright ? LLDrawPool::POOL_FULLBRIGHT : LLDrawPool::POOL_SIMPLE; }