diff options
Diffstat (limited to 'indra')
89 files changed, 2878 insertions, 3433 deletions
diff --git a/indra/llinventory/llsettingsbase.cpp b/indra/llinventory/llsettingsbase.cpp index abe1a1a04a..b763a06ab4 100644 --- a/indra/llinventory/llsettingsbase.cpp +++ b/indra/llinventory/llsettingsbase.cpp @@ -207,6 +207,11 @@ LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F LLQuaternion q = slerp(mix, LLQuaternion(value), LLQuaternion(other_value)); newvalue = q.getValue(); } + else if (value[0].type() == LLSD::TypeMap) + { + // TODO + // determine if lerping between maps is both feasible and reasonable + } else { // TODO: We could expand this to inspect the type and do a deep lerp based on type. // for now assume a heterogeneous array of reals. @@ -214,7 +219,6 @@ LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F for (size_t i = 0; i < len; ++i) { - newvalue[i] = lerp(value[i].asReal(), other_value[i].asReal(), mix); } } diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp index 7da3a336cc..491381213f 100644 --- a/indra/llinventory/llsettingssky.cpp +++ b/indra/llinventory/llsettingssky.cpp @@ -106,9 +106,36 @@ const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR("exp_s const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM("linear_term"); const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM("constant_term"); +const std::string LLSettingsSky::SETTING_LEGACY_HAZE("legacy_haze"); + namespace { +LLSettingsSky::validation_list_t legacyHazeValidationList() +{ + static LLSettingsBase::validation_list_t legacyHazeValidation; + if (legacyHazeValidation.empty()) + { + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_BLUE_DENSITY, true, LLSD::TypeArray, + boost::bind(&LLSettingsBase::Validator::verifyVectorMinMax, _1, + LLSD(LLSDArray(0.0f)(0.0f)(0.0f)("*")), + LLSD(LLSDArray(2.0f)(2.0f)(2.0f)("*"))))); + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_BLUE_HORIZON, true, LLSD::TypeArray, + boost::bind(&LLSettingsBase::Validator::verifyVectorMinMax, _1, + LLSD(LLSDArray(0.0f)(0.0f)(0.0f)("*")), + LLSD(LLSDArray(2.0f)(2.0f)(2.0f)("*"))))); + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_HAZE_DENSITY, true, LLSD::TypeReal, + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(4.0f))))); + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_HAZE_HORIZON, true, LLSD::TypeReal, + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_DENSITY_MULTIPLIER, true, LLSD::TypeReal, + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(0.0009f))))); + legacyHazeValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_DISTANCE_MULTIPLIER, true, LLSD::TypeReal, + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(100.0f))))); + } + return legacyHazeValidation; +} + LLSettingsSky::validation_list_t rayleighValidationList() { static LLSettingsBase::validation_list_t rayleighValidation; @@ -173,14 +200,29 @@ LLSettingsSky::validation_list_t mieValidationList() boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(2.0f))))); mieValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM, true, LLSD::TypeReal, - boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); - - mieValidation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_MIE_ANISOTROPY_FACTOR, true, LLSD::TypeReal, - boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); } return mieValidation; } +bool validateLegacyHaze(LLSD &value) +{ + LLSettingsSky::validation_list_t legacyHazeValidations = legacyHazeValidationList(); + llassert(value.type() == LLSD::Type::TypeMap); + LLSD result = LLSettingsBase::settingValidation(value, legacyHazeValidations); + if (result["errors"].size() > 0) + { + LL_WARNS("SETTINGS") << "Legacy Haze Config Validation errors: " << result["errors"] << LL_ENDL; + return false; + } + if (result["warnings"].size() > 0) + { + LL_WARNS("SETTINGS") << "Legacy Haze Config Validation warnings: " << result["errors"] << LL_ENDL; + return false; + } + return true; +} + bool validateRayleighLayers(LLSD &value) { LLSettingsSky::validation_list_t rayleighValidations = rayleighValidationList(); @@ -383,28 +425,27 @@ LLSettingsSky::validation_list_t LLSettingsSky::validationList() // copy constructor for LLSDArray. Directly binding the LLSDArray as // a parameter without first wrapping it in a pure LLSD object will result // in deeply nested arrays like this [[[[[[[[[[v1,v2,v3]]]]]]]]]] - -// LEGACY_ATMOSPHERICS - validation.push_back(Validator(SETTING_AMBIENT, true, LLSD::TypeArray, + validation.push_back(Validator(SETTING_BLUE_DENSITY, false, LLSD::TypeArray, boost::bind(&Validator::verifyVectorMinMax, _1, LLSD(LLSDArray(0.0f)(0.0f)(0.0f)("*")), - LLSD(LLSDArray(3.0f)(3.0f)(3.0f)("*"))))); - validation.push_back(Validator(SETTING_BLUE_DENSITY, true, LLSD::TypeArray, + LLSD(LLSDArray(2.0f)(2.0f)(2.0f)("*"))))); + validation.push_back(Validator(SETTING_BLUE_HORIZON, false, LLSD::TypeArray, boost::bind(&Validator::verifyVectorMinMax, _1, LLSD(LLSDArray(0.0f)(0.0f)(0.0f)("*")), LLSD(LLSDArray(2.0f)(2.0f)(2.0f)("*"))))); - validation.push_back(Validator(SETTING_BLUE_HORIZON, true, LLSD::TypeArray, + validation.push_back(Validator(SETTING_HAZE_DENSITY, false, LLSD::TypeReal, + boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(4.0f))))); + validation.push_back(Validator(SETTING_HAZE_HORIZON, false, LLSD::TypeReal, + boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); + validation.push_back(Validator(SETTING_AMBIENT, false, LLSD::TypeArray, boost::bind(&Validator::verifyVectorMinMax, _1, LLSD(LLSDArray(0.0f)(0.0f)(0.0f)("*")), - LLSD(LLSDArray(2.0f)(2.0f)(2.0f)("*"))))); - validation.push_back(Validator(SETTING_DENSITY_MULTIPLIER, true, LLSD::TypeReal, + LLSD(LLSDArray(3.0f)(3.0f)(3.0f)("*"))))); + validation.push_back(Validator(SETTING_DENSITY_MULTIPLIER, false, LLSD::TypeReal, boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(0.0009f))))); - validation.push_back(Validator(SETTING_DISTANCE_MULTIPLIER, true, LLSD::TypeReal, + validation.push_back(Validator(SETTING_DISTANCE_MULTIPLIER, false, LLSD::TypeReal, boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(100.0f))))); - validation.push_back(Validator(SETTING_HAZE_DENSITY, true, LLSD::TypeReal, - boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(4.0f))))); - validation.push_back(Validator(SETTING_HAZE_HORIZON, true, LLSD::TypeReal, - boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); + validation.push_back(Validator(SETTING_BLOOM_TEXTUREID, true, LLSD::TypeUUID)); validation.push_back(Validator(SETTING_CLOUD_COLOR, true, LLSD::TypeArray, @@ -467,9 +508,13 @@ LLSettingsSky::validation_list_t LLSettingsSky::validationList() validation.push_back(Validator(SETTING_SUN_ARC_RADIANS, true, LLSD::TypeReal, boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(0.1f))))); + validation.push_back(LLSettingsBase::Validator(LLSettingsSky::SETTING_MIE_ANISOTROPY_FACTOR, true, LLSD::TypeReal, + boost::bind(&LLSettingsBase::Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(1.0f))))); + validation.push_back(Validator(SETTING_RAYLEIGH_CONFIG, true, LLSD::TypeArray, &validateRayleighLayers)); validation.push_back(Validator(SETTING_ABSORPTION_CONFIG, true, LLSD::TypeArray, &validateAbsorptionLayers)); validation.push_back(Validator(SETTING_MIE_CONFIG, true, LLSD::TypeArray, &validateMieLayers)); + validation.push_back(Validator(SETTING_LEGACY_HAZE, false, LLSD::TypeMap, &validateLegacyHaze)); } return validation; } @@ -477,11 +522,13 @@ LLSettingsSky::validation_list_t LLSettingsSky::validationList() LLSD LLSettingsSky::rayleighConfigDefault() { LLSD dflt_rayleigh; - dflt_rayleigh[SETTING_DENSITY_PROFILE_WIDTH] = 0.0f; // 0 -> the entire atmosphere - dflt_rayleigh[SETTING_DENSITY_PROFILE_EXP_TERM] = 1.0f; - dflt_rayleigh[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = -1.0f / 8000.0f; - dflt_rayleigh[SETTING_DENSITY_PROFILE_LINEAR_TERM] = 0.0f; - dflt_rayleigh[SETTING_DENSITY_PROFILE_CONSTANT_TERM] = 0.0f; + LLSD dflt_rayleigh_layer; + dflt_rayleigh_layer[SETTING_DENSITY_PROFILE_WIDTH] = 0.0f; // 0 -> the entire atmosphere + dflt_rayleigh_layer[SETTING_DENSITY_PROFILE_EXP_TERM] = 1.0f; + dflt_rayleigh_layer[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = -1.0f / 8000.0f; + dflt_rayleigh_layer[SETTING_DENSITY_PROFILE_LINEAR_TERM] = 0.0f; + dflt_rayleigh_layer[SETTING_DENSITY_PROFILE_CONSTANT_TERM] = 0.0f; + dflt_rayleigh.append(dflt_rayleigh_layer); return dflt_rayleigh; } @@ -511,12 +558,13 @@ LLSD LLSettingsSky::absorptionConfigDefault() LLSD LLSettingsSky::mieConfigDefault() { LLSD dflt_mie; - dflt_mie[SETTING_DENSITY_PROFILE_WIDTH] = 0.0f; // 0 -> the entire atmosphere - dflt_mie[SETTING_DENSITY_PROFILE_EXP_TERM] = 1.0f; - dflt_mie[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = -1.0f / 1200.0f; - dflt_mie[SETTING_DENSITY_PROFILE_LINEAR_TERM] = 0.0f; - dflt_mie[SETTING_DENSITY_PROFILE_CONSTANT_TERM] = 0.0f; - dflt_mie[SETTING_MIE_ANISOTROPY_FACTOR] = 0.9f; + LLSD dflt_mie_layer; + dflt_mie_layer[SETTING_DENSITY_PROFILE_WIDTH] = 0.0f; // 0 -> the entire atmosphere + dflt_mie_layer[SETTING_DENSITY_PROFILE_EXP_TERM] = 1.0f; + dflt_mie_layer[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = -1.0f / 1200.0f; + dflt_mie_layer[SETTING_DENSITY_PROFILE_LINEAR_TERM] = 0.0f; + dflt_mie_layer[SETTING_DENSITY_PROFILE_CONSTANT_TERM] = 0.0f; + dflt_mie.append(dflt_mie_layer); return dflt_mie; } @@ -528,15 +576,6 @@ LLSD LLSettingsSky::defaults() LLQuaternion moonquat = ~sunquat; // Magic constants copied form dfltsetting.xml -// LEGACY_ATMOSPHERICS - dfltsetting[SETTING_AMBIENT] = LLColor4::white.getValue(); - dfltsetting[SETTING_BLUE_DENSITY] = LLColor4(0.2447, 0.4487, 0.7599, 0.0).getValue(); - dfltsetting[SETTING_BLUE_HORIZON] = LLColor4(0.4954, 0.4954, 0.6399, 0.0).getValue(); - dfltsetting[SETTING_DENSITY_MULTIPLIER] = LLSD::Real(0.0001); - dfltsetting[SETTING_DISTANCE_MULTIPLIER] = LLSD::Real(0.8000); - dfltsetting[SETTING_HAZE_DENSITY] = LLSD::Real(0.6999); - dfltsetting[SETTING_HAZE_HORIZON] = LLSD::Real(0.1899); - dfltsetting[SETTING_CLOUD_COLOR] = LLColor4(0.4099, 0.4099, 0.4099, 0.0).getValue(); dfltsetting[SETTING_CLOUD_POS_DENSITY1] = LLColor4(1.0000, 0.5260, 1.0000, 0.0).getValue(); dfltsetting[SETTING_CLOUD_POS_DENSITY2] = LLColor4(1.0000, 0.5260, 1.0000, 0.0).getValue(); @@ -564,71 +603,71 @@ LLSD LLSettingsSky::defaults() dfltsetting[SETTING_TYPE] = "sky"; // defaults are for earth... - dfltsetting[SETTING_PLANET_RADIUS] = 6360.0f; - dfltsetting[SETTING_SKY_BOTTOM_RADIUS] = 6360.0f; - dfltsetting[SETTING_SKY_TOP_RADIUS] = 6420.0f; - dfltsetting[SETTING_SUN_ARC_RADIANS] = 0.00935f / 2.0f; + dfltsetting[SETTING_PLANET_RADIUS] = 6360.0f; + dfltsetting[SETTING_SKY_BOTTOM_RADIUS] = 6360.0f; + dfltsetting[SETTING_SKY_TOP_RADIUS] = 6420.0f; + dfltsetting[SETTING_SUN_ARC_RADIANS] = 0.00935f / 2.0f; + dfltsetting[SETTING_MIE_ANISOTROPY_FACTOR] = 0.8f; - // These are technically capable of handling multiple layers of density config - // and so are expected to be an array, but we make an array of size 1 w/ each default density config - dfltsetting[SETTING_RAYLEIGH_CONFIG].append(rayleighConfigDefault()); - dfltsetting[SETTING_MIE_CONFIG].append(mieConfigDefault()); - dfltsetting[SETTING_ABSORPTION_CONFIG].append(absorptionConfigDefault()); + dfltsetting[SETTING_RAYLEIGH_CONFIG] = rayleighConfigDefault(); + dfltsetting[SETTING_MIE_CONFIG] = mieConfigDefault(); + dfltsetting[SETTING_ABSORPTION_CONFIG] = absorptionConfigDefault(); return dfltsetting; } -LLSD LLSettingsSky::translateLegacySettings(LLSD legacy) +LLSD LLSettingsSky::translateLegacyHazeSettings(const LLSD& legacy) { - LLSD newsettings(defaults()); + LLSD legacyhazesettings; // AdvancedAtmospherics TODO // These need to be translated into density profile info in the new settings format... -// LEGACY_ATMOSPHERICS - if (legacy.has(SETTING_AMBIENT)) - { - newsettings[SETTING_AMBIENT] = LLColor3(legacy[SETTING_AMBIENT]).getValue(); - } +// LEGACY_ATMOSPHERICS if (legacy.has(SETTING_BLUE_DENSITY)) { - newsettings[SETTING_BLUE_DENSITY] = LLColor3(legacy[SETTING_BLUE_DENSITY]).getValue(); + legacyhazesettings[SETTING_BLUE_DENSITY] = LLColor3(legacy[SETTING_BLUE_DENSITY]).getValue(); } if (legacy.has(SETTING_BLUE_HORIZON)) { - newsettings[SETTING_BLUE_HORIZON] = LLColor3(legacy[SETTING_BLUE_HORIZON]).getValue(); + legacyhazesettings[SETTING_BLUE_HORIZON] = LLColor3(legacy[SETTING_BLUE_HORIZON]).getValue(); } if (legacy.has(SETTING_DENSITY_MULTIPLIER)) { - newsettings[SETTING_DENSITY_MULTIPLIER] = LLSD::Real(legacy[SETTING_DENSITY_MULTIPLIER][0].asReal()); + legacyhazesettings[SETTING_DENSITY_MULTIPLIER] = LLSD::Real(legacy[SETTING_DENSITY_MULTIPLIER][0].asReal()); } if (legacy.has(SETTING_DISTANCE_MULTIPLIER)) { - newsettings[SETTING_DISTANCE_MULTIPLIER] = LLSD::Real(legacy[SETTING_DISTANCE_MULTIPLIER][0].asReal()); + legacyhazesettings[SETTING_DISTANCE_MULTIPLIER] = LLSD::Real(legacy[SETTING_DISTANCE_MULTIPLIER][0].asReal()); } if (legacy.has(SETTING_HAZE_DENSITY)) { - newsettings[SETTING_HAZE_DENSITY] = LLSD::Real(legacy[SETTING_HAZE_DENSITY][0].asReal()); + legacyhazesettings[SETTING_HAZE_DENSITY] = LLSD::Real(legacy[SETTING_HAZE_DENSITY][0].asReal()); } if (legacy.has(SETTING_HAZE_HORIZON)) { - newsettings[SETTING_HAZE_HORIZON] = LLSD::Real(legacy[SETTING_HAZE_HORIZON][0].asReal()); + legacyhazesettings[SETTING_HAZE_HORIZON] = LLSD::Real(legacy[SETTING_HAZE_HORIZON][0].asReal()); } - if (!legacy.has(SETTING_RAYLEIGH_CONFIG)) - { - newsettings[SETTING_RAYLEIGH_CONFIG].append(rayleighConfigDefault()); - } + return legacyhazesettings; +} - if (!legacy.has(SETTING_ABSORPTION_CONFIG)) +LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy) +{ + LLSD newsettings(defaults()); + + // Move legacy haze parameters to an inner map + // allowing backward compat and simple conversion to legacy format + LLSD legacyhazesettings; + legacyhazesettings = translateLegacyHazeSettings(legacy); + if (legacyhazesettings.size() > 0) { - newsettings[SETTING_ABSORPTION_CONFIG].append(absorptionConfigDefault()); + newsettings[SETTING_LEGACY_HAZE] = legacyhazesettings; } - if (!legacy.has(SETTING_MIE_CONFIG)) + if (legacy.has(SETTING_AMBIENT)) { - newsettings[SETTING_MIE_CONFIG].append(mieConfigDefault()); + newsettings[SETTING_AMBIENT] = LLColor3(legacy[SETTING_AMBIENT]).getValue(); } - if (legacy.has(SETTING_CLOUD_COLOR)) { newsettings[SETTING_CLOUD_COLOR] = LLColor3(legacy[SETTING_CLOUD_COLOR]).getValue(); @@ -696,37 +735,21 @@ LLSD LLSettingsSky::translateLegacySettings(LLSD legacy) { newsettings[SETTING_PLANET_RADIUS] = LLSD::Real(legacy[SETTING_PLANET_RADIUS].asReal()); } - else - { - newsettings[SETTING_PLANET_RADIUS] = 6360.0f; - } if (legacy.has(SETTING_SKY_BOTTOM_RADIUS)) { newsettings[SETTING_SKY_BOTTOM_RADIUS] = LLSD::Real(legacy[SETTING_SKY_BOTTOM_RADIUS].asReal()); } - else - { - newsettings[SETTING_SKY_BOTTOM_RADIUS] = 6360.0f; - } if (legacy.has(SETTING_SKY_TOP_RADIUS)) { newsettings[SETTING_SKY_TOP_RADIUS] = LLSD::Real(legacy[SETTING_SKY_TOP_RADIUS].asReal()); } - else - { - newsettings[SETTING_SKY_TOP_RADIUS] = 6420.0f; - } if (legacy.has(SETTING_SUN_ARC_RADIANS)) { newsettings[SETTING_SUN_ARC_RADIANS] = LLSD::Real(legacy[SETTING_SUN_ARC_RADIANS].asReal()); } - else - { - newsettings[SETTING_SUN_ARC_RADIANS] = 0.00935f / 2.0f; - } if (legacy.has(SETTING_LEGACY_EAST_ANGLE) && legacy.has(SETTING_LEGACY_SUN_ANGLE)) { // convert the east and sun angles into a quaternion. @@ -794,101 +817,143 @@ void LLSettingsSky::calculateHeavnlyBodyPositions() } } -void LLSettingsSky::calculateLightSettings() +LLColor3 LLSettingsSky::getBlueDensity() const { + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_BLUE_DENSITY)) + { + return LLColor3(mSettings[SETTING_LEGACY_HAZE][SETTING_BLUE_DENSITY]); + } + return LLColor3(0.2447f, 0.4487f, 0.7599f); +} -// LEGACY_ATMOSPHERICS - LLColor3 vary_HazeColor; - LLColor3 vary_SunlightColor; - LLColor3 vary_AmbientColor; - { - // Initialize temp variables - LLColor3 sunlight = getSunlightColor(); - LLColor3 ambient = getAmbientColor(); - F32 gamma = getGamma(); - LLColor3 blue_density = getBlueDensity(); - LLColor3 blue_horizon = getBlueHorizon(); - F32 haze_density = getHazeDensity(); - F32 haze_horizon = getHazeHorizon(); - - F32 density_multiplier = getDensityMultiplier(); - F32 max_y = getMaxY(); - F32 cloud_shadow = getCloudShadow(); - LLVector3 lightnorm = getLightDirection(); - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - LLColor3 light_atten = (blue_density * 1.0 + smear(haze_density * 0.25f)) * (density_multiplier * max_y); - - // Calculate relative weights - LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = blue_density + smear(haze_density); - LLColor3 blue_weight = componentDiv(blue_density, temp1); - LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); - - // Compute sunlight from P & lightnorm (for long rays like sky) - /// USE only lightnorm. - // temp2[1] = llmax(0.f, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - - // and vary_sunlight will work properly with moon light - F32 lighty = lightnorm[1]; - if (lighty < NIGHTTIME_ELEVATION_COS) - { - lighty = -lighty; - } +LLColor3 LLSettingsSky::getBlueHorizon() const +{ + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_BLUE_DENSITY)) + { + return LLColor3(mSettings[SETTING_LEGACY_HAZE][SETTING_BLUE_HORIZON]); + } + return LLColor3(0.4954f, 0.4954f, 0.6399f); +} - temp2.mV[1] = llmax(0.f, lighty); - if(temp2.mV[1] > 0.f) - { - temp2.mV[1] = 1.f / temp2.mV[1]; - } - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); +F32 LLSettingsSky::getHazeDensity() const +{ + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_HAZE_DENSITY)) + { + return mSettings[SETTING_LEGACY_HAZE][SETTING_HAZE_DENSITY].asReal(); + } + return 0.7f; +} - // Distance - temp2.mV[2] = density_multiplier; +F32 LLSettingsSky::getHazeHorizon() const +{ + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_HAZE_HORIZON)) + { + return mSettings[SETTING_LEGACY_HAZE][SETTING_HAZE_HORIZON].asReal(); + } + return 0.19f; +} + +F32 LLSettingsSky::getDensityMultiplier() const +{ + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_DENSITY_MULTIPLIER)) + { + return mSettings[SETTING_LEGACY_HAZE][SETTING_DENSITY_MULTIPLIER].asReal(); + } + return 0.0001f; +} - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); +F32 LLSettingsSky::getDistanceMultiplier() const +{ + if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_DISTANCE_MULTIPLIER)) + { + return mSettings[SETTING_LEGACY_HAZE][SETTING_DISTANCE_MULTIPLIER].asReal(); + } + return 0.8f; +} - // vary_AtmosAttenuation = temp1; +// Sunlight attenuation effect (hue and brightness) due to atmosphere +// this is used later for sunlight modulation at various altitudes +LLColor3 LLSettingsSky::getLightAttenuation(F32 distance) const +{ +// LEGACY_ATMOSPHERICS + LLColor3 blue_density = getBlueDensity(); + F32 haze_density = getHazeDensity(); + F32 density_multiplier = getDensityMultiplier(); + LLColor3 density = (blue_density * 1.0 + smear(haze_density * 0.25f)); + LLColor3 light_atten = density * density_multiplier * distance; + return light_atten; +} - //increase ambient when there are more clouds - LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5f; +LLColor3 LLSettingsSky::getLightTransmittance() const +{ +// LEGACY_ATMOSPHERICS + LLColor3 blue_density = getBlueDensity(); + F32 haze_density = getHazeDensity(); + F32 density_multiplier = getDensityMultiplier(); + LLColor3 temp1 = blue_density + smear(haze_density); + // Transparency (-> temp1) + temp1 = componentExp((temp1 * -1.f) * density_multiplier); + return temp1; +} - //haze color - vary_HazeColor = - (blue_horizon * blue_weight * (sunlight*(1.f - cloud_shadow) + tmpAmbient) - + componentMult(haze_horizon * haze_weight, sunlight*(1.f - cloud_shadow) * temp2.mV[0] + tmpAmbient) - ); +LLColor3 LLSettingsSky::gammaCorrect(const LLColor3& in) const +{ + F32 gamma = getGamma(); + LLColor3 v(in); + v.clamp(); + v= smear(1.0f) - v; + v = componentPow(v, gamma); + v = smear(1.0f) - v; + return v; +} - //brightness of surface both sunlight and ambient - vary_SunlightColor = componentMult(sunlight, temp1) * 1.f; - vary_SunlightColor.clamp(); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_SunlightColor = componentPow(vary_SunlightColor, gamma); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_AmbientColor = componentMult(tmpAmbient, temp1) * 0.5; - vary_AmbientColor.clamp(); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; - vary_AmbientColor = componentPow(vary_AmbientColor, gamma); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; +void LLSettingsSky::calculateLightSettings() +{ + // Initialize temp variables + LLColor3 sunlight = getSunlightColor(); + LLColor3 ambient = getAmbientColor(); + F32 cloud_shadow = getCloudShadow(); + LLVector3 lightnorm = getLightDirection(); + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + F32 max_y = getMaxY(); + LLColor3 light_atten = getLightAttenuation(max_y); + LLColor3 light_transmittance = getLightTransmittance(); + + // Compute sunlight from P & lightnorm (for long rays like sky) + /// USE only lightnorm. + // temp2[1] = llmax(0.f, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - componentMultBy(vary_HazeColor, LLColor3(1.f, 1.f, 1.f) - temp1); + // and vary_sunlight will work properly with moon light + F32 lighty = lightnorm[1]; + if (lighty < NIGHTTIME_ELEVATION_COS) + { + lighty = -lighty; + } + lighty = llmax(0.f, lighty); + if(lighty > 0.f) + { + lighty = 1.f / lighty; } + componentMultBy(sunlight, componentExp((light_atten * -1.f) * lighty)); + + //increase ambient when there are more clouds + LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5f; - mSunDiffuse = vary_SunlightColor; - mSunAmbient = vary_AmbientColor; - mMoonDiffuse = vary_SunlightColor; - mMoonAmbient = vary_AmbientColor; + //brightness of surface both sunlight and ambient + mSunDiffuse = gammaCorrect(componentMult(sunlight, light_transmittance)); + mSunAmbient = gammaCorrect(componentMult(tmpAmbient, light_transmittance) * 0.5); - mTotalAmbient = LLColor4(vary_AmbientColor, 1.0f); + mMoonDiffuse = gammaCorrect(componentMult(LLColor3::white, light_transmittance)); + mMoonAmbient = gammaCorrect(componentMult(LLColor3::white, light_transmittance) * 0.5f); + mTotalAmbient = mSunAmbient; mFadeColor = mTotalAmbient + (mSunDiffuse + mMoonDiffuse) * 0.5f; mFadeColor.setAlpha(0); } - //========================================================================= namespace { diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h index d08e2bbd03..4fb8c101ee 100644 --- a/indra/llinventory/llsettingssky.h +++ b/indra/llinventory/llsettingssky.h @@ -66,6 +66,7 @@ public: static const std::string SETTING_SKY_BOTTOM_RADIUS; static const std::string SETTING_SKY_TOP_RADIUS; static const std::string SETTING_SUN_ARC_RADIANS; + static const std::string SETTING_MIE_ANISOTROPY_FACTOR; static const std::string SETTING_RAYLEIGH_CONFIG; static const std::string SETTING_MIE_CONFIG; @@ -77,7 +78,9 @@ public: static const std::string SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR; static const std::string SETTING_DENSITY_PROFILE_LINEAR_TERM; static const std::string SETTING_DENSITY_PROFILE_CONSTANT_TERM; - static const std::string SETTING_MIE_ANISOTROPY_FACTOR; + + + static const std::string SETTING_LEGACY_HAZE; typedef std::shared_ptr<LLSettingsSky> ptr_t; typedef std::pair<F32, F32> azimalt_t; @@ -98,80 +101,60 @@ public: static LLSD defaults(); - LLUUID getBloomTextureId() const - { - return mSettings[SETTING_BLOOM_TEXTUREID].asUUID(); - } - - //--------------------------------------------------------------------- - LLColor3 getAmbientColor() const - { - return LLColor3(mSettings[SETTING_AMBIENT]); - } - - void setAmbientColor(const LLColor3 &val) + F32 getPlanetRadius() const { - setValue(SETTING_AMBIENT, val); + return mSettings[SETTING_PLANET_RADIUS].asReal(); } - LLColor3 getBlueDensity() const + F32 getSkyBottomRadius() const { - return LLColor3(mSettings[SETTING_BLUE_DENSITY]); + return mSettings[SETTING_SKY_BOTTOM_RADIUS].asReal(); } - void setBlueDensity(const LLColor3 &val) + F32 getSkyTopRadius() const { - setValue(SETTING_BLUE_DENSITY, val); + return mSettings[SETTING_SKY_TOP_RADIUS].asReal(); } - LLColor3 getBlueHorizon() const + F32 getSunArcRadians() const { - return LLColor3(mSettings[SETTING_BLUE_HORIZON]); + return mSettings[SETTING_SUN_ARC_RADIANS].asReal(); } - void setBlueHorizon(const LLColor3 &val) + F32 getMieAnisotropy() const { - setValue(SETTING_BLUE_HORIZON, val); + return mSettings[SETTING_MIE_ANISOTROPY_FACTOR].asReal(); } - - F32 getDensityMultiplier() const - { - return mSettings[SETTING_DENSITY_MULTIPLIER].asReal(); - } - - void setDensityMultiplier(F32 val) - { - setValue(SETTING_DENSITY_MULTIPLIER, val); - } - - F32 getDistanceMultiplier() const + + LLSD getRayleighConfigs() const { - return mSettings[SETTING_DISTANCE_MULTIPLIER].asReal(); + return mSettings[SETTING_RAYLEIGH_CONFIG]; } - void setDistanceMultiplier(F32 val) + LLSD getMieConfigs() const { - setValue(SETTING_DISTANCE_MULTIPLIER, val); + return mSettings[SETTING_MIE_CONFIG]; } - F32 getHazeDensity() const + LLSD getAbsorptionConfigs() const { - return mSettings[SETTING_HAZE_DENSITY].asReal(); + return mSettings[SETTING_ABSORPTION_CONFIG]; } - void setHazeDensity(F32 val) + LLUUID getBloomTextureId() const { - setValue(SETTING_HAZE_DENSITY, val); + return mSettings[SETTING_BLOOM_TEXTUREID].asUUID(); } - F32 getHazeHorizon() const + //--------------------------------------------------------------------- + LLColor3 getAmbientColor() const { - return mSettings[SETTING_HAZE_HORIZON].asReal(); + return LLColor3(mSettings[SETTING_AMBIENT]); } - void setHazeHorizon(F32 val) + void setAmbientColor(const LLColor3 &val) { - setValue(SETTING_HAZE_HORIZON, val); + setValue(SETTING_AMBIENT, val); } LLColor3 getCloudColor() const @@ -432,7 +415,20 @@ public: virtual validation_list_t getValidationList() const override; static validation_list_t validationList(); - static LLSD translateLegacySettings(LLSD legacy); + static LLSD translateLegacySettings(const LLSD& legacy); + static LLSD translateLegacyHazeSettings(const LLSD& legacy); + + LLColor3 getLightAttenuation(F32 distance) const; + LLColor3 getLightTransmittance() const; + LLColor3 gammaCorrect(const LLColor3& in) const; + +// LEGACY_ATMOSPHERICS + LLColor3 getBlueDensity() const; + LLColor3 getBlueHorizon() const; + F32 getHazeDensity() const; + F32 getHazeHorizon() const; + F32 getDensityMultiplier() const; + F32 getDistanceMultiplier() const; protected: static const std::string SETTING_LEGACY_EAST_ANGLE; diff --git a/indra/llinventory/llsettingswater.h b/indra/llinventory/llsettingswater.h index 92190fa7b1..e9d8cb9613 100644 --- a/indra/llinventory/llsettingswater.h +++ b/indra/llinventory/llsettingswater.h @@ -76,22 +76,22 @@ public: setValue(SETTING_BLUR_MULTIPILER, val); } - LLColor3 getFogColor() const + LLColor3 getWaterFogColor() const { return LLColor3(mSettings[SETTING_FOG_COLOR]); } - void setFogColor(LLColor3 val) + void setWaterFogColor(LLColor3 val) { setValue(SETTING_FOG_COLOR, val); } - F32 getFogDensity() const + F32 getWaterFogDensity() const { return mSettings[SETTING_FOG_DENSITY].asReal(); } - void setFogDensity(F32 val) + void setWaterFogDensity(F32 val) { setValue(SETTING_FOG_DENSITY, val); } diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index daf3a6857b..41dbdb8cd5 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -100,6 +100,23 @@ public: const LLColor3& operator=(const LLColor4 &a); + LL_FORCE_INLINE LLColor3 divide(const LLColor3 &col2)
+ {
+ return LLColor3(
+ mV[0] / col2.mV[0],
+ mV[1] / col2.mV[1],
+ mV[2] / col2.mV[2] );
+ }
+
+ LL_FORCE_INLINE LLColor3 color_norm()
+ {
+ F32 l = length();
+ return LLColor3(
+ mV[0] / l,
+ mV[1] / l,
+ mV[2] / l );
+ }
+ friend std::ostream& operator<<(std::ostream& s, const LLColor3 &a); // Print a friend LLColor3 operator+(const LLColor3 &a, const LLColor3 &b); // Return vector a + b friend LLColor3 operator-(const LLColor3 &a, const LLColor3 &b); // Return vector a minus b diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 6ce5292839..eca129cfe9 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -1,221 +1,288 @@ -/** - * @file llatmosphere.cpp - * @brief LLAtmosphere integration impl - * - * $LicenseInfo:firstyear=2018&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2018, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "llatmosphere.h" -#include "llfasttimer.h" -#include "llsys.h" -#include "llglheaders.h" -#include "llrender.h" -#include "llshadermgr.h" -#include "llglslshader.h" - -LLAtmosphere* gAtmosphere = nullptr; - -void LLAtmosphere::initClass() -{ - if (!gAtmosphere) - { - gAtmosphere = new LLAtmosphere; - } -} - -void LLAtmosphere::cleanupClass() +/**
+ * @file llatmosphere.cpp
+ * @brief LLAtmosphere integration impl
+ *
+ * $LicenseInfo:firstyear=2018&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2018, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+
+#include "llatmosphere.h"
+#include "llfasttimer.h"
+#include "llsys.h"
+#include "llglheaders.h"
+#include "llrender.h"
+#include "llshadermgr.h"
+#include "llglslshader.h"
+
+LLAtmosphere* gAtmosphere = nullptr;
+
+// Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column
+// (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html),
+// summed and averaged in each bin (e.g. the value for 360nm is the average
+// of the ASTM G-173 values for all wavelengths between 360 and 370nm).
+// Values in W.m^-2.
+const int kLambdaMin = 360;
+const int kLambdaMax = 830;
+const double kSolarIrradiance[48] = {
+ 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253,
+ 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298,
+ 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533,
+ 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482,
+ 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082,
+ 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992
+};
+
+// Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/
+// referencespectra/o3spectra2011/index.html for 233K, summed and averaged in
+// each bin (e.g. the value for 360nm is the average of the original values
+// for all wavelengths between 360 and 370nm). Values in m^2.
+const double kOzoneCrossSection[48] = {
+ 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27,
+ 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26,
+ 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25,
+ 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25,
+ 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26,
+ 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26,
+ 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27
+};
+
+// From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2.
+const double kDobsonUnit = 2.687e20;
+// Maximum number density of ozone molecules, in m^-3 (computed so at to get
+// 300 Dobson units of ozone - for this we divide 300 DU by the integral of
+// the ozone density profile defined below, which is equal to 15km).
+const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0;
+const double kRayleigh = 1.24062e-6;
+const double kRayleighScaleHeight = 8000.0;
+const double kMieScaleHeight = 1200.0;
+const double kMieAngstromAlpha = 0.0;
+const double kMieAngstromBeta = 5.328e-3;
+const double kMieSingleScatteringAlbedo = 0.9;
+const double max_sun_zenith_angle = F_PI * 2.0 / 3.0;
+
+AtmosphericModelSettings::AtmosphericModelSettings()
+ : m_skyBottomRadius(6360.0f)
+ , m_skyTopRadius(6420.0f)
+ , m_sunArcRadians(0.00045f)
+ , m_mieAnisotropy(0.8f)
+{
+ atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0);
+ atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0);
+
+ m_rayleighProfile.push_back(rayleigh_density);
+ m_mieProfile.push_back(mie_density);
+
+ // Density profile increasing linearly from 0 to 1 between 10 and 25km, and
+ // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate
+ // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/
+ // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10).
+ m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0));
+ m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0));
+}
+
+AtmosphericModelSettings::AtmosphericModelSettings( + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile) +: m_skyBottomRadius(6360.0f) +, m_skyTopRadius(6420.0f) +, m_rayleighProfile(rayleighProfile) +, m_mieProfile(mieProfile) +, m_absorptionProfile(absorptionProfile) +, m_sunArcRadians(0.00045f) +, m_mieAnisotropy(0.8f) { - if(gAtmosphere) - { - delete gAtmosphere; - } - gAtmosphere = NULL; } -LLAtmosphere::LLAtmosphere() +AtmosphericModelSettings::AtmosphericModelSettings( + F32 skyBottomRadius, + F32 skyTopRadius, + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile, + F32 sunArcRadians, + F32 mieAniso) +: m_skyBottomRadius(skyBottomRadius) +, m_skyTopRadius(skyTopRadius) +, m_rayleighProfile(rayleighProfile) +, m_mieProfile(mieProfile) +, m_absorptionProfile(absorptionProfile) +, m_sunArcRadians(sunArcRadians) +, m_mieAnisotropy(mieAniso) { - // Init libatmosphere model - m_config.num_scattering_orders = 4; - - // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column - // (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), - // summed and averaged in each bin (e.g. the value for 360nm is the average - // of the ASTM G-173 values for all wavelengths between 360 and 370nm). - // Values in W.m^-2. - const int kLambdaMin = 360; - const int kLambdaMax = 830; - const double kSolarIrradiance[48] = { - 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, - 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, - 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, - 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, - 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, - 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 - }; - - // Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ - // referencespectra/o3spectra2011/index.html for 233K, summed and averaged in - // each bin (e.g. the value for 360nm is the average of the original values - // for all wavelengths between 360 and 370nm). Values in m^2. - const double kOzoneCrossSection[48] = { - 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, - 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, - 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, - 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, - 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, - 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, - 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 - }; - - // From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. - const double kDobsonUnit = 2.687e20; - - // Maximum number density of ozone molecules, in m^-3 (computed so at to get - // 300 Dobson units of ozone - for this we divide 300 DU by the integral of - // the ozone density profile defined below, which is equal to 15km). - const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; - - const double kSunAngularRadius = 0.00935 / 2.0; - const double kBottomRadius = 6360000.0; - const double kTopRadius = 6420000.0; - const double kRayleigh = 1.24062e-6; - const double kRayleighScaleHeight = 8000.0; - const double kMieScaleHeight = 1200.0; - const double kMieAngstromAlpha = 0.0; - const double kMieAngstromBeta = 5.328e-3; - const double kMieSingleScatteringAlbedo = 0.9; - const double kMiePhaseFunctionG = 0.8; - const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; - - atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); - atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); - - // Density profile increasing linearly from 0 to 1 between 10 and 25km, and - // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate - // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ - // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). - std::vector<atmosphere::DensityProfileLayer> ozone_density; - ozone_density.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); - ozone_density.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); - - std::vector<double> wavelengths; - std::vector<double> solar_irradiance; - std::vector<double> rayleigh_scattering; - std::vector<double> mie_scattering; - std::vector<double> mie_extinction; - std::vector<double> absorption_extinction; - std::vector<double> ground_albedo; - - for (int l = kLambdaMin; l <= kLambdaMax; l += 10) - { - double lambda = static_cast<double>(l) * 1e-3; // micro-meters - double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); - wavelengths.push_back(l); - solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); - rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); - mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); - mie_extinction.push_back(mie); - absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); - ground_albedo.push_back(0.1f); - } - - m_model = new atmosphere::Model( - wavelengths, - solar_irradiance, - kSunAngularRadius, - kBottomRadius, - kTopRadius, - {rayleigh_density}, - rayleigh_scattering, - {mie_density}, - mie_scattering, - mie_extinction, - kMiePhaseFunctionG, - ozone_density, - absorption_extinction, - ground_albedo, - max_sun_zenith_angle, - 1000.0, - 15, - false, - true); - - m_model->Init(m_config, m_textures); - - m_transmittance = new LLGLTexture; - m_scattering = new LLGLTexture; - m_mie_scattering = new LLGLTexture; - - m_transmittance->generateGLTexture(); - m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_transmittance->setTexName(m_textures.transmittance_texture); - m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); - - m_scattering->generateGLTexture(); - m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_scattering->setTexName(m_textures.transmittance_texture); - m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); - - m_mie_scattering->generateGLTexture(); - m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_mie_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_mie_scattering->setTexName(m_textures.transmittance_texture); - m_mie_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); -}; - -LLAtmosphere::~LLAtmosphere() -{ - // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. - m_transmittance->setTexName(0); - m_scattering->setTexName(0); - m_mie_scattering->setTexName(0); - - delete m_model; - m_model = nullptr; -} - -LLGLTexture* LLAtmosphere::getTransmittance() const -{ - return m_transmittance; -} - -LLGLTexture* LLAtmosphere::getScattering() const -{ - return m_scattering; -} - -LLGLTexture* LLAtmosphere::getMieScattering() const -{ - return m_mie_scattering; -} - -GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const -{ - return m_model ? m_model->GetShader() : 0; -} +}
+
+void LLAtmosphere::initClass()
+{
+ if (!gAtmosphere)
+ {
+ gAtmosphere = new LLAtmosphere;
+ }
+}
+
+void LLAtmosphere::cleanupClass()
+{
+ if(gAtmosphere)
+ {
+ delete gAtmosphere;
+ }
+ gAtmosphere = NULL;
+}
+
+LLAtmosphere::LLAtmosphere()
+{
+ for (int l = kLambdaMin; l <= kLambdaMax; l += 10)
+ {
+ double lambda = static_cast<double>(l) * 1e-3; // micro-meters
+ double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha);
+ m_wavelengths.push_back(l);
+ m_solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]);
+ m_rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4));
+ m_mie_scattering.push_back(mie * kMieSingleScatteringAlbedo);
+ m_mie_extinction.push_back(mie);
+ m_absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]);
+ m_ground_albedo.push_back(0.6f);
+ }
+
+ AtmosphericModelSettings defaults;
+ configureAtmosphericModel(defaults);
+}
+
+LLAtmosphere::~LLAtmosphere()
+{
+ // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same.
+ if (m_transmittance)
+ {
+ m_transmittance->setTexName(0);
+ }
+
+ if (m_scattering)
+ {
+ m_scattering->setTexName(0);
+ }
+
+ if (m_mie_scatter_texture)
+ {
+ m_mie_scatter_texture->setTexName(0);
+ }
+
+ delete m_model;
+ m_model = nullptr;
+}
+
+bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings)
+{
+// Advanced Atmospherics TODO
+// Make this store a hash of the precomputed data
+// and avoid redundant calcs for identical settings
+
+ if (m_model)
+ {
+ delete m_model;
+ }
+ m_model = nullptr;
+ getTransmittance()->setTexName(0);
+ getScattering()->setTexName(0);
+ getMieScattering()->setTexName(0);
+
+ // Init libatmosphere model
+ m_config.num_scattering_orders = 4;
+
+ m_model = new atmosphere::Model(
+ m_wavelengths,
+ m_solar_irradiance,
+ settings.m_sunArcRadians,
+ settings.m_skyBottomRadius * 1000.0f,
+ settings.m_skyTopRadius * 1000.0f,
+ settings.m_rayleighProfile,
+ m_rayleigh_scattering,
+ settings.m_mieProfile,
+ m_mie_scattering,
+ m_mie_extinction,
+ settings.m_mieAnisotropy,
+ settings.m_absorptionProfile,
+ m_absorption_extinction,
+ m_ground_albedo,
+ max_sun_zenith_angle,
+ 1000.0,
+ 15,
+ false,
+ true);
+
+ if (m_model)
+ {
+ m_model->Init(m_config, m_textures);
+ getTransmittance()->setTexName(m_textures.transmittance_texture);
+ getScattering()->setTexName(m_textures.transmittance_texture);
+ getMieScattering()->setTexName(m_textures.transmittance_texture);
+ }
+
+ return m_model != nullptr;
+}
+
+LLGLTexture* LLAtmosphere::getTransmittance()
+{
+ if (!m_transmittance)
+ {
+ m_transmittance = new LLGLTexture;
+ m_transmittance->generateGLTexture();
+ m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP);
+ m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR);
+ m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT);
+ m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE);
+ }
+ return m_transmittance;
+}
+
+LLGLTexture* LLAtmosphere::getScattering()
+{
+ if (!m_scattering)
+ {
+ m_scattering = new LLGLTexture;
+ m_scattering->generateGLTexture();
+ m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP);
+ m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR);
+ m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT);
+ m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D);
+ }
+ return m_scattering;
+}
+
+LLGLTexture* LLAtmosphere::getMieScattering()
+{
+ if (!m_mie_scatter_texture)
+ {
+ m_mie_scatter_texture = new LLGLTexture;
+ m_mie_scatter_texture->generateGLTexture();
+ m_mie_scatter_texture->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP);
+ m_mie_scatter_texture->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR);
+ m_mie_scatter_texture->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT);
+ m_mie_scatter_texture->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D);
+ }
+ return m_mie_scatter_texture;
+}
+
+GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const
+{
+ return m_model ? m_model->GetShader() : 0;
+}
diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index 6a9d1a4438..53dc1dd354 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -31,6 +31,36 @@ #include "llgltexture.h" #include "libatmosphere/model.h" +typedef std::vector<atmosphere::DensityProfileLayer> DensityProfile; + +class AtmosphericModelSettings +{ +public: + AtmosphericModelSettings(); + + AtmosphericModelSettings( + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile); + + AtmosphericModelSettings( + F32 skyBottomRadius, + F32 skyTopRadius, + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile, + F32 sunArcRadians, + F32 mieAniso); + + F32 m_skyBottomRadius; + F32 m_skyTopRadius; + DensityProfile m_rayleighProfile; + DensityProfile m_mieProfile; + DensityProfile m_absorptionProfile; + F32 m_sunArcRadians; + F32 m_mieAnisotropy; +}; + class LLAtmosphere { public: @@ -46,12 +76,14 @@ public: return *this; } - LLGLTexture* getTransmittance() const; - LLGLTexture* getScattering() const; - LLGLTexture* getMieScattering() const; + LLGLTexture* getTransmittance(); + LLGLTexture* getScattering(); + LLGLTexture* getMieScattering(); GLhandleARB getAtmosphericShaderForLink() const; + bool configureAtmosphericModel(AtmosphericModelSettings& settings); + protected: LLAtmosphere(const LLAtmosphere& rhs) { @@ -64,7 +96,15 @@ protected: LLPointer<LLGLTexture> m_transmittance; LLPointer<LLGLTexture> m_scattering; - LLPointer<LLGLTexture> m_mie_scattering; + LLPointer<LLGLTexture> m_mie_scatter_texture; + + std::vector<double> m_wavelengths; + std::vector<double> m_solar_irradiance; + std::vector<double> m_rayleigh_scattering; + std::vector<double> m_mie_scattering; + std::vector<double> m_mie_extinction; + std::vector<double> m_absorption_extinction; + std::vector<double> m_ground_albedo; }; extern LLAtmosphere* gAtmosphere; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b09ec53bc0..73ab95cf3b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -84,6 +84,9 @@ LLShaderFeatures::LLShaderFeatures() , hasObjectSkinning(false) , hasAtmospherics(false) , hasGamma(false) + , hasSrgb(false) + , encodesNormal(false) + , decodesNormal(false) , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index a7a9e27fcd..562cbdcba9 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -48,6 +48,9 @@ public: bool hasObjectSkinning; bool hasAtmospherics; bool hasGamma; + bool hasSrgb; + bool encodesNormal; + bool decodesNormal; S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 287f22783f..60cbbd942f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -98,7 +98,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - if (features->calculatesLighting || features->atmosphericHelpers) + if (features->calculatesLighting || features->calculatesAtmospherics) { if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) { @@ -194,6 +194,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } + if (features->calculatesLighting || features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + { + return FALSE; + } + } + // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->hasGamma) { @@ -202,7 +210,31 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) return FALSE; } } - + + if (features->hasSrgb) + { + if (!shader->attachObject("environment/srgbF.glsl")) + { + return FALSE; + } + } + + if (features->encodesNormal) + { + if (!shader->attachObject("environment/encodeNormF.glsl")) + { + return FALSE; + } + } + + if (features->decodesNormal) + { + if (!shader->attachObject("environment/decodeNormF.glsl")) + { + return FALSE; + } + } + if (features->hasAtmospherics) { if (!shader->attachObject("windlight/atmosphericsF.glsl")) diff --git a/indra/llui/llui.h b/indra/llui/llui.h index d7151dbee9..111f6472cd 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -33,7 +33,6 @@ #include "llcontrol.h" #include "llcoord.h" #include "llcontrol.h" -#include "llglslshader.h" #include "llinitparam.h" #include "llregistry.h" #include "llrender2dutils.h" @@ -49,7 +48,6 @@ // for initparam specialization #include "llfontgl.h" - class LLUUID; class LLWindow; class LLView; diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 1a19e81010..a1fbcf9451 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -365,6 +365,7 @@ set(viewer_SOURCE_FILES lljoystickbutton.cpp lllandmarkactions.cpp lllandmarklist.cpp + lllegacyatmospherics.cpp lllistbrowser.cpp lllistcontextmenu.cpp lllistview.cpp diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b9c8f34cb0..2234ceeb53 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -39,19 +39,6 @@ out vec4 frag_color; uniform float display_gamma; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -84,12 +71,6 @@ VARYING vec3 vary_norm; VARYING vec4 vertex_color; #endif -vec3 vary_PositionEye; -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -98,59 +79,20 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec2 encode_normal (vec3 n); +vec3 decode_normal (vec2 enc); -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAmbient(vec3 light, vec3 sunlit); +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); +vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 calcDirectionalLight(vec3 n, vec3 l) { @@ -219,237 +161,6 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} void main() { @@ -566,10 +277,15 @@ void main() vec3 norm = vary_norm; - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + norm.xyz = decode_normal(abnormal.xy); float da = dot(norm.xyz, sun_dir.xyz); @@ -581,7 +297,7 @@ void main() vec4 color = vec4(0,0,0,0); - color.rgb = atmosAmbient(color.rgb); + color.rgb = atmosFragAmbient(color.rgb, amblit); color.a = final_alpha; float ambient = abs(da); @@ -590,13 +306,13 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(final_da); + color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit); color.rgb *= gamma_diff.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); - color.rgb = atmosLighting(color.rgb); - color.rgb = scaleSoftClip(color.rgb); + color.rgb = atmosFragLighting(color.rgb, additive, atten); + color.rgb = scaleFragSoftClip(color.rgb); vec4 light = vec4(0,0,0,0); @@ -621,9 +337,8 @@ void main() color.rgb = linear_to_srgb(color.rgb); #ifdef WATER_FOG - color = applyWaterFogDeferred(pos.xyz, color); + color = applyWaterFogView(pos.xyz, color); #endif - #endif frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl index 22c9a4d14e..8e9a5fcd41 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl @@ -22,6 +22,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 662c762bca..60d83cc623 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -36,11 +38,7 @@ uniform float minimum_alpha; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index b809b73973..8e46425ea8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -22,7 +22,9 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index cbd8d2ebfc..b56abb66d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -61,22 +61,7 @@ vec4 getPosition(vec2 pos_screen) return pos; } -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 58fb01d200..b5677a07ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -22,6 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -40,11 +42,7 @@ VARYING vec3 vary_mat2; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1d8ca04ccd..7b971fcc66 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -22,7 +22,7 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index 7930b5d18b..b328ee9483 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -37,11 +39,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 8525e13333..fc5c86b4d6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -36,11 +38,7 @@ uniform float minimum_alpha; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 37d70a2412..1bb8eb8bd0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -37,11 +38,7 @@ uniform sampler2D diffuseMap; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 6befb1bd8b..8319e61242 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -22,6 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -35,11 +37,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index adc361d7a2..828c325c9d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -33,12 +35,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 756e625d07..134e9c3b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -41,43 +41,12 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; - -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 fullbrightAtmosTransportDeferred(vec3 light) { @@ -94,52 +63,6 @@ vec3 fullbrightScaleSoftClipDeferred(vec3 light) uniform float minimum_alpha; #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - void main() { #if HAS_DIFFUSE_LOOKUP @@ -166,7 +89,7 @@ void main() #ifdef WATER_FOG vec3 pos = vary_position; - vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); + vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); color.rgb = fogged.rgb; color.a = fogged.a; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index b0db9876d3..30e560450b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ - +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index f8fdde43f9..6ba16b169c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -38,41 +40,7 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index dcf474824d..be1003a7e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -22,8 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform sampler2DRect diffuseMap; + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -31,6 +31,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +uniform sampler2DRect diffuseMap; VARYING vec2 vary_fragcoord; void main() diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 07d28ed4cd..a90e433622 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #define DIFFUSE_ALPHA_MODE_IGNORE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 @@ -31,42 +33,18 @@ uniform float emissive_brightness; uniform float display_gamma; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -116,19 +94,6 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -137,13 +102,6 @@ VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -152,52 +110,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -283,198 +195,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } -#ifndef WATER_FOG -vec3 getPositionEye() -{ - return vary_PositionEye; -} -#endif - -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} #else #ifdef DEFINE_GL_FRAGCOLOR @@ -515,22 +235,8 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec2 encode_normal(vec3 n); +vec3 decode_normal (vec2 enc); void main() { @@ -673,7 +379,12 @@ void main() vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -686,7 +397,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = atmosAmbient(col); + col.rgb = atmosFragAmbient(col, amblit); float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -695,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); col.rgb *= gamma_diff.rgb; @@ -708,7 +419,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -742,8 +453,8 @@ void main() //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosLighting(col); - col = scaleSoftClip(col); + col = atmosFragLighting(col, additive, atten); + col = scaleFragSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); @@ -771,7 +482,7 @@ void main() col.rgb = linear_to_srgb(col.rgb); #ifdef WATER_FOG - vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); + vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 9974f8f31b..d1ac19270d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -57,22 +57,7 @@ uniform float far_z; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3a3e871ade..1d75322b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -30,14 +30,14 @@ #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -/*[EXTRA_CODE_HERE]*/ - uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect depthMap; @@ -72,59 +72,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - +vec3 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index aba4a01754..13b803e03e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,22 +56,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 6669947d1b..cbc19bbba3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -40,25 +40,7 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index 018ced4cad..e33254304b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl new file mode 100644 index 0000000000..12bc690553 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl @@ -0,0 +1,55 @@ +/** + * @file shadowAlphaMaskF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ + float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + + frag_color = vec4(alpha, alpha, alpha, 1); + +#if !DEPTH_CLAMP + gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl new file mode 100644 index 0000000000..11411a605c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl @@ -0,0 +1,67 @@ +/** + * @file shadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + + pos_w = pos.w; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 91a96977f0..ae1b19a35c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 3d1b182875..242aef821d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 22f4729e2e..46bf718270 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7f1a8cce0d..fbfd43a4da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -51,83 +51,32 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -147,243 +96,6 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - - -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} void main() { @@ -411,9 +123,13 @@ void main() vec3 col; float bloom = 0.0; { - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - col = atmosAmbient(vec3(0)); + col = atmosFragAmbient(vec3(0), amblit); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; @@ -421,7 +137,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(final_da); + col += atmosFragAffectDirectionalLight(final_da, sunlit); col *= diffuse.rgb; @@ -433,7 +149,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -457,12 +173,12 @@ void main() if (norm.w < 0.5) { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index f1aec315cc..2b6428963d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,59 +70,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 821058804c..029a98e16a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 930255729b..403df87853 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -51,22 +51,7 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 52a429465f..0cd90b0d97 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -39,11 +41,7 @@ VARYING vec3 vary_normal; VARYING vec4 vary_texcoord0; VARYING vec4 vary_texcoord1; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 808750496f..89e354558a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -37,11 +39,7 @@ VARYING vec2 vary_texcoord0; uniform float minimum_alpha; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index d4d2f5f571..e34d75ba1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 78f841c733..3a8565ee38 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -56,48 +58,10 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); vec4 applyWaterFog(vec4 color, vec3 viewVec) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 37dcd3ad34..b321eb508b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -69,48 +69,8 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec3 srgb_to_linear(vec3 cs); +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl new file mode 100644 index 0000000000..0abb1e43db --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl @@ -0,0 +1,11 @@ +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl new file mode 100644 index 0000000000..ee21715c1d --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl @@ -0,0 +1,7 @@ + +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index 6cc1e6e798..835662732a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -1,5 +1,5 @@ /** - * @file srgb.glsl + * @file srgbF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -27,14 +27,18 @@ vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); +#ifdef OLD_SELECT vec3 result; result.r = lte.r ? low_range.r : high_range.r; result.g = lte.g ? low_range.g : high_range.g; result.b = lte.b ? low_range.b : high_range.b; return result; +#else + return mix(high_range, low_range, lte); +#endif + } vec3 linear_to_srgb(vec3 cl) @@ -42,13 +46,17 @@ vec3 linear_to_srgb(vec3 cl) cl = clamp(cl, vec3(0), vec3(1)); vec3 low_range = cl * 12.92; vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); +#ifdef OLD_SELECT vec3 result; result.r = lt.r ? low_range.r : high_range.r; result.g = lt.g ? low_range.g : high_range.g; result.b = lt.b ? low_range.b : high_range.b; - return result; + return result; +#else + return mix(high_range, low_range, lt); +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 4bdfce9260..a7c28a1ac3 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -33,10 +33,10 @@ uniform float waterFogKS; vec3 getPositionEye(); -vec4 applyWaterFog(vec4 color) +vec4 applyWaterFogView(vec3 pos, vec4 color) { + vec3 view = normalize(pos); //normalize view vector - vec3 view = normalize(getPositionEye()); float es = -(dot(view, waterPlane.xyz)); //find intersection point with water plane and eye vector @@ -47,7 +47,7 @@ vec4 applyWaterFog(vec4 color) vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); //get object depth - float depth = length(getPositionEye() - int_v); + float depth = length(pos - int_v); //get "thickness" of water float l = max(depth, 0.1); @@ -72,3 +72,9 @@ vec4 applyWaterFog(vec4 color) return color; } +vec4 applyWaterFog(vec4 color) +{ + //normalize view vector + return applyWaterFogView(getPositionEye(), color); +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl index 5c088b3a3c..b5bbbb5c73 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl @@ -25,14 +25,14 @@ #extension GL_ARB_texture_rectangle : enable +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -/*[EXTRA_CODE_HERE]*/ - uniform sampler2D glowMap; uniform sampler2DRect screenMap; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index aacc503e13..584bd568c5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -31,3 +31,8 @@ vec3 atmosLighting(vec3 light) return light; } + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { + /* stub function for fallback compatibility on class1 hardware */ +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3f70a8935b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,55 @@ +/** + * @file atmosphericsHelpersF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform vec4 sunlight_color; +uniform vec4 light_ambient; + +vec3 atmosAmbient(vec3 light) +{ + return light + light_ambient.rgb; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return sunlight_color.rgb * lightIntensity; +} + +vec3 atmosGetDiffuseSunlightColor() +{ + return sunlight_color.rgb; +} + +vec3 scaleDownLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 scaleUpLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index b9bb522842..864ba4859d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,59 +71,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index cf076d156a..c20092bfe0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -70,69 +70,18 @@ uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -152,243 +101,11 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} #ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} +vec4 applyWaterFogDeferred(vec3 pos, vec4 color); #endif -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - void main() { vec2 tc = vary_fragcoord.xy; @@ -422,8 +139,13 @@ void main() float ambocc = scol_ambocc.g; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmospherics(pos.xyz, ambocc); + calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); col = atmosAmbient(vec3(0)); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); @@ -433,7 +155,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(max(min(da, scol), 0.0)); + col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit); col *= diffuse.rgb; @@ -469,8 +191,8 @@ void main() if (norm.w < 0.5) { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + col = mix(scaleFragSoftClip(col), fullbrightFragScaleSoftClip(col), diffuse.a); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index b2d9de6e73..a7da140b31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,59 +71,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 265da8df99..aa5e99a2f7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -67,22 +67,7 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 5c6fe30daa..58f3f2f91e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -68,22 +68,7 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index fea3cbf69b..fee1a7f311 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -22,23 +22,127 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - - - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -////////////////////////////////////////////////////////// vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; +uniform vec4 gamma; uniform vec4 cloud_pos_density1; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; -vec3 atmosLighting(vec3 light) +vec3 scaleFragSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; +} + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); + light *= atten.r; + light += additive; return (2.0 * light); } +vec3 atmosLighting(vec3 light) +{ + return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + + vec3 P = inPositionEye; + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); + + //brightness of surface both sunlight and ambient + sunlit = vec3(sunlight * .5); + amblit = vec3(tmpAmbient * .25); + additive *= vec3(1.0 - temp1); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3582759e62 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,49 @@ +/** + * @file atmosphericsHelpersV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Output variables + +uniform float scene_light_strength; + +vec3 atmosFragAmbient(vec3 light, vec3 amblit) +{ + return amblit + light / 2.0; +} + +vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) +{ + return sunlit * lightIntensity; +} + +vec3 scaleDownLightFrag(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLightFrag(vec3 light) +{ + return (light * scene_light_strength); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 478373d729..2db633cd01 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -38,7 +38,12 @@ vec3 scaleSoftClip(vec3 light) { return light; } +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +{ + return mix(scaleSoftClip(light.rgb), light.rgb, atten); +} + vec3 fullbrightScaleSoftClip(vec3 light) { - return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); + return fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 8a8e4cb0f6..82e1d7fe35 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -33,21 +33,30 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { + light *= atten.r; + light += additive * 2.0; return light; } -vec3 fullbrightAtmosTransport(vec3 light) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} - return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 atmosTransport(vec3 light) { + return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } +vec3 fullbrightAtmosTransport(vec3 light) { + return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { + return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index d27363a60c..014ab9d11b 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -33,6 +33,7 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_direction; +uniform float sun_size; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; @@ -54,7 +55,7 @@ void main() radiance *= transmittance; // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size.y) + if (dot(view_direction, sun_direction) >= sun_size) { radiance = radiance + transmittance * GetSolarLuminance(); } diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl new file mode 100644 index 0000000000..fee1a7f311 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -0,0 +1,148 @@ +/** + * @file atmosphericsF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); + +uniform sampler2D cloudMap; +uniform vec4 gamma; +uniform vec4 cloud_pos_density1; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; + +vec3 scaleFragSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; +} + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +{ + light *= atten.r; + light += additive; + return (2.0 * light); +} + +vec3 atmosLighting(vec3 light) +{ + return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + + vec3 P = inPositionEye; + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); + + //brightness of surface both sunlight and ambient + sunlit = vec3(sunlight * .5); + amblit = vec3(tmpAmbient * .25); + additive *= vec3(1.0 - temp1); +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl new file mode 100644 index 0000000000..3270c243a4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -0,0 +1,133 @@ +/** + * @file atmosphericsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// VARYING param funcs +void setSunlitColor(vec3 v); +void setAmblitColor(vec3 v); +void setAdditiveColor(vec3 v); +void setAtmosAttenuation(vec3 v); +void setPositionEye(vec3 v); + +vec3 getAdditiveColor(); + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; + +void calcAtmospherics(vec3 inPositionEye) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + //tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl index c71eaf4b13..08b6ec3f97 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl @@ -49,16 +49,16 @@ void main() { vec3 view_direction = normalize(view_dir); - vec3 camPos = cameraPosLocal; + vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); vec3 transmittance; vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - radiance *= transmittance; + //radiance *= transmittance; // If the view ray intersects the Sun, add the Sun radiance. if (dot(view_direction, sun_direction) >= sun_size.y) { - radiance = radiance + transmittance * GetSolarLuminance(); + radiance = radiance + (transmittance * GetSolarLuminance()); } vec3 color = vec3(1.0) - exp(-radiance); diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 8a8e4cb0f6..82e1d7fe35 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -33,21 +33,30 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { + light *= atten.r; + light += additive * 2.0; return light; } -vec3 fullbrightAtmosTransport(vec3 light) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} - return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 atmosTransport(vec3 light) { + return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } +vec3 fullbrightAtmosTransport(vec3 light) { + return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { + return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 567172e647..493c619a99 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -488,22 +488,21 @@ void LLDrawPoolWater::shade() LLVector3 light_dir; LLColor3 light_color; - LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); - light_dir = psky->getLightDirection(); + light_dir = voskyp->getLightDirection(); if (LLEnvironment::instance().getIsDayTime()) { - light_color = psky->getSunAmbient(); - light_diffuse = psky->getSunDiffuse(); + light_color = voskyp->getSunAmbientColor(); + light_diffuse = voskyp->getSunDiffuseColor(); light_diffuse.normalize(); light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0.f); light_diffuse *= (light_exp + 0.25f); } else { - light_color = psky->getMoonAmbient(); - light_diffuse = psky->getMoonDiffuse(); + light_color = voskyp->getMoonAmbientColor(); + light_diffuse = voskyp->getMoonDiffuseColor(); light_diffuse.normalize(); light_diffuse *= 0.5f; light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0.f); @@ -609,8 +608,8 @@ void LLDrawPoolWater::shade() if (screentex > -1) { - shader->uniform3fv(LLShaderMgr::WATER_FOGCOLOR, 1, pwater->getFogColor().mV); - shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, pwater->getFogDensity()); + shader->uniform3fv(LLShaderMgr::WATER_FOGCOLOR, 1, pwater->getWaterFogColor().mV); + shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, pwater->getWaterFogDensity()); gPipeline.mWaterDis.bindTexture(0, screentex); } @@ -620,8 +619,8 @@ void LLDrawPoolWater::shade() if (mVertexShaderLevel == 1) { - LLColor4 fog_color(pwater->getFogColor(), 0.f); - fog_color[3] = pwater->getFogDensity(); + LLColor4 fog_color(pwater->getWaterFogColor(), 0.f); + fog_color[3] = pwater->getWaterFogDensity(); shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, fog_color.mV); } diff --git a/indra/newview/llenvadapters.cpp b/indra/newview/llenvadapters.cpp index 57c7a75d52..fdbcf68fa4 100644 --- a/indra/newview/llenvadapters.cpp +++ b/indra/newview/llenvadapters.cpp @@ -33,16 +33,6 @@ LLSkySettingsAdapter::LLSkySettingsAdapter(): mWLGamma(1.0f, LLSettingsSky::SETTING_GAMMA), - -// LEGACY_ATMOSPHERICS - mAmbient(LLColor4(0.5f, 0.75f, 1.0f, 1.19f), LLSettingsSky::SETTING_AMBIENT, "WLAmbient"), - mBlueHorizon(LLColor4(0.25f, 0.25f, 1.0f, 1.0f), LLSettingsSky::SETTING_BLUE_HORIZON, "WLBlueHorizon"), - mBlueDensity(LLColor4(0.25f, 0.25f, 0.25f, 1.0f), LLSettingsSky::SETTING_BLUE_DENSITY, "WLBlueDensity"), - mHazeDensity(1.0f, LLSettingsSky::SETTING_HAZE_DENSITY), - mHazeHorizon(1.0f, LLSettingsSky::SETTING_HAZE_HORIZON), - mDensityMult(1.0f, LLSettingsSky::SETTING_DENSITY_MULTIPLIER, 1000), - mDistanceMult(1.0f, LLSettingsSky::SETTING_DISTANCE_MULTIPLIER), - mMaxAlt(4000.0f, LLSettingsSky::SETTING_MAX_Y), // Lighting mLightnorm(LLColor4(0.f, 0.707f, -0.707f, 1.f), LLSettingsSky::SETTING_LIGHT_NORMAL), diff --git a/indra/newview/llenvadapters.h b/indra/newview/llenvadapters.h index c53423c5ae..bd58db0589 100644 --- a/indra/newview/llenvadapters.h +++ b/indra/newview/llenvadapters.h @@ -418,17 +418,6 @@ public: WLFloatControl mWLGamma; - /// Atmospherics -// LEGACY_ATMOSPHERICS - WLColorControl mAmbient; - WLColorControl mBlueHorizon; - WLFloatControl mHazeDensity; - WLColorControl mBlueDensity; - WLFloatControl mDensityMult; - WLFloatControl mDistanceMult; - WLFloatControl mHazeHorizon; - WLFloatControl mMaxAlt; - /// Lighting WLColorControl mLightnorm; WLColorControl mSunlight; diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp index c5a1af8747..a795628e8f 100644 --- a/indra/newview/llenvironment.cpp +++ b/indra/newview/llenvironment.cpp @@ -54,6 +54,8 @@ #include <boost/make_shared.hpp> +#include "llatmosphere.h" + //define EXPORT_PRESETS 1 //========================================================================= namespace @@ -135,6 +137,55 @@ bool LLEnvironment::canEdit() const return true; } +void LLEnvironment::getAtmosphericModelSettings(AtmosphericModelSettings& settingsOut, const LLSettingsSky::ptr_t &psky) +{ + settingsOut.m_skyBottomRadius = psky->getSkyBottomRadius(); + settingsOut.m_skyTopRadius = psky->getSkyTopRadius(); + settingsOut.m_sunArcRadians = psky->getSunArcRadians(); + settingsOut.m_mieAnisotropy = psky->getMieAnisotropy(); + + LLSD rayleigh = psky->getRayleighConfigs(); + settingsOut.m_rayleighProfile.clear(); + for (LLSD::array_iterator itf = rayleigh.beginArray(); itf != rayleigh.endArray(); ++itf) + { + atmosphere::DensityProfileLayer layer; + LLSD& layerConfig = (*itf); + layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal(); + layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal(); + layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal(); + layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal(); + layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal(); + settingsOut.m_rayleighProfile.push_back(layer); + } + + LLSD mie = psky->getMieConfigs(); + settingsOut.m_mieProfile.clear(); + for (LLSD::array_iterator itf = mie.beginArray(); itf != mie.endArray(); ++itf) + { + atmosphere::DensityProfileLayer layer; + LLSD& layerConfig = (*itf); + layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal(); + layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal(); + layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal(); + layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal(); + layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal(); + settingsOut.m_mieProfile.push_back(layer); + } + + LLSD absorption = psky->getAbsorptionConfigs(); + settingsOut.m_absorptionProfile.clear(); + for (LLSD::array_iterator itf = absorption.beginArray(); itf != absorption.endArray(); ++itf) + { + atmosphere::DensityProfileLayer layer; + LLSD& layerConfig = (*itf); + layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal(); + layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal(); + layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal(); + layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal(); + layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal(); + settingsOut.m_absorptionProfile.push_back(layer); + } +} LLEnvironment::connection_t LLEnvironment::setSkyListChange(const LLEnvironment::change_signal_t::slot_type& cb) { @@ -440,12 +491,24 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS LLSettingsBase::parammapping_t params = psetting->getParameterMap(); for (auto &it: params) { - if (!psetting->mSettings.has(it.first)) + LLSD value; + + bool found_in_settings = psetting->mSettings.has(it.first); + bool found_in_legacy_settings = !found_in_settings && psetting->mSettings.has(LLSettingsSky::SETTING_LEGACY_HAZE) && psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE].has(it.first); + + if (!found_in_settings && !found_in_legacy_settings) continue; - LLSD value = psetting->mSettings[it.first]; - LLSD::Type setting_type = value.type(); + if (found_in_settings) + { + value = psetting->mSettings[it.first]; + } + else if (found_in_legacy_settings) + { + value = psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE][it.first]; + } + LLSD::Type setting_type = value.type(); stop_glerror(); switch (setting_type) { @@ -1314,6 +1377,7 @@ void LLEnvironment::DayInstance::setDay(const LLSettingsDay::ptr_t &pday, S64Sec } + void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky) { if (mType == TYPE_CYCLED) @@ -1323,6 +1387,13 @@ void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky) mSky = psky; mBlenderSky.reset(); + + if (gAtmosphere) + { + AtmosphericModelSettings settings; + LLEnvironment::getAtmosphericModelSettings(settings, psky); + gAtmosphere->configureAtmosphericModel(settings); + } } void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater) diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h index a7159ca84d..55ade803ac 100644 --- a/indra/newview/llenvironment.h +++ b/indra/newview/llenvironment.h @@ -41,6 +41,7 @@ //------------------------------------------------------------------------- class LLViewerCamera; class LLGLSLShader; +class AtmosphericModelSettings; //------------------------------------------------------------------------- class LLEnvironment : public LLSingleton<LLEnvironment> @@ -137,6 +138,8 @@ public: LLSettingsSky::ptr_t getCurrentSky() const { return mCurrentEnvironment->getSky(); } LLSettingsWater::ptr_t getCurrentWater() const { return mCurrentEnvironment->getWater(); } + static void getAtmosphericModelSettings(AtmosphericModelSettings& settingsOut, const LLSettingsSky::ptr_t &psky); + void update(const LLViewerCamera * cam); void updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting); diff --git a/indra/newview/llfloatereditsky.cpp b/indra/newview/llfloatereditsky.cpp index 763f9e4d5a..6bdc5ee823 100644 --- a/indra/newview/llfloatereditsky.cpp +++ b/indra/newview/llfloatereditsky.cpp @@ -151,22 +151,6 @@ void LLFloaterEditSky::initCallbacks(void) // Connect to region info updates. LLRegionInfoModel::instance().setUpdateCallback(boost::bind(&LLFloaterEditSky::onRegionInfoUpdate, this)); - //------------------------------------------------------------------------- -// LEGACY_ATMOSPHERICS - // ambient - getChild<LLUICtrl>("WLAmbient")->setCommitCallback(boost::bind(&LLFloaterEditSky::onColorControlMoved, this, _1, &mSkyAdapter->mAmbient)); - - // blue horizon/density - getChild<LLUICtrl>("WLBlueHorizon")->setCommitCallback(boost::bind(&LLFloaterEditSky::onColorControlMoved, this, _1, &mSkyAdapter->mBlueHorizon)); - getChild<LLUICtrl>("WLBlueDensity")->setCommitCallback(boost::bind(&LLFloaterEditSky::onColorControlMoved, this, _1, &mSkyAdapter->mBlueDensity)); - - // haze density, horizon, mult, and altitude - getChild<LLUICtrl>("WLHazeDensity")->setCommitCallback(boost::bind(&LLFloaterEditSky::onFloatControlMoved, this, _1, &mSkyAdapter->mHazeDensity)); - getChild<LLUICtrl>("WLHazeHorizon")->setCommitCallback(boost::bind(&LLFloaterEditSky::onFloatControlMoved, this, _1, &mSkyAdapter->mHazeHorizon)); - getChild<LLUICtrl>("WLDensityMult")->setCommitCallback(boost::bind(&LLFloaterEditSky::onFloatControlMoved, this, _1, &mSkyAdapter->mDensityMult)); - getChild<LLUICtrl>("WLDistanceMult")->setCommitCallback(boost::bind(&LLFloaterEditSky::onFloatControlMoved, this, _1, &mSkyAdapter->mDistanceMult)); - getChild<LLUICtrl>("WLMaxAltitude")->setCommitCallback(boost::bind(&LLFloaterEditSky::onFloatControlMoved, this, _1, &mSkyAdapter->mMaxAlt)); - // sunlight getChild<LLUICtrl>("WLSunlight")->setCommitCallback(boost::bind(&LLFloaterEditSky::onColorControlMoved, this, _1, &mSkyAdapter->mSunlight)); @@ -220,29 +204,6 @@ void LLFloaterEditSky::syncControls() mSkyPresetNameEditor->setText(name); mSkyPresetCombo->setValue(name); -// LEGACY_ATMOSPHERICS - // ambient - mSkyAdapter->mAmbient.setColor3( psky->getAmbientColor() ); - setColorSwatch("WLAmbient", mSkyAdapter->mAmbient, WL_SUN_AMBIENT_SLIDER_SCALE); - - // blue horizon / density - mSkyAdapter->mBlueHorizon.setColor3( psky->getBlueHorizon() ); - setColorSwatch("WLBlueHorizon", mSkyAdapter->mBlueHorizon, WL_BLUE_HORIZON_DENSITY_SCALE); - mSkyAdapter->mBlueDensity.setColor3( psky->getBlueDensity() ); - setColorSwatch("WLBlueDensity", mSkyAdapter->mBlueDensity, WL_BLUE_HORIZON_DENSITY_SCALE); - - // haze density, horizon, mult, and altitude - mSkyAdapter->mHazeDensity = psky->getHazeDensity(); - childSetValue("WLHazeDensity", (F32) mSkyAdapter->mHazeDensity); - mSkyAdapter->mHazeHorizon = psky->getHazeHorizon(); - childSetValue("WLHazeHorizon", (F32) mSkyAdapter->mHazeHorizon); - mSkyAdapter->mDensityMult = psky->getDensityMultiplier(); - childSetValue("WLDensityMult", ((F32) mSkyAdapter->mDensityMult) * mSkyAdapter->mDensityMult.getMult()); - mSkyAdapter->mMaxAlt = psky->getMaxY(); - mSkyAdapter->mDistanceMult = psky->getDistanceMultiplier(); - childSetValue("WLDistanceMult", (F32) mSkyAdapter->mDistanceMult); - childSetValue("WLMaxAltitude", (F32) mSkyAdapter->mMaxAlt); - // Lighting // sunlight @@ -254,9 +215,7 @@ void LLFloaterEditSky::syncControls() childSetValue("WLGlowR", 2 - mSkyAdapter->mGlow.getRed() / 20.0f); childSetValue("WLGlowB", -mSkyAdapter->mGlow.getBlue() / 5.0f); - - -// LLSettingsSky::azimalt_t azal = psky->getSunRotationAzAl(); +// LLSettingsSky::azimalt_t azal = psky->getSunRotationAzAl(); // // F32 time24 = sun_pos_to_time24(azal.second / F_TWO_PI); // getChild<LLMultiSliderCtrl>("WLSunPos")->setCurSliderValue(time24, TRUE); diff --git a/indra/newview/llfloatereditwater.cpp b/indra/newview/llfloatereditwater.cpp index 4d8ffdef21..6e7b777e70 100644 --- a/indra/newview/llfloatereditwater.cpp +++ b/indra/newview/llfloatereditwater.cpp @@ -184,10 +184,10 @@ void LLFloaterEditWater::syncControls() mWaterPresetCombo->setValue(name); //getChild<LLUICtrl>("WaterGlow")->setValue(col.mV[3]); - getChild<LLColorSwatchCtrl>("WaterFogColor")->set(LLColor4(pwater->getFogColor())); + getChild<LLColorSwatchCtrl>("WaterFogColor")->set(LLColor4(pwater->getWaterFogColor())); // fog and wavelets - mWaterAdapter->mFogDensity = pwater->getFogDensity(); + mWaterAdapter->mFogDensity = pwater->getWaterFogDensity(); getChild<LLUICtrl>("WaterFogDensity")->setValue(mWaterAdapter->mFogDensity.getExp()); mWaterAdapter->mUnderWaterFogMod = pwater->getFogMod(); diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp new file mode 100644 index 0000000000..ff09e62f76 --- /dev/null +++ b/indra/newview/lllegacyatmospherics.cpp @@ -0,0 +1,643 @@ +/** + * @file lllegacyatmospherics.cpp + * @brief LLAtmospherics class implementation + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "lllegacyatmospherics.h" + +#include "llfeaturemanager.h" +#include "llviewercontrol.h" +#include "llframetimer.h" + +#include "llagent.h" +#include "llagentcamera.h" +#include "lldrawable.h" +#include "llface.h" +#include "llglheaders.h" +#include "llsky.h" +#include "llviewercamera.h" +#include "llviewertexturelist.h" +#include "llviewerobjectlist.h" +#include "llviewerregion.h" +#include "llworld.h" +#include "pipeline.h" +#include "v3colorutil.h" + +#include "llsettingssky.h" +#include "llenvironment.h" +#include "lldrawpoolwater.h" + +class LLFastLn +{ +public: + LLFastLn() + { + mTable[0] = 0; + for( S32 i = 1; i < 257; i++ ) + { + mTable[i] = log((F32)i); + } + } + + F32 ln( F32 x ) + { + const F32 OO_255 = 0.003921568627450980392156862745098f; + const F32 LN_255 = 5.5412635451584261462455391880218f; + + if( x < OO_255 ) + { + return log(x); + } + else + if( x < 1 ) + { + x *= 255.f; + S32 index = llfloor(x); + F32 t = x - index; + F32 low = mTable[index]; + F32 high = mTable[index + 1]; + return low + t * (high - low) - LN_255; + } + else + if( x <= 255 ) + { + S32 index = llfloor(x); + F32 t = x - index; + F32 low = mTable[index]; + F32 high = mTable[index + 1]; + return low + t * (high - low); + } + else + { + return log( x ); + } + } + + F32 pow( F32 x, F32 y ) + { + return (F32)LL_FAST_EXP(y * ln(x)); + } + + +private: + F32 mTable[257]; // index 0 is unused +}; + +static LLFastLn gFastLn; + + +// Functions used a lot. + +inline F32 LLHaze::calcPhase(const F32 cos_theta) const +{ + const F32 g2 = mG * mG; + const F32 den = 1 + g2 - 2 * mG * cos_theta; + return (1 - g2) * gFastLn.pow(den, -1.5); +} + +inline void color_pow(LLColor3 &col, const F32 e) +{ + col.mV[0] = gFastLn.pow(col.mV[0], e); + col.mV[1] = gFastLn.pow(col.mV[1], e); + col.mV[2] = gFastLn.pow(col.mV[2], e); +} + +inline LLColor3 color_norm(const LLColor3 &col) +{ + const F32 m = color_max(col); + if (m > 1.f) + { + return 1.f/m * col; + } + else return col; +} + +inline void color_gamma_correct(LLColor3 &col) +{ + const F32 gamma_inv = 1.f/1.2f; + if (col.mV[0] != 0.f) + { + col.mV[0] = gFastLn.pow(col.mV[0], gamma_inv); + } + if (col.mV[1] != 0.f) + { + col.mV[1] = gFastLn.pow(col.mV[1], gamma_inv); + } + if (col.mV[2] != 0.f) + { + col.mV[2] = gFastLn.pow(col.mV[2], gamma_inv); + } +} + +static LLColor3 calc_air_sca_sea_level() +{ + static LLColor3 WAVE_LEN(675, 520, 445); + static LLColor3 refr_ind = refr_ind_calc(WAVE_LEN); + static LLColor3 n21 = refr_ind * refr_ind - LLColor3(1, 1, 1); + static LLColor3 n4 = n21 * n21; + static LLColor3 wl2 = WAVE_LEN * WAVE_LEN * 1e-6f; + static LLColor3 wl4 = wl2 * wl2; + static LLColor3 mult_const = fsigma * 2.0f/ 3.0f * 1e24f * (F_PI * F_PI) * n4; + static F32 dens_div_N = F32( ATM_SEA_LEVEL_NDENS / Ndens2); + return dens_div_N * mult_const.divide(wl4); +} + +// static constants. +LLColor3 const LLHaze::sAirScaSeaLevel = calc_air_sca_sea_level(); +F32 const LLHaze::sAirScaIntense = color_intens(LLHaze::sAirScaSeaLevel); +F32 const LLHaze::sAirScaAvg = LLHaze::sAirScaIntense / 3.f; + +/*************************************** + Atmospherics +***************************************/ + +LLAtmospherics::LLAtmospherics() +: mCloudDensity(0.2f), + mWind(0.f), + mWorldScale(1.f) +{ + /// WL PARAMS + mInitialized = FALSE; + mUpdateTimer.reset(); + mAmbientScale = gSavedSettings.getF32("SkyAmbientScale"); + mNightColorShift = gSavedSettings.getColor3("SkyNightColorShift"); + mFogColor.mV[VRED] = mFogColor.mV[VGREEN] = mFogColor.mV[VBLUE] = 0.5f; + mFogColor.mV[VALPHA] = 0.0f; + mFogRatio = 1.2f; + mHazeConcentration = 0.f; + mInterpVal = 0.f; +} + + +LLAtmospherics::~LLAtmospherics() +{ +} + +void LLAtmospherics::init() +{ + const F32 haze_int = color_intens(mHaze.calcSigSca(0)); + mHazeConcentration = haze_int / (color_intens(mHaze.calcAirSca(0)) + haze_int); + mInitialized = true; +} + +LLColor4 LLAtmospherics::calcSkyColorInDir(const LLVector3 &dir, bool isShiny) +{ + F32 saturation = 0.3f; + if (dir.mV[VZ] < -0.02f) + { + LLColor4 col = LLColor4(llmax(mFogColor[0],0.2f), llmax(mFogColor[1],0.2f), llmax(mFogColor[2],0.22f),0.f); + if (isShiny) + { + LLColor3 desat_fog = LLColor3(mFogColor); + F32 brightness = desat_fog.brightness(); + // So that shiny somewhat shows up at night. + if (brightness < 0.15f) + { + brightness = 0.15f; + desat_fog = smear(0.15f); + } + LLColor3 greyscale = smear(brightness); + desat_fog = desat_fog * saturation + greyscale * (1.0f - saturation); + if (!gPipeline.canUseWindLightShaders()) + { + col = LLColor4(desat_fog, 0.f); + } + else + { + col = LLColor4(desat_fog * 0.5f, 0.f); + } + } + float x = 1.0f-fabsf(-0.1f-dir.mV[VZ]); + x *= x; + col.mV[0] *= x*x; + col.mV[1] *= powf(x, 2.5f); + col.mV[2] *= x*x*x; + return col; + } + + // undo OGL_TO_CFR_ROTATION and negate vertical direction. + LLVector3 Pn = LLVector3(-dir[1] , -dir[2], -dir[0]); + + AtmosphericsVars vars; + calcSkyColorWLVert(Pn, vars); + + LLColor3 sky_color = calcSkyColorWLFrag(Pn, vars); + if (isShiny) + { + F32 brightness = sky_color.brightness(); + LLColor3 greyscale = smear(brightness); + sky_color = sky_color * saturation + greyscale * (1.0f - saturation); + sky_color *= (0.5f + 0.5f * brightness); + } + return LLColor4(sky_color, 0.0f); +} + +void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) +{ +// LEGACY_ATMOSPHERICS + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + LLColor3 blue_density = psky->getBlueDensity(); + LLColor3 blue_horizon = psky->getBlueHorizon(); + F32 haze_density = psky->getHazeDensity(); + F32 haze_horizon = psky->getHazeHorizon(); + F32 density_multiplier = psky->getDensityMultiplier(); + + F32 max_y = psky->getMaxY(); + LLVector3 lightnorm = psky->getLightNormal(); + + // project the direction ray onto the sky dome. + F32 phi = acos(Pn[1]); + F32 sinA = sin(F_PI - phi); + if (fabsf(sinA) < 0.01f) + { //avoid division by zero + sinA = 0.01f; + } + + F32 Plen = psky->getDomeRadius() * sin(F_PI + phi + asin(psky->getDomeOffset() * sinA)) / sinA; + + Pn *= Plen; + + vars.horizontalProjection[0] = LLVector2(Pn[0], Pn[2]); + vars.horizontalProjection[0] /= - 2.f * Plen; + + // Set altitude + if (Pn[1] > 0.f) + { + Pn *= (max_y / Pn[1]); + } + else + { + Pn *= (-32000.f / Pn[1]); + } + + Plen = Pn.length(); + Pn /= Plen; + + // Initialize temp variables + LLColor3 sunlight = psky->getSunlightColor(); + LLColor3 ambient = psky->getAmbientColor(); + + LLColor3 glow = psky->getGlow(); + F32 cloud_shadow = psky->getCloudShadow(); + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + LLColor3 light_atten = psky->getLightAttenuation(psky->getMaxY()); + + // Calculate relative weights + LLColor3 temp2(0.f, 0.f, 0.f); + LLColor3 temp1 = psky->getLightTransmittance(); + + LLColor3 blue_weight = componentDiv(blue_density, temp1); + LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); + + temp2.mV[1] = 1.f / temp2.mV[1]; + componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + + // Distance + temp2.mV[2] = Plen * density_multiplier; + + // Transparency (-> temp1) + temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); + + + // Compute haze glow + temp2.mV[0] = Pn * lightnorm; + + temp2.mV[0] = 1.f - temp2.mV[0]; + // temp2.x is 0 at the sun and increases away from sun + temp2.mV[0] = llmax(temp2.mV[0], .001f); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.mV[0] *= glow.mV[0]; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.mV[0] = pow(temp2.mV[0], glow.mV[2]); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.mV[0] += .25f; + + + // Haze color above cloud + vars.hazeColor = (blue_horizon * blue_weight * (sunlight + ambient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + ambient)); + + // Increase ambient when there are more clouds + LLColor3 tmpAmbient = ambient + (LLColor3::white - ambient) * cloud_shadow * 0.5f; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1.f - cloud_shadow); + + // Haze color below cloud + vars.hazeColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + tmpAmbient)); + + // Final atmosphere additive + componentMultBy(vars.hazeColor, LLColor3::white - temp1); + + sunlight = psky->getSunlightColor(); + temp2.mV[1] = llmax(0.f, lightnorm[1] * 2.f); + temp2.mV[1] = 1.f / temp2.mV[1]; + componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + + // Attenuate cloud color by atmosphere + temp1 = componentSqrt(temp1); //less atmos opacity (more transparency) below clouds + + // At horizon, blend high altitude sky color towards the darker color below the clouds + vars.hazeColor += componentMult(vars.hazeColorBelowCloud - vars.hazeColor, LLColor3::white - componentSqrt(temp1)); + + if (Pn[1] < 0.f) + { + // Eric's original: + // LLColor3 dark_brown(0.143f, 0.129f, 0.114f); + LLColor3 dark_brown(0.082f, 0.076f, 0.066f); + LLColor3 brown(0.430f, 0.386f, 0.322f); + LLColor3 sky_lighting = sunlight + ambient; + F32 haze_brightness = vars.hazeColor.brightness(); + + if (Pn[1] < -0.05f) + { + vars.hazeColor = colorMix(dark_brown, brown, -Pn[1] * 0.9f) * sky_lighting * haze_brightness; + } + + if (Pn[1] > -0.1f) + { + vars.hazeColor = colorMix(LLColor3::white * haze_brightness, vars.hazeColor, fabs((Pn[1] + 0.05f) * -20.f)); + } + } +} + +LLColor3 LLAtmospherics::calcSkyColorWLFrag(LLVector3 & Pn, AtmosphericsVars& vars) +{ + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + + LLColor3 res; + LLColor3 color0 = vars.hazeColor; + + if (!gPipeline.canUseWindLightShaders()) + { + res = psky->gammaCorrect(color0 * 2.0f); + } + else + { + res = color0; + } + +#ifndef LL_RELEASE_FOR_DOWNLOAD + F32 gamma = psky->getGamma(); + LLColor3 color2 = 2.f * color0; + LLColor3 color3 = LLColor3(1.f, 1.f, 1.f) - componentSaturate(color2); + componentPow(color3, gamma); + color3 = LLColor3(1.f, 1.f, 1.f) - color3; + + static enum { + OUT_DEFAULT = 0, + OUT_SKY_BLUE = 1, + OUT_RED = 2, + OUT_PN = 3, + OUT_HAZE = 4, + } debugOut = OUT_DEFAULT; + + switch(debugOut) + { + case OUT_DEFAULT: + break; + case OUT_SKY_BLUE: + res = LLColor3(0.4f, 0.4f, 0.9f); + break; + case OUT_RED: + res = LLColor3(1.f, 0.f, 0.f); + break; + case OUT_PN: + res = LLColor3(Pn[0], Pn[1], Pn[2]); + break; + case OUT_HAZE: + res = vars.hazeColor; + break; + } +#endif // LL_RELEASE_FOR_DOWNLOAD + return res; +} + +void LLAtmospherics::updateFog(const F32 distance, LLVector3& tosun) +{ + if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOG)) + { + if (!LLGLSLShader::sNoFixedFunction) + { + glFogf(GL_FOG_DENSITY, 0); + glFogfv(GL_FOG_COLOR, (F32 *) &LLColor4::white.mV); + glFogf(GL_FOG_END, 1000000.f); + } + return; + } + + const BOOL hide_clip_plane = TRUE; + LLColor4 target_fog(0.f, 0.2f, 0.5f, 0.f); + + const F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : 0.f; + // LLWorld::getInstance()->getWaterHeight(); + F32 camera_height = gAgentCamera.getCameraPositionAgent().mV[2]; + + F32 near_clip_height = LLViewerCamera::getInstance()->getAtAxis().mV[VZ] * LLViewerCamera::getInstance()->getNear(); + camera_height += near_clip_height; + + F32 fog_distance = 0.f; + LLColor3 res_color[3]; + + LLColor3 sky_fog_color = LLColor3::white; + LLColor3 render_fog_color = LLColor3::white; + + const F32 tosun_z = tosun.mV[VZ]; + tosun.mV[VZ] = 0.f; + tosun.normalize(); + LLVector3 perp_tosun; + perp_tosun.mV[VX] = -tosun.mV[VY]; + perp_tosun.mV[VY] = tosun.mV[VX]; + LLVector3 tosun_45 = tosun + perp_tosun; + tosun_45.normalize(); + + F32 delta = 0.06f; + tosun.mV[VZ] = delta; + perp_tosun.mV[VZ] = delta; + tosun_45.mV[VZ] = delta; + tosun.normalize(); + perp_tosun.normalize(); + tosun_45.normalize(); + + // Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun. + res_color[0] = calcSkyColorInDir(tosun); + res_color[1] = calcSkyColorInDir(perp_tosun); + res_color[2] = calcSkyColorInDir(tosun_45); + + sky_fog_color = color_norm(res_color[0] + res_color[1] + res_color[2]); + + F32 full_off = -0.25f; + F32 full_on = 0.00f; + F32 on = (tosun_z - full_off) / (full_on - full_off); + on = llclamp(on, 0.01f, 1.f); + sky_fog_color *= 0.5f * on; + + + // We need to clamp these to non-zero, in order for the gamma correction to work. 0^y = ??? + S32 i; + for (i = 0; i < 3; i++) + { + sky_fog_color.mV[i] = llmax(0.0001f, sky_fog_color.mV[i]); + } + + color_gamma_correct(sky_fog_color); + + render_fog_color = sky_fog_color; + + F32 fog_density = 0.f; + fog_distance = mFogRatio * distance; + + if (camera_height > water_height) + { + LLColor4 fog(render_fog_color); + if (!LLGLSLShader::sNoFixedFunction) + { + glFogfv(GL_FOG_COLOR, fog.mV); + } + mGLFogCol = fog; + + if (hide_clip_plane) + { + // For now, set the density to extend to the cull distance. + const F32 f_log = 2.14596602628934723963618357029f; // sqrt(fabs(log(0.01f))) + fog_density = f_log/fog_distance; + if (!LLGLSLShader::sNoFixedFunction) + { + glFogi(GL_FOG_MODE, GL_EXP2); + } + } + else + { + const F32 f_log = 4.6051701859880913680359829093687f; // fabs(log(0.01f)) + fog_density = (f_log)/fog_distance; + if (!LLGLSLShader::sNoFixedFunction) + { + glFogi(GL_FOG_MODE, GL_EXP); + } + } + } + else + { + LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); + F32 depth = water_height - camera_height; + + // get the water param manager variables + float water_fog_density = pwater->getWaterFogDensity(); + LLColor4 water_fog_color(pwater->getWaterFogColor()); + + // adjust the color based on depth. We're doing linear approximations + float depth_scale = gSavedSettings.getF32("WaterGLFogDepthScale"); + float depth_modifier = 1.0f - llmin(llmax(depth / depth_scale, 0.01f), + gSavedSettings.getF32("WaterGLFogDepthFloor")); + + LLColor4 fogCol = water_fog_color * depth_modifier; + fogCol.setAlpha(1); + + // set the gl fog color + mGLFogCol = fogCol; + + // set the density based on what the shaders use + fog_density = water_fog_density * gSavedSettings.getF32("WaterGLFogDensityScale"); + + if (!LLGLSLShader::sNoFixedFunction) + { + glFogfv(GL_FOG_COLOR, (F32 *) &fogCol.mV); + glFogi(GL_FOG_MODE, GL_EXP2); + } + } + + mFogColor = sky_fog_color; + mFogColor.setAlpha(1); + + LLDrawPoolWater::sWaterFogEnd = fog_distance*2.2f; + + if (!LLGLSLShader::sNoFixedFunction) + { + LLGLSFog gls_fog; + glFogf(GL_FOG_END, fog_distance*2.2f); + glFogf(GL_FOG_DENSITY, fog_density); + glHint(GL_FOG_HINT, GL_NICEST); + } + stop_glerror(); +} + +// Functions used a lot. +F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply) +{ + F32 mv = color_max(col); + if (0 == mv) + { + return 0; + } + + col *= 1.f / mv; + color_pow(col, e); + if (postmultiply) + { + col *= mv; + } + return mv; +} + +// Returns angle (RADIANs) between the horizontal projection of "v" and the x_axis. +// Range of output is 0.0f to 2pi //359.99999...f +// Returns 0.0f when "v" = +/- z_axis. +F32 azimuth(const LLVector3 &v) +{ + F32 azimuth = 0.0f; + if (v.mV[VX] == 0.0f) + { + if (v.mV[VY] > 0.0f) + { + azimuth = F_PI * 0.5f; + } + else if (v.mV[VY] < 0.0f) + { + azimuth = F_PI * 1.5f;// 270.f; + } + } + else + { + azimuth = (F32) atan(v.mV[VY] / v.mV[VX]); + if (v.mV[VX] < 0.0f) + { + azimuth += F_PI; + } + else if (v.mV[VY] < 0.0f) + { + azimuth += F_PI * 2; + } + } + return azimuth; +} diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h new file mode 100644 index 0000000000..5a5b9c0022 --- /dev/null +++ b/indra/newview/lllegacyatmospherics.h @@ -0,0 +1,251 @@ +/** + * @file lllegacyatmospherics.h + * @brief LLVOSky class header file + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLLEGACYATMOSPHERICS_H +#define LL_LLLEGACYATMOSPHERICS_H + +#include "stdtypes.h" +#include "v3color.h" +#include "v4coloru.h" +#include "llviewertexture.h" +#include "llviewerobject.h" +#include "llframetimer.h" +#include "v3colorutil.h" +#include "llsettingssky.h" + +////////////////////////////////// +// +// Lots of constants +// +// Will clean these up at some point... +// + +const F32 HORIZON_DIST = 1024.0f; +const F32 EARTH_RADIUS = 6.4e6f; // exact radius = 6.37 x 10^6 m +const F32 ATM_EXP_FALLOFF = 0.000126f; +const F32 ATM_SEA_LEVEL_NDENS = 2.55e25f; +const F32 ATM_HEIGHT = 100000.f; + +// constants used in calculation of scattering coeff of clear air +const F32 sigma = 0.035f; +const F32 fsigma = (6.f + 3.f * sigma) / (6.f-7.f*sigma); +const F64 Ndens = 2.55e25; +const F64 Ndens2 = Ndens*Ndens; + +class LLFace; +class LLHaze; + +LL_FORCE_INLINE LLColor3 refr_ind_calc(const LLColor3 &wave_length) +{ + LLColor3 refr_ind; + for (S32 i = 0; i < 3; ++i) + { + const F32 wl2 = wave_length.mV[i] * wave_length.mV[i] * 1e-6f; + refr_ind.mV[i] = 6.43e3f + ( 2.95e6f / ( 146.0f - 1.f/wl2 ) ) + ( 2.55e4f / ( 41.0f - 1.f/wl2 ) ); + refr_ind.mV[i] *= 1.0e-8f; + refr_ind.mV[i] += 1.f; + } + return refr_ind; +} + + +class LLHaze +{ +public: + LLHaze() : mG(0), mFalloff(1), mAbsCoef(0.f) {mSigSca.setToBlack();} + LLHaze(const F32 g, const LLColor3& sca, const F32 fo = 2.f) : + mG(g), mSigSca(0.25f/F_PI * sca), mFalloff(fo), mAbsCoef(0.f) + { + mAbsCoef = color_intens(mSigSca) / sAirScaIntense; + } + + LLHaze(const F32 g, const F32 sca, const F32 fo = 2.f) : mG(g), + mSigSca(0.25f/F_PI * LLColor3(sca, sca, sca)), mFalloff(fo) + { + mAbsCoef = 0.01f * sca / sAirScaAvg; + } + +/* Proportion of light that is scattered into 'path' from 'in' over distance dt. */ +/* assumes that vectors 'path' and 'in' are normalized. Scattering coef / 2pi */ + + LL_FORCE_INLINE LLColor3 calcAirSca(const F32 h) + { + return calcFalloff(h) * sAirScaSeaLevel; + } + + LL_FORCE_INLINE void calcAirSca(const F32 h, LLColor3 &result) + { + result = sAirScaSeaLevel; + result *= calcFalloff(h); + } + + F32 getG() const { return mG; } + + void setG(const F32 g) + { + mG = g; + } + + const LLColor3& getSigSca() const // sea level + { + return mSigSca; + } + + void setSigSca(const LLColor3& s) + { + mSigSca = s; + mAbsCoef = 0.01f * color_intens(mSigSca) / sAirScaIntense; + } + + void setSigSca(const F32 s0, const F32 s1, const F32 s2) + { + mSigSca = sAirScaAvg * LLColor3 (s0, s1, s2); + mAbsCoef = 0.01f * (s0 + s1 + s2) / 3; + } + + F32 getFalloff() const + { + return mFalloff; + } + + void setFalloff(const F32 fo) + { + mFalloff = fo; + } + + F32 getAbsCoef() const + { + return mAbsCoef; + } + + inline static F32 calcFalloff(const F32 h) + { + return (h <= 0) ? 1.0f : (F32)LL_FAST_EXP(-ATM_EXP_FALLOFF * h); + } + + inline LLColor3 calcSigSca(const F32 h) const + { + return calcFalloff(h * mFalloff) * mSigSca; + } + + inline void calcSigSca(const F32 h, LLColor3 &result) const + { + result = mSigSca; + result *= calcFalloff(h * mFalloff); + } + + LLColor3 calcSigExt(const F32 h) const + { + return calcFalloff(h * mFalloff) * (1 + mAbsCoef) * mSigSca; + } + + F32 calcPhase(const F32 cos_theta) const; + +private: + static LLColor3 const sAirScaSeaLevel; + static F32 const sAirScaIntense; + static F32 const sAirScaAvg; + +protected: + F32 mG; + LLColor3 mSigSca; + F32 mFalloff; // 1 - slow, >1 - faster + F32 mAbsCoef; +}; + + +class LLCubeMap; + +class AtmosphericsVars +{ +public: + AtmosphericsVars() + : hazeColor(0,0,0) + , hazeColorBelowCloud(0,0,0) + , cloudColorSun(0,0,0) + , cloudColorAmbient(0,0,0) + , cloudDensity(0.0f) + { + horizontalProjection[0] = LLVector2(0,0); + horizontalProjection[1] = LLVector2(0,0); + } + + LLColor3 hazeColor; + LLColor3 hazeColorBelowCloud; + LLColor3 cloudColorSun; + LLColor3 cloudColorAmbient; + F32 cloudDensity; + LLVector2 horizontalProjection[2]; +}; + +class LLAtmospherics +{ +public: + LLAtmospherics(); + ~LLAtmospherics(); + + void init(); + void updateFog(const F32 distance, LLVector3& tosun); + + const LLHaze& getHaze() const { return mHaze; } + LLHaze& getHaze() { return mHaze; } + F32 getHazeConcentration() const { return mHazeConcentration; } + void setHaze(const LLHaze& h) { mHaze = h; } + void setFogRatio(const F32 fog_ratio) { mFogRatio = fog_ratio; } + + F32 getFogRatio() const { return mFogRatio; } + LLColor4 getFogColor() const { return mFogColor; } + LLColor4 getGLFogColor() const { return mGLFogCol; } + + void setCloudDensity(F32 cloud_density) { mCloudDensity = cloud_density; } + void setWind ( const LLVector3& wind ) { mWind = wind.length(); } + + LLColor4 calcSkyColorInDir(const LLVector3& dir, bool isShiny = false); + +protected: + + void calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars); + LLColor3 calcSkyColorWLFrag(LLVector3 & Pn, AtmosphericsVars& vars); + LLColor3 getHazeColor(LLSettingsSky::ptr_t psky, AtmosphericsVars& vars, F32 costheta, F32 cloud_shadow); + + LLHaze mHaze; + F32 mHazeConcentration; + F32 mCloudDensity; + F32 mWind; + BOOL mInitialized; + LLVector3 mLastLightingDirection; + LLColor3 mLastTotalAmbient; + F32 mAmbientScale; + LLColor3 mNightColorShift; + F32 mInterpVal; + LLColor4 mFogColor; + LLColor4 mGLFogCol; + F32 mFogRatio; + F32 mWorldScale; + LLFrameTimer mUpdateTimer; +}; + +#endif diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp index 01d7ab3dcf..e398b4ee46 100644 --- a/indra/newview/llsettingsvo.cpp +++ b/indra/newview/llsettingsvo.cpp @@ -430,23 +430,19 @@ LLSettingsSky::ptr_t LLSettingsVOSky::buildClone() void LLSettingsVOSky::convertAtmosphericsToLegacy(LLSD& legacy, LLSD& settings) { -// LEGACY_ATMOSPHERICS // These will need to be inferred from new settings' density profiles - legacy[SETTING_AMBIENT] = ensureArray4(settings[SETTING_AMBIENT], 1.0f); - legacy[SETTING_BLUE_DENSITY] = ensureArray4(settings[SETTING_BLUE_DENSITY], 1.0); - legacy[SETTING_BLUE_HORIZON] = ensureArray4(settings[SETTING_BLUE_HORIZON], 1.0); - legacy[SETTING_DENSITY_MULTIPLIER] = LLSDArray(settings[SETTING_DENSITY_MULTIPLIER].asReal())(0.0f)(0.0f)(1.0f); - legacy[SETTING_DISTANCE_MULTIPLIER] = LLSDArray(settings[SETTING_DISTANCE_MULTIPLIER].asReal())(0.0f)(0.0f)(1.0f); - legacy[SETTING_HAZE_DENSITY] = LLSDArray(settings[SETTING_HAZE_DENSITY])(0.0f)(0.0f)(1.0f); - legacy[SETTING_HAZE_HORIZON] = LLSDArray(settings[SETTING_HAZE_HORIZON])(0.0f)(0.0f)(1.0f); - - //legacy[SETTING_AMBIENT] = LLColor4::black.getValue(); - //legacy[SETTING_BLUE_DENSITY] = LLColor4(0.2447, 0.4487, 0.7599, 0.0).getValue(); - //legacy[SETTING_BLUE_HORIZON] = LLColor4(0.4954, 0.4954, 0.6399, 0.0).getValue(); - //legacy[SETTING_HAZE_DENSITY] = LLSDArray(0.6999f)(0.0f)(0.0f)(1.0f); - //legacy[SETTING_HAZE_HORIZON] = LLSDArray(0.1899f)(0.0f)(0.0f)(1.0f); - //legacy[SETTING_DENSITY_MULTIPLIER] = LLSDArray(0.0001f)(0.0f)(0.0f)(1.0f);LLSD::Real(0.0001); - //legacy[SETTING_DISTANCE_MULTIPLIER] = LLSDArray(0.8f)(0.0f)(0.0f)(1.0f); + if (settings.has(SETTING_LEGACY_HAZE)) + { + LLSD legacyhaze = settings[SETTING_LEGACY_HAZE]; + + legacy[SETTING_AMBIENT] = ensureArray4(legacyhaze[SETTING_AMBIENT], 1.0f); + legacy[SETTING_BLUE_DENSITY] = ensureArray4(legacyhaze[SETTING_BLUE_DENSITY], 1.0); + legacy[SETTING_BLUE_HORIZON] = ensureArray4(legacyhaze[SETTING_BLUE_HORIZON], 1.0); + legacy[SETTING_DENSITY_MULTIPLIER] = LLSDArray(legacyhaze[SETTING_DENSITY_MULTIPLIER].asReal())(0.0f)(0.0f)(1.0f); + legacy[SETTING_DISTANCE_MULTIPLIER] = LLSDArray(legacyhaze[SETTING_DISTANCE_MULTIPLIER].asReal())(0.0f)(0.0f)(1.0f); + legacy[SETTING_HAZE_DENSITY] = LLSDArray(legacyhaze[SETTING_HAZE_DENSITY])(0.0f)(0.0f)(1.0f); + legacy[SETTING_HAZE_HORIZON] = LLSDArray(legacyhaze[SETTING_HAZE_HORIZON])(0.0f)(0.0f)(1.0f); + } } LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isAdvanced) @@ -515,12 +511,12 @@ LLSettingsSky::parammapping_t LLSettingsVOSky::getParameterMap() const if (param_map.empty()) { -// LEGACY_ATMOSPHERICS - param_map[SETTING_AMBIENT] = LLShaderMgr::AMBIENT; param_map[SETTING_BLUE_DENSITY] = LLShaderMgr::BLUE_DENSITY; param_map[SETTING_BLUE_HORIZON] = LLShaderMgr::BLUE_HORIZON; param_map[SETTING_HAZE_DENSITY] = LLShaderMgr::HAZE_DENSITY; param_map[SETTING_HAZE_HORIZON] = LLShaderMgr::HAZE_HORIZON; + + param_map[SETTING_AMBIENT] = LLShaderMgr::AMBIENT; param_map[SETTING_DENSITY_MULTIPLIER] = LLShaderMgr::DENSITY_MULTIPLIER; param_map[SETTING_DISTANCE_MULTIPLIER] = LLShaderMgr::DISTANCE_MULTIPLIER; diff --git a/indra/newview/llsky.cpp b/indra/newview/llsky.cpp index fb3123fd81..15aebda5ad 100644 --- a/indra/newview/llsky.cpp +++ b/indra/newview/llsky.cpp @@ -377,11 +377,11 @@ void LLSky::setSunPhase(const F32 phase) ////////////////////////////////////////////////////////////////////// -LLColor4 LLSky::getFogColor() const +LLColor4 LLSky::getSkyFogColor() const { if (mVOSkyp) { - return mVOSkyp->getFogColor(); + return mVOSkyp->getSkyFogColor(); } return LLColor4(1.f, 1.f, 1.f, 1.f); diff --git a/indra/newview/llsky.h b/indra/newview/llsky.h index 79549948f6..010cc30d55 100644 --- a/indra/newview/llsky.h +++ b/indra/newview/llsky.h @@ -54,7 +54,7 @@ public: void setSunDirection(const LLVector3 &sun_direction, const LLVector3 &moon_direction); - LLColor4 getFogColor() const; + LLColor4 getSkyFogColor() const; void setCloudDensityAtAgent(F32 cloud_density); void setWind(const LLVector3& wind); diff --git a/indra/newview/lltracker.cpp b/indra/newview/lltracker.cpp index 2ec5c41b88..728d0c9417 100644 --- a/indra/newview/lltracker.cpp +++ b/indra/newview/lltracker.cpp @@ -570,8 +570,8 @@ void LLTracker::renderBeacon(LLVector3d pos_global, color_frac = 1.f - 0.6f*(dist/LLViewerCamera::getInstance()->getFar()); } - LLColor4 fogged_color = color_frac * color + (1 - color_frac)*gSky.getFogColor(); - LLColor4 fogged_color_under = color_frac * color_under + (1 - color_frac) * gSky.getFogColor(); + LLColor4 fogged_color = color_frac * color + (1 - color_frac)*gSky.getSkyFogColor(); + LLColor4 fogged_color_under = color_frac * color_under + (1 - color_frac) * gSky.getSkyFogColor(); F32 FADE_DIST = 3.f; fogged_color.mV[3] = llmax(0.2f, llmin(0.5f,(dist-FADE_DIST)/FADE_DIST)); diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 46a8d75595..950243949f 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -920,7 +920,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) gPipeline.mScreen.bindTarget(); if (LLPipeline::sUnderWaterRender && !gPipeline.canUseWindLightShaders()) { - const LLColor4 &col = LLEnvironment::instance().getCurrentWater()->getFogColor(); + const LLColor4 &col = LLEnvironment::instance().getCurrentWater()->getWaterFogColor(); glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); } gPipeline.mScreen.clear(); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 1c78bf36db..4db039ace3 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -549,27 +549,67 @@ void LLViewerShaderMgr::setShaders() if (loaded) { loaded = loadShadersWater(); + if (loaded) + { + LL_INFOS() << "Loaded water shaders." << LL_ENDL; + } + else + { + LL_WARNS() << "Failed to load water shaders." << LL_ENDL; + } } if (loaded) { loaded = loadShadersWindLight(); + if (loaded) + { + LL_INFOS() << "Loaded windlight shaders." << LL_ENDL; + } + else + { + LL_WARNS() << "Failed to load windlight shaders." << LL_ENDL; + } } if (loaded) { loaded = loadShadersEffects(); + if (loaded) + { + LL_INFOS() << "Loaded effects shaders." << LL_ENDL; + } + else + { + LL_WARNS() << "Failed to load effects shaders." << LL_ENDL; + } } if (loaded) { loaded = loadShadersInterface(); + if (loaded) + { + LL_INFOS() << "Loaded interface shaders." << LL_ENDL; + } + else + { + LL_WARNS() << "Failed to load interface shaders." << LL_ENDL; + } } if (loaded) { loaded = loadTransformShaders(); + if (loaded) + { + LL_INFOS() << "Loaded transform shaders." << LL_ENDL; + } + else + { + LL_WARNS() << "Failed to load transform shaders." << LL_ENDL; + } } if (loaded) @@ -628,6 +668,7 @@ void LLViewerShaderMgr::setShaders() if (gSavedSettings.getBOOL("WindLightUseAtmosShaders")) { //disable windlight and try again gSavedSettings.setBOOL("WindLightUseAtmosShaders", FALSE); + LL_WARNS() << "Falling back to no windlight shaders." << LL_ENDL; reentrance = false; setShaders(); return; @@ -636,6 +677,7 @@ void LLViewerShaderMgr::setShaders() if (gSavedSettings.getBOOL("VertexShaderEnable")) { //disable shaders outright and try again gSavedSettings.setBOOL("VertexShaderEnable", FALSE); + LL_WARNS() << "Falling back to no vertex shaders." << LL_ENDL; reentrance = false; setShaders(); return; @@ -645,6 +687,7 @@ void LLViewerShaderMgr::setShaders() if (loaded && !loadShadersDeferred()) { //everything else succeeded but deferred failed, disable deferred and try again gSavedSettings.setBOOL("RenderDeferred", FALSE); + LL_WARNS() << "Falling back to no deferred shaders." << LL_ENDL; reentrance = false; setShaders(); return; @@ -898,13 +941,17 @@ BOOL LLViewerShaderMgr::loadBasicShaders() ch = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); } - std::vector<S32> index_channels; + std::vector<S32> index_channels; index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsVarsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsVarsWaterF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsHelpersF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/gammaF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT]) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "environment/encodeNormF.glsl", mVertexShaderLevel[SHADER_ENVIRONMENT] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "environment/decodeNormF.glsl", mVertexShaderLevel[SHADER_ENVIRONMENT] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "environment/srgbF.glsl", mVertexShaderLevel[SHADER_ENVIRONMENT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightFullbrightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); @@ -1180,6 +1227,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader"; + gDeferredDiffuseProgram.mFeatures.encodesNormal = true; gDeferredDiffuseProgram.mShaderFiles.clear(); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseIndexedF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1191,6 +1239,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Alpha Mask Shader"; + gDeferredDiffuseAlphaMaskProgram.mFeatures.encodesNormal = true; gDeferredDiffuseAlphaMaskProgram.mShaderFiles.clear(); gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskIndexedF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1202,6 +1251,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredNonIndexedDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask Shader"; + gDeferredNonIndexedDiffuseAlphaMaskProgram.mFeatures.encodesNormal = true; gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.clear(); gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1212,6 +1262,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask Shader"; + gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mFeatures.encodesNormal = true; gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.clear(); gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseNoColorV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskNoColorF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1222,6 +1273,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredNonIndexedDiffuseProgram.mName = "Non Indexed Deferred Diffuse Shader"; + gDeferredNonIndexedDiffuseProgram.mFeatures.encodesNormal = true; gDeferredNonIndexedDiffuseProgram.mShaderFiles.clear(); gDeferredNonIndexedDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredNonIndexedDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1234,6 +1286,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSkinnedDiffuseProgram.mName = "Deferred Skinned Diffuse Shader"; gDeferredSkinnedDiffuseProgram.mFeatures.hasObjectSkinning = true; + gDeferredSkinnedDiffuseProgram.mFeatures.encodesNormal = true; gDeferredSkinnedDiffuseProgram.mShaderFiles.clear(); gDeferredSkinnedDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseSkinnedV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSkinnedDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1245,6 +1298,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSkinnedBumpProgram.mName = "Deferred Skinned Bump Shader"; gDeferredSkinnedBumpProgram.mFeatures.hasObjectSkinning = true; + gDeferredSkinnedBumpProgram.mFeatures.encodesNormal = true; gDeferredSkinnedBumpProgram.mShaderFiles.clear(); gDeferredSkinnedBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpSkinnedV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSkinnedBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1260,6 +1314,14 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.isAlphaLighting = true; gDeferredSkinnedAlphaProgram.mFeatures.disableTextureIndex = true; + gDeferredSkinnedAlphaProgram.mFeatures.hasSrgb = true; + gDeferredSkinnedAlphaProgram.mFeatures.decodesNormal = true; + gDeferredSkinnedAlphaProgram.mFeatures.encodesNormal = true; + gDeferredSkinnedAlphaProgram.mFeatures.calculatesAtmospherics = true; + gDeferredSkinnedAlphaProgram.mFeatures.hasAtmospherics = true; + gDeferredSkinnedAlphaProgram.mFeatures.hasTransport = true; + gDeferredSkinnedAlphaProgram.mFeatures.hasGamma = true; + gDeferredSkinnedAlphaProgram.mShaderFiles.clear(); gDeferredSkinnedAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSkinnedAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1278,6 +1340,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredBumpProgram.mName = "Deferred Bump Shader"; + gDeferredBumpProgram.mFeatures.encodesNormal = true; gDeferredBumpProgram.mShaderFiles.clear(); gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1322,6 +1385,12 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() bool has_skin = i & 0x10; gDeferredMaterialProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); + gDeferredMaterialProgram[i].mFeatures.hasSrgb = true; + gDeferredMaterialProgram[i].mFeatures.decodesNormal = true; + gDeferredMaterialProgram[i].mFeatures.encodesNormal = true; + gDeferredMaterialProgram[i].mFeatures.calculatesAtmospherics = true; + gDeferredMaterialProgram[i].mFeatures.hasAtmospherics = true; + if (has_skin) { gDeferredMaterialProgram[i].mFeatures.hasObjectSkinning = true; @@ -1350,6 +1419,13 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMaterialWaterProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); gDeferredMaterialWaterProgram[i].addPermutation("WATER_FOG","1"); + gDeferredMaterialWaterProgram[i].mFeatures.hasWaterFog = true; + gDeferredMaterialWaterProgram[i].mFeatures.hasSrgb = true; + gDeferredMaterialWaterProgram[i].mFeatures.decodesNormal = true; + gDeferredMaterialWaterProgram[i].mFeatures.encodesNormal = true; + gDeferredMaterialWaterProgram[i].mFeatures.calculatesAtmospherics = true; + gDeferredMaterialWaterProgram[i].mFeatures.hasAtmospherics = true; + if (has_skin) { gDeferredMaterialWaterProgram[i].mFeatures.hasObjectSkinning = true; @@ -1382,6 +1458,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredTreeProgram.mName = "Deferred Tree Shader"; gDeferredTreeProgram.mShaderFiles.clear(); + gDeferredTreeProgram.mFeatures.encodesNormal = true; gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredTreeProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1401,6 +1478,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredImpostorProgram.mName = "Deferred Impostor Shader"; + gDeferredImpostorProgram.mFeatures.hasSrgb = true; + gDeferredImpostorProgram.mFeatures.decodesNormal = true; + gDeferredImpostorProgram.mFeatures.encodesNormal = true; gDeferredImpostorProgram.mShaderFiles.clear(); gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1411,6 +1491,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredLightProgram.mName = "Deferred Light Shader"; + gDeferredLightProgram.mFeatures.decodesNormal = true; gDeferredLightProgram.mShaderFiles.clear(); gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1424,6 +1505,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i); + gDeferredMultiLightProgram[i].mFeatures.decodesNormal = true; gDeferredMultiLightProgram[i].mShaderFiles.clear(); gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1437,6 +1519,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader"; gDeferredSpotLightProgram.mShaderFiles.clear(); + gDeferredSpotLightProgram.mFeatures.hasSrgb = true; + gDeferredSpotLightProgram.mFeatures.decodesNormal = true; gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1447,6 +1531,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader"; + gDeferredMultiSpotLightProgram.mFeatures.hasSrgb = true; + gDeferredMultiSpotLightProgram.mFeatures.decodesNormal = true; gDeferredMultiSpotLightProgram.mShaderFiles.clear(); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1474,6 +1560,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() } gDeferredSunProgram.mName = "Deferred Sun Shader"; + gDeferredSunProgram.mFeatures.decodesNormal = true; gDeferredSunProgram.mShaderFiles.clear(); gDeferredSunProgram.mShaderFiles.push_back(make_pair(vertex, GL_VERTEX_SHADER_ARB)); gDeferredSunProgram.mShaderFiles.push_back(make_pair(fragment, GL_FRAGMENT_SHADER_ARB)); @@ -1485,6 +1572,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredBlurLightProgram.mName = "Deferred Blur Light Shader"; + gDeferredBlurLightProgram.mFeatures.decodesNormal = true; gDeferredBlurLightProgram.mShaderFiles.clear(); gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1501,6 +1589,12 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; gDeferredAlphaProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels + gDeferredAlphaProgram.mFeatures.hasSrgb = true; + gDeferredAlphaProgram.mFeatures.decodesNormal = true; + gDeferredAlphaProgram.mFeatures.encodesNormal = true; + gDeferredAlphaProgram.mFeatures.calculatesAtmospherics = true; + gDeferredAlphaProgram.mFeatures.hasAtmospherics = true; + if (mVertexShaderLevel[SHADER_DEFERRED] < 1) { gDeferredAlphaProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; @@ -1527,11 +1621,14 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { - gDeferredAlphaImpostorProgram.mName = "Deferred Alpha Shader"; + gDeferredAlphaImpostorProgram.mName = "Deferred Alpha Impostor Shader"; gDeferredAlphaImpostorProgram.mFeatures.calculatesLighting = false; gDeferredAlphaImpostorProgram.mFeatures.hasLighting = false; gDeferredAlphaImpostorProgram.mFeatures.isAlphaLighting = true; + gDeferredAlphaImpostorProgram.mFeatures.hasSrgb = true; + gDeferredAlphaImpostorProgram.mFeatures.decodesNormal = true; + gDeferredAlphaImpostorProgram.mFeatures.encodesNormal = true; gDeferredAlphaImpostorProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels if (mVertexShaderLevel[SHADER_DEFERRED] < 1) { @@ -1566,6 +1663,13 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; gDeferredAlphaWaterProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels + gDeferredAlphaWaterProgram.mFeatures.hasWaterFog = true; + gDeferredAlphaWaterProgram.mFeatures.hasSrgb = true; + gDeferredAlphaWaterProgram.mFeatures.decodesNormal = true; + gDeferredAlphaWaterProgram.mFeatures.encodesNormal = true; + gDeferredAlphaWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredAlphaWaterProgram.mFeatures.hasAtmospherics = true; + if (mVertexShaderLevel[SHADER_DEFERRED] < 1) { gDeferredAlphaWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; @@ -1598,6 +1702,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAvatarEyesProgram.mFeatures.hasGamma = true; gDeferredAvatarEyesProgram.mFeatures.hasTransport = true; gDeferredAvatarEyesProgram.mFeatures.disableTextureIndex = true; + gDeferredAvatarEyesProgram.mFeatures.hasSrgb = true; + gDeferredAvatarEyesProgram.mFeatures.encodesNormal = true; gDeferredAvatarEyesProgram.mShaderFiles.clear(); gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/avatarEyesV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1611,6 +1717,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightProgram.mFeatures.hasGamma = true; gDeferredFullbrightProgram.mFeatures.hasTransport = true; + gDeferredFullbrightProgram.mFeatures.hasSrgb = true; gDeferredFullbrightProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightProgram.mShaderFiles.clear(); gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -1625,6 +1732,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; + gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSrgb = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -1640,6 +1748,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightWaterProgram.mFeatures.hasTransport = true; + gDeferredFullbrightWaterProgram.mFeatures.hasWaterFog = true; + gDeferredFullbrightWaterProgram.mFeatures.hasSrgb = true; gDeferredFullbrightWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightWaterProgram.mShaderFiles.clear(); gDeferredFullbrightWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -1656,6 +1766,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasTransport = true; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasWaterFog = true; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasSrgb = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -1689,6 +1801,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSkinnedFullbrightProgram.mFeatures.hasTransport = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasObjectSkinning = true; gDeferredSkinnedFullbrightProgram.mFeatures.disableTextureIndex = true; + gDeferredSkinnedFullbrightProgram.mFeatures.hasSrgb = true; gDeferredSkinnedFullbrightProgram.mShaderFiles.clear(); gDeferredSkinnedFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightSkinnedV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSkinnedFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1732,6 +1845,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredWaterProgram.mFeatures.hasGamma = true; gDeferredWaterProgram.mFeatures.hasTransport = true; + gDeferredWaterProgram.mFeatures.encodesNormal = true; gDeferredWaterProgram.mShaderFiles.clear(); gDeferredWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1746,6 +1860,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredUnderWaterProgram.mFeatures.hasGamma = true; gDeferredUnderWaterProgram.mFeatures.hasTransport = true; + gDeferredUnderWaterProgram.mFeatures.hasSrgb = true; + gDeferredUnderWaterProgram.mFeatures.encodesNormal = true; gDeferredUnderWaterProgram.mShaderFiles.clear(); gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1757,6 +1873,13 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; gDeferredSoftenProgram.mShaderFiles.clear(); + gDeferredSoftenProgram.mFeatures.hasSrgb = true; + gDeferredSoftenProgram.mFeatures.decodesNormal = true; + gDeferredSoftenProgram.mFeatures.calculatesAtmospherics = true; + gDeferredSoftenProgram.mFeatures.hasAtmospherics = true; + gDeferredSoftenProgram.mFeatures.hasTransport = true; + gDeferredSoftenProgram.mFeatures.hasGamma = true; + gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1780,6 +1903,13 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSoftenWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredSoftenWaterProgram.addPermutation("WATER_FOG", "1"); gDeferredSoftenWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredSoftenWaterProgram.mFeatures.hasWaterFog = true; + gDeferredSoftenWaterProgram.mFeatures.hasSrgb = true; + gDeferredSoftenWaterProgram.mFeatures.decodesNormal = true; + gDeferredSoftenWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredSoftenWaterProgram.mFeatures.hasAtmospherics = true; + gDeferredSoftenWaterProgram.mFeatures.hasTransport = true; + gDeferredSoftenWaterProgram.mFeatures.hasGamma = true; if (gSavedSettings.getBOOL("RenderDeferredSSAO")) { //if using SSAO, take screen space light map into account as if shadows are enabled @@ -1850,6 +1980,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gTerrainProgram.mName = "Deferred Terrain Shader"; + gDeferredTerrainProgram.mFeatures.encodesNormal = true; gDeferredTerrainProgram.mShaderFiles.clear(); gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1861,6 +1992,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredAvatarProgram.mName = "Avatar Shader"; gDeferredAvatarProgram.mFeatures.hasSkinning = true; + gDeferredAvatarProgram.mFeatures.encodesNormal = true; gDeferredAvatarProgram.mShaderFiles.clear(); gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1876,6 +2008,14 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; gDeferredAvatarAlphaProgram.mFeatures.isAlphaLighting = true; gDeferredAvatarAlphaProgram.mFeatures.disableTextureIndex = true; + gDeferredAvatarAlphaProgram.mFeatures.hasSrgb = true; + gDeferredAvatarAlphaProgram.mFeatures.encodesNormal = true; + gDeferredAvatarAlphaProgram.mFeatures.decodesNormal = true; + gDeferredAvatarAlphaProgram.mFeatures.calculatesAtmospherics = true; + gDeferredAvatarAlphaProgram.mFeatures.hasAtmospherics = true; + gDeferredAvatarAlphaProgram.mFeatures.hasTransport = true; + gDeferredAvatarAlphaProgram.mFeatures.hasGamma = true; + gDeferredAvatarAlphaProgram.mShaderFiles.clear(); gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1893,6 +2033,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process"; + gDeferredPostGammaCorrectProgram.mFeatures.hasSrgb = true; gDeferredPostGammaCorrectProgram.mShaderFiles.clear(); gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2239,6 +2380,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightNonIndexedProgram.mFeatures.hasTransport = true; gObjectFullbrightNonIndexedProgram.mFeatures.isFullbright = true; gObjectFullbrightNonIndexedProgram.mFeatures.disableTextureIndex = true; + gObjectFullbrightNonIndexedProgram.mFeatures.hasSrgb = true; gObjectFullbrightNonIndexedProgram.mShaderFiles.clear(); gObjectFullbrightNonIndexedProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); gObjectFullbrightNonIndexedProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2254,6 +2396,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightNonIndexedWaterProgram.mFeatures.hasWaterFog = true; gObjectFullbrightNonIndexedWaterProgram.mFeatures.hasTransport = true; gObjectFullbrightNonIndexedWaterProgram.mFeatures.disableTextureIndex = true; + gObjectFullbrightNonIndexedWaterProgram.mFeatures.hasSrgb = true; gObjectFullbrightNonIndexedWaterProgram.mShaderFiles.clear(); gObjectFullbrightNonIndexedWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); gObjectFullbrightNonIndexedWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2270,6 +2413,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectEmissiveNonIndexedProgram.mFeatures.hasTransport = true; gObjectEmissiveNonIndexedProgram.mFeatures.isFullbright = true; gObjectEmissiveNonIndexedProgram.mFeatures.disableTextureIndex = true; + gObjectEmissiveNonIndexedProgram.mFeatures.hasSrgb = true; gObjectEmissiveNonIndexedProgram.mShaderFiles.clear(); gObjectEmissiveNonIndexedProgram.mShaderFiles.push_back(make_pair("objects/emissiveV.glsl", GL_VERTEX_SHADER_ARB)); gObjectEmissiveNonIndexedProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2300,6 +2444,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightNoColorProgram.mFeatures.hasGamma = true; gObjectFullbrightNoColorProgram.mFeatures.hasTransport = true; gObjectFullbrightNoColorProgram.mFeatures.isFullbright = true; + gObjectFullbrightNoColorProgram.mFeatures.hasSrgb = true; gObjectFullbrightNoColorProgram.mFeatures.disableTextureIndex = true; gObjectFullbrightNoColorProgram.mShaderFiles.clear(); gObjectFullbrightNoColorProgram.mShaderFiles.push_back(make_pair("objects/fullbrightNoColorV.glsl", GL_VERTEX_SHADER_ARB)); @@ -2395,6 +2540,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() { gImpostorProgram.mName = "Impostor Shader"; gImpostorProgram.mFeatures.disableTextureIndex = true; + gImpostorProgram.mFeatures.hasSrgb = true; gImpostorProgram.mShaderFiles.clear(); gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorV.glsl", GL_VERTEX_SHADER_ARB)); gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2483,6 +2629,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectBumpProgram.mFeatures.hasAtmospherics = true; gObjectBumpProgram.mFeatures.hasLighting = true; gObjectBumpProgram.mFeatures.mIndexedTextureChannels = 0;*/ + gObjectBumpProgram.mFeatures.encodesNormal = true; gObjectBumpProgram.mShaderFiles.clear(); gObjectBumpProgram.mShaderFiles.push_back(make_pair("objects/bumpV.glsl", GL_VERTEX_SHADER_ARB)); gObjectBumpProgram.mShaderFiles.push_back(make_pair("objects/bumpF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2540,6 +2687,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightProgram.mFeatures.hasGamma = true; gObjectFullbrightProgram.mFeatures.hasTransport = true; gObjectFullbrightProgram.mFeatures.isFullbright = true; + gObjectFullbrightProgram.mFeatures.hasSrgb = true; gObjectFullbrightProgram.mFeatures.mIndexedTextureChannels = 0; gObjectFullbrightProgram.mShaderFiles.clear(); gObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -2571,6 +2719,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectEmissiveProgram.mFeatures.hasGamma = true; gObjectEmissiveProgram.mFeatures.hasTransport = true; gObjectEmissiveProgram.mFeatures.isFullbright = true; + gObjectEmissiveProgram.mFeatures.hasSrgb = true; gObjectEmissiveProgram.mFeatures.mIndexedTextureChannels = 0; gObjectEmissiveProgram.mShaderFiles.clear(); gObjectEmissiveProgram.mShaderFiles.push_back(make_pair("objects/emissiveV.glsl", GL_VERTEX_SHADER_ARB)); @@ -2603,6 +2752,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; gObjectFullbrightAlphaMaskProgram.mFeatures.isFullbright = true; gObjectFullbrightAlphaMaskProgram.mFeatures.hasAlphaMask = true; + gObjectFullbrightAlphaMaskProgram.mFeatures.hasSrgb = true; gObjectFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = 0; gObjectFullbrightAlphaMaskProgram.mShaderFiles.clear(); gObjectFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); @@ -2725,6 +2875,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gSkinnedObjectFullbrightProgram.mFeatures.hasObjectSkinning = true; gSkinnedObjectFullbrightProgram.mFeatures.hasAlphaMask = true; gSkinnedObjectFullbrightProgram.mFeatures.disableTextureIndex = true; + gSkinnedObjectFullbrightProgram.mFeatures.hasSrgb = true; gSkinnedObjectFullbrightProgram.mShaderFiles.clear(); gSkinnedObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightSkinnedV.glsl", GL_VERTEX_SHADER_ARB)); gSkinnedObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -2741,6 +2892,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gSkinnedObjectEmissiveProgram.mFeatures.isFullbright = true; gSkinnedObjectEmissiveProgram.mFeatures.hasObjectSkinning = true; gSkinnedObjectEmissiveProgram.mFeatures.disableTextureIndex = true; + gSkinnedObjectEmissiveProgram.mFeatures.hasSrgb = true; gSkinnedObjectEmissiveProgram.mShaderFiles.clear(); gSkinnedObjectEmissiveProgram.mShaderFiles.push_back(make_pair("objects/emissiveSkinnedV.glsl", GL_VERTEX_SHADER_ARB)); gSkinnedObjectEmissiveProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -3331,7 +3483,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() success = gInscatterRectProgram.createShader(NULL, NULL); } - if (success && (mVertexShaderLevel[SHADER_WINDLIGHT] < 3)) + if (success) { gWLSkyProgram.mName = "Windlight Sky Shader"; //gWLSkyProgram.mFeatures.hasGamma = true; @@ -3340,10 +3492,12 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() gWLSkyProgram.mShaderFiles.push_back(make_pair("windlight/skyF.glsl", GL_FRAGMENT_SHADER_ARB)); gWLSkyProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT]; gWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY; + if (gAtmosphere != nullptr) + gWLSkyProgram.mExtraLinkObject = gAtmosphere->getAtmosphericShaderForLink(); success = gWLSkyProgram.createShader(NULL, NULL); } - if (success && (mVertexShaderLevel[SHADER_WINDLIGHT] < 3)) + if (success) { gWLCloudProgram.mName = "Windlight Cloud Program"; //gWLCloudProgram.mFeatures.hasGamma = true; @@ -3352,6 +3506,8 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB)); gWLCloudProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT]; gWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY; + if (gAtmosphere != nullptr) + gWLCloudProgram.mExtraLinkObject = gAtmosphere->getAtmosphericShaderForLink(); success = gWLCloudProgram.createShader(NULL, NULL); } diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 74deaffe16..3f3d5e54cd 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -597,7 +597,7 @@ public: addText(xpos, ypos, llformat("%d Unique Textures", LLImageGL::sUniqueCount)); ypos += y_inc; - addText(xpos, ypos, llformat("%d Render Calls", last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize))); + addText(xpos, ypos, llformat("%d Render Calls", (U32)last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize))); ypos += y_inc; addText(xpos, ypos, llformat("%d/%d Objects Active", gObjectList.getNumActiveObjects(), gObjectList.getNumObjects())); @@ -612,9 +612,9 @@ public: gPipeline.mTextureMatrixOps = 0; gPipeline.mMatrixOpCount = 0; - if (last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize) > 0) + if ((U32)last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize) > 0) { - addText(xpos, ypos, llformat("Batch min/max/mean: %d/%d/%d", last_frame_recording.getMin(LLPipeline::sStatBatchSize), last_frame_recording.getMax(LLPipeline::sStatBatchSize), last_frame_recording.getMean(LLPipeline::sStatBatchSize))); + addText(xpos, ypos, llformat("Batch min/max/mean: %d/%d/%d", (U32)last_frame_recording.getMin(LLPipeline::sStatBatchSize), (U32)last_frame_recording.getMax(LLPipeline::sStatBatchSize), (U32)last_frame_recording.getMean(LLPipeline::sStatBatchSize))); } ypos += y_inc; diff --git a/indra/newview/llvoground.cpp b/indra/newview/llvoground.cpp index 71a7623fb4..52a6395618 100644 --- a/indra/newview/llvoground.cpp +++ b/indra/newview/llvoground.cpp @@ -126,7 +126,7 @@ BOOL LLVOGround::updateGeometry(LLDrawable *drawable) left_dir.normVec(); // Our center top point - LLColor4 ground_color = gSky.getFogColor(); + LLColor4 ground_color = gSky.getSkyFogColor(); ground_color.mV[3] = 1.f; face->setFaceColor(ground_color); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 61500aebfe..125dbce24c 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -75,127 +75,77 @@ static const LLVector2 TEX11 = LLVector2(1.f, 1.f); LLUUID gSunTextureID = IMG_SUN; LLUUID gMoonTextureID = IMG_MOON; -class LLFastLn +F32 clip_side_to_horizon(const LLVector3& V0, const LLVector3& V1, const F32 cos_max_angle) { -public: - LLFastLn() + const LLVector3 V = V1 - V0; + const F32 k2 = 1.f/(cos_max_angle * cos_max_angle) - 1; + const F32 A = V.mV[0] * V.mV[0] + V.mV[1] * V.mV[1] - k2 * V.mV[2] * V.mV[2]; + const F32 B = V0.mV[0] * V.mV[0] + V0.mV[1] * V.mV[1] - k2 * V0.mV[2] * V.mV[2]; + const F32 C = V0.mV[0] * V0.mV[0] + V0.mV[1] * V0.mV[1] - k2 * V0.mV[2] * V0.mV[2]; + + if (fabs(A) < 1e-7) { - mTable[0] = 0; - for( S32 i = 1; i < 257; i++ ) - { - mTable[i] = log((F32)i); - } + return -0.1f; // v0 is cone origin and v1 is on the surface of the cone. } - F32 ln( F32 x ) + const F32 det = sqrt(B*B - A*C); + const F32 t1 = (-B - det) / A; + const F32 t2 = (-B + det) / A; + const F32 z1 = V0.mV[2] + t1 * V.mV[2]; + const F32 z2 = V0.mV[2] + t2 * V.mV[2]; + if (z1 * cos_max_angle < 0) { - const F32 OO_255 = 0.003921568627450980392156862745098f; - const F32 LN_255 = 5.5412635451584261462455391880218f; - - if( x < OO_255 ) - { - return log(x); - } - else - if( x < 1 ) - { - x *= 255.f; - S32 index = llfloor(x); - F32 t = x - index; - F32 low = mTable[index]; - F32 high = mTable[index + 1]; - return low + t * (high - low) - LN_255; - } - else - if( x <= 255 ) - { - S32 index = llfloor(x); - F32 t = x - index; - F32 low = mTable[index]; - F32 high = mTable[index + 1]; - return low + t * (high - low); - } - else - { - return log( x ); - } + return t2; } - - F32 pow( F32 x, F32 y ) + else if (z2 * cos_max_angle < 0) { - return (F32)LL_FAST_EXP(y * ln(x)); + return t1; } - - -private: - F32 mTable[257]; // index 0 is unused -}; - -static LLFastLn gFastLn; - - -// Functions used a lot. - -inline F32 LLHaze::calcPhase(const F32 cos_theta) const -{ - const F32 g2 = mG * mG; - const F32 den = 1 + g2 - 2 * mG * cos_theta; - return (1 - g2) * gFastLn.pow(den, -1.5); -} - -inline void color_pow(LLColor3 &col, const F32 e) -{ - col.mV[0] = gFastLn.pow(col.mV[0], e); - col.mV[1] = gFastLn.pow(col.mV[1], e); - col.mV[2] = gFastLn.pow(col.mV[2], e); -} - -inline LLColor3 color_norm(const LLColor3 &col) -{ - const F32 m = color_max(col); - if (m > 1.f) + else if ((t1 < 0) || (t1 > 1)) { - return 1.f/m * col; + return t2; + } + else + { + return t1; } - else return col; } -inline void color_gamma_correct(LLColor3 &col) +// Clips quads with top and bottom sides parallel to horizon. +BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4], + const LLVector3 v_corner[4], const F32 cos_max_angle) { - const F32 gamma_inv = 1.f/1.2f; - if (col.mV[0] != 0.f) + t_left = clip_side_to_horizon(v_corner[1], v_corner[0], cos_max_angle); + t_right = clip_side_to_horizon(v_corner[3], v_corner[2], cos_max_angle); + + if ((t_left >= 1) || (t_right >= 1)) { - col.mV[0] = gFastLn.pow(col.mV[0], gamma_inv); + return FALSE; } - if (col.mV[1] != 0.f) + + //const BOOL left_clip = (t_left > 0); + //const BOOL right_clip = (t_right > 0); + + //if (!left_clip && !right_clip) { - col.mV[1] = gFastLn.pow(col.mV[1], gamma_inv); + for (S32 vtx = 0; vtx < 4; ++vtx) + { + v_clipped[vtx] = v_corner[vtx]; + } } - if (col.mV[2] != 0.f) +/* else { - col.mV[2] = gFastLn.pow(col.mV[2], gamma_inv); - } -} + v_clipped[0] = v_corner[0]; + v_clipped[1] = left_clip ? ((1 - t_left) * v_corner[1] + t_left * v_corner[0]) + : v_corner[1]; + v_clipped[2] = v_corner[2]; + v_clipped[3] = right_clip ? ((1 - t_right) * v_corner[3] + t_right * v_corner[2]) + : v_corner[3]; + }*/ -static LLColor3 calc_air_sca_sea_level() -{ - static LLColor3 WAVE_LEN(675, 520, 445); - static LLColor3 refr_ind = refr_ind_calc(WAVE_LEN); - static LLColor3 n21 = refr_ind * refr_ind - LLColor3(1, 1, 1); - static LLColor3 n4 = n21 * n21; - static LLColor3 wl2 = WAVE_LEN * WAVE_LEN * 1e-6f; - static LLColor3 wl4 = wl2 * wl2; - static LLColor3 mult_const = fsigma * 2.0f/ 3.0f * 1e24f * (F_PI * F_PI) * n4; - static F32 dens_div_N = F32( ATM_SEA_LEVEL_NDENS / Ndens2); - return dens_div_N * color_div ( mult_const, wl4 ); + return TRUE; } -// static constants. -LLColor3 const LLHaze::sAirScaSeaLevel = calc_air_sca_sea_level(); -F32 const LLHaze::sAirScaIntense = color_intens(LLHaze::sAirScaSeaLevel); -F32 const LLHaze::sAirScaAvg = LLHaze::sAirScaIntense / 3.f; - - /*************************************** SkyTex ***************************************/ @@ -356,11 +306,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) initSunDirection(LLVector3(mSunDefaultPosition.mV[2], mSunDefaultPosition.mV[0], mSunDefaultPosition.mV[1]), LLVector3(0, 0, 0)); } - mAmbientScale = gSavedSettings.getF32("SkyAmbientScale"); - mNightColorShift = gSavedSettings.getColor3("SkyNightColorShift"); - mFogColor.mV[VRED] = mFogColor.mV[VGREEN] = mFogColor.mV[VBLUE] = 0.5f; - mFogColor.mV[VALPHA] = 0.0f; - mFogRatio = 1.2f; + mSun.setIntensity(SUN_INTENSITY); mMoon.setIntensity(0.1f * SUN_INTENSITY); @@ -376,8 +322,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mHeavenlyBodyUpdated = FALSE ; mDrawRefl = 0; - mHazeConcentration = 0.f; - mInterpVal = 0.f; + mInterpVal = 0.f; } @@ -391,13 +336,8 @@ LLVOSky::~LLVOSky() void LLVOSky::init() { - const F32 haze_int = color_intens(mHaze.calcSigSca(0)); - mHazeConcentration = haze_int / - (color_intens(LLHaze::calcAirSca(0)) + haze_int); - - calcAtmospherics(); + updateDirections(); -// LEGACY_ATMOSPHERICS // Initialize the cached normalized direction vectors for (S32 side = 0; side < 6; ++side) { @@ -468,7 +408,7 @@ void LLVOSky::restoreGL() mBloomTexturep->setNoDelete() ; mBloomTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - calcAtmospherics(); + updateDirections(); if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) @@ -495,7 +435,6 @@ void LLVOSky::restoreGL() } -// LEGACY_ATMOSPHERICS void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) { S32 tile_x = tile % NUM_TILES_X; @@ -541,290 +480,13 @@ void LLVOSky::createSkyTexture(const S32 side, const S32 tile) { for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) { - mSkyTex[side].setPixel(calcSkyColorInDir(mSkyTex[side].getDir(x, y)), x, y); - mShinyTex[side].setPixel(calcSkyColorInDir(mSkyTex[side].getDir(x, y), true), x, y); - } - } -} - -LLColor4 LLVOSky::calcSkyColorInDir(const LLVector3 &dir, bool isShiny) -{ - F32 saturation = 0.3f; - if (dir.mV[VZ] < -0.02f) - { - LLColor4 col = LLColor4(llmax(mFogColor[0],0.2f), llmax(mFogColor[1],0.2f), llmax(mFogColor[2],0.22f),0.f); - if (isShiny) - { - LLColor3 desat_fog = LLColor3(mFogColor); - F32 brightness = desat_fog.brightness(); - // So that shiny somewhat shows up at night. - if (brightness < 0.15f) - { - brightness = 0.15f; - desat_fog = smear(0.15f); - } - LLColor3 greyscale = smear(brightness); - desat_fog = desat_fog * saturation + greyscale * (1.0f - saturation); - if (!gPipeline.canUseWindLightShaders()) - { - col = LLColor4(desat_fog, 0.f); - } - else - { - col = LLColor4(desat_fog * 0.5f, 0.f); - } - } - float x = 1.0f-fabsf(-0.1f-dir.mV[VZ]); - x *= x; - col.mV[0] *= x*x; - col.mV[1] *= powf(x, 2.5f); - col.mV[2] *= x*x*x; - return col; - } - - // undo OGL_TO_CFR_ROTATION and negate vertical direction. - LLVector3 Pn = LLVector3(-dir[1] , -dir[2], -dir[0]); - - LLColor3 vary_HazeColor(0,0,0); - LLColor3 vary_CloudColorSun(0,0,0); - LLColor3 vary_CloudColorAmbient(0,0,0); - F32 vary_CloudDensity(0); - LLVector2 vary_HorizontalProjection[2]; - vary_HorizontalProjection[0] = LLVector2(0,0); - vary_HorizontalProjection[1] = LLVector2(0,0); - - calcSkyColorWLVert(Pn, vary_HazeColor, vary_CloudColorSun, vary_CloudColorAmbient, - vary_CloudDensity, vary_HorizontalProjection); - - LLColor3 sky_color = calcSkyColorWLFrag(Pn, vary_HazeColor, vary_CloudColorSun, vary_CloudColorAmbient, - vary_CloudDensity, vary_HorizontalProjection); - if (isShiny) - { - F32 brightness = sky_color.brightness(); - LLColor3 greyscale = smear(brightness); - sky_color = sky_color * saturation + greyscale * (1.0f - saturation); - sky_color *= (0.5f + 0.5f * brightness); - } - return LLColor4(sky_color, 0.0f); -} - -// turn on floating point precision -// in vs2003 for this function. Otherwise -// sky is aliased looking 7:10 - 8:50 -#if LL_MSVC && __MSVC_VER__ < 8 -#pragma optimize("p", on) -#endif - -void LLVOSky::calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]) -{ - LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); - - LLColor3 blue_density = psky->getBlueDensity(); - F32 max_y = psky->getMaxY(); - LLVector3 lightnorm = psky->getLightNormal(); - - // project the direction ray onto the sky dome. - F32 phi = acos(Pn[1]); - F32 sinA = sin(F_PI - phi); - if (fabsf(sinA) < 0.01f) - { //avoid division by zero - sinA = 0.01f; - } - - F32 Plen = psky->getDomeRadius() * sin(F_PI + phi + asin(psky->getDomeOffset() * sinA)) / sinA; - - Pn *= Plen; - - vary_HorizontalProjection[0] = LLVector2(Pn[0], Pn[2]); - vary_HorizontalProjection[0] /= - 2.f * Plen; - - // Set altitude - if (Pn[1] > 0.f) - { - Pn *= (max_y / Pn[1]); - } - else - { - Pn *= (-32000.f / Pn[1]); - } - - Plen = Pn.length(); - Pn /= Plen; - - // Initialize temp variables - LLColor3 sunlight = psky->getSunlightColor(); - LLColor3 ambient = psky->getAmbientColor(); - LLColor3 blue_horizon = psky->getBlueHorizon(); - F32 haze_density = psky->getHazeDensity(); - F32 haze_horizon = psky->getHazeHorizon(); - F32 density_multiplier = psky->getDensityMultiplier(); - LLColor3 glow = psky->getGlow(); - F32 cloud_shadow = psky->getCloudShadow(); - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - LLColor3 light_atten = (blue_density * 1.0 + smear(haze_density * 0.25f)) * (density_multiplier * max_y); - - // Calculate relative weights - LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = blue_density + smear(haze_density); - LLColor3 blue_weight = componentDiv(blue_density, temp1); - LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Distance - temp2.mV[2] = Plen * density_multiplier; - - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); - - - // Compute haze glow - temp2.mV[0] = Pn * lightnorm; - - temp2.mV[0] = 1.f - temp2.mV[0]; - // temp2.x is 0 at the sun and increases away from sun - temp2.mV[0] = llmax(temp2.mV[0], .001f); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.mV[0] *= glow.mV[0]; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.mV[0] = pow(temp2.mV[0], glow.mV[2]); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.mV[0] += .25f; - - - // Haze color above cloud - vary_HazeColor = (blue_horizon * blue_weight * (sunlight + ambient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + ambient)); - - // Increase ambient when there are more clouds - LLColor3 tmpAmbient = ambient + (LLColor3::white - ambient) * cloud_shadow * 0.5f; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1.f - cloud_shadow); - - // Haze color below cloud - LLColor3 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + tmpAmbient)); - - // Final atmosphere additive - componentMultBy(vary_HazeColor, LLColor3::white - temp1); - - sunlight = psky->getSunlightColor(); - temp2.mV[1] = llmax(0.f, lightnorm[1] * 2.f); - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Attenuate cloud color by atmosphere - temp1 = componentSqrt(temp1); //less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - vary_HazeColor += componentMult(additiveColorBelowCloud - vary_HazeColor, LLColor3::white - componentSqrt(temp1)); - - if (Pn[1] < 0.f) - { - // Eric's original: - // LLColor3 dark_brown(0.143f, 0.129f, 0.114f); - LLColor3 dark_brown(0.082f, 0.076f, 0.066f); - LLColor3 brown(0.430f, 0.386f, 0.322f); - LLColor3 sky_lighting = sunlight + ambient; - F32 haze_brightness = vary_HazeColor.brightness(); - - if (Pn[1] < -0.05f) - { - vary_HazeColor = colorMix(dark_brown, brown, -Pn[1] * 0.9f) * sky_lighting * haze_brightness; - } - - if (Pn[1] > -0.1f) - { - vary_HazeColor = colorMix(LLColor3::white * haze_brightness, vary_HazeColor, fabs((Pn[1] + 0.05f) * -20.f)); + mSkyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(mSkyTex[side].getDir(x, y)), x, y); + mShinyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(mSkyTex[side].getDir(x, y), true), x, y); } } } -#if LL_MSVC && __MSVC_VER__ < 8 -#pragma optimize("p", off) -#endif - -LLColor3 LLVOSky::calcSkyColorWLFrag(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]) -{ - LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); - F32 gamma = psky->getGamma(); - - LLColor3 res; - LLColor3 color0 = vary_HazeColor; - - if (!gPipeline.canUseWindLightShaders()) - { - LLColor3 color1 = color0 * 2.0f; - color1 = smear(1.f) - componentSaturate(color1); - componentPow(color1, gamma); - res = smear(1.f) - color1; - } - else - { - res = color0; - } - -# ifndef LL_RELEASE_FOR_DOWNLOAD - - LLColor3 color2 = 2.f * color0; - - LLColor3 color3 = LLColor3(1.f, 1.f, 1.f) - componentSaturate(color2); - componentPow(color3, gamma); - color3 = LLColor3(1.f, 1.f, 1.f) - color3; - - static enum { - OUT_DEFAULT = 0, - OUT_SKY_BLUE = 1, - OUT_RED = 2, - OUT_PN = 3, - OUT_HAZE = 4, - } debugOut = OUT_DEFAULT; - - switch(debugOut) - { - case OUT_DEFAULT: - break; - case OUT_SKY_BLUE: - res = LLColor3(0.4f, 0.4f, 0.9f); - break; - case OUT_RED: - res = LLColor3(1.f, 0.f, 0.f); - break; - case OUT_PN: - res = LLColor3(Pn[0], Pn[1], Pn[2]); - break; - case OUT_HAZE: - res = vary_HazeColor; - break; - } -# endif // LL_RELEASE_FOR_DOWNLOAD - return res; -} - - -LLColor3 LLVOSky::createDiffuseFromWL(LLColor3 diffuse, LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient) -{ - return componentMult(diffuse, sundiffuse) * 4.0f + - componentMult(ambient, sundiffuse) * 2.0f + sunambient; -} - -LLColor3 LLVOSky::createAmbientFromWL(LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient) -{ - return (componentMult(ambient, sundiffuse) + sunambient) * 0.8f; -} - -void LLVOSky::calcAtmospherics(void) +void LLVOSky::updateDirections(void) { LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); @@ -846,7 +508,6 @@ void LLVOSky::calcAtmospherics(void) // between sunlight and point lights in windlight to normalize point lights. F32 sun_dynamic_range = llmax(gSavedSettings.getF32("RenderSunDynamicRange"), 0.0001f); LLEnvironment::instance().setSceneLightStrength(2.0f * (1.0f + sun_dynamic_range * dp)); - } void LLVOSky::idleUpdate(LLAgent &agent, const F64 &time) @@ -874,12 +535,11 @@ BOOL LLVOSky::updateSky() return TRUE; } -// LEGACY_ATMOSPHERICS static S32 next_frame = 0; const S32 total_no_tiles = 6 * NUM_TILES; const S32 cycle_frame_no = total_no_tiles + 1; - if (mUpdateTimer.getElapsedTimeF32() > 0.001f) + if (mUpdateTimer.getElapsedTimeF32() > 0.025f) { mUpdateTimer.reset(); const S32 frame = next_frame; @@ -891,103 +551,89 @@ BOOL LLVOSky::updateSky() // sInterpVal = (F32)next_frame / cycle_frame_no; LLSkyTex::setInterpVal( mInterpVal ); LLHeavenBody::setInterpVal( mInterpVal ); - calcAtmospherics(); + updateDirections(); if (mForceUpdate || total_no_tiles == frame) { - LLSkyTex::stepCurrent(); + LLSkyTex::stepCurrent(); - const static F32 LIGHT_DIRECTION_THRESHOLD = (F32) cos(DEG_TO_RAD * 1.f); - const static F32 COLOR_CHANGE_THRESHOLD = 0.01f; - - LLVector3 direction = mSun.getDirection(); - direction.normalize(); - const F32 dot_lighting = direction * mLastLightingDirection; - - LLColor3 delta_color; - delta_color.setVec(mLastTotalAmbient.mV[0] - total_ambient.mV[0], - mLastTotalAmbient.mV[1] - total_ambient.mV[1], - mLastTotalAmbient.mV[2] - total_ambient.mV[2]); - - if ( mForceUpdate - || (((dot_lighting < LIGHT_DIRECTION_THRESHOLD) - || (delta_color.length() > COLOR_CHANGE_THRESHOLD) - || !mInitialized) - && !direction.isExactlyZero())) - { - mLastLightingDirection = direction; + const static F32 LIGHT_DIRECTION_THRESHOLD = (F32) cos(DEG_TO_RAD * 1.f); + const static F32 COLOR_CHANGE_THRESHOLD = 0.01f; + + LLVector3 direction = mSun.getDirection(); + direction.normalize(); + const F32 dot_lighting = direction * mLastLightingDirection; + + LLColor3 delta_color; + delta_color.setVec(mLastTotalAmbient.mV[0] - total_ambient.mV[0], + mLastTotalAmbient.mV[1] - total_ambient.mV[1], + mLastTotalAmbient.mV[2] - total_ambient.mV[2]); + + if ( mForceUpdate + || (((dot_lighting < LIGHT_DIRECTION_THRESHOLD) + || (delta_color.length() > COLOR_CHANGE_THRESHOLD) + || !mInitialized) + && !direction.isExactlyZero())) + { + mLastLightingDirection = direction; mLastTotalAmbient = total_ambient; - mInitialized = TRUE; + mInitialized = TRUE; - if (mCubeMap) - { + if (mCubeMap) + { if (mForceUpdate) - { - updateFog(LLViewerCamera::getInstance()->getFar()); - - for (int side = 0; side < 6; side++) - { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(side, tile); - } - } - - calcAtmospherics(); - - for (int side = 0; side < 6; side++) - { - LLImageRaw* raw1 = mSkyTex[side].getImageRaw(TRUE); - LLImageRaw* raw2 = mSkyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mSkyTex[side].createGLImage(mSkyTex[side].getWhich(FALSE)); - - raw1 = mShinyTex[side].getImageRaw(TRUE); - raw2 = mShinyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mShinyTex[side].createGLImage(mShinyTex[side].getWhich(FALSE)); - } - next_frame = 0; - } - } - } - - /// *TODO really, sky texture and env map should be shared on a single texture - /// I'll let Brad take this at some point - - // update the sky texture - for (S32 i = 0; i < 6; ++i) - { - mSkyTex[i].create(1.0f); - mShinyTex[i].create(1.0f); - } - - // update the environment map - if (mCubeMap) - { - std::vector<LLPointer<LLImageRaw> > images; - images.reserve(6); - for (S32 side = 0; side < 6; side++) - { - images.push_back(mShinyTex[side].getImageRaw(TRUE)); - } - mCubeMap->init(images); + { + updateFog(LLViewerCamera::getInstance()->getFar()); + + for (int side = 0; side < 6; side++) + { + for (int tile = 0; tile < NUM_TILES; tile++) + { + createSkyTexture(side, tile); + } + } + + for (int side = 0; side < 6; side++) + { + LLImageRaw* raw1 = mSkyTex[side].getImageRaw(TRUE); + LLImageRaw* raw2 = mSkyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mSkyTex[side].createGLImage(mSkyTex[side].getWhich(FALSE)); + + raw1 = mShinyTex[side].getImageRaw(TRUE); + raw2 = mShinyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mShinyTex[side].createGLImage(mShinyTex[side].getWhich(FALSE)); + } + next_frame = 0; + + // update the sky texture + for (S32 i = 0; i < 6; ++i) + { + mSkyTex[i].create(1.0f); + mShinyTex[i].create(1.0f); + } + + // update the environment map + if (mCubeMap) + { + std::vector<LLPointer<LLImageRaw> > images; + images.reserve(6); + for (S32 side = 0; side < 6; side++) + { + images.push_back(mShinyTex[side].getImageRaw(TRUE)); + } + mCubeMap->init(images); gGL.getTexUnit(0)->disable(); } + } + } + } - gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - // *TODO: decide whether we need to update the stars vertex buffer in LLVOWLSky -Brad. - //gPipeline.markRebuild(gSky.mVOWLSkyp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - - mForceUpdate = FALSE; - } - else - { - const S32 side = frame / NUM_TILES; - const S32 tile = frame % NUM_TILES; - createSkyTexture(side, tile); - } - } + gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); + mForceUpdate = FALSE; + } + } if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) { @@ -1028,53 +674,6 @@ LLDrawable *LLVOSky::createDrawable(LLPipeline *pipeline) return mDrawable; } -//by bao -//fake vertex buffer updating -//to guarantee at least updating one VBO buffer every frame -//to walk around the bug caused by ATI card --> DEV-3855 -// -void LLVOSky::createDummyVertexBuffer() -{ - if(!mFace[FACE_DUMMY]) - { - LLDrawPoolSky *poolp = (LLDrawPoolSky*) gPipeline.getPool(LLDrawPool::POOL_SKY); - mFace[FACE_DUMMY] = mDrawable->addFace(poolp, NULL); - } - - if(!mFace[FACE_DUMMY]->getVertexBuffer()) - { - LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolSky::VERTEX_DATA_MASK, GL_DYNAMIC_DRAW_ARB); - buff->allocateBuffer(1, 1, TRUE); - mFace[FACE_DUMMY]->setVertexBuffer(buff); - } -} - -static LLTrace::BlockTimerStatHandle FTM_RENDER_FAKE_VBO_UPDATE("Fake VBO Update"); - -void LLVOSky::updateDummyVertexBuffer() -{ - if(!LLVertexBuffer::sEnableVBOs) - return ; - - if(mHeavenlyBodyUpdated) - { - mHeavenlyBodyUpdated = FALSE ; - return ; - } - - LL_RECORD_BLOCK_TIME(FTM_RENDER_FAKE_VBO_UPDATE) ; - - if(!mFace[FACE_DUMMY] || !mFace[FACE_DUMMY]->getVertexBuffer()) - createDummyVertexBuffer() ; - - LLStrider<LLVector3> vertices ; - mFace[FACE_DUMMY]->getVertexBuffer()->getVertexStrider(vertices, 0); - *vertices = mCameraPosAgent ; - mFace[FACE_DUMMY]->getVertexBuffer()->flush(); -} -//---------------------------------- -//end of fake vertex buffer updating -//---------------------------------- static LLTrace::BlockTimerStatHandle FTM_GEO_SKY("Sky Geometry"); BOOL LLVOSky::updateGeometry(LLDrawable *drawable) @@ -1344,83 +943,6 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, cons return TRUE; } - - - -// Clips quads with top and bottom sides parallel to horizon. - -BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4], - const LLVector3 v_corner[4], const F32 cos_max_angle) -{ - t_left = clip_side_to_horizon(v_corner[1], v_corner[0], cos_max_angle); - t_right = clip_side_to_horizon(v_corner[3], v_corner[2], cos_max_angle); - - if ((t_left >= 1) || (t_right >= 1)) - { - return FALSE; - } - - //const BOOL left_clip = (t_left > 0); - //const BOOL right_clip = (t_right > 0); - - //if (!left_clip && !right_clip) - { - for (S32 vtx = 0; vtx < 4; ++vtx) - { - v_clipped[vtx] = v_corner[vtx]; - } - } -/* else - { - v_clipped[0] = v_corner[0]; - v_clipped[1] = left_clip ? ((1 - t_left) * v_corner[1] + t_left * v_corner[0]) - : v_corner[1]; - v_clipped[2] = v_corner[2]; - v_clipped[3] = right_clip ? ((1 - t_right) * v_corner[3] + t_right * v_corner[2]) - : v_corner[3]; - }*/ - - return TRUE; -} - - -F32 clip_side_to_horizon(const LLVector3& V0, const LLVector3& V1, const F32 cos_max_angle) -{ - const LLVector3 V = V1 - V0; - const F32 k2 = 1.f/(cos_max_angle * cos_max_angle) - 1; - const F32 A = V.mV[0] * V.mV[0] + V.mV[1] * V.mV[1] - k2 * V.mV[2] * V.mV[2]; - const F32 B = V0.mV[0] * V.mV[0] + V0.mV[1] * V.mV[1] - k2 * V0.mV[2] * V.mV[2]; - const F32 C = V0.mV[0] * V0.mV[0] + V0.mV[1] * V0.mV[1] - k2 * V0.mV[2] * V0.mV[2]; - - if (fabs(A) < 1e-7) - { - return -0.1f; // v0 is cone origin and v1 is on the surface of the cone. - } - - const F32 det = sqrt(B*B - A*C); - const F32 t1 = (-B - det) / A; - const F32 t2 = (-B + det) / A; - const F32 z1 = V0.mV[2] + t1 * V.mV[2]; - const F32 z2 = V0.mV[2] + t2 * V.mV[2]; - if (z1 * cos_max_angle < 0) - { - return t2; - } - else if (z2 * cos_max_angle < 0) - { - return t1; - } - else if ((t1 < 0) || (t1 > 1)) - { - return t2; - } - else - { - return t1; - } -} - - void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable ) { #if 0 @@ -1732,7 +1254,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, const F32 attenuation = min_attenuation + cos_angle_of_view * (max_attenuation - min_attenuation); - LLColor4 hb_refl_col = (1 - attenuation) * hb_col + attenuation * mFogColor; + LLColor4 hb_refl_col = (1 - attenuation) * hb_col + attenuation * getSkyFogColor(); face->setFaceColor(hb_refl_col); LLVector3 v_far[2]; @@ -1850,208 +1372,10 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, } } - - - void LLVOSky::updateFog(const F32 distance) { - -// LEGACY_ATMOSPHERICS - if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOG)) - { - if (!LLGLSLShader::sNoFixedFunction) - { - glFogf(GL_FOG_DENSITY, 0); - glFogfv(GL_FOG_COLOR, (F32 *) &LLColor4::white.mV); - glFogf(GL_FOG_END, 1000000.f); - } - return; - } - - const BOOL hide_clip_plane = TRUE; - LLColor4 target_fog(0.f, 0.2f, 0.5f, 0.f); - - const F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : 0.f; - // LLWorld::getInstance()->getWaterHeight(); - F32 camera_height = gAgentCamera.getCameraPositionAgent().mV[2]; - - F32 near_clip_height = LLViewerCamera::getInstance()->getAtAxis().mV[VZ] * LLViewerCamera::getInstance()->getNear(); - camera_height += near_clip_height; - - F32 fog_distance = 0.f; - LLColor3 res_color[3]; - - LLColor3 sky_fog_color = LLColor3::white; - LLColor3 render_fog_color = LLColor3::white; - - LLVector3 tosun = getToSunLast(); - const F32 tosun_z = tosun.mV[VZ]; - tosun.mV[VZ] = 0.f; - tosun.normalize(); - LLVector3 perp_tosun; - perp_tosun.mV[VX] = -tosun.mV[VY]; - perp_tosun.mV[VY] = tosun.mV[VX]; - LLVector3 tosun_45 = tosun + perp_tosun; - tosun_45.normalize(); - - F32 delta = 0.06f; - tosun.mV[VZ] = delta; - perp_tosun.mV[VZ] = delta; - tosun_45.mV[VZ] = delta; - tosun.normalize(); - perp_tosun.normalize(); - tosun_45.normalize(); - - // Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun. - res_color[0] = calcSkyColorInDir(tosun); - res_color[1] = calcSkyColorInDir(perp_tosun); - res_color[2] = calcSkyColorInDir(tosun_45); - - sky_fog_color = color_norm(res_color[0] + res_color[1] + res_color[2]); - - F32 full_off = -0.25f; - F32 full_on = 0.00f; - F32 on = (tosun_z - full_off) / (full_on - full_off); - on = llclamp(on, 0.01f, 1.f); - sky_fog_color *= 0.5f * on; - - - // We need to clamp these to non-zero, in order for the gamma correction to work. 0^y = ??? - S32 i; - for (i = 0; i < 3; i++) - { - sky_fog_color.mV[i] = llmax(0.0001f, sky_fog_color.mV[i]); - } - - color_gamma_correct(sky_fog_color); - - render_fog_color = sky_fog_color; - - F32 fog_density = 0.f; - fog_distance = mFogRatio * distance; - - if (camera_height > water_height) - { - LLColor4 fog(render_fog_color); - if (!LLGLSLShader::sNoFixedFunction) - { - glFogfv(GL_FOG_COLOR, fog.mV); - } - mGLFogCol = fog; - - if (hide_clip_plane) - { - // For now, set the density to extend to the cull distance. - const F32 f_log = 2.14596602628934723963618357029f; // sqrt(fabs(log(0.01f))) - fog_density = f_log/fog_distance; - if (!LLGLSLShader::sNoFixedFunction) - { - glFogi(GL_FOG_MODE, GL_EXP2); - } - } - else - { - const F32 f_log = 4.6051701859880913680359829093687f; // fabs(log(0.01f)) - fog_density = (f_log)/fog_distance; - if (!LLGLSLShader::sNoFixedFunction) - { - glFogi(GL_FOG_MODE, GL_EXP); - } - } - } - else - { - LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); - F32 depth = water_height - camera_height; - - // get the water param manager variables - float water_fog_density = pwater->getFogDensity(); - LLColor4 water_fog_color(pwater->getFogColor()); - - // adjust the color based on depth. We're doing linear approximations - float depth_scale = gSavedSettings.getF32("WaterGLFogDepthScale"); - float depth_modifier = 1.0f - llmin(llmax(depth / depth_scale, 0.01f), - gSavedSettings.getF32("WaterGLFogDepthFloor")); - - LLColor4 fogCol = water_fog_color * depth_modifier; - fogCol.setAlpha(1); - - // set the gl fog color - mGLFogCol = fogCol; - - // set the density based on what the shaders use - fog_density = water_fog_density * gSavedSettings.getF32("WaterGLFogDensityScale"); - - if (!LLGLSLShader::sNoFixedFunction) - { - glFogfv(GL_FOG_COLOR, (F32 *) &fogCol.mV); - glFogi(GL_FOG_MODE, GL_EXP2); - } - } - - mFogColor = sky_fog_color; - mFogColor.setAlpha(1); - LLDrawPoolWater::sWaterFogEnd = fog_distance*2.2f; - - if (!LLGLSLShader::sNoFixedFunction) - { - LLGLSFog gls_fog; - glFogf(GL_FOG_END, fog_distance*2.2f); - glFogf(GL_FOG_DENSITY, fog_density); - glHint(GL_FOG_HINT, GL_NICEST); - } - stop_glerror(); -} - - -// Functions used a lot. -F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply) -{ - F32 mv = color_max(col); - if (0 == mv) - { - return 0; - } - - col *= 1.f / mv; - color_pow(col, e); - if (postmultiply) - { - col *= mv; - } - return mv; -} - -// Returns angle (RADIANs) between the horizontal projection of "v" and the x_axis. -// Range of output is 0.0f to 2pi //359.99999...f -// Returns 0.0f when "v" = +/- z_axis. -F32 azimuth(const LLVector3 &v) -{ - F32 azimuth = 0.0f; - if (v.mV[VX] == 0.0f) - { - if (v.mV[VY] > 0.0f) - { - azimuth = F_PI * 0.5f; - } - else if (v.mV[VY] < 0.0f) - { - azimuth = F_PI * 1.5f;// 270.f; - } - } - else - { - azimuth = (F32) atan(v.mV[VY] / v.mV[VX]); - if (v.mV[VX] < 0.0f) - { - azimuth += F_PI; - } - else if (v.mV[VY] < 0.0f) - { - azimuth += F_PI * 2; - } - } - return azimuth; + LLVector3 toSun = getToSunLast(); + m_legacyAtmospherics.updateFog(distance, toSun); } void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) @@ -2065,7 +1389,7 @@ void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_an mMoon.renewDirection(); mLastLightingDirection = mSun.getDirection(); - calcAtmospherics(); + updateDirections(); if ( !mInitialized ) { @@ -2099,12 +1423,17 @@ void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &moon_di mSun.setDirection(sun_direction); mMoon.setDirection(moon_dir); - calcAtmospherics(); + updateDirections(); + if (dp < 0.995f) { //the sun jumped a great deal, update immediately mForceUpdate = TRUE; } } +LLVector3 LLVOSky::getLightDirection() const +{ + return LLEnvironment::instance().getCurrentSky()->getLightDirection(); +} LLColor4U LLVOSky::getFadeColor() const { diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 2c253aed51..7b5ea38999 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -35,36 +35,12 @@ #include "llframetimer.h" #include "v3colorutil.h" #include "llsettingssky.h" +#include "lllegacyatmospherics.h" -////////////////////////////////// -// -// Lots of constants -// -// Will clean these up at some point... -// - -const F32 HORIZON_DIST = 1024.0f; const F32 SKY_BOX_MULT = 16.0f; -const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 10.f; +const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 10.f; const F32 HEAVENLY_BODY_FACTOR = 0.1f; const F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR; -const F32 EARTH_RADIUS = 6.4e6f; // exact radius = 6.37 x 10^6 m -const F32 ATM_EXP_FALLOFF = 0.000126f; -const F32 ATM_SEA_LEVEL_NDENS = 2.55e25f; -// Somewhat arbitrary: -const F32 ATM_HEIGHT = 100000.f; - -const F32 FIRST_STEP = 5000.f; -const F32 INV_FIRST_STEP = 1.f/FIRST_STEP; -const S32 NO_STEPS = 15; -const F32 INV_NO_STEPS = 1.f/NO_STEPS; - - -// constants used in calculation of scattering coeff of clear air -const F32 sigma = 0.035f; -const F32 fsigma = (6.f + 3.f * sigma) / (6.f-7.f*sigma); -const F64 Ndens = 2.55e25; -const F64 Ndens2 = Ndens*Ndens; // HACK: Allow server to change sun and moon IDs. // I can't figure out how to pass the appropriate @@ -72,25 +48,9 @@ const F64 Ndens2 = Ndens*Ndens; extern LLUUID gSunTextureID; extern LLUUID gMoonTextureID; - -LL_FORCE_INLINE LLColor3 color_div(const LLColor3 &col1, const LLColor3 &col2) -{ - return LLColor3( - col1.mV[0] / col2.mV[0], - col1.mV[1] / col2.mV[1], - col1.mV[2] / col2.mV[2] ); -} - -LLColor3 color_norm(const LLColor3 &col); -BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4], - const LLVector3 v_corner[4], const F32 cos_max_angle); -F32 clip_side_to_horizon(const LLVector3& v0, const LLVector3& v1, const F32 cos_max_angle); - - class LLFace; class LLHaze; - class LLSkyTex { friend class LLVOSky; @@ -258,115 +218,6 @@ public: void setV(const LLVector3& v) { mV = v; } }; - -LL_FORCE_INLINE LLColor3 refr_ind_calc(const LLColor3 &wave_length) -{ - LLColor3 refr_ind; - for (S32 i = 0; i < 3; ++i) - { - const F32 wl2 = wave_length.mV[i] * wave_length.mV[i] * 1e-6f; - refr_ind.mV[i] = 6.43e3f + ( 2.95e6f / ( 146.0f - 1.f/wl2 ) ) + ( 2.55e4f / ( 41.0f - 1.f/wl2 ) ); - refr_ind.mV[i] *= 1.0e-8f; - refr_ind.mV[i] += 1.f; - } - return refr_ind; -} - - -class LLHaze -{ -public: - LLHaze() : mG(0), mFalloff(1), mAbsCoef(0.f) {mSigSca.setToBlack();} - LLHaze(const F32 g, const LLColor3& sca, const F32 fo = 2.f) : - mG(g), mSigSca(0.25f/F_PI * sca), mFalloff(fo), mAbsCoef(0.f) - { - mAbsCoef = color_intens(mSigSca) / sAirScaIntense; - } - - LLHaze(const F32 g, const F32 sca, const F32 fo = 2.f) : mG(g), - mSigSca(0.25f/F_PI * LLColor3(sca, sca, sca)), mFalloff(fo) - { - mAbsCoef = 0.01f * sca / sAirScaAvg; - } - - F32 getG() const { return mG; } - - void setG(const F32 g) - { - mG = g; - } - - const LLColor3& getSigSca() const // sea level - { - return mSigSca; - } - - void setSigSca(const LLColor3& s) - { - mSigSca = s; - mAbsCoef = 0.01f * color_intens(mSigSca) / sAirScaIntense; - } - - void setSigSca(const F32 s0, const F32 s1, const F32 s2) - { - mSigSca = sAirScaAvg * LLColor3 (s0, s1, s2); - mAbsCoef = 0.01f * (s0 + s1 + s2) / 3; - } - - F32 getFalloff() const - { - return mFalloff; - } - - void setFalloff(const F32 fo) - { - mFalloff = fo; - } - - F32 getAbsCoef() const - { - return mAbsCoef; - } - - inline static F32 calcFalloff(const F32 h) - { - return (h <= 0) ? 1.0f : (F32)LL_FAST_EXP(-ATM_EXP_FALLOFF * h); - } - - inline LLColor3 calcSigSca(const F32 h) const - { - return calcFalloff(h * mFalloff) * mSigSca; - } - - inline void calcSigSca(const F32 h, LLColor3 &result) const - { - result = mSigSca; - result *= calcFalloff(h * mFalloff); - } - - LLColor3 calcSigExt(const F32 h) const - { - return calcFalloff(h * mFalloff) * (1 + mAbsCoef) * mSigSca; - } - - F32 calcPhase(const F32 cos_theta) const; - - static inline LLColor3 calcAirSca(const F32 h); - static inline void calcAirSca(const F32 h, LLColor3 &result); - -private: - static LLColor3 const sAirScaSeaLevel; - static F32 const sAirScaIntense; - static F32 const sAirScaAvg; - -protected: - F32 mG; - LLColor3 mSigSca; - F32 mFalloff; // 1 - slow, >1 - faster - F32 mAbsCoef; -}; - - class LLCubeMap; // turn on floating point precision @@ -379,31 +230,7 @@ class LLCubeMap; class LLVOSky : public LLStaticViewerObject { - -public: - void calcAtmospherics(void); - -// LEGACY_ATMOSPHERICS - LLColor3 createDiffuseFromWL(LLColor3 diffuse, LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient); - LLColor3 createAmbientFromWL(LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient); - - void calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]); - - LLColor3 calcSkyColorWLFrag(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]); - LLColor4 calcSkyColorInDir(const LLVector3& dir, bool isShiny = false); - - LLColor3 calcRadianceAtPoint(const LLVector3& pos) const - { - F32 radiance = mBrightnessScaleGuess * mSun.getIntensity(); - return LLColor3(radiance, radiance, radiance); - } - void initSkyTextureDirs(const S32 side, const S32 tile); - void createSkyTexture(const S32 side, const S32 tile); - +public: enum { FACE_SIDE0, @@ -416,7 +243,6 @@ public: FACE_MOON, // was 7 FACE_BLOOM, // was 8 FACE_REFLECTION, // was 10 - FACE_DUMMY, //for an ATI bug --bao FACE_COUNT }; @@ -448,13 +274,12 @@ public: const LLVector3& getToMoonLast() const { return mMoon.getDirectionCached(); } BOOL isSunUp() const { return mSun.getDirectionCached().mV[2] > -0.05f; } + LLVector3 getLightDirection() const; LLColor3 getSunDiffuseColor() const; LLColor3 getMoonDiffuseColor() const; LLColor4 getSunAmbientColor() const; LLColor4 getMoonAmbientColor() const; LLColor4 getTotalAmbientColor() const; - LLColor4 getFogColor() const { return mFogColor; } - LLColor4 getGLFogColor() const { return mGLFogCol; } BOOL isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; } @@ -476,16 +301,18 @@ public: void updateReflectionGeometry(LLDrawable *drawable, F32 H, const LLHeavenBody& HB); - const LLHaze& getHaze() const { return mHaze; } - LLHaze& getHaze() { return mHaze; } - F32 getHazeConcentration() const { return mHazeConcentration; } - void setHaze(const LLHaze& h) { mHaze = h; } F32 getWorldScale() const { return mWorldScale; } void setWorldScale(const F32 s) { mWorldScale = s; } void updateFog(const F32 distance); - void setFogRatio(const F32 fog_ratio) { mFogRatio = fog_ratio; } + + void setFogRatio(const F32 fog_ratio) { m_legacyAtmospherics.setFogRatio(fog_ratio); } + F32 getFogRatio() const { return m_legacyAtmospherics.getFogRatio(); } + + LLColor4 getSkyFogColor() const { return m_legacyAtmospherics.getFogColor(); } + LLColor4 getGLFogColor() const { return m_legacyAtmospherics.getGLFogColor(); } + LLColor4U getFadeColor() const; - F32 getFogRatio() const { return mFogRatio; } + void setCloudDensity(F32 cloud_density) { mCloudDensity = cloud_density; } void setWind ( const LLVector3& wind ) { mWind = wind.length(); } @@ -510,6 +337,11 @@ public: protected: ~LLVOSky(); + void updateDirections(void); + + void initSkyTextureDirs(const S32 side, const S32 tile); + void createSkyTexture(const S32 side, const S32 tile); + LLPointer<LLViewerFetchedTexture> mSunTexturep; LLPointer<LLViewerFetchedTexture> mMoonTexturep; LLPointer<LLViewerFetchedTexture> mBloomTexturep; @@ -532,8 +364,6 @@ protected: LLColor3 mBrightestPointNew; F32 mBrightnessScaleGuess; LLColor3 mBrightestPointGuess; - LLHaze mHaze; - F32 mHazeConcentration; BOOL mWeatherChange; F32 mCloudDensity; F32 mWind; @@ -545,53 +375,16 @@ protected: F32 mAmbientScale; LLColor3 mNightColorShift; F32 mInterpVal; - - LLColor4 mFogColor; - LLColor4 mGLFogCol; - - F32 mFogRatio; F32 mWorldScale; - LLPointer<LLCubeMap> mCubeMap; // Cube map for the environment - S32 mDrawRefl; + LLPointer<LLCubeMap> mCubeMap; // Cube map for the environment + S32 mDrawRefl; LLFrameTimer mUpdateTimer; -public: - //by bao - //fake vertex buffer updating - //to guarantee at least updating one VBO buffer every frame - //to work around the bug caused by ATI card --> DEV-3855 - // - void createDummyVertexBuffer() ; - void updateDummyVertexBuffer() ; - - BOOL mHeavenlyBodyUpdated ; -}; - -// turn it off -#if LL_MSVC && __MSVC_VER__ < 8 -#pragma optimize("p", off) -#endif - -// Utility functions -F32 azimuth(const LLVector3 &v); -F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply = FALSE); - - -/* Proportion of light that is scattered into 'path' from 'in' over distance dt. */ -/* assumes that vectors 'path' and 'in' are normalized. Scattering coef / 2pi */ - -inline LLColor3 LLHaze::calcAirSca(const F32 h) -{ - return calcFalloff(h) * sAirScaSeaLevel; -} - -inline void LLHaze::calcAirSca(const F32 h, LLColor3 &result) -{ - result = sAirScaSeaLevel; - result *= calcFalloff(h); -} + BOOL mHeavenlyBodyUpdated ; + LLAtmospherics m_legacyAtmospherics; +}; #endif diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 634a23b461..4f34f58b76 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -10043,7 +10043,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLColor3 col = LLEnvironment::instance().getCurrentWater()->getFogColor(); + LLColor3 col = LLEnvironment::instance().getCurrentWater()->getWaterFogColor(); glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); mWaterDis.bindTarget(); LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER1; @@ -12050,4 +12050,4 @@ void LLPipeline::restoreHiddenObject( const LLUUID& id ) bool LLPipeline::useAdvancedAtmospherics() const { return sUseAdvancedAtmospherics; -} +}
\ No newline at end of file |