llsettingssky.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. /**
  2. * @file llsettingssky.cpp
  3. * @brief The sky settings asset support class.
  4. *
  5. * $LicenseInfo:firstyear=2018&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2019, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llsettingssky.h"
  34. const std::string LLSettingsSky::SETTING_AMBIENT = "ambient";
  35. const std::string LLSettingsSky::SETTING_BLUE_DENSITY = "blue_density";
  36. const std::string LLSettingsSky::SETTING_BLUE_HORIZON = "blue_horizon";
  37. const std::string LLSettingsSky::SETTING_DENSITY_MULTIPLIER =
  38. "density_multiplier";
  39. const std::string LLSettingsSky::SETTING_DISTANCE_MULTIPLIER =
  40. "distance_multiplier";
  41. const std::string LLSettingsSky::SETTING_HAZE_DENSITY = "haze_density";
  42. const std::string LLSettingsSky::SETTING_HAZE_HORIZON = "haze_horizon";
  43. const std::string LLSettingsSky::SETTING_BLOOM_TEXTUREID = "bloom_id";
  44. const std::string LLSettingsSky::SETTING_RAINBOW_TEXTUREID = "rainbow_id";
  45. const std::string LLSettingsSky::SETTING_HALO_TEXTUREID = "halo_id";
  46. const std::string LLSettingsSky::SETTING_CLOUD_COLOR = "cloud_color";
  47. const std::string LLSettingsSky::SETTING_CLOUD_POS_DENSITY1 =
  48. "cloud_pos_density1";
  49. const std::string LLSettingsSky::SETTING_CLOUD_POS_DENSITY2 =
  50. "cloud_pos_density2";
  51. const std::string LLSettingsSky::SETTING_CLOUD_SCALE = "cloud_scale";
  52. const std::string LLSettingsSky::SETTING_CLOUD_SCROLL_RATE =
  53. "cloud_scroll_rate";
  54. const std::string LLSettingsSky::SETTING_CLOUD_SHADOW = "cloud_shadow";
  55. const std::string LLSettingsSky::SETTING_CLOUD_TEXTUREID = "cloud_id";
  56. const std::string LLSettingsSky::SETTING_CLOUD_VARIANCE = "cloud_variance";
  57. const std::string LLSettingsSky::SETTING_DOME_OFFSET = "dome_offset";
  58. const std::string LLSettingsSky::SETTING_DOME_RADIUS = "dome_radius";
  59. const std::string LLSettingsSky::SETTING_GAMMA = "gamma";
  60. const std::string LLSettingsSky::SETTING_GLOW = "glow";
  61. const std::string LLSettingsSky::SETTING_LIGHT_NORMAL = "lightnorm";
  62. const std::string LLSettingsSky::SETTING_MAX_Y = "max_y";
  63. const std::string LLSettingsSky::SETTING_MOON_ROTATION = "moon_rotation";
  64. const std::string LLSettingsSky::SETTING_MOON_SCALE = "moon_scale";
  65. const std::string LLSettingsSky::SETTING_MOON_TEXTUREID = "moon_id";
  66. const std::string LLSettingsSky::SETTING_MOON_BRIGHTNESS = "moon_brightness";
  67. const std::string LLSettingsSky::SETTING_STAR_BRIGHTNESS = "star_brightness";
  68. const std::string LLSettingsSky::SETTING_SUNLIGHT_COLOR = "sunlight_color";
  69. const std::string LLSettingsSky::SETTING_SUN_ROTATION = "sun_rotation";
  70. const std::string LLSettingsSky::SETTING_SUN_SCALE = "sun_scale";
  71. const std::string LLSettingsSky::SETTING_SUN_TEXTUREID = "sun_id";
  72. const std::string LLSettingsSky::SETTING_LEGACY_EAST_ANGLE = "east_angle";
  73. const std::string LLSettingsSky::SETTING_LEGACY_ENABLE_CLOUD_SCROLL =
  74. "enable_cloud_scroll";
  75. const std::string LLSettingsSky::SETTING_LEGACY_SUN_ANGLE = "sun_angle";
  76. const std::string LLSettingsSky::SETTING_LEGACY_HAZE = "legacy_haze";
  77. const std::string LLSettingsSky::KEY_DENSITY_PROFILE = "density";
  78. const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH = "width";
  79. const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM = "exp_term";
  80. const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR =
  81. "exp_scale";
  82. const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM =
  83. "linear_term";
  84. const std::string LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM =
  85. "constant_term";
  86. const std::string LLSettingsSky::SETTING_SKY_MOISTURE_LEVEL = "moisture_level";
  87. const std::string LLSettingsSky::SETTING_SKY_DROPLET_RADIUS = "droplet_radius";
  88. const std::string LLSettingsSky::SETTING_SKY_ICE_LEVEL = "ice_level";
  89. const std::string LLSettingsSky::SETTING_REFLECTION_PROBE_AMBIANCE = "reflection_probe_ambiance";
  90. // These are settings for an advanced atmospherics model (which was never fully
  91. // implemented) and that are not currently in use for rendering... HB
  92. const std::string LLSettingsSky::SETTING_PLANET_RADIUS = "planet_radius";
  93. const std::string LLSettingsSky::SETTING_SKY_BOTTOM_RADIUS =
  94. "sky_bottom_radius";
  95. const std::string LLSettingsSky::SETTING_SKY_TOP_RADIUS = "sky_top_radius";
  96. const std::string LLSettingsSky::SETTING_SUN_ARC_RADIANS = "sun_arc_radians";
  97. const std::string LLSettingsSky::SETTING_RAYLEIGH_CONFIG = "rayleigh_config";
  98. const std::string LLSettingsSky::SETTING_MIE_CONFIG = "mie_config";
  99. const std::string LLSettingsSky::SETTING_MIE_ANISOTROPY_FACTOR = "anisotropy";
  100. const std::string LLSettingsSky::SETTING_ABSORPTION_CONFIG =
  101. "absorption_config";
  102. // Default (fixed) sky settings asset
  103. const LLUUID LLSettingsSky::DEFAULT_ASSET_ID("eb3a7080-831f-9f37-10f0-7b1f9ea4043c");
  104. //static
  105. F32 LLSettingsSky::sAutoAdjustProbeAmbiance = 1.f;
  106. // Helper functions
  107. static LLQuaternion convert_azimuth_and_altitude_to_quat(F32 azimuth,
  108. F32 altitude)
  109. {
  110. F32 sin_theta = sinf(azimuth);
  111. F32 cos_theta = cosf(azimuth);
  112. F32 sin_phi = sinf(altitude);
  113. F32 cos_phi = cosf(altitude);
  114. // +x right, +z up, +y at...
  115. LLVector3 dir(cos_theta * cos_phi, sin_theta * cos_phi, sin_phi);
  116. LLVector3 axis = LLVector3::x_axis % dir;
  117. axis.normalize();
  118. F32 angle = acosf(LLVector3::x_axis * dir);
  119. LLQuaternion quat;
  120. quat.setAngleAxis(angle, axis);
  121. return quat;
  122. }
  123. ///////////////////////////////////////////////////////////////////////////////
  124. // LLSettingsSky class proper
  125. ///////////////////////////////////////////////////////////////////////////////
  126. LLSettingsSky::LLSettingsSky(const LLSD& data)
  127. : LLSettingsBase(data),
  128. mDensityMultiplier(0.0001f),
  129. mDistanceMultiplier(0.8f),
  130. mGamma(1.f),
  131. mMaxY(0.f),
  132. mSunScale(1.f),
  133. mMoonScale(1.f),
  134. mMoonBrightness(1.f),
  135. mStarBrightness(1.f),
  136. mSkyMoistureLevel(0.f),
  137. mSkyDropletRadius(0.f),
  138. mSkyIceLevel(0.f),
  139. mCloudShadow(0.f),
  140. mCloudVariance(0.f),
  141. mReflectionProbeAmbiance(0.f),
  142. mCanAutoAdjust(true)
  143. {
  144. }
  145. LLSettingsSky::LLSettingsSky()
  146. : LLSettingsBase(),
  147. mDensityMultiplier(0.0001f),
  148. mDistanceMultiplier(0.8f),
  149. mGamma(1.f),
  150. mMaxY(0.f),
  151. mSunScale(1.f),
  152. mMoonScale(1.f),
  153. mMoonBrightness(1.f),
  154. mStarBrightness(1.f),
  155. mSkyMoistureLevel(0.f),
  156. mSkyDropletRadius(0.f),
  157. mSkyIceLevel(0.f),
  158. mCloudShadow(0.f),
  159. mCloudVariance(0.f),
  160. mReflectionProbeAmbiance(0.f),
  161. mCanAutoAdjust(true)
  162. {
  163. }
  164. void LLSettingsSky::replaceSettings(const LLSD& settings)
  165. {
  166. LLSettingsBase::replaceSettings(settings);
  167. mNextSunTextureId.setNull();
  168. mNextMoonTextureId.setNull();
  169. mNextCloudTextureId.setNull();
  170. mNextBloomTextureId.setNull();
  171. mNextRainbowTextureId.setNull();
  172. mNextHaloTextureId.setNull();
  173. mCanAutoAdjust = !settings.has(SETTING_REFLECTION_PROBE_AMBIANCE);
  174. }
  175. void LLSettingsSky::replaceWithSky(LLSettingsSky::ptr_t otherp)
  176. {
  177. replaceWith(otherp);
  178. mNextSunTextureId = otherp->mNextSunTextureId;
  179. mNextMoonTextureId = otherp->mNextMoonTextureId;
  180. mNextCloudTextureId = otherp->mNextCloudTextureId;
  181. mNextBloomTextureId = otherp->mNextBloomTextureId;
  182. mNextRainbowTextureId = otherp->mNextRainbowTextureId;
  183. mNextHaloTextureId = otherp->mNextHaloTextureId;
  184. mCanAutoAdjust = otherp->mCanAutoAdjust;
  185. }
  186. void LLSettingsSky::blend(const LLSettingsBase::ptr_t& end, F64 blendf)
  187. {
  188. llassert(getSettingsType() == end->getSettingsType());
  189. LLSettingsSky::ptr_t other = std::dynamic_pointer_cast<LLSettingsSky>(end);
  190. if (other)
  191. {
  192. if (other->mSettings.has(SETTING_LEGACY_HAZE))
  193. {
  194. if (!mSettings.has(SETTING_LEGACY_HAZE) ||
  195. !mSettings[SETTING_LEGACY_HAZE].has(SETTING_AMBIENT))
  196. {
  197. // Special case since SETTING_AMBIENT is both in outer and
  198. // legacy maps, we prioritize legacy one.
  199. // See getAmbientColor(), we are about to replaceSettings(), so
  200. // we are free to set it
  201. setAmbientColor(getAmbientColor());
  202. }
  203. }
  204. else if (mSettings.has(SETTING_LEGACY_HAZE) &&
  205. mSettings[SETTING_LEGACY_HAZE].has(SETTING_AMBIENT))
  206. {
  207. // Special case due to ambient's duality. We need to match
  208. // 'other's' structure for interpolation. We are free to change
  209. // mSettings, since we are about to reset it
  210. mSettings[SETTING_AMBIENT] = getAmbientColor().getValue();
  211. mSettings[SETTING_LEGACY_HAZE].erase(SETTING_AMBIENT);
  212. }
  213. LLUUID cloud_noise_id = getCloudNoiseTextureId();
  214. LLUUID cloud_noise_id_next = other->getCloudNoiseTextureId();
  215. F64 cloud_shadow = 0.0;
  216. if (!cloud_noise_id.isNull() && cloud_noise_id_next.isNull())
  217. {
  218. // If there is no cloud texture in destination, reduce coverage to
  219. // imitate disappearance. See LLDrawPoolWLSky::renderSkyClouds...
  220. // We do not blend present texture with null Note: probably can be
  221. // done by shader
  222. cloud_shadow = lerp(mSettings[SETTING_CLOUD_SHADOW].asReal(), 0.0,
  223. blendf);
  224. cloud_noise_id_next = cloud_noise_id;
  225. }
  226. else if (cloud_noise_id.isNull() && !cloud_noise_id_next.isNull())
  227. {
  228. // Source has no cloud texture, reduce initial coverage to imitate
  229. // appearance use same texture as destination.
  230. cloud_shadow =
  231. lerp(0.0, other->mSettings[SETTING_CLOUD_SHADOW].asReal(),
  232. blendf);
  233. setCloudNoiseTextureId(cloud_noise_id_next);
  234. }
  235. else
  236. {
  237. cloud_shadow =
  238. lerp(mSettings[SETTING_CLOUD_SHADOW].asReal(),
  239. other->mSettings[SETTING_CLOUD_SHADOW].asReal(), blendf);
  240. }
  241. LLSD blenddata = interpolateSDMap(mSettings, other->mSettings,
  242. other->getParameterMap(), blendf);
  243. blenddata[SETTING_CLOUD_SHADOW] = LLSD::Real(cloud_shadow);
  244. replaceSettings(blenddata);
  245. mNextSunTextureId = other->getSunTextureId();
  246. mNextMoonTextureId = other->getMoonTextureId();
  247. mNextCloudTextureId = cloud_noise_id_next;
  248. mNextBloomTextureId = other->getBloomTextureId();
  249. mNextRainbowTextureId = other->getRainbowTextureId();
  250. mNextHaloTextureId = other->getHaloTextureId();
  251. }
  252. else
  253. {
  254. llwarns << "Could not cast end settings to sky. No blend performed."
  255. << llendl;
  256. }
  257. setBlendFactor(blendf);
  258. }
  259. const LLSettingsSky::stringset_t& LLSettingsSky::getSkipInterpolateKeys() const
  260. {
  261. static stringset_t skip_set;
  262. if (skip_set.empty())
  263. {
  264. skip_set = LLSettingsBase::getSkipInterpolateKeys();
  265. skip_set.insert(SETTING_RAYLEIGH_CONFIG);
  266. skip_set.insert(SETTING_MIE_CONFIG);
  267. skip_set.insert(SETTING_ABSORPTION_CONFIG);
  268. skip_set.insert(SETTING_CLOUD_SHADOW);
  269. }
  270. return skip_set;
  271. }
  272. const LLSettingsSky::stringset_t& LLSettingsSky::getSlerpKeys() const
  273. {
  274. static stringset_t slerp_set;
  275. if (slerp_set.empty())
  276. {
  277. slerp_set.insert(SETTING_SUN_ROTATION);
  278. slerp_set.insert(SETTING_MOON_ROTATION);
  279. }
  280. return slerp_set;
  281. }
  282. LLSettingsSky::validation_list_t LLSettingsSky::legacyHazeValidationList()
  283. {
  284. static validation_list_t legacy_haze;
  285. if (legacy_haze.empty())
  286. {
  287. legacy_haze.emplace_back(SETTING_AMBIENT, false, LLSD::TypeArray,
  288. boost::bind(&Validator::verifyVectorMinMax,
  289. _1, _2,
  290. llsd::array(0.0, 0.0, 0.0, "*"),
  291. llsd::array(3.0, 3.0, 3.0, "*")));
  292. legacy_haze.emplace_back(SETTING_BLUE_DENSITY, false, LLSD::TypeArray,
  293. boost::bind(&Validator::verifyVectorMinMax,
  294. _1, _2,
  295. llsd::array(0.0, 0.0, 0.0, "*"),
  296. llsd::array(3.0, 3.0, 3.0, "*")));
  297. legacy_haze.emplace_back(SETTING_BLUE_HORIZON, false, LLSD::TypeArray,
  298. boost::bind(&Validator::verifyVectorMinMax,
  299. _1, _2,
  300. llsd::array(0.0, 0.0, 0.0, "*"),
  301. llsd::array(3.0, 3.0, 3.0, "*")));
  302. legacy_haze.emplace_back(SETTING_HAZE_DENSITY, false, LLSD::TypeReal,
  303. boost::bind(&Validator::verifyFloatRange,
  304. _1, _2, llsd::array(0.0, 5.0)));
  305. legacy_haze.emplace_back(SETTING_HAZE_HORIZON, false, LLSD::TypeReal,
  306. boost::bind(&Validator::verifyFloatRange,
  307. _1, _2, llsd::array(0.0, 5.0)));
  308. legacy_haze.emplace_back(SETTING_DENSITY_MULTIPLIER, false,
  309. LLSD::TypeReal,
  310. boost::bind(&Validator::verifyFloatRange,
  311. _1, _2,
  312. llsd::array(0.0000001, 2.0)));
  313. legacy_haze.emplace_back(SETTING_DISTANCE_MULTIPLIER, false,
  314. LLSD::TypeReal,
  315. boost::bind(&Validator::verifyFloatRange,
  316. _1, _2,
  317. llsd::array(0.0001, 1000.0)));
  318. }
  319. return legacy_haze;
  320. }
  321. LLSettingsSky::validation_list_t LLSettingsSky::rayleighValidationList()
  322. {
  323. static validation_list_t rayleigh;
  324. if (rayleigh.empty())
  325. {
  326. rayleigh.emplace_back(SETTING_DENSITY_PROFILE_WIDTH, false,
  327. LLSD::TypeReal,
  328. boost::bind(&Validator::verifyFloatRange, _1, _2,
  329. llsd::array(0.0, 32768.0)));
  330. rayleigh.emplace_back(SETTING_DENSITY_PROFILE_EXP_TERM, false,
  331. LLSD::TypeReal,
  332. boost::bind(&Validator::verifyFloatRange, _1, _2,
  333. llsd::array(0.0, 2.0)));
  334. rayleigh.emplace_back(SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR, false,
  335. LLSD::TypeReal,
  336. boost::bind(&Validator::verifyFloatRange, _1, _2,
  337. llsd::array(-1.0, 1.0)));
  338. rayleigh.emplace_back(SETTING_DENSITY_PROFILE_LINEAR_TERM, false,
  339. LLSD::TypeReal,
  340. boost::bind(&Validator::verifyFloatRange, _1, _2,
  341. llsd::array(0.0, 2.0)));
  342. rayleigh.emplace_back(SETTING_DENSITY_PROFILE_CONSTANT_TERM, false,
  343. LLSD::TypeReal,
  344. boost::bind(&Validator::verifyFloatRange, _1, _2,
  345. llsd::array(0.0, 1.0)));
  346. }
  347. return rayleigh;
  348. }
  349. LLSettingsSky::validation_list_t LLSettingsSky::absorptionValidationList()
  350. {
  351. static validation_list_t absorption;
  352. if (absorption.empty())
  353. {
  354. absorption.emplace_back(SETTING_DENSITY_PROFILE_WIDTH, false,
  355. LLSD::TypeReal,
  356. boost::bind(&Validator::verifyFloatRange,
  357. _1, _2,
  358. llsd::array(0.0, 32768.0)));
  359. absorption.emplace_back(SETTING_DENSITY_PROFILE_EXP_TERM, false,
  360. LLSD::TypeReal,
  361. boost::bind(&Validator::verifyFloatRange,
  362. _1, _2, llsd::array(0.0, 2.0)));
  363. absorption.emplace_back(SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR,
  364. false, LLSD::TypeReal,
  365. boost::bind(&Validator::verifyFloatRange,
  366. _1, _2, llsd::array(-1.0, 1.0)));
  367. absorption.emplace_back(SETTING_DENSITY_PROFILE_LINEAR_TERM, false,
  368. LLSD::TypeReal,
  369. boost::bind(&Validator::verifyFloatRange,
  370. _1, _2, llsd::array(0.0, 2.0)));
  371. absorption.emplace_back(SETTING_DENSITY_PROFILE_CONSTANT_TERM, false,
  372. LLSD::TypeReal,
  373. boost::bind(&Validator::verifyFloatRange,
  374. _1, _2, llsd::array(0.0, 1.0)));
  375. }
  376. return absorption;
  377. }
  378. LLSettingsSky::validation_list_t LLSettingsSky::mieValidationList()
  379. {
  380. static validation_list_t mie;
  381. if (mie.empty())
  382. {
  383. mie.emplace_back(SETTING_DENSITY_PROFILE_WIDTH, false, LLSD::TypeReal,
  384. boost::bind(&Validator::verifyFloatRange, _1, _2,
  385. llsd::array(0.0, 32768.0)));
  386. mie.emplace_back(SETTING_DENSITY_PROFILE_EXP_TERM, false,
  387. LLSD::TypeReal,
  388. boost::bind(&Validator::verifyFloatRange, _1, _2,
  389. llsd::array(0.0, 2.0)));
  390. mie.emplace_back(SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR, false,
  391. LLSD::TypeReal,
  392. boost::bind(&Validator::verifyFloatRange, _1, _2,
  393. llsd::array(-1.0, 1.0)));
  394. mie.emplace_back(SETTING_DENSITY_PROFILE_LINEAR_TERM, false,
  395. LLSD::TypeReal,
  396. boost::bind(&Validator::verifyFloatRange, _1, _2,
  397. llsd::array(0.0, 2.0)));
  398. mie.emplace_back(SETTING_DENSITY_PROFILE_CONSTANT_TERM, false,
  399. LLSD::TypeReal,
  400. boost::bind(&Validator::verifyFloatRange, _1, _2,
  401. llsd::array(0.0, 1.0)));
  402. mie.emplace_back(SETTING_MIE_ANISOTROPY_FACTOR, false, LLSD::TypeReal,
  403. boost::bind(&Validator::verifyFloatRange, _1, _2,
  404. llsd::array(0.0, 1.0)));
  405. }
  406. return mie;
  407. }
  408. bool LLSettingsSky::validateLegacyHaze(LLSD& value, U32 flags)
  409. {
  410. llassert(value.type() == LLSD::TypeMap);
  411. validation_list_t validations = legacyHazeValidationList();
  412. LLSD result = settingValidation(value, validations, flags);
  413. if (result["errors"].size() > 0)
  414. {
  415. llwarns << "Legacy haze config validation errors: " << result["errors"]
  416. << llendl;
  417. return false;
  418. }
  419. if (result["warnings"].size() > 0)
  420. {
  421. llwarns << "Legacy haze config validation warnings: "
  422. << result["warnings"] << llendl;
  423. return false;
  424. }
  425. return true;
  426. }
  427. bool LLSettingsSky::validateRayleighLayers(LLSD& value, U32 flags)
  428. {
  429. validation_list_t validations = rayleighValidationList();
  430. if (value.isArray())
  431. {
  432. bool all_good = true;
  433. for (LLSD::array_iterator it = value.beginArray(),
  434. end = value.endArray();
  435. it != end; ++it)
  436. {
  437. LLSD& layerConfig = *it;
  438. if (layerConfig.type() == LLSD::TypeMap)
  439. {
  440. if (!validateRayleighLayers(layerConfig, flags))
  441. {
  442. all_good = false;
  443. }
  444. }
  445. else if (layerConfig.type() == LLSD::TypeArray)
  446. {
  447. return validateRayleighLayers(layerConfig, flags);
  448. }
  449. else
  450. {
  451. return settingValidation(value, validations, flags);
  452. }
  453. }
  454. return all_good;
  455. }
  456. llassert(value.type() == LLSD::TypeMap);
  457. LLSD result = settingValidation(value, validations, flags);
  458. if (result["errors"].size() > 0)
  459. {
  460. llwarns << "Rayleigh config validation errors: " << result["errors"]
  461. << llendl;
  462. return false;
  463. }
  464. if (result["warnings"].size() > 0)
  465. {
  466. llwarns << "Rayleigh config validation warnings: " << result["errors"]
  467. << llendl;
  468. return false;
  469. }
  470. return true;
  471. }
  472. bool LLSettingsSky::validateAbsorptionLayers(LLSD& value, U32 flags)
  473. {
  474. validation_list_t validations = absorptionValidationList();
  475. if (value.isArray())
  476. {
  477. bool all_good = true;
  478. for (LLSD::array_iterator it = value.beginArray(),
  479. end = value.endArray();
  480. it != end; ++it)
  481. {
  482. LLSD& layerConfig = *it;
  483. if (layerConfig.type() == LLSD::TypeMap)
  484. {
  485. if (!validateAbsorptionLayers(layerConfig, flags))
  486. {
  487. all_good = false;
  488. }
  489. }
  490. else if (layerConfig.type() == LLSD::TypeArray)
  491. {
  492. return validateAbsorptionLayers(layerConfig, flags);
  493. }
  494. else
  495. {
  496. return settingValidation(value, validations, flags);
  497. }
  498. }
  499. return all_good;
  500. }
  501. llassert(value.type() == LLSD::TypeMap);
  502. LLSD result = settingValidation(value, validations, flags);
  503. if (result["errors"].size() > 0)
  504. {
  505. llwarns << "Absorption config validation errors: " << result["errors"]
  506. << llendl;
  507. return false;
  508. }
  509. if (result["warnings"].size() > 0)
  510. {
  511. llwarns << "Absorption config validation warnings: "
  512. << result["errors"] << llendl;
  513. return false;
  514. }
  515. return true;
  516. }
  517. bool LLSettingsSky::validateMieLayers(LLSD& value, U32 flags)
  518. {
  519. validation_list_t validations = mieValidationList();
  520. if (value.isArray())
  521. {
  522. bool all_good = true;
  523. for (LLSD::array_iterator it = value.beginArray(),
  524. end = value.endArray();
  525. it != end; ++it)
  526. {
  527. LLSD& layerConfig = *it;
  528. if (layerConfig.type() == LLSD::TypeMap)
  529. {
  530. if (!validateMieLayers(layerConfig, flags))
  531. {
  532. all_good = false;
  533. }
  534. }
  535. else if (layerConfig.type() == LLSD::TypeArray)
  536. {
  537. return validateMieLayers(layerConfig, flags);
  538. }
  539. else
  540. {
  541. return settingValidation(value, validations, flags);
  542. }
  543. }
  544. return all_good;
  545. }
  546. LLSD result = settingValidation(value, validations, flags);
  547. if (result["errors"].size() > 0)
  548. {
  549. llwarns << "Mie config validation errors: " << result["errors"]
  550. << llendl;
  551. return false;
  552. }
  553. if (result["warnings"].size() > 0)
  554. {
  555. llwarns << "Mie config validation warnings: " << result["warnings"]
  556. << llendl;
  557. return false;
  558. }
  559. return true;
  560. }
  561. //virtual
  562. const LLSettingsSky::validation_list_t& LLSettingsSky::getValidationList() const
  563. {
  564. return validationList();
  565. }
  566. //static
  567. const LLSettingsSky::validation_list_t& LLSettingsSky::validationList()
  568. {
  569. static validation_list_t validation;
  570. if (validation.empty())
  571. {
  572. validation.emplace_back(SETTING_BLOOM_TEXTUREID, true, LLSD::TypeUUID);
  573. validation.emplace_back(SETTING_RAINBOW_TEXTUREID, false,
  574. LLSD::TypeUUID);
  575. validation.emplace_back(SETTING_HALO_TEXTUREID, false, LLSD::TypeUUID);
  576. validation.emplace_back(SETTING_CLOUD_COLOR, true, LLSD::TypeArray,
  577. boost::bind(&Validator::verifyVectorMinMax,
  578. _1, _2,
  579. llsd::array(0.0, 0.0, 0.0, "*"),
  580. llsd::array(1.0, 1.0, 1.0, "*")));
  581. validation.emplace_back(SETTING_CLOUD_POS_DENSITY1, true,
  582. LLSD::TypeArray,
  583. boost::bind(&Validator::verifyVectorMinMax,
  584. _1, _2,
  585. llsd::array(0.0, 0.0, 0.0, "*"),
  586. llsd::array(1.0, 1.0, 3.0, "*")));
  587. validation.emplace_back(SETTING_CLOUD_POS_DENSITY2, true,
  588. LLSD::TypeArray,
  589. boost::bind(&Validator::verifyVectorMinMax,
  590. _1, _2,
  591. llsd::array(0.0, 0.0, 0.0, "*"),
  592. llsd::array(1.0, 1.0, 1.0, "*")));
  593. validation.emplace_back(SETTING_CLOUD_SCALE, true, LLSD::TypeReal,
  594. boost::bind(&Validator::verifyFloatRange,
  595. _1, _2, llsd::array(0.001f, 3.0)));
  596. validation.emplace_back(SETTING_CLOUD_SCROLL_RATE, true,
  597. LLSD::TypeArray,
  598. boost::bind(&Validator::verifyVectorMinMax,
  599. _1, _2, llsd::array(-50.0, -50.0),
  600. llsd::array(50.0, 50.0)));
  601. validation.emplace_back(SETTING_CLOUD_SHADOW, true, LLSD::TypeReal,
  602. boost::bind(&Validator::verifyFloatRange,
  603. _1, _2, llsd::array(0.0, 1.0)));
  604. validation.emplace_back(SETTING_CLOUD_TEXTUREID, false,
  605. LLSD::TypeUUID);
  606. validation.emplace_back(SETTING_CLOUD_VARIANCE, false, LLSD::TypeReal,
  607. boost::bind(&Validator::verifyFloatRange,
  608. _1, _2, llsd::array(0.0, 1.0)));
  609. validation.emplace_back(SETTING_DOME_OFFSET, false, LLSD::TypeReal,
  610. boost::bind(&Validator::verifyFloatRange,
  611. _1, _2, llsd::array(0.0, 1.0)));
  612. validation.emplace_back(SETTING_DOME_RADIUS, false, LLSD::TypeReal,
  613. boost::bind(&Validator::verifyFloatRange,
  614. _1, _2,
  615. llsd::array(1000.0, 2000.0)));
  616. validation.emplace_back(SETTING_GAMMA, true, LLSD::TypeReal,
  617. boost::bind(&Validator::verifyFloatRange,
  618. _1, _2, llsd::array(0.0, 20.0)));
  619. validation.emplace_back(SETTING_GLOW, true, LLSD::TypeArray,
  620. boost::bind(&Validator::verifyVectorMinMax,
  621. _1, _2,
  622. llsd::array(0.2, "*", -10.0, "*"),
  623. llsd::array(40.0, "*", 10.0, "*")));
  624. validation.emplace_back(SETTING_MAX_Y, true, LLSD::TypeReal,
  625. boost::bind(&Validator::verifyFloatRange,
  626. _1, _2,
  627. llsd::array(0.0, 10000.0)));
  628. validation.emplace_back(SETTING_MOON_ROTATION, true, LLSD::TypeArray,
  629. &Validator::verifyQuaternionNormal);
  630. validation.emplace_back(SETTING_MOON_SCALE, false, LLSD::TypeReal,
  631. boost::bind(&Validator::verifyFloatRange,
  632. _1, _2, llsd::array(0.25, 20.0)),
  633. LLSD::Real(1.0));
  634. validation.emplace_back(SETTING_MOON_TEXTUREID, false, LLSD::TypeUUID);
  635. validation.emplace_back(SETTING_MOON_BRIGHTNESS, false, LLSD::TypeReal,
  636. boost::bind(&Validator::verifyFloatRange,
  637. _1, _2, llsd::array(0.0, 1.0)));
  638. validation.emplace_back(SETTING_STAR_BRIGHTNESS, true, LLSD::TypeReal,
  639. boost::bind(&Validator::verifyFloatRange,
  640. _1, _2, llsd::array(0.0, 500.0)));
  641. validation.emplace_back(SETTING_SUNLIGHT_COLOR, true, LLSD::TypeArray,
  642. boost::bind(&Validator::verifyVectorMinMax,
  643. _1, _2,
  644. llsd::array(0.0, 0.0, 0.0, "*"),
  645. llsd::array(3.0, 3.0, 3.0, "*")));
  646. validation.emplace_back(SETTING_SUN_ROTATION, true, LLSD::TypeArray,
  647. &Validator::verifyQuaternionNormal);
  648. validation.emplace_back(SETTING_SUN_SCALE, false, LLSD::TypeReal,
  649. boost::bind(&Validator::verifyFloatRange,
  650. _1, _2, llsd::array(0.25, 20.0)),
  651. LLSD::Real(1.0));
  652. validation.emplace_back(SETTING_SUN_TEXTUREID, false, LLSD::TypeUUID);
  653. validation.emplace_back(SETTING_PLANET_RADIUS, true, LLSD::TypeReal,
  654. boost::bind(&Validator::verifyFloatRange,
  655. _1, _2,
  656. llsd::array(1000.0, 32768.0)));
  657. validation.emplace_back(SETTING_SKY_BOTTOM_RADIUS, true,
  658. LLSD::TypeReal,
  659. boost::bind(&Validator::verifyFloatRange,
  660. _1, _2,
  661. llsd::array(1000.0, 32768.0)));
  662. validation.emplace_back(SETTING_SKY_TOP_RADIUS, true, LLSD::TypeReal,
  663. boost::bind(&Validator::verifyFloatRange,
  664. _1, _2,
  665. llsd::array(1000.0, 32768.0)));
  666. validation.emplace_back(SETTING_SUN_ARC_RADIANS, true, LLSD::TypeReal,
  667. boost::bind(&Validator::verifyFloatRange,
  668. _1, _2, llsd::array(0.0, 0.1)));
  669. validation.emplace_back(SETTING_SKY_MOISTURE_LEVEL, false,
  670. LLSD::TypeReal,
  671. boost::bind(&Validator::verifyFloatRange,
  672. _1, _2, llsd::array(0.0, 1.0)));
  673. validation.emplace_back(SETTING_SKY_DROPLET_RADIUS, false,
  674. LLSD::TypeReal,
  675. boost::bind(&Validator::verifyFloatRange,
  676. _1, _2, llsd::array(5.0, 1000.0)));
  677. validation.emplace_back(SETTING_SKY_ICE_LEVEL, false, LLSD::TypeReal,
  678. boost::bind(&Validator::verifyFloatRange,
  679. _1, _2, llsd::array(0.0, 1.0)));
  680. validation.emplace_back(SETTING_REFLECTION_PROBE_AMBIANCE, false,
  681. LLSD::TypeReal,
  682. boost::bind(&Validator::verifyFloatRange,
  683. _1, _2, llsd::array(0.0, 10.0)));
  684. validation.emplace_back(SETTING_RAYLEIGH_CONFIG, true, LLSD::TypeArray,
  685. &validateRayleighLayers);
  686. validation.emplace_back(SETTING_ABSORPTION_CONFIG, true,
  687. LLSD::TypeArray, &validateAbsorptionLayers);
  688. validation.emplace_back(SETTING_MIE_CONFIG, true, LLSD::TypeArray,
  689. &validateMieLayers);
  690. validation.emplace_back(SETTING_LEGACY_HAZE, false, LLSD::TypeMap,
  691. &validateLegacyHaze);
  692. }
  693. return validation;
  694. }
  695. LLSD LLSettingsSky::createDensityProfileLayer(F32 width, F32 exponential_term,
  696. F32 exponential_scale_factor,
  697. F32 linear_term,
  698. F32 constant_term,
  699. F32 aniso_factor)
  700. {
  701. LLSD dflt_layer;
  702. // width = 0 -> the entire atmosphere
  703. dflt_layer[SETTING_DENSITY_PROFILE_WIDTH] = width;
  704. dflt_layer[SETTING_DENSITY_PROFILE_EXP_TERM] = exponential_term;
  705. dflt_layer[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] =
  706. exponential_scale_factor;
  707. dflt_layer[SETTING_DENSITY_PROFILE_LINEAR_TERM] = linear_term;
  708. dflt_layer[SETTING_DENSITY_PROFILE_CONSTANT_TERM] = constant_term;
  709. if (aniso_factor != 0.f)
  710. {
  711. dflt_layer[SETTING_MIE_ANISOTROPY_FACTOR] = aniso_factor;
  712. }
  713. return dflt_layer;
  714. }
  715. LLSD LLSettingsSky::createSingleLayerDensityProfile(F32 width,
  716. F32 exponential_term,
  717. F32 exponential_scale_factor,
  718. F32 linear_term,
  719. F32 constant_term,
  720. F32 aniso_factor)
  721. {
  722. LLSD dflt;
  723. LLSD dflt_layer = createDensityProfileLayer(width, exponential_term,
  724. exponential_scale_factor,
  725. linear_term, constant_term,
  726. aniso_factor);
  727. dflt.append(dflt_layer);
  728. return dflt;
  729. }
  730. LLSD LLSettingsSky::rayleighConfigDefault()
  731. {
  732. return createSingleLayerDensityProfile(0.f, 1.f, -1.f / 8000.f, 0.f, 0.f);
  733. }
  734. LLSD LLSettingsSky::absorptionConfigDefault()
  735. {
  736. // Absorption (ozone) has two linear ramping zones
  737. LLSD dflt_absorption_layer_a = createDensityProfileLayer(25000.f, 0.f, 0.f,
  738. -1.f / 25000.f,
  739. -2.f / 3.f);
  740. LLSD dflt_absorption_layer_b = createDensityProfileLayer(0.f, 0.f, 0.f,
  741. -1.f / 15000.f,
  742. 8.f / 3.f);
  743. LLSD dflt_absorption;
  744. dflt_absorption.append(dflt_absorption_layer_a);
  745. dflt_absorption.append(dflt_absorption_layer_b);
  746. return dflt_absorption;
  747. }
  748. LLSD LLSettingsSky::mieConfigDefault()
  749. {
  750. LLSD dflt_mie = createSingleLayerDensityProfile(0.f, 1.f, -1.f / 1200.f,
  751. 0.f, 0.f, 0.8f);
  752. return dflt_mie;
  753. }
  754. //static
  755. LLSD LLSettingsSky::defaults(F32 position)
  756. {
  757. static LLSD dfltsetting;
  758. if (dfltsetting.size() == 0)
  759. {
  760. // Magic constants copied from Default.xml
  761. dfltsetting[SETTING_CLOUD_COLOR] =
  762. LLColor4(0.4099f, 0.4099f, 0.4099f, 0.f).getValue();
  763. dfltsetting[SETTING_CLOUD_POS_DENSITY1] =
  764. LLColor4(1.f, 0.526f, 1.f, 0.f).getValue();
  765. dfltsetting[SETTING_CLOUD_POS_DENSITY2] =
  766. LLColor4(1.f, 0.526f, 0.12f, 0.f).getValue();
  767. dfltsetting[SETTING_CLOUD_SCALE] = LLSD::Real(0.4199);
  768. dfltsetting[SETTING_CLOUD_SCROLL_RATE] = llsd::array(0.2, 0.01);
  769. dfltsetting[SETTING_CLOUD_SHADOW] = LLSD::Real(0.2699);
  770. dfltsetting[SETTING_CLOUD_VARIANCE] = LLSD::Real(0.0);
  771. dfltsetting[SETTING_DOME_OFFSET] = LLSD::Real(0.96);
  772. dfltsetting[SETTING_DOME_RADIUS] = LLSD::Real(15000.0);
  773. dfltsetting[SETTING_GAMMA] = LLSD::Real(1.0);
  774. dfltsetting[SETTING_GLOW] =
  775. LLColor4(5.f, 0.001f, -0.4799f, 1.f).getValue();
  776. dfltsetting[SETTING_MAX_Y] = LLSD::Real(1605);
  777. dfltsetting[SETTING_MOON_BRIGHTNESS] = LLSD::Real(0.5);
  778. dfltsetting[SETTING_STAR_BRIGHTNESS] = LLSD::Real(250.0000);
  779. dfltsetting[SETTING_SUNLIGHT_COLOR] =
  780. LLColor4(0.7342f, 0.7815f, 0.8999f, 0.f).getValue();
  781. dfltsetting[SETTING_BLOOM_TEXTUREID] = getDefaultBloomTextureId();
  782. dfltsetting[SETTING_CLOUD_TEXTUREID] = getDefaultCloudNoiseTextureId();
  783. dfltsetting[SETTING_MOON_TEXTUREID] = getDefaultMoonTextureId();
  784. dfltsetting[SETTING_SUN_TEXTUREID] = getDefaultSunTextureId();
  785. dfltsetting[SETTING_RAINBOW_TEXTUREID] = getDefaultRainbowTextureId();
  786. dfltsetting[SETTING_HALO_TEXTUREID] = getDefaultHaloTextureId();
  787. dfltsetting[SETTING_TYPE] = "sky";
  788. // Defaults are for earth...
  789. dfltsetting[SETTING_PLANET_RADIUS] = 6360.0;
  790. dfltsetting[SETTING_SKY_BOTTOM_RADIUS] = 6360.0;
  791. dfltsetting[SETTING_SKY_TOP_RADIUS] = 6420.0;
  792. dfltsetting[SETTING_SUN_ARC_RADIANS] = 0.00045;
  793. dfltsetting[SETTING_SKY_MOISTURE_LEVEL] = 0.0;
  794. dfltsetting[SETTING_SKY_DROPLET_RADIUS] = 800.0;
  795. dfltsetting[SETTING_SKY_ICE_LEVEL] = 0.0;
  796. #if 0 // By default (legacy sky), this setting does not exist ! HB
  797. dfltsetting[SETTING_REFLECTION_PROBE_AMBIANCE] = 0.0;
  798. #endif
  799. dfltsetting[SETTING_RAYLEIGH_CONFIG] = rayleighConfigDefault();
  800. dfltsetting[SETTING_MIE_CONFIG] = mieConfigDefault();
  801. dfltsetting[SETTING_ABSORPTION_CONFIG] = absorptionConfigDefault();
  802. }
  803. // Give the Sun and Moon slightly different tracks through the sky
  804. // instead of positioning them at opposite poles from each other...
  805. F32 azimuth = F_PI * position + 80.f * DEG_TO_RAD;
  806. F32 altitude = F_PI * position;
  807. LLQuaternion sunquat =
  808. convert_azimuth_and_altitude_to_quat(altitude, azimuth);
  809. LLQuaternion moonquat =
  810. convert_azimuth_and_altitude_to_quat(altitude + F_PI * 0.125f,
  811. azimuth + F_PI * 0.125f);
  812. dfltsetting[SETTING_SUN_ROTATION] = sunquat.getValue();
  813. dfltsetting[SETTING_MOON_ROTATION] = moonquat.getValue();
  814. return dfltsetting;
  815. }
  816. //static
  817. void LLSettingsSky::adjustTime(LLSD& settings, F32 position)
  818. {
  819. if (!settings.has(SETTING_SUN_ROTATION))
  820. {
  821. // Settings empty or invalid: use default settings.
  822. settings = defaults(position);
  823. return;
  824. }
  825. // Give the Sun and Moon slightly different tracks through the sky
  826. // instead of positioning them at opposite poles from each other...
  827. F32 azimuth = F_PI * position + 80.f * DEG_TO_RAD;
  828. F32 altitude = F_PI * position;
  829. LLQuaternion sunquat =
  830. convert_azimuth_and_altitude_to_quat(altitude, azimuth);
  831. LLQuaternion moonquat =
  832. convert_azimuth_and_altitude_to_quat(altitude + F_PI * 0.125f,
  833. azimuth + F_PI * 0.125f);
  834. settings[SETTING_MOON_ROTATION] = moonquat.getValue();
  835. settings[SETTING_SUN_ROTATION] = sunquat.getValue();
  836. }
  837. LLSD LLSettingsSky::translateLegacyHazeSettings(const LLSD& legacy)
  838. {
  839. LLSD legacyhazesettings;
  840. // *TODO: AdvancedAtmospherics. These need to be translated into density
  841. // profile info in the new settings format...
  842. // LEGACY_ATMOSPHERICS
  843. if (legacy.has(SETTING_AMBIENT))
  844. {
  845. legacyhazesettings[SETTING_AMBIENT] =
  846. LLColor3(legacy[SETTING_AMBIENT]).getValue();
  847. }
  848. if (legacy.has(SETTING_BLUE_DENSITY))
  849. {
  850. legacyhazesettings[SETTING_BLUE_DENSITY] =
  851. LLColor3(legacy[SETTING_BLUE_DENSITY]).getValue();
  852. }
  853. if (legacy.has(SETTING_BLUE_HORIZON))
  854. {
  855. legacyhazesettings[SETTING_BLUE_HORIZON] =
  856. LLColor3(legacy[SETTING_BLUE_HORIZON]).getValue();
  857. }
  858. if (legacy.has(SETTING_DENSITY_MULTIPLIER))
  859. {
  860. legacyhazesettings[SETTING_DENSITY_MULTIPLIER] =
  861. LLSD::Real(legacy[SETTING_DENSITY_MULTIPLIER][0].asReal());
  862. }
  863. if (legacy.has(SETTING_DISTANCE_MULTIPLIER))
  864. {
  865. legacyhazesettings[SETTING_DISTANCE_MULTIPLIER] =
  866. LLSD::Real(legacy[SETTING_DISTANCE_MULTIPLIER][0].asReal());
  867. }
  868. if (legacy.has(SETTING_HAZE_DENSITY))
  869. {
  870. legacyhazesettings[SETTING_HAZE_DENSITY] =
  871. LLSD::Real(legacy[SETTING_HAZE_DENSITY][0].asReal());
  872. }
  873. if (legacy.has(SETTING_HAZE_HORIZON))
  874. {
  875. legacyhazesettings[SETTING_HAZE_HORIZON] =
  876. LLSD::Real(legacy[SETTING_HAZE_HORIZON][0].asReal());
  877. }
  878. return legacyhazesettings;
  879. }
  880. LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy)
  881. {
  882. bool converted_something = false;
  883. LLSD newsettings(defaults());
  884. // Move legacy haze parameters to an inner map allowing backward
  885. // compatibility and simple conversion to legacy format
  886. LLSD legacyhazesettings = translateLegacyHazeSettings(legacy);
  887. if (legacyhazesettings.size() > 0)
  888. {
  889. newsettings[SETTING_LEGACY_HAZE] = legacyhazesettings;
  890. converted_something = true;
  891. }
  892. if (legacy.has(SETTING_CLOUD_COLOR))
  893. {
  894. newsettings[SETTING_CLOUD_COLOR] =
  895. LLColor3(legacy[SETTING_CLOUD_COLOR]).getValue();
  896. converted_something = true;
  897. }
  898. if (legacy.has(SETTING_CLOUD_POS_DENSITY1))
  899. {
  900. newsettings[SETTING_CLOUD_POS_DENSITY1] =
  901. LLColor3(legacy[SETTING_CLOUD_POS_DENSITY1]).getValue();
  902. converted_something = true;
  903. }
  904. if (legacy.has(SETTING_CLOUD_POS_DENSITY2))
  905. {
  906. newsettings[SETTING_CLOUD_POS_DENSITY2] =
  907. LLColor3(legacy[SETTING_CLOUD_POS_DENSITY2]).getValue();
  908. converted_something = true;
  909. }
  910. if (legacy.has(SETTING_CLOUD_SCALE))
  911. {
  912. newsettings[SETTING_CLOUD_SCALE] =
  913. LLSD::Real(legacy[SETTING_CLOUD_SCALE][0].asReal());
  914. converted_something = true;
  915. }
  916. if (legacy.has(SETTING_CLOUD_SCROLL_RATE))
  917. {
  918. LLVector2 cloud_scroll(legacy[SETTING_CLOUD_SCROLL_RATE]);
  919. cloud_scroll -= LLVector2(10, 10);
  920. if (legacy.has(SETTING_LEGACY_ENABLE_CLOUD_SCROLL))
  921. {
  922. LLSD enabled = legacy[SETTING_LEGACY_ENABLE_CLOUD_SCROLL];
  923. if (!enabled[0].asBoolean())
  924. {
  925. cloud_scroll.mV[0] = 0.f;
  926. }
  927. if (!enabled[1].asBoolean())
  928. {
  929. cloud_scroll.mV[1] = 0.f;
  930. }
  931. }
  932. newsettings[SETTING_CLOUD_SCROLL_RATE] = cloud_scroll.getValue();
  933. converted_something = true;
  934. }
  935. if (legacy.has(SETTING_CLOUD_SHADOW))
  936. {
  937. newsettings[SETTING_CLOUD_SHADOW] =
  938. LLSD::Real(legacy[SETTING_CLOUD_SHADOW][0].asReal());
  939. converted_something = true;
  940. }
  941. if (legacy.has(SETTING_GAMMA))
  942. {
  943. newsettings[SETTING_GAMMA] = legacy[SETTING_GAMMA][0].asReal();
  944. converted_something = true;
  945. }
  946. if (legacy.has(SETTING_GLOW))
  947. {
  948. newsettings[SETTING_GLOW] = LLColor3(legacy[SETTING_GLOW]).getValue();
  949. converted_something = true;
  950. }
  951. if (legacy.has(SETTING_MAX_Y))
  952. {
  953. newsettings[SETTING_MAX_Y] =
  954. LLSD::Real(legacy[SETTING_MAX_Y][0].asReal());
  955. converted_something = true;
  956. }
  957. if (legacy.has(SETTING_STAR_BRIGHTNESS))
  958. {
  959. newsettings[SETTING_STAR_BRIGHTNESS] =
  960. LLSD::Real(legacy[SETTING_STAR_BRIGHTNESS].asReal() * 250.0);
  961. converted_something = true;
  962. }
  963. if (legacy.has(SETTING_SUNLIGHT_COLOR))
  964. {
  965. newsettings[SETTING_SUNLIGHT_COLOR] =
  966. LLColor4(legacy[SETTING_SUNLIGHT_COLOR]).getValue();
  967. converted_something = true;
  968. }
  969. if (legacy.has(SETTING_PLANET_RADIUS))
  970. {
  971. newsettings[SETTING_PLANET_RADIUS] =
  972. LLSD::Real(legacy[SETTING_PLANET_RADIUS].asReal());
  973. converted_something = true;
  974. }
  975. if (legacy.has(SETTING_SKY_BOTTOM_RADIUS))
  976. {
  977. newsettings[SETTING_SKY_BOTTOM_RADIUS] =
  978. LLSD::Real(legacy[SETTING_SKY_BOTTOM_RADIUS].asReal());
  979. converted_something = true;
  980. }
  981. if (legacy.has(SETTING_SKY_TOP_RADIUS))
  982. {
  983. newsettings[SETTING_SKY_TOP_RADIUS] =
  984. LLSD::Real(legacy[SETTING_SKY_TOP_RADIUS].asReal());
  985. converted_something = true;
  986. }
  987. if (legacy.has(SETTING_SUN_ARC_RADIANS))
  988. {
  989. newsettings[SETTING_SUN_ARC_RADIANS] =
  990. LLSD::Real(legacy[SETTING_SUN_ARC_RADIANS].asReal());
  991. converted_something = true;
  992. }
  993. if (legacy.has(SETTING_LEGACY_EAST_ANGLE) &&
  994. legacy.has(SETTING_LEGACY_SUN_ANGLE))
  995. {
  996. // Get counter-clockwise radian angle from clockwise legacy WL East
  997. // angle...
  998. F32 azimuth = -legacy[SETTING_LEGACY_EAST_ANGLE].asReal();
  999. F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal();
  1000. LLQuaternion sunquat = convert_azimuth_and_altitude_to_quat(azimuth,
  1001. altitude);
  1002. // Original WL Moon dir was diametrically opposed to the Sun dir
  1003. LLQuaternion moonquat =
  1004. convert_azimuth_and_altitude_to_quat(azimuth + F_PI, -altitude);
  1005. newsettings[SETTING_SUN_ROTATION] = sunquat.getValue();
  1006. newsettings[SETTING_MOON_ROTATION] = moonquat.getValue();
  1007. converted_something = true;
  1008. }
  1009. return converted_something ? newsettings : LLSD();
  1010. }
  1011. void LLSettingsSky::updateSettings()
  1012. {
  1013. // Base class clears dirty flag so as to not trigger recursive update.
  1014. // NOTE: this *must* be invoked first in this method ! HB
  1015. LLSettingsBase::updateSettings();
  1016. calculateHeavenlyBodyPositions();
  1017. calculateLightSettings();
  1018. mCloudPosDensity1.setValue(mSettings[SETTING_CLOUD_POS_DENSITY1]);
  1019. mSunlightColor.setValue(mSettings[SETTING_SUNLIGHT_COLOR]);
  1020. mSunScale = mSettings[SETTING_SUN_SCALE].asReal();
  1021. mMoonBrightness = mSettings[SETTING_MOON_BRIGHTNESS].asReal();
  1022. mMoonScale = mSettings[SETTING_MOON_SCALE].asReal();
  1023. mCloudColor.setValue(mSettings[SETTING_CLOUD_COLOR]);
  1024. mCloudScrollRate.setValue(mSettings[SETTING_CLOUD_SCROLL_RATE]);
  1025. mGamma = mSettings[SETTING_GAMMA].asReal();
  1026. mGlow.setValue(mSettings[SETTING_GLOW]);
  1027. mMaxY = mSettings[SETTING_MAX_Y].asReal();
  1028. mDensityMultiplier = getFloat(SETTING_DENSITY_MULTIPLIER, 0.0001f);
  1029. mDistanceMultiplier = getFloat(SETTING_DISTANCE_MULTIPLIER, 0.8f);
  1030. mStarBrightness = mSettings[SETTING_STAR_BRIGHTNESS].asReal();
  1031. mSkyMoistureLevel = mSettings[SETTING_SKY_MOISTURE_LEVEL].asReal();
  1032. mSkyDropletRadius = mSettings[SETTING_SKY_DROPLET_RADIUS].asReal();
  1033. mSkyIceLevel = mSettings[SETTING_SKY_ICE_LEVEL].asReal();
  1034. mCloudShadow = mSettings[SETTING_CLOUD_SHADOW].asReal();
  1035. mCloudVariance = mSettings[SETTING_CLOUD_VARIANCE].asReal();
  1036. if (mSettings.has(SETTING_REFLECTION_PROBE_AMBIANCE))
  1037. {
  1038. mReflectionProbeAmbiance =
  1039. mSettings[SETTING_REFLECTION_PROBE_AMBIANCE].asReal();
  1040. mCanAutoAdjust = false;
  1041. }
  1042. else
  1043. {
  1044. mReflectionProbeAmbiance = 0.f;
  1045. mCanAutoAdjust = true;
  1046. }
  1047. }
  1048. F32 LLSettingsSky::getSunMoonGlowFactor() const
  1049. {
  1050. return getIsSunUp() ? 1.f
  1051. : (getIsMoonUp() ? getMoonBrightness() * 0.25f : 0.f);
  1052. }
  1053. bool LLSettingsSky::getIsSunUp() const
  1054. {
  1055. LLVector3 sun_dir = getSunDirection();
  1056. return sun_dir.mV[2] >= 0.f;
  1057. }
  1058. bool LLSettingsSky::getIsMoonUp() const
  1059. {
  1060. LLVector3 moon_dir = getMoonDirection();
  1061. return moon_dir.mV[2] >= 0.f;
  1062. }
  1063. void LLSettingsSky::calculateHeavenlyBodyPositions() const
  1064. {
  1065. LLQuaternion sunq = getSunRotation();
  1066. LLQuaternion moonq = getMoonRotation();
  1067. mSunDirection = LLVector3::x_axis * sunq;
  1068. mMoonDirection = LLVector3::x_axis * moonq;
  1069. mSunDirection.normalize();
  1070. mMoonDirection.normalize();
  1071. if (mSunDirection.lengthSquared() < 0.01f)
  1072. {
  1073. llwarns << "Zero length Sun direction." << llendl;
  1074. }
  1075. if (mMoonDirection.lengthSquared() < 0.01f)
  1076. {
  1077. llwarns << "Zero length moon direction." << llendl;
  1078. }
  1079. }
  1080. LLVector3 LLSettingsSky::getLightDirection() const
  1081. {
  1082. update();
  1083. // Is the normal from the Sun or the Moon ?
  1084. if (getIsSunUp())
  1085. {
  1086. return mSunDirection;
  1087. }
  1088. if (getIsMoonUp())
  1089. {
  1090. return mMoonDirection;
  1091. }
  1092. return LLVector3::z_axis_neg;
  1093. }
  1094. LLColor3 LLSettingsSky::getLightDiffuse() const
  1095. {
  1096. update();
  1097. // Is the normal from the Sun or the Moon ?
  1098. if (getIsSunUp())
  1099. {
  1100. return getSunDiffuse();
  1101. }
  1102. if (getIsMoonUp())
  1103. {
  1104. return getMoonDiffuse();
  1105. }
  1106. return LLColor3::white;
  1107. }
  1108. LLColor3 LLSettingsSky::getColor(const std::string& key,
  1109. const LLColor3& default_value) const
  1110. {
  1111. LLSD::map_const_iterator it = mSettings.find(SETTING_LEGACY_HAZE);
  1112. LLSD::map_const_iterator end = mSettings.endMap();
  1113. if (it != end)
  1114. {
  1115. LLSD::map_const_iterator it2 = it->second.find(key);
  1116. if (it2 != it->second.endMap())
  1117. {
  1118. return LLColor3(it2->second);
  1119. }
  1120. }
  1121. it = mSettings.find(key);
  1122. if (it != end)
  1123. {
  1124. return LLColor3(it->second);
  1125. }
  1126. return default_value;
  1127. }
  1128. F32 LLSettingsSky::getFloat(const std::string& key, F32 default_value) const
  1129. {
  1130. LLSD::map_const_iterator it = mSettings.find(SETTING_LEGACY_HAZE);
  1131. LLSD::map_const_iterator end = mSettings.endMap();
  1132. if (it != end)
  1133. {
  1134. LLSD::map_const_iterator it2 = it->second.find(key);
  1135. if (it2 != it->second.endMap())
  1136. {
  1137. return it2->second.asReal();
  1138. }
  1139. }
  1140. it = mSettings.find(key);
  1141. if (it != end)
  1142. {
  1143. return it->second.asReal();
  1144. }
  1145. return default_value;
  1146. }
  1147. void LLSettingsSky::removeProbeAmbiance()
  1148. {
  1149. if (mSettings.has(SETTING_REFLECTION_PROBE_AMBIANCE))
  1150. {
  1151. mSettings.erase(SETTING_REFLECTION_PROBE_AMBIANCE);
  1152. setDirtyFlag(true);
  1153. update();
  1154. }
  1155. }
  1156. LLColor3 LLSettingsSky::getAmbientColorClamped() const
  1157. {
  1158. LLColor3 ambient = getAmbientColor();
  1159. F32 max_color = llmax(ambient.mV[0], ambient.mV[1], ambient.mV[2]);
  1160. if (max_color > 1.f)
  1161. {
  1162. ambient *= 1.f / max_color;
  1163. }
  1164. return ambient;
  1165. }
  1166. // Get total from rayleigh and mie density values for normalization
  1167. LLColor3 LLSettingsSky::getTotalDensity() const
  1168. {
  1169. return getBlueDensity() + smear(getHazeDensity());
  1170. }
  1171. // Sunlight attenuation effect (hue and brightness) due to atmosphere
  1172. // this is used later for sunlight modulation at various altitudes
  1173. LLColor3 LLSettingsSky::getLightAttenuation(F32 distance) const
  1174. {
  1175. // Approximate line integral over requested distance
  1176. return (getBlueDensity() + smear(getHazeDensity() * 0.25f)) *
  1177. getDensityMultiplier() * distance;
  1178. }
  1179. LLColor3 LLSettingsSky::getLightTransmittance(F32 distance) const
  1180. {
  1181. // Transparency (-> density) from Beer's law
  1182. return componentExp(getTotalDensity() *
  1183. (-distance * getDensityMultiplier()));
  1184. }
  1185. // Performs soft scale clip and gamma correction following the shader
  1186. // implementation scales colors down to 0 - 1 range preserving relative ratios
  1187. //static
  1188. LLColor3 LLSettingsSky::gammaCorrect(const LLColor3& in, F32 gamma)
  1189. {
  1190. #if 0 // 'v' is not used, so why bothering ???
  1191. LLColor3 v(in);
  1192. // Scale down to 0 to 1 range preserving relative ratio (AKA homegenize)
  1193. F32 max_color = llmax(llmax(in.mV[0], in.mV[1]), in.mV[2]);
  1194. if (max_color > 1.f)
  1195. {
  1196. v *= 1.f / max_color;
  1197. }
  1198. #endif
  1199. LLColor3 color = in * 2.f;
  1200. // Clamping after mul seems wrong, but prevents negative colors...
  1201. color = smear(1.f) - componentSaturate(color);
  1202. componentPow(color, gamma);
  1203. return smear(1.f) - color;
  1204. }
  1205. void LLSettingsSky::calculateLightSettings() const
  1206. {
  1207. // Sunlight attenuation effect (hue and brightness) due to atmosphere
  1208. // this is used later for sunlight modulation at various altitudes
  1209. F32 max_y = getMaxY();
  1210. LLColor3 light_atten = getLightAttenuation(max_y);
  1211. LLColor3 light_transmittance = getLightTransmittance(max_y);
  1212. // And vary_sunlight will work properly with moon light
  1213. LLVector3 lightnorm = getLightDirection();
  1214. F32 lighty = fabs(lightnorm[2]);
  1215. constexpr F32 LIMIT = FLT_EPSILON * 8.f;
  1216. if (lighty >= LIMIT)
  1217. {
  1218. lighty = 1.f / lighty;
  1219. }
  1220. lighty = llmax(LIMIT, lighty);
  1221. LLColor3 sunlight = getSunlightColor();
  1222. componentMultBy(sunlight, componentExp(light_atten * -lighty));
  1223. componentMultBy(sunlight, light_transmittance);
  1224. // Increase ambient when there are more clouds
  1225. F32 cloud_shadow = getCloudShadow();
  1226. LLColor3 ambient = getAmbientColor();
  1227. LLColor3 tmp_ambient = ambient +
  1228. (smear(1.f) - ambient) * cloud_shadow * 0.5f;
  1229. // Brightness of surface both sunlight and ambient
  1230. mSunDiffuse = sunlight;
  1231. mSunAmbient = tmp_ambient;
  1232. sunlight *= 1.f - cloud_shadow;
  1233. sunlight += tmp_ambient;
  1234. F32 haze_horizon = getHazeHorizon();
  1235. mHazeColor = getBlueHorizon() * getBlueDensity() * sunlight;
  1236. mHazeColor += LLColor4(haze_horizon, haze_horizon, haze_horizon,
  1237. haze_horizon) * getHazeDensity() * sunlight;
  1238. F32 moon_brightness = getIsMoonUp() ? getMoonBrightness() : 0.001f;
  1239. LLColor3 moonlight = getMoonlightColor();
  1240. // Scotopic ambient value
  1241. static const LLColor3 moonlight_b(0.66f, 0.66f, 1.2f);
  1242. componentMultBy(moonlight, componentExp((light_atten * -1.f) * lighty));
  1243. mMoonDiffuse = componentMult(moonlight, light_transmittance) *
  1244. moon_brightness;
  1245. mMoonAmbient = moonlight_b * 0.0125f;
  1246. mTotalAmbient = ambient;
  1247. }
  1248. LLColor3 LLSettingsSky::getSunlightColorClamped() const
  1249. {
  1250. LLColor3 sunlight = getSunlightColor();
  1251. F32 max_color = llmax(sunlight.mV[0], sunlight.mV[1], sunlight.mV[2]);
  1252. if (max_color > 1.f)
  1253. {
  1254. sunlight *= 1.f / max_color;
  1255. }
  1256. return sunlight;
  1257. }
  1258. #if LL_VARIABLE_SKY_DOME_SIZE
  1259. F32 LLSettingsSky::getDomeOffset() const
  1260. {
  1261. return mSettings[SETTING_DOME_OFFSET].asReal();
  1262. }
  1263. F32 LLSettingsSky::getDomeRadius() const
  1264. {
  1265. return mSettings[SETTING_DOME_RADIUS].asReal();
  1266. }
  1267. #endif
  1268. //virtual
  1269. LLSD LLSettingsSky::interpolateSDValue(const std::string& key_name,
  1270. const LLSD& value,
  1271. const LLSD& other_value,
  1272. const parammapping_t& defaults,
  1273. F64 mix,
  1274. const stringset_t& slerps) const
  1275. {
  1276. // SETTING_REFLECTION_PROBE_AMBIANCE does not exist in legacy (pre-PBR) sky
  1277. // settings, so we must deal with such a case here... HB
  1278. if (key_name == SETTING_REFLECTION_PROBE_AMBIANCE)
  1279. {
  1280. if (value.isUndefined() && other_value.isUndefined())
  1281. {
  1282. return value;
  1283. }
  1284. if (value.isUndefined())
  1285. {
  1286. return LLSettingsBase::interpolateSDValue(key_name,
  1287. LLSD::Real(0.0),
  1288. other_value, defaults,
  1289. mix, slerps);
  1290. }
  1291. if (other_value.isUndefined())
  1292. {
  1293. return LLSettingsBase::interpolateSDValue(key_name, value,
  1294. LLSD::Real(0.0),
  1295. defaults, mix, slerps);
  1296. }
  1297. }
  1298. return LLSettingsBase::interpolateSDValue(key_name, value, other_value,
  1299. defaults, mix, slerps);
  1300. }