llviewershadermgr.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:54k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llviewershadermgr.cpp
  3.  * @brief Viewer shader manager implementation.
  4.  *
  5.  * $LicenseInfo:firstyear=2005&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2005-2010, 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 "llviewerprecompiledheaders.h"
  33. #include "llfeaturemanager.h"
  34. #include "llviewershadermgr.h"
  35. #include "llfile.h"
  36. #include "llviewerwindow.h"
  37. #include "llviewercontrol.h"
  38. #include "pipeline.h"
  39. #include "llworld.h"
  40. #include "llwlparammanager.h"
  41. #include "llwaterparammanager.h"
  42. #include "llsky.h"
  43. #include "llvosky.h"
  44. #include "llrender.h"
  45. #if LL_DARWIN
  46. #include "OpenGL/OpenGL.h"
  47. #endif
  48. #ifdef LL_RELEASE_FOR_DOWNLOAD
  49. #define UNIFORM_ERRS LL_WARNS_ONCE("Shader")
  50. #else
  51. #define UNIFORM_ERRS LL_ERRS("Shader")
  52. #endif
  53. // Lots of STL stuff in here, using namespace std to keep things more readable
  54. using std::vector;
  55. using std::pair;
  56. using std::make_pair;
  57. using std::string;
  58. BOOL LLViewerShaderMgr::sInitialized = FALSE;
  59. LLVector4 gShinyOrigin;
  60. //object shaders
  61. LLGLSLShader gObjectSimpleProgram;
  62. LLGLSLShader gObjectSimpleWaterProgram;
  63. LLGLSLShader gObjectFullbrightProgram;
  64. LLGLSLShader gObjectFullbrightWaterProgram;
  65. LLGLSLShader gObjectFullbrightShinyProgram;
  66. LLGLSLShader gObjectShinyProgram;
  67. LLGLSLShader gObjectShinyWaterProgram;
  68. //environment shaders
  69. LLGLSLShader gTerrainProgram;
  70. LLGLSLShader gTerrainWaterProgram;
  71. LLGLSLShader gWaterProgram;
  72. LLGLSLShader gUnderWaterProgram;
  73. //interface shaders
  74. LLGLSLShader gHighlightProgram;
  75. //avatar shader handles
  76. LLGLSLShader gAvatarProgram;
  77. LLGLSLShader gAvatarWaterProgram;
  78. LLGLSLShader gAvatarEyeballProgram;
  79. LLGLSLShader gAvatarPickProgram;
  80. // WindLight shader handles
  81. LLGLSLShader gWLSkyProgram;
  82. LLGLSLShader gWLCloudProgram;
  83. // Effects Shaders
  84. LLGLSLShader gGlowProgram;
  85. LLGLSLShader gGlowExtractProgram;
  86. LLGLSLShader gPostColorFilterProgram;
  87. LLGLSLShader gPostNightVisionProgram;
  88. // Deferred rendering shaders
  89. LLGLSLShader gDeferredImpostorProgram;
  90. LLGLSLShader gDeferredEdgeProgram;
  91. LLGLSLShader gDeferredWaterProgram;
  92. LLGLSLShader gDeferredDiffuseProgram;
  93. LLGLSLShader gDeferredBumpProgram;
  94. LLGLSLShader gDeferredTerrainProgram;
  95. LLGLSLShader gDeferredTreeProgram;
  96. LLGLSLShader gDeferredAvatarProgram;
  97. LLGLSLShader gDeferredAvatarAlphaProgram;
  98. LLGLSLShader gDeferredLightProgram;
  99. LLGLSLShader gDeferredMultiLightProgram;
  100. LLGLSLShader gDeferredSpotLightProgram;
  101. LLGLSLShader gDeferredMultiSpotLightProgram;
  102. LLGLSLShader gDeferredSunProgram;
  103. LLGLSLShader gDeferredBlurLightProgram;
  104. LLGLSLShader gDeferredSoftenProgram;
  105. LLGLSLShader gDeferredShadowProgram;
  106. LLGLSLShader gDeferredAvatarShadowProgram;
  107. LLGLSLShader gDeferredAlphaProgram;
  108. LLGLSLShader gDeferredFullbrightProgram;
  109. LLGLSLShader gDeferredGIProgram;
  110. LLGLSLShader gDeferredGIFinalProgram;
  111. LLGLSLShader gDeferredPostGIProgram;
  112. LLGLSLShader gDeferredPostProgram;
  113. LLGLSLShader gLuminanceGatherProgram;
  114. //current avatar shader parameter pointer
  115. GLint gAvatarMatrixParam;
  116. LLViewerShaderMgr::LLViewerShaderMgr() :
  117. mVertexShaderLevel(SHADER_COUNT, 0),
  118. mMaxAvatarShaderLevel(0)
  119. {
  120. /// Make sure WL Sky is the first program
  121. mShaderList.push_back(&gWLSkyProgram);
  122. mShaderList.push_back(&gWLCloudProgram);
  123. mShaderList.push_back(&gAvatarProgram);
  124. mShaderList.push_back(&gObjectShinyProgram);
  125. mShaderList.push_back(&gWaterProgram);
  126. mShaderList.push_back(&gAvatarEyeballProgram); 
  127. mShaderList.push_back(&gObjectSimpleProgram);
  128. mShaderList.push_back(&gObjectFullbrightProgram);
  129. mShaderList.push_back(&gObjectFullbrightShinyProgram);
  130. mShaderList.push_back(&gTerrainProgram);
  131. mShaderList.push_back(&gTerrainWaterProgram);
  132. mShaderList.push_back(&gObjectSimpleWaterProgram);
  133. mShaderList.push_back(&gObjectFullbrightWaterProgram);
  134. mShaderList.push_back(&gAvatarWaterProgram);
  135. mShaderList.push_back(&gObjectShinyWaterProgram);
  136. mShaderList.push_back(&gUnderWaterProgram);
  137. mShaderList.push_back(&gDeferredSunProgram);
  138. mShaderList.push_back(&gDeferredBlurLightProgram);
  139. mShaderList.push_back(&gDeferredSoftenProgram);
  140. mShaderList.push_back(&gDeferredLightProgram);
  141. mShaderList.push_back(&gDeferredMultiLightProgram);
  142. mShaderList.push_back(&gDeferredAlphaProgram);
  143. mShaderList.push_back(&gDeferredFullbrightProgram);
  144. mShaderList.push_back(&gDeferredPostGIProgram);
  145. mShaderList.push_back(&gDeferredEdgeProgram);
  146. mShaderList.push_back(&gDeferredPostProgram);
  147. mShaderList.push_back(&gDeferredGIProgram);
  148. mShaderList.push_back(&gDeferredGIFinalProgram);
  149. mShaderList.push_back(&gDeferredWaterProgram);
  150. mShaderList.push_back(&gDeferredAvatarAlphaProgram);
  151. }
  152. LLViewerShaderMgr::~LLViewerShaderMgr()
  153. {
  154. mVertexShaderLevel.clear();
  155. mShaderList.clear();
  156. }
  157. // static
  158. LLViewerShaderMgr * LLViewerShaderMgr::instance()
  159. {
  160. if(NULL == sInstance)
  161. {
  162. sInstance = new LLViewerShaderMgr();
  163. }
  164. return static_cast<LLViewerShaderMgr*>(sInstance);
  165. }
  166. void LLViewerShaderMgr::initAttribsAndUniforms(void)
  167. {
  168. if (mReservedAttribs.empty())
  169. {
  170. mReservedAttribs.push_back("materialColor");
  171. mReservedAttribs.push_back("specularColor");
  172. mReservedAttribs.push_back("binormal");
  173. mAvatarAttribs.reserve(5);
  174. mAvatarAttribs.push_back("weight");
  175. mAvatarAttribs.push_back("clothing");
  176. mAvatarAttribs.push_back("gWindDir");
  177. mAvatarAttribs.push_back("gSinWaveParams");
  178. mAvatarAttribs.push_back("gGravity");
  179. mAvatarUniforms.push_back("matrixPalette");
  180. mReservedUniforms.reserve(24);
  181. mReservedUniforms.push_back("diffuseMap");
  182. mReservedUniforms.push_back("specularMap");
  183. mReservedUniforms.push_back("bumpMap");
  184. mReservedUniforms.push_back("environmentMap");
  185. mReservedUniforms.push_back("cloude_noise_texture");
  186. mReservedUniforms.push_back("fullbright");
  187. mReservedUniforms.push_back("lightnorm");
  188. mReservedUniforms.push_back("sunlight_color");
  189. mReservedUniforms.push_back("ambient");
  190. mReservedUniforms.push_back("blue_horizon");
  191. mReservedUniforms.push_back("blue_density");
  192. mReservedUniforms.push_back("haze_horizon");
  193. mReservedUniforms.push_back("haze_density");
  194. mReservedUniforms.push_back("cloud_shadow");
  195. mReservedUniforms.push_back("density_multiplier");
  196. mReservedUniforms.push_back("distance_multiplier");
  197. mReservedUniforms.push_back("max_y");
  198. mReservedUniforms.push_back("glow");
  199. mReservedUniforms.push_back("cloud_color");
  200. mReservedUniforms.push_back("cloud_pos_density1");
  201. mReservedUniforms.push_back("cloud_pos_density2");
  202. mReservedUniforms.push_back("cloud_scale");
  203. mReservedUniforms.push_back("gamma");
  204. mReservedUniforms.push_back("scene_light_strength");
  205. mReservedUniforms.push_back("depthMap");
  206. mReservedUniforms.push_back("shadowMap0");
  207. mReservedUniforms.push_back("shadowMap1");
  208. mReservedUniforms.push_back("shadowMap2");
  209. mReservedUniforms.push_back("shadowMap3");
  210. mReservedUniforms.push_back("shadowMap4");
  211. mReservedUniforms.push_back("shadowMap5");
  212. mReservedUniforms.push_back("normalMap");
  213. mReservedUniforms.push_back("positionMap");
  214. mReservedUniforms.push_back("diffuseRect");
  215. mReservedUniforms.push_back("specularRect");
  216. mReservedUniforms.push_back("noiseMap");
  217. mReservedUniforms.push_back("lightFunc");
  218. mReservedUniforms.push_back("lightMap");
  219. mReservedUniforms.push_back("luminanceMap");
  220. mReservedUniforms.push_back("giLightMap");
  221. mReservedUniforms.push_back("giMip");
  222. mReservedUniforms.push_back("edgeMap");
  223. mReservedUniforms.push_back("bloomMap");
  224. mReservedUniforms.push_back("sunLightMap");
  225. mReservedUniforms.push_back("localLightMap");
  226. mReservedUniforms.push_back("projectionMap");
  227. mReservedUniforms.push_back("diffuseGIMap");
  228. mReservedUniforms.push_back("specularGIMap");
  229. mReservedUniforms.push_back("normalGIMap");
  230. mReservedUniforms.push_back("minpGIMap");
  231. mReservedUniforms.push_back("maxpGIMap");
  232. mReservedUniforms.push_back("depthGIMap");
  233. mReservedUniforms.push_back("lastDiffuseGIMap");
  234. mReservedUniforms.push_back("lastNormalGIMap");
  235. mReservedUniforms.push_back("lastMinpGIMap");
  236. mReservedUniforms.push_back("lastMaxpGIMap");
  237. mWLUniforms.push_back("camPosLocal");
  238. mTerrainUniforms.reserve(5);
  239. mTerrainUniforms.push_back("detail_0");
  240. mTerrainUniforms.push_back("detail_1");
  241. mTerrainUniforms.push_back("detail_2");
  242. mTerrainUniforms.push_back("detail_3");
  243. mTerrainUniforms.push_back("alpha_ramp");
  244. mGlowUniforms.push_back("glowDelta");
  245. mGlowUniforms.push_back("glowStrength");
  246. mGlowExtractUniforms.push_back("minLuminance");
  247. mGlowExtractUniforms.push_back("maxExtractAlpha");
  248. mGlowExtractUniforms.push_back("lumWeights");
  249. mGlowExtractUniforms.push_back("warmthWeights");
  250. mGlowExtractUniforms.push_back("warmthAmount");
  251. mShinyUniforms.push_back("origin");
  252. mWaterUniforms.reserve(12);
  253. mWaterUniforms.push_back("screenTex");
  254. mWaterUniforms.push_back("screenDepth");
  255. mWaterUniforms.push_back("refTex");
  256. mWaterUniforms.push_back("eyeVec");
  257. mWaterUniforms.push_back("time");
  258. mWaterUniforms.push_back("d1");
  259. mWaterUniforms.push_back("d2");
  260. mWaterUniforms.push_back("lightDir");
  261. mWaterUniforms.push_back("specular");
  262. mWaterUniforms.push_back("lightExp");
  263. mWaterUniforms.push_back("fogCol");
  264. mWaterUniforms.push_back("kd");
  265. mWaterUniforms.push_back("refScale");
  266. mWaterUniforms.push_back("waterHeight");
  267. }
  268. }
  269. //============================================================================
  270. // Set Levels
  271. S32 LLViewerShaderMgr::getVertexShaderLevel(S32 type)
  272. {
  273. return LLPipeline::sDisableShaders ? 0 : mVertexShaderLevel[type];
  274. }
  275. //============================================================================
  276. // Shader Management
  277. void LLViewerShaderMgr::setShaders()
  278. {
  279. if (!gPipeline.mInitialized || !sInitialized)
  280. {
  281. return;
  282. }
  283. // Make sure the compiled shader map is cleared before we recompile shaders.
  284. mShaderObjects.clear();
  285. initAttribsAndUniforms();
  286. gPipeline.releaseGLBuffers();
  287. if (gSavedSettings.getBOOL("VertexShaderEnable"))
  288. {
  289. LLPipeline::sWaterReflections = gGLManager.mHasCubeMap;
  290. LLPipeline::sRenderGlow = gSavedSettings.getBOOL("RenderGlow"); 
  291. LLPipeline::updateRenderDeferred();
  292. }
  293. else
  294. {
  295. LLPipeline::sRenderGlow = 
  296. LLPipeline::sWaterReflections = FALSE;
  297. }
  298. //hack to reset buffers that change behavior with shaders
  299. gPipeline.resetVertexBuffers();
  300. if (gViewerWindow)
  301. {
  302. gViewerWindow->setCursor(UI_CURSOR_WAIT);
  303. }
  304. // Lighting
  305. gPipeline.setLightingDetail(-1);
  306. // Shaders
  307. LL_INFOS("ShaderLoading") << "n~~~~~~~~~~~~~~~~~~n Loading Shaders:n~~~~~~~~~~~~~~~~~~" << LL_ENDL;
  308. for (S32 i = 0; i < SHADER_COUNT; i++)
  309. {
  310. mVertexShaderLevel[i] = 0;
  311. }
  312. mMaxAvatarShaderLevel = 0;
  313. if (LLFeatureManager::getInstance()->isFeatureAvailable("VertexShaderEnable") 
  314. && gSavedSettings.getBOOL("VertexShaderEnable"))
  315. {
  316. S32 light_class = 2;
  317. S32 env_class = 2;
  318. S32 obj_class = 2;
  319. S32 effect_class = 2;
  320. S32 wl_class = 2;
  321. S32 water_class = 2;
  322. S32 deferred_class = 0;
  323. if (!(LLFeatureManager::getInstance()->isFeatureAvailable("WindLightUseAtmosShaders")
  324.   && gSavedSettings.getBOOL("WindLightUseAtmosShaders")))
  325. {
  326. // user has disabled WindLight in their settings, downgrade
  327. // windlight shaders to stub versions.
  328. wl_class = 1;
  329. }
  330. if (LLPipeline::sRenderDeferred)
  331. {
  332. if (gSavedSettings.getBOOL("RenderDeferredShadow"))
  333. {
  334. if (gSavedSettings.getBOOL("RenderDeferredGI"))
  335. { //shadows + gi
  336. deferred_class = 3;
  337. }
  338. else
  339. { //shadows
  340. deferred_class = 2;
  341. }
  342. }
  343. else
  344. { //no shadows
  345. deferred_class = 1;
  346. }
  347. }
  348. if(!gSavedSettings.getBOOL("EnableRippleWater"))
  349. {
  350. water_class = 0;
  351. }
  352. // Trigger a full rebuild of the fallback skybox / cubemap if we've toggled windlight shaders
  353. if (mVertexShaderLevel[SHADER_WINDLIGHT] != wl_class && gSky.mVOSkyp.notNull())
  354. {
  355. gSky.mVOSkyp->forceSkyUpdate();
  356. }
  357. // Load lighting shaders
  358. mVertexShaderLevel[SHADER_LIGHTING] = light_class;
  359. mVertexShaderLevel[SHADER_INTERFACE] = light_class;
  360. mVertexShaderLevel[SHADER_ENVIRONMENT] = env_class;
  361. mVertexShaderLevel[SHADER_WATER] = water_class;
  362. mVertexShaderLevel[SHADER_OBJECT] = obj_class;
  363. mVertexShaderLevel[SHADER_EFFECT] = effect_class;
  364. mVertexShaderLevel[SHADER_WINDLIGHT] = wl_class;
  365. mVertexShaderLevel[SHADER_DEFERRED] = deferred_class;
  366. BOOL loaded = loadBasicShaders();
  367. if (loaded)
  368. {
  369. gPipeline.mVertexShadersEnabled = TRUE;
  370. gPipeline.mVertexShadersLoaded = 1;
  371. // Load all shaders to set max levels
  372. loadShadersEnvironment();
  373. loadShadersWater();
  374. loadShadersObject();
  375. loadShadersWindLight();
  376. loadShadersEffects();
  377. loadShadersInterface();
  378. // Load max avatar shaders to set the max level
  379. mVertexShaderLevel[SHADER_AVATAR] = 3;
  380. mMaxAvatarShaderLevel = 3;
  381. loadShadersAvatar();
  382. #if 0 && LL_DARWIN // force avatar shaders off for mac
  383. mVertexShaderLevel[SHADER_AVATAR] = 0;
  384. sMaxAvatarShaderLevel = 0;
  385. #else
  386. if (gSavedSettings.getBOOL("RenderAvatarVP"))
  387. {
  388. BOOL avatar_cloth = gSavedSettings.getBOOL("RenderAvatarCloth");
  389. S32 avatar_class = 1;
  390. // cloth is a class3 shader
  391. if(avatar_cloth)
  392. {
  393. avatar_class = 3;
  394. }
  395. // Set the actual level
  396. mVertexShaderLevel[SHADER_AVATAR] = avatar_class;
  397. loadShadersAvatar();
  398. if (mVertexShaderLevel[SHADER_AVATAR] != avatar_class)
  399. {
  400. if (mVertexShaderLevel[SHADER_AVATAR] == 0)
  401. {
  402. gSavedSettings.setBOOL("RenderAvatarVP", FALSE);
  403. }
  404. if(llmax(mVertexShaderLevel[SHADER_AVATAR]-1,0) >= 3)
  405. {
  406. avatar_cloth = true;
  407. }
  408. else
  409. {
  410. avatar_cloth = false;
  411. }
  412. gSavedSettings.setBOOL("RenderAvatarCloth", avatar_cloth);
  413. }
  414. }
  415. else
  416. {
  417. mVertexShaderLevel[SHADER_AVATAR] = 0;
  418. gSavedSettings.setBOOL("RenderAvatarCloth", FALSE);
  419. loadShadersAvatar(); // unloads
  420. }
  421. if (!loadShadersDeferred())
  422. {
  423. gSavedSettings.setBOOL("RenderDeferred", FALSE);
  424. }
  425. #endif
  426. }
  427. else
  428. {
  429. gPipeline.mVertexShadersEnabled = FALSE;
  430. gPipeline.mVertexShadersLoaded = 0;
  431. mVertexShaderLevel[SHADER_LIGHTING] = 0;
  432. mVertexShaderLevel[SHADER_INTERFACE] = 0;
  433. mVertexShaderLevel[SHADER_ENVIRONMENT] = 0;
  434. mVertexShaderLevel[SHADER_WATER] = 0;
  435. mVertexShaderLevel[SHADER_OBJECT] = 0;
  436. mVertexShaderLevel[SHADER_EFFECT] = 0;
  437. mVertexShaderLevel[SHADER_WINDLIGHT] = 0;
  438. mVertexShaderLevel[SHADER_AVATAR] = 0;
  439. }
  440. }
  441. else
  442. {
  443. gPipeline.mVertexShadersEnabled = FALSE;
  444. gPipeline.mVertexShadersLoaded = 0;
  445. mVertexShaderLevel[SHADER_LIGHTING] = 0;
  446. mVertexShaderLevel[SHADER_INTERFACE] = 0;
  447. mVertexShaderLevel[SHADER_ENVIRONMENT] = 0;
  448. mVertexShaderLevel[SHADER_WATER] = 0;
  449. mVertexShaderLevel[SHADER_OBJECT] = 0;
  450. mVertexShaderLevel[SHADER_EFFECT] = 0;
  451. mVertexShaderLevel[SHADER_WINDLIGHT] = 0;
  452. mVertexShaderLevel[SHADER_AVATAR] = 0;
  453. }
  454. if (gViewerWindow)
  455. {
  456. gViewerWindow->setCursor(UI_CURSOR_ARROW);
  457. }
  458. gPipeline.createGLBuffers();
  459. }
  460. void LLViewerShaderMgr::unloadShaders()
  461. {
  462. gObjectSimpleProgram.unload();
  463. gObjectSimpleWaterProgram.unload();
  464. gObjectFullbrightProgram.unload();
  465. gObjectFullbrightWaterProgram.unload();
  466. gObjectShinyProgram.unload();
  467. gObjectFullbrightShinyProgram.unload();
  468. gObjectShinyWaterProgram.unload();
  469. gWaterProgram.unload();
  470. gUnderWaterProgram.unload();
  471. gTerrainProgram.unload();
  472. gTerrainWaterProgram.unload();
  473. gGlowProgram.unload();
  474. gGlowExtractProgram.unload();
  475. gAvatarProgram.unload();
  476. gAvatarWaterProgram.unload();
  477. gAvatarEyeballProgram.unload();
  478. gAvatarPickProgram.unload();
  479. gHighlightProgram.unload();
  480. gWLSkyProgram.unload();
  481. gWLCloudProgram.unload();
  482. gPostColorFilterProgram.unload();
  483. gPostNightVisionProgram.unload();
  484. gDeferredDiffuseProgram.unload();
  485. mVertexShaderLevel[SHADER_LIGHTING] = 0;
  486. mVertexShaderLevel[SHADER_OBJECT] = 0;
  487. mVertexShaderLevel[SHADER_AVATAR] = 0;
  488. mVertexShaderLevel[SHADER_ENVIRONMENT] = 0;
  489. mVertexShaderLevel[SHADER_WATER] = 0;
  490. mVertexShaderLevel[SHADER_INTERFACE] = 0;
  491. mVertexShaderLevel[SHADER_EFFECT] = 0;
  492. mVertexShaderLevel[SHADER_WINDLIGHT] = 0;
  493. gPipeline.mVertexShadersLoaded = 0;
  494. }
  495. BOOL LLViewerShaderMgr::loadBasicShaders()
  496. {
  497. // Load basic dependency shaders first
  498. // All of these have to load for any shaders to function
  499. #if LL_DARWIN // Mac can't currently handle all 8 lights, 
  500. S32 sum_lights_class = 2;
  501. #else 
  502. S32 sum_lights_class = 3;
  503. // class one cards will get the lower sum lights
  504. // class zero we're not going to think about
  505. // since a class zero card COULD be a ridiculous new card
  506. // and old cards should have the features masked
  507. if(LLFeatureManager::getInstance()->getGPUClass() == GPU_CLASS_1)
  508. {
  509. sum_lights_class = 2;
  510. }
  511. #endif
  512. // If we have sun and moon only checked, then only sum those lights.
  513. if (gPipeline.getLightingDetail() == 0)
  514. {
  515. sum_lights_class = 1;
  516. }
  517. // Use the feature table to mask out the max light level to use.  Also make sure it's at least 1.
  518. S32 max_light_class = gSavedSettings.getS32("RenderShaderLightingMaxLevel");
  519. sum_lights_class = llclamp(sum_lights_class, 1, max_light_class);
  520. // Load the Basic Vertex Shaders at the appropriate level. 
  521. // (in order of shader function call depth for reference purposes, deepest level first)
  522. vector< pair<string, S32> > shaders;
  523. shaders.reserve(10);
  524. shaders.push_back( make_pair( "windlight/atmosphericsVarsV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  525. shaders.push_back( make_pair( "windlight/atmosphericsHelpersV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  526. shaders.push_back( make_pair( "lighting/lightFuncV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  527. shaders.push_back( make_pair( "lighting/sumLightsV.glsl", sum_lights_class ) );
  528. shaders.push_back( make_pair( "lighting/lightV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  529. shaders.push_back( make_pair( "lighting/lightFuncSpecularV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  530. shaders.push_back( make_pair( "lighting/sumLightsSpecularV.glsl", sum_lights_class ) );
  531. shaders.push_back( make_pair( "lighting/lightSpecularV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  532. shaders.push_back( make_pair( "windlight/atmosphericsV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  533. shaders.push_back( make_pair( "avatar/avatarSkinV.glsl", 1 ) );
  534. // We no longer have to bind the shaders to global glhandles, they are automatically added to a map now.
  535. for (U32 i = 0; i < shaders.size(); i++)
  536. {
  537. // Note usage of GL_VERTEX_SHADER_ARB
  538. if (loadShaderFile(shaders[i].first, shaders[i].second, GL_VERTEX_SHADER_ARB) == 0)
  539. {
  540. return FALSE;
  541. }
  542. }
  543. // Load the Basic Fragment Shaders at the appropriate level. 
  544. // (in order of shader function call depth for reference purposes, deepest level first)
  545. shaders.clear();
  546. shaders.reserve(12);
  547. shaders.push_back( make_pair( "windlight/atmosphericsVarsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  548. shaders.push_back( make_pair( "windlight/gammaF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT]) );
  549. shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  550. shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) );
  551. shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) );
  552. shaders.push_back( make_pair( "lighting/lightF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  553. shaders.push_back( make_pair( "lighting/lightFullbrightF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  554. shaders.push_back( make_pair( "lighting/lightWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  555. shaders.push_back( make_pair( "lighting/lightFullbrightWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  556. shaders.push_back( make_pair( "lighting/lightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  557. shaders.push_back( make_pair( "lighting/lightFullbrightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  558. shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
  559. for (U32 i = 0; i < shaders.size(); i++)
  560. {
  561. // Note usage of GL_FRAGMENT_SHADER_ARB
  562. if (loadShaderFile(shaders[i].first, shaders[i].second, GL_FRAGMENT_SHADER_ARB) == 0)
  563. {
  564. return FALSE;
  565. }
  566. }
  567. return TRUE;
  568. }
  569. BOOL LLViewerShaderMgr::loadShadersEnvironment()
  570. {
  571. BOOL success = TRUE;
  572. if (mVertexShaderLevel[SHADER_ENVIRONMENT] == 0)
  573. {
  574. gTerrainProgram.unload();
  575. return FALSE;
  576. }
  577. if (success)
  578. {
  579. gTerrainProgram.mName = "Terrain Shader";
  580. gTerrainProgram.mFeatures.calculatesLighting = true;
  581. gTerrainProgram.mFeatures.calculatesAtmospherics = true;
  582. gTerrainProgram.mFeatures.hasAtmospherics = true;
  583. gTerrainProgram.mFeatures.hasGamma = true;
  584. gTerrainProgram.mShaderFiles.clear();
  585. gTerrainProgram.mShaderFiles.push_back(make_pair("environment/terrainV.glsl", GL_VERTEX_SHADER_ARB));
  586. gTerrainProgram.mShaderFiles.push_back(make_pair("environment/terrainF.glsl", GL_FRAGMENT_SHADER_ARB));
  587. gTerrainProgram.mShaderLevel = mVertexShaderLevel[SHADER_ENVIRONMENT];
  588. success = gTerrainProgram.createShader(NULL, &mTerrainUniforms);
  589. }
  590. if (!success)
  591. {
  592. mVertexShaderLevel[SHADER_ENVIRONMENT] = 0;
  593. return FALSE;
  594. }
  595. LLWorld::getInstance()->updateWaterObjects();
  596. return TRUE;
  597. }
  598. BOOL LLViewerShaderMgr::loadShadersWater()
  599. {
  600. BOOL success = TRUE;
  601. BOOL terrainWaterSuccess = TRUE;
  602. if (mVertexShaderLevel[SHADER_WATER] == 0)
  603. {
  604. gWaterProgram.unload();
  605. gUnderWaterProgram.unload();
  606. gTerrainWaterProgram.unload();
  607. return FALSE;
  608. }
  609. if (success)
  610. {
  611. // load water shader
  612. gWaterProgram.mName = "Water Shader";
  613. gWaterProgram.mFeatures.calculatesAtmospherics = true;
  614. gWaterProgram.mFeatures.hasGamma = true;
  615. gWaterProgram.mFeatures.hasTransport = true;
  616. gWaterProgram.mShaderFiles.clear();
  617. gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER_ARB));
  618. gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER_ARB));
  619. gWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER];
  620. success = gWaterProgram.createShader(NULL, &mWaterUniforms);
  621. }
  622. if (success)
  623. {
  624. //load under water vertex shader
  625. gUnderWaterProgram.mName = "Underwater Shader";
  626. gUnderWaterProgram.mFeatures.calculatesAtmospherics = true;
  627. gUnderWaterProgram.mShaderFiles.clear();
  628. gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER_ARB));
  629. gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  630. gUnderWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER];
  631. gUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  632. success = gUnderWaterProgram.createShader(NULL, &mWaterUniforms);
  633. }
  634. if (success)
  635. {
  636. //load terrain water shader
  637. gTerrainWaterProgram.mName = "Terrain Water Shader";
  638. gTerrainWaterProgram.mFeatures.calculatesLighting = true;
  639. gTerrainWaterProgram.mFeatures.calculatesAtmospherics = true;
  640. gTerrainWaterProgram.mFeatures.hasAtmospherics = true;
  641. gTerrainWaterProgram.mFeatures.hasWaterFog = true;
  642. gTerrainWaterProgram.mShaderFiles.clear();
  643. gTerrainWaterProgram.mShaderFiles.push_back(make_pair("environment/terrainV.glsl", GL_VERTEX_SHADER_ARB));
  644. gTerrainWaterProgram.mShaderFiles.push_back(make_pair("environment/terrainWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  645. gTerrainWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_ENVIRONMENT];
  646. gTerrainWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  647. terrainWaterSuccess = gTerrainWaterProgram.createShader(NULL, &mTerrainUniforms);
  648. }
  649. /// Keep track of water shader levels
  650. if (gWaterProgram.mShaderLevel != mVertexShaderLevel[SHADER_WATER]
  651. || gUnderWaterProgram.mShaderLevel != mVertexShaderLevel[SHADER_WATER])
  652. {
  653. mVertexShaderLevel[SHADER_WATER] = llmin(gWaterProgram.mShaderLevel, gUnderWaterProgram.mShaderLevel);
  654. }
  655. if (!success)
  656. {
  657. mVertexShaderLevel[SHADER_WATER] = 0;
  658. return FALSE;
  659. }
  660. // if we failed to load the terrain water shaders and we need them (using class2 water),
  661. // then drop down to class1 water.
  662. if (mVertexShaderLevel[SHADER_WATER] > 1 && !terrainWaterSuccess)
  663. {
  664. mVertexShaderLevel[SHADER_WATER]--;
  665. return loadShadersWater();
  666. }
  667. LLWorld::getInstance()->updateWaterObjects();
  668. return TRUE;
  669. }
  670. BOOL LLViewerShaderMgr::loadShadersEffects()
  671. {
  672. BOOL success = TRUE;
  673. if (mVertexShaderLevel[SHADER_EFFECT] == 0)
  674. {
  675. gGlowProgram.unload();
  676. gGlowExtractProgram.unload();
  677. gPostColorFilterProgram.unload();
  678. gPostNightVisionProgram.unload();
  679. return FALSE;
  680. }
  681. if (success)
  682. {
  683. gGlowProgram.mName = "Glow Shader (Post)";
  684. gGlowProgram.mShaderFiles.clear();
  685. gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowV.glsl", GL_VERTEX_SHADER_ARB));
  686. gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowF.glsl", GL_FRAGMENT_SHADER_ARB));
  687. gGlowProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT];
  688. success = gGlowProgram.createShader(NULL, &mGlowUniforms);
  689. if (!success)
  690. {
  691. LLPipeline::sRenderGlow = FALSE;
  692. }
  693. }
  694. if (success)
  695. {
  696. gGlowExtractProgram.mName = "Glow Extract Shader (Post)";
  697. gGlowExtractProgram.mShaderFiles.clear();
  698. gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractV.glsl", GL_VERTEX_SHADER_ARB));
  699. gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractF.glsl", GL_FRAGMENT_SHADER_ARB));
  700. gGlowExtractProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT];
  701. success = gGlowExtractProgram.createShader(NULL, &mGlowExtractUniforms);
  702. if (!success)
  703. {
  704. LLPipeline::sRenderGlow = FALSE;
  705. }
  706. }
  707. #if 0
  708. // disabling loading of postprocess shaders until we fix
  709. // ATI sampler2DRect compatibility.
  710. //load Color Filter Shader
  711. if (success)
  712. {
  713. vector<string> shaderUniforms;
  714. shaderUniforms.reserve(7);
  715. shaderUniforms.push_back("RenderTexture");
  716. shaderUniforms.push_back("gamma");
  717. shaderUniforms.push_back("brightness");
  718. shaderUniforms.push_back("contrast");
  719. shaderUniforms.push_back("contrastBase");
  720. shaderUniforms.push_back("saturation");
  721. shaderUniforms.push_back("lumWeights");
  722. gPostColorFilterProgram.mName = "Color Filter Shader (Post)";
  723. gPostColorFilterProgram.mShaderFiles.clear();
  724. gPostColorFilterProgram.mShaderFiles.push_back(make_pair("effects/colorFilterF.glsl", GL_FRAGMENT_SHADER_ARB));
  725. gPostColorFilterProgram.mShaderFiles.push_back(make_pair("effects/drawQuadV.glsl", GL_VERTEX_SHADER_ARB));
  726. gPostColorFilterProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT];
  727. success = gPostColorFilterProgram.createShader(NULL, &shaderUniforms);
  728. }
  729. //load Night Vision Shader
  730. if (success)
  731. {
  732. vector<string> shaderUniforms;
  733. shaderUniforms.reserve(5);
  734. shaderUniforms.push_back("RenderTexture");
  735. shaderUniforms.push_back("NoiseTexture");
  736. shaderUniforms.push_back("brightMult");
  737. shaderUniforms.push_back("noiseStrength");
  738. shaderUniforms.push_back("lumWeights");
  739. gPostNightVisionProgram.mName = "Night Vision Shader (Post)";
  740. gPostNightVisionProgram.mShaderFiles.clear();
  741. gPostNightVisionProgram.mShaderFiles.push_back(make_pair("effects/nightVisionF.glsl", GL_FRAGMENT_SHADER_ARB));
  742. gPostNightVisionProgram.mShaderFiles.push_back(make_pair("effects/drawQuadV.glsl", GL_VERTEX_SHADER_ARB));
  743. gPostNightVisionProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT];
  744. success = gPostNightVisionProgram.createShader(NULL, &shaderUniforms);
  745. }
  746. #endif
  747. return success;
  748. }
  749. BOOL LLViewerShaderMgr::loadShadersDeferred()
  750. {
  751. if (mVertexShaderLevel[SHADER_DEFERRED] == 0)
  752. {
  753. gDeferredTreeProgram.unload();
  754. gDeferredDiffuseProgram.unload();
  755. gDeferredBumpProgram.unload();
  756. gDeferredImpostorProgram.unload();
  757. gDeferredTerrainProgram.unload();
  758. gDeferredLightProgram.unload();
  759. gDeferredMultiLightProgram.unload();
  760. gDeferredSpotLightProgram.unload();
  761. gDeferredMultiSpotLightProgram.unload();
  762. gDeferredSunProgram.unload();
  763. gDeferredBlurLightProgram.unload();
  764. gDeferredSoftenProgram.unload();
  765. gDeferredShadowProgram.unload();
  766. gDeferredAvatarShadowProgram.unload();
  767. gDeferredAvatarProgram.unload();
  768. gDeferredAvatarAlphaProgram.unload();
  769. gDeferredAlphaProgram.unload();
  770. gDeferredFullbrightProgram.unload();
  771. gDeferredPostGIProgram.unload();
  772. gDeferredEdgeProgram.unload();
  773. gDeferredPostProgram.unload();
  774. gLuminanceGatherProgram.unload();
  775. gDeferredGIProgram.unload();
  776. gDeferredGIFinalProgram.unload();
  777. gDeferredWaterProgram.unload();
  778. return FALSE;
  779. }
  780. mVertexShaderLevel[SHADER_AVATAR] = 1;
  781. BOOL success = TRUE;
  782. if (success)
  783. {
  784. gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader";
  785. gDeferredDiffuseProgram.mShaderFiles.clear();
  786. gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB));
  787. gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER_ARB));
  788. gDeferredDiffuseProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  789. success = gDeferredDiffuseProgram.createShader(NULL, NULL);
  790. }
  791. if (success)
  792. {
  793. gDeferredBumpProgram.mName = "Deferred Bump Shader";
  794. gDeferredBumpProgram.mShaderFiles.clear();
  795. gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpV.glsl", GL_VERTEX_SHADER_ARB));
  796. gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpF.glsl", GL_FRAGMENT_SHADER_ARB));
  797. gDeferredBumpProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  798. success = gDeferredBumpProgram.createShader(NULL, NULL);
  799. }
  800. if (success)
  801. {
  802. gDeferredTreeProgram.mName = "Deferred Tree Shader";
  803. gDeferredTreeProgram.mShaderFiles.clear();
  804. gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeV.glsl", GL_VERTEX_SHADER_ARB));
  805. gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeF.glsl", GL_FRAGMENT_SHADER_ARB));
  806. gDeferredTreeProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  807. success = gDeferredTreeProgram.createShader(NULL, NULL);
  808. }
  809. if (success)
  810. {
  811. gDeferredImpostorProgram.mName = "Deferred Impostor Shader";
  812. gDeferredImpostorProgram.mShaderFiles.clear();
  813. gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorV.glsl", GL_VERTEX_SHADER_ARB));
  814. gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorF.glsl", GL_FRAGMENT_SHADER_ARB));
  815. gDeferredImpostorProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  816. success = gDeferredImpostorProgram.createShader(NULL, NULL);
  817. }
  818. if (success)
  819. {
  820. gDeferredLightProgram.mName = "Deferred Light Shader";
  821. gDeferredLightProgram.mShaderFiles.clear();
  822. gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB));
  823. gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  824. gDeferredLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  825. success = gDeferredLightProgram.createShader(NULL, NULL);
  826. }
  827. if (success)
  828. {
  829. gDeferredMultiLightProgram.mName = "Deferred MultiLight Shader";
  830. gDeferredMultiLightProgram.mShaderFiles.clear();
  831. gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB));
  832. gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  833. gDeferredMultiLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  834. success = gDeferredMultiLightProgram.createShader(NULL, NULL);
  835. }
  836. if (success)
  837. {
  838. gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader";
  839. gDeferredSpotLightProgram.mShaderFiles.clear();
  840. gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB));
  841. gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  842. gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  843. success = gDeferredSpotLightProgram.createShader(NULL, NULL);
  844. }
  845. if (success)
  846. {
  847. gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader";
  848. gDeferredMultiSpotLightProgram.mShaderFiles.clear();
  849. gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB));
  850. gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  851. gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  852. success = gDeferredMultiSpotLightProgram.createShader(NULL, NULL);
  853. }
  854. if (success)
  855. {
  856. gDeferredSunProgram.mName = "Deferred Sun Shader";
  857. gDeferredSunProgram.mShaderFiles.clear();
  858. gDeferredSunProgram.mShaderFiles.push_back(make_pair("deferred/sunLightV.glsl", GL_VERTEX_SHADER_ARB));
  859. gDeferredSunProgram.mShaderFiles.push_back(make_pair("deferred/sunLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  860. gDeferredSunProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  861. success = gDeferredSunProgram.createShader(NULL, NULL);
  862. }
  863. if (success)
  864. {
  865. gDeferredBlurLightProgram.mName = "Deferred Blur Light Shader";
  866. gDeferredBlurLightProgram.mShaderFiles.clear();
  867. gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightV.glsl", GL_VERTEX_SHADER_ARB));
  868. gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  869. gDeferredBlurLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  870. success = gDeferredBlurLightProgram.createShader(NULL, NULL);
  871. }
  872. if (success)
  873. {
  874. gDeferredAlphaProgram.mName = "Deferred Alpha Shader";
  875. gDeferredAlphaProgram.mFeatures.calculatesLighting = true;
  876. gDeferredAlphaProgram.mFeatures.calculatesAtmospherics = true;
  877. gDeferredAlphaProgram.mFeatures.hasGamma = true;
  878. gDeferredAlphaProgram.mFeatures.hasAtmospherics = true;
  879. gDeferredAlphaProgram.mFeatures.hasLighting = true;
  880. gDeferredAlphaProgram.mShaderFiles.clear();
  881. gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB));
  882. gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB));
  883. gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  884. success = gDeferredAlphaProgram.createShader(NULL, NULL);
  885. }
  886. if (success)
  887. {
  888. gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader";
  889. gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true;
  890. gDeferredFullbrightProgram.mFeatures.hasGamma = true;
  891. gDeferredFullbrightProgram.mFeatures.hasTransport = true;
  892. gDeferredFullbrightProgram.mFeatures.isFullbright = true;
  893. gDeferredFullbrightProgram.mShaderFiles.clear();
  894. gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB));
  895. gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB));
  896. gDeferredFullbrightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  897. success = gDeferredFullbrightProgram.createShader(NULL, NULL);
  898. }
  899. if (success)
  900. {
  901. // load water shader
  902. gDeferredWaterProgram.mName = "Deferred Water Shader";
  903. gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true;
  904. gDeferredWaterProgram.mFeatures.hasGamma = true;
  905. gDeferredWaterProgram.mFeatures.hasTransport = true;
  906. gDeferredWaterProgram.mShaderFiles.clear();
  907. gDeferredWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB));
  908. gDeferredWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterF.glsl", GL_FRAGMENT_SHADER_ARB));
  909. gDeferredWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  910. success = gDeferredWaterProgram.createShader(NULL, &mWaterUniforms);
  911. }
  912. if (success)
  913. {
  914. gDeferredSoftenProgram.mName = "Deferred Soften Shader";
  915. gDeferredSoftenProgram.mShaderFiles.clear();
  916. gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB));
  917. gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB));
  918. gDeferredSoftenProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  919. success = gDeferredSoftenProgram.createShader(NULL, NULL);
  920. }
  921. if (success)
  922. {
  923. gDeferredShadowProgram.mName = "Deferred Shadow Shader";
  924. gDeferredShadowProgram.mShaderFiles.clear();
  925. gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowV.glsl", GL_VERTEX_SHADER_ARB));
  926. gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowF.glsl", GL_FRAGMENT_SHADER_ARB));
  927. gDeferredShadowProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  928. success = gDeferredShadowProgram.createShader(NULL, NULL);
  929. }
  930. if (success)
  931. {
  932. gDeferredAvatarShadowProgram.mName = "Deferred Avatar Shadow Shader";
  933. gDeferredAvatarShadowProgram.mFeatures.hasSkinning = true;
  934. gDeferredAvatarShadowProgram.mShaderFiles.clear();
  935. gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowV.glsl", GL_VERTEX_SHADER_ARB));
  936. gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowF.glsl", GL_FRAGMENT_SHADER_ARB));
  937. gDeferredAvatarShadowProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  938. success = gDeferredAvatarShadowProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  939. }
  940. if (success)
  941. {
  942. gTerrainProgram.mName = "Deferred Terrain Shader";
  943. gDeferredTerrainProgram.mShaderFiles.clear();
  944. gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainV.glsl", GL_VERTEX_SHADER_ARB));
  945. gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainF.glsl", GL_FRAGMENT_SHADER_ARB));
  946. gDeferredTerrainProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  947. success = gDeferredTerrainProgram.createShader(NULL, &mTerrainUniforms);
  948. }
  949. if (success)
  950. {
  951. gDeferredAvatarProgram.mName = "Avatar Shader";
  952. gDeferredAvatarProgram.mFeatures.hasSkinning = true;
  953. gDeferredAvatarProgram.mShaderFiles.clear();
  954. gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarV.glsl", GL_VERTEX_SHADER_ARB));
  955. gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarF.glsl", GL_FRAGMENT_SHADER_ARB));
  956. gDeferredAvatarProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  957. success = gDeferredAvatarProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  958. }
  959. if (success)
  960. {
  961. gDeferredAvatarAlphaProgram.mName = "Avatar Alpha Shader";
  962. gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true;
  963. gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = true;
  964. gDeferredAvatarAlphaProgram.mFeatures.calculatesAtmospherics = true;
  965. gDeferredAvatarAlphaProgram.mFeatures.hasGamma = true;
  966. gDeferredAvatarAlphaProgram.mFeatures.hasAtmospherics = true;
  967. gDeferredAvatarAlphaProgram.mFeatures.hasLighting = true;
  968. gDeferredAvatarAlphaProgram.mShaderFiles.clear();
  969. gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaV.glsl", GL_VERTEX_SHADER_ARB));
  970. gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaF.glsl", GL_FRAGMENT_SHADER_ARB));
  971. gDeferredAvatarAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  972. success = gDeferredAvatarAlphaProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  973. }
  974. if (mVertexShaderLevel[SHADER_DEFERRED] > 1)
  975. {
  976. if (success)
  977. {
  978. gDeferredEdgeProgram.mName = "Deferred Edge Shader";
  979. gDeferredEdgeProgram.mShaderFiles.clear();
  980. gDeferredEdgeProgram.mShaderFiles.push_back(make_pair("deferred/edgeV.glsl", GL_VERTEX_SHADER_ARB));
  981. gDeferredEdgeProgram.mShaderFiles.push_back(make_pair("deferred/edgeF.glsl", GL_FRAGMENT_SHADER_ARB));
  982. gDeferredEdgeProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  983. success = gDeferredEdgeProgram.createShader(NULL, NULL);
  984. }
  985. }
  986. if (mVertexShaderLevel[SHADER_DEFERRED] > 2)
  987. {
  988. if (success)
  989. {
  990. gDeferredPostProgram.mName = "Deferred Post Shader";
  991. gDeferredPostProgram.mShaderFiles.clear();
  992. gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredV.glsl", GL_VERTEX_SHADER_ARB));
  993. gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredF.glsl", GL_FRAGMENT_SHADER_ARB));
  994. gDeferredPostProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  995. success = gDeferredPostProgram.createShader(NULL, NULL);
  996. }
  997. if (success)
  998. {
  999. gDeferredPostGIProgram.mName = "Deferred Post GI Shader";
  1000. gDeferredPostGIProgram.mShaderFiles.clear();
  1001. gDeferredPostGIProgram.mShaderFiles.push_back(make_pair("deferred/postgiV.glsl", GL_VERTEX_SHADER_ARB));
  1002. gDeferredPostGIProgram.mShaderFiles.push_back(make_pair("deferred/postgiF.glsl", GL_FRAGMENT_SHADER_ARB));
  1003. gDeferredPostGIProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  1004. success = gDeferredPostGIProgram.createShader(NULL, NULL);
  1005. }
  1006. if (success)
  1007. {
  1008. gDeferredGIProgram.mName = "Deferred GI Shader";
  1009. gDeferredGIProgram.mShaderFiles.clear();
  1010. gDeferredGIProgram.mShaderFiles.push_back(make_pair("deferred/giV.glsl", GL_VERTEX_SHADER_ARB));
  1011. gDeferredGIProgram.mShaderFiles.push_back(make_pair("deferred/giF.glsl", GL_FRAGMENT_SHADER_ARB));
  1012. gDeferredGIProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  1013. success = gDeferredGIProgram.createShader(NULL, NULL);
  1014. }
  1015. if (success)
  1016. {
  1017. gDeferredGIFinalProgram.mName = "Deferred GI Final Shader";
  1018. gDeferredGIFinalProgram.mShaderFiles.clear();
  1019. gDeferredGIFinalProgram.mShaderFiles.push_back(make_pair("deferred/giFinalV.glsl", GL_VERTEX_SHADER_ARB));
  1020. gDeferredGIFinalProgram.mShaderFiles.push_back(make_pair("deferred/giFinalF.glsl", GL_FRAGMENT_SHADER_ARB));
  1021. gDeferredGIFinalProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  1022. success = gDeferredGIFinalProgram.createShader(NULL, NULL);
  1023. }
  1024. if (success)
  1025. {
  1026. gLuminanceGatherProgram.mName = "Luminance Gather Shader";
  1027. gLuminanceGatherProgram.mShaderFiles.clear();
  1028. gLuminanceGatherProgram.mShaderFiles.push_back(make_pair("deferred/luminanceV.glsl", GL_VERTEX_SHADER_ARB));
  1029. gLuminanceGatherProgram.mShaderFiles.push_back(make_pair("deferred/luminanceF.glsl", GL_FRAGMENT_SHADER_ARB));
  1030. gLuminanceGatherProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
  1031. success = gLuminanceGatherProgram.createShader(NULL, NULL);
  1032. }
  1033. }
  1034. return success;
  1035. }
  1036. BOOL LLViewerShaderMgr::loadShadersObject()
  1037. {
  1038. BOOL success = TRUE;
  1039. if (mVertexShaderLevel[SHADER_OBJECT] == 0)
  1040. {
  1041. gObjectShinyProgram.unload();
  1042. gObjectFullbrightShinyProgram.unload();
  1043. gObjectShinyWaterProgram.unload();
  1044. gObjectSimpleProgram.unload();
  1045. gObjectSimpleWaterProgram.unload();
  1046. gObjectFullbrightProgram.unload();
  1047. gObjectFullbrightWaterProgram.unload();
  1048. return FALSE;
  1049. }
  1050. if (success)
  1051. {
  1052. gObjectSimpleProgram.mName = "Simple Shader";
  1053. gObjectSimpleProgram.mFeatures.calculatesLighting = true;
  1054. gObjectSimpleProgram.mFeatures.calculatesAtmospherics = true;
  1055. gObjectSimpleProgram.mFeatures.hasGamma = true;
  1056. gObjectSimpleProgram.mFeatures.hasAtmospherics = true;
  1057. gObjectSimpleProgram.mFeatures.hasLighting = true;
  1058. gObjectSimpleProgram.mShaderFiles.clear();
  1059. gObjectSimpleProgram.mShaderFiles.push_back(make_pair("objects/simpleV.glsl", GL_VERTEX_SHADER_ARB));
  1060. gObjectSimpleProgram.mShaderFiles.push_back(make_pair("objects/simpleF.glsl", GL_FRAGMENT_SHADER_ARB));
  1061. gObjectSimpleProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1062. success = gObjectSimpleProgram.createShader(NULL, NULL);
  1063. }
  1064. if (success)
  1065. {
  1066. gObjectSimpleWaterProgram.mName = "Simple Water Shader";
  1067. gObjectSimpleWaterProgram.mFeatures.calculatesLighting = true;
  1068. gObjectSimpleWaterProgram.mFeatures.calculatesAtmospherics = true;
  1069. gObjectSimpleWaterProgram.mFeatures.hasWaterFog = true;
  1070. gObjectSimpleWaterProgram.mFeatures.hasAtmospherics = true;
  1071. gObjectSimpleWaterProgram.mFeatures.hasLighting = true;
  1072. gObjectSimpleWaterProgram.mShaderFiles.clear();
  1073. gObjectSimpleWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleV.glsl", GL_VERTEX_SHADER_ARB));
  1074. gObjectSimpleWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  1075. gObjectSimpleWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1076. gObjectSimpleWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1077. success = gObjectSimpleWaterProgram.createShader(NULL, NULL);
  1078. }
  1079. if (success)
  1080. {
  1081. gObjectFullbrightProgram.mName = "Fullbright Shader";
  1082. gObjectFullbrightProgram.mFeatures.calculatesAtmospherics = true;
  1083. gObjectFullbrightProgram.mFeatures.hasGamma = true;
  1084. gObjectFullbrightProgram.mFeatures.hasTransport = true;
  1085. gObjectFullbrightProgram.mFeatures.isFullbright = true;
  1086. gObjectFullbrightProgram.mShaderFiles.clear();
  1087. gObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB));
  1088. gObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB));
  1089. gObjectFullbrightProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1090. success = gObjectFullbrightProgram.createShader(NULL, NULL);
  1091. }
  1092. if (success)
  1093. {
  1094. gObjectFullbrightWaterProgram.mName = "Fullbright Water Shader";
  1095. gObjectFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true;
  1096. gObjectFullbrightWaterProgram.mFeatures.isFullbright = true;
  1097. gObjectFullbrightWaterProgram.mFeatures.hasWaterFog = true;
  1098. gObjectFullbrightWaterProgram.mFeatures.hasTransport = true;
  1099. gObjectFullbrightWaterProgram.mShaderFiles.clear();
  1100. gObjectFullbrightWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB));
  1101. gObjectFullbrightWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  1102. gObjectFullbrightWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1103. gObjectFullbrightWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1104. success = gObjectFullbrightWaterProgram.createShader(NULL, NULL);
  1105. }
  1106. if (success)
  1107. {
  1108. gObjectShinyProgram.mName = "Shiny Shader";
  1109. gObjectShinyProgram.mFeatures.calculatesAtmospherics = true;
  1110. gObjectShinyProgram.mFeatures.calculatesLighting = true;
  1111. gObjectShinyProgram.mFeatures.hasGamma = true;
  1112. gObjectShinyProgram.mFeatures.hasAtmospherics = true;
  1113. gObjectShinyProgram.mFeatures.isShiny = true;
  1114. gObjectShinyProgram.mShaderFiles.clear();
  1115. gObjectShinyProgram.mShaderFiles.push_back(make_pair("objects/shinyV.glsl", GL_VERTEX_SHADER_ARB));
  1116. gObjectShinyProgram.mShaderFiles.push_back(make_pair("objects/shinyF.glsl", GL_FRAGMENT_SHADER_ARB));
  1117. gObjectShinyProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1118. success = gObjectShinyProgram.createShader(NULL, &mShinyUniforms);
  1119. }
  1120. if (success)
  1121. {
  1122. gObjectShinyWaterProgram.mName = "Shiny Water Shader";
  1123. gObjectShinyWaterProgram.mFeatures.calculatesAtmospherics = true;
  1124. gObjectShinyWaterProgram.mFeatures.calculatesLighting = true;
  1125. gObjectShinyWaterProgram.mFeatures.isShiny = true;
  1126. gObjectShinyWaterProgram.mFeatures.hasWaterFog = true;
  1127. gObjectShinyWaterProgram.mFeatures.hasAtmospherics = true;
  1128. gObjectShinyWaterProgram.mShaderFiles.clear();
  1129. gObjectShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/shinyWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  1130. gObjectShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/shinyV.glsl", GL_VERTEX_SHADER_ARB));
  1131. gObjectShinyWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1132. gObjectShinyWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1133. success = gObjectShinyWaterProgram.createShader(NULL, &mShinyUniforms);
  1134. }
  1135. if (success)
  1136. {
  1137. gObjectFullbrightShinyProgram.mName = "Fullbright Shiny Shader";
  1138. gObjectFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
  1139. gObjectFullbrightShinyProgram.mFeatures.isFullbright = true;
  1140. gObjectFullbrightShinyProgram.mFeatures.isShiny = true;
  1141. gObjectFullbrightShinyProgram.mFeatures.hasGamma = true;
  1142. gObjectFullbrightShinyProgram.mFeatures.hasTransport = true;
  1143. gObjectFullbrightShinyProgram.mShaderFiles.clear();
  1144. gObjectFullbrightShinyProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyV.glsl", GL_VERTEX_SHADER_ARB));
  1145. gObjectFullbrightShinyProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyF.glsl", GL_FRAGMENT_SHADER_ARB));
  1146. gObjectFullbrightShinyProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
  1147. success = gObjectFullbrightShinyProgram.createShader(NULL, &mShinyUniforms);
  1148. }
  1149. if( !success )
  1150. {
  1151. mVertexShaderLevel[SHADER_OBJECT] = 0;
  1152. return FALSE;
  1153. }
  1154. return TRUE;
  1155. }
  1156. BOOL LLViewerShaderMgr::loadShadersAvatar()
  1157. {
  1158. BOOL success = TRUE;
  1159. if (mVertexShaderLevel[SHADER_AVATAR] == 0)
  1160. {
  1161. gAvatarProgram.unload();
  1162. gAvatarWaterProgram.unload();
  1163. gAvatarEyeballProgram.unload();
  1164. gAvatarPickProgram.unload();
  1165. return FALSE;
  1166. }
  1167. if (success)
  1168. {
  1169. gAvatarProgram.mName = "Avatar Shader";
  1170. gAvatarProgram.mFeatures.hasSkinning = true;
  1171. gAvatarProgram.mFeatures.calculatesAtmospherics = true;
  1172. gAvatarProgram.mFeatures.calculatesLighting = true;
  1173. gAvatarProgram.mFeatures.hasGamma = true;
  1174. gAvatarProgram.mFeatures.hasAtmospherics = true;
  1175. gAvatarProgram.mFeatures.hasLighting = true;
  1176. gAvatarProgram.mShaderFiles.clear();
  1177. gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER_ARB));
  1178. gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarF.glsl", GL_FRAGMENT_SHADER_ARB));
  1179. gAvatarProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR];
  1180. success = gAvatarProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  1181. if (success)
  1182. {
  1183. gAvatarWaterProgram.mName = "Avatar Water Shader";
  1184. gAvatarWaterProgram.mFeatures.hasSkinning = true;
  1185. gAvatarWaterProgram.mFeatures.calculatesAtmospherics = true;
  1186. gAvatarWaterProgram.mFeatures.calculatesLighting = true;
  1187. gAvatarWaterProgram.mFeatures.hasWaterFog = true;
  1188. gAvatarWaterProgram.mFeatures.hasAtmospherics = true;
  1189. gAvatarWaterProgram.mFeatures.hasLighting = true;
  1190. gAvatarWaterProgram.mShaderFiles.clear();
  1191. gAvatarWaterProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER_ARB));
  1192. gAvatarWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
  1193. // Note: no cloth under water:
  1194. gAvatarWaterProgram.mShaderLevel = llmin(mVertexShaderLevel[SHADER_AVATAR], 1);
  1195. gAvatarWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1196. success = gAvatarWaterProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  1197. }
  1198. /// Keep track of avatar levels
  1199. if (gAvatarProgram.mShaderLevel != mVertexShaderLevel[SHADER_AVATAR])
  1200. {
  1201. mMaxAvatarShaderLevel = mVertexShaderLevel[SHADER_AVATAR] = gAvatarProgram.mShaderLevel;
  1202. }
  1203. }
  1204. if (success)
  1205. {
  1206. gAvatarPickProgram.mName = "Avatar Pick Shader";
  1207. gAvatarPickProgram.mFeatures.hasSkinning = true;
  1208. gAvatarPickProgram.mShaderFiles.clear();
  1209. gAvatarPickProgram.mShaderFiles.push_back(make_pair("avatar/pickAvatarV.glsl", GL_VERTEX_SHADER_ARB));
  1210. gAvatarPickProgram.mShaderFiles.push_back(make_pair("avatar/pickAvatarF.glsl", GL_FRAGMENT_SHADER_ARB));
  1211. gAvatarPickProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR];
  1212. success = gAvatarPickProgram.createShader(&mAvatarAttribs, &mAvatarUniforms);
  1213. }
  1214. if (success)
  1215. {
  1216. gAvatarEyeballProgram.mName = "Avatar Eyeball Program";
  1217. gAvatarEyeballProgram.mFeatures.calculatesLighting = true;
  1218. gAvatarEyeballProgram.mFeatures.isSpecular = true;
  1219. gAvatarEyeballProgram.mFeatures.calculatesAtmospherics = true;
  1220. gAvatarEyeballProgram.mFeatures.hasGamma = true;
  1221. gAvatarEyeballProgram.mFeatures.hasAtmospherics = true;
  1222. gAvatarEyeballProgram.mFeatures.hasLighting = true;
  1223. gAvatarEyeballProgram.mShaderFiles.clear();
  1224. gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballV.glsl", GL_VERTEX_SHADER_ARB));
  1225. gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballF.glsl", GL_FRAGMENT_SHADER_ARB));
  1226. gAvatarEyeballProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR];
  1227. success = gAvatarEyeballProgram.createShader(NULL, NULL);
  1228. }
  1229. if( !success )
  1230. {
  1231. mVertexShaderLevel[SHADER_AVATAR] = 0;
  1232. mMaxAvatarShaderLevel = 0;
  1233. return FALSE;
  1234. }
  1235. return TRUE;
  1236. }
  1237. BOOL LLViewerShaderMgr::loadShadersInterface()
  1238. {
  1239. BOOL success = TRUE;
  1240. if (mVertexShaderLevel[SHADER_INTERFACE] == 0)
  1241. {
  1242. gHighlightProgram.unload();
  1243. return FALSE;
  1244. }
  1245. if (success)
  1246. {
  1247. gHighlightProgram.mName = "Highlight Shader";
  1248. gHighlightProgram.mShaderFiles.clear();
  1249. gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER_ARB));
  1250. gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER_ARB));
  1251. gHighlightProgram.mShaderLevel = mVertexShaderLevel[SHADER_INTERFACE];
  1252. success = gHighlightProgram.createShader(NULL, NULL);
  1253. }
  1254. if( !success )
  1255. {
  1256. mVertexShaderLevel[SHADER_INTERFACE] = 0;
  1257. return FALSE;
  1258. }
  1259. return TRUE;
  1260. }
  1261. BOOL LLViewerShaderMgr::loadShadersWindLight()
  1262. {
  1263. BOOL success = TRUE;
  1264. if (mVertexShaderLevel[SHADER_WINDLIGHT] < 2)
  1265. {
  1266. gWLSkyProgram.unload();
  1267. gWLCloudProgram.unload();
  1268. return FALSE;
  1269. }
  1270. if (success)
  1271. {
  1272. gWLSkyProgram.mName = "Windlight Sky Shader";
  1273. //gWLSkyProgram.mFeatures.hasGamma = true;
  1274. gWLSkyProgram.mShaderFiles.clear();
  1275. gWLSkyProgram.mShaderFiles.push_back(make_pair("windlight/skyV.glsl", GL_VERTEX_SHADER_ARB));
  1276. gWLSkyProgram.mShaderFiles.push_back(make_pair("windlight/skyF.glsl", GL_FRAGMENT_SHADER_ARB));
  1277. gWLSkyProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT];
  1278. gWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  1279. success = gWLSkyProgram.createShader(NULL, &mWLUniforms);
  1280. }
  1281. if (success)
  1282. {
  1283. gWLCloudProgram.mName = "Windlight Cloud Program";
  1284. //gWLCloudProgram.mFeatures.hasGamma = true;
  1285. gWLCloudProgram.mShaderFiles.clear();
  1286. gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsV.glsl", GL_VERTEX_SHADER_ARB));
  1287. gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB));
  1288. gWLCloudProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT];
  1289. gWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  1290. success = gWLCloudProgram.createShader(NULL, &mWLUniforms);
  1291. }
  1292. return success;
  1293. }
  1294. std::string LLViewerShaderMgr::getShaderDirPrefix(void)
  1295. {
  1296. return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/class");
  1297. }
  1298. void LLViewerShaderMgr::updateShaderUniforms(LLGLSLShader * shader)
  1299. {
  1300. LLWLParamManager::instance()->updateShaderUniforms(shader);
  1301. LLWaterParamManager::instance()->updateShaderUniforms(shader);
  1302. }