diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llviewershadermgr.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/newview/llviewershadermgr.cpp')
-rw-r--r-- | linden/indra/newview/llviewershadermgr.cpp | 1098 |
1 files changed, 1098 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewershadermgr.cpp b/linden/indra/newview/llviewershadermgr.cpp new file mode 100644 index 0000000..a654120 --- /dev/null +++ b/linden/indra/newview/llviewershadermgr.cpp | |||
@@ -0,0 +1,1098 @@ | |||
1 | /** | ||
2 | * @file llviewershadermgr.cpp | ||
3 | * @brief Viewer shader manager implementation. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2005&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2005-2008, 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | |||
33 | #include "llviewerprecompiledheaders.h" | ||
34 | |||
35 | #include "llfeaturemanager.h" | ||
36 | #include "llviewershadermgr.h" | ||
37 | |||
38 | #include "llfile.h" | ||
39 | #include "llviewerwindow.h" | ||
40 | #include "llviewercontrol.h" | ||
41 | #include "pipeline.h" | ||
42 | #include "llworld.h" | ||
43 | #include "llwlparammanager.h" | ||
44 | #include "llwaterparammanager.h" | ||
45 | #include "llsky.h" | ||
46 | #include "llvosky.h" | ||
47 | #include "llrender.h" | ||
48 | |||
49 | #if LL_DARWIN | ||
50 | #include "OpenGL/OpenGL.h" | ||
51 | #endif | ||
52 | |||
53 | #ifdef LL_RELEASE_FOR_DOWNLOAD | ||
54 | #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") | ||
55 | #else | ||
56 | #define UNIFORM_ERRS LL_ERRS("Shader") | ||
57 | #endif | ||
58 | |||
59 | // Lots of STL stuff in here, using namespace std to keep things more readable | ||
60 | using std::vector; | ||
61 | using std::pair; | ||
62 | using std::make_pair; | ||
63 | using std::string; | ||
64 | |||
65 | LLVector4 gShinyOrigin; | ||
66 | |||
67 | //object shaders | ||
68 | LLGLSLShader gObjectSimpleProgram; | ||
69 | LLGLSLShader gObjectSimpleWaterProgram; | ||
70 | LLGLSLShader gObjectFullbrightProgram; | ||
71 | LLGLSLShader gObjectFullbrightWaterProgram; | ||
72 | |||
73 | LLGLSLShader gObjectFullbrightShinyProgram; | ||
74 | LLGLSLShader gObjectShinyProgram; | ||
75 | LLGLSLShader gObjectShinyWaterProgram; | ||
76 | |||
77 | //environment shaders | ||
78 | LLGLSLShader gTerrainProgram; | ||
79 | LLGLSLShader gTerrainWaterProgram; | ||
80 | LLGLSLShader gWaterProgram; | ||
81 | LLGLSLShader gUnderWaterProgram; | ||
82 | |||
83 | //interface shaders | ||
84 | LLGLSLShader gHighlightProgram; | ||
85 | |||
86 | //avatar shader handles | ||
87 | LLGLSLShader gAvatarProgram; | ||
88 | LLGLSLShader gAvatarWaterProgram; | ||
89 | LLGLSLShader gAvatarEyeballProgram; | ||
90 | LLGLSLShader gAvatarPickProgram; | ||
91 | |||
92 | // WindLight shader handles | ||
93 | LLGLSLShader gWLSkyProgram; | ||
94 | LLGLSLShader gWLCloudProgram; | ||
95 | |||
96 | // Effects Shaders | ||
97 | LLGLSLShader gGlowProgram; | ||
98 | LLGLSLShader gGlowExtractProgram; | ||
99 | LLGLSLShader gPostColorFilterProgram; | ||
100 | LLGLSLShader gPostNightVisionProgram; | ||
101 | |||
102 | // Deferred rendering shaders | ||
103 | LLGLSLShader gDeferredDiffuseProgram; | ||
104 | |||
105 | //current avatar shader parameter pointer | ||
106 | GLint gAvatarMatrixParam; | ||
107 | |||
108 | LLViewerShaderMgr::LLViewerShaderMgr() : | ||
109 | mVertexShaderLevel(SHADER_COUNT, 0) | ||
110 | { | ||
111 | /// Make sure WL Sky is the first program | ||
112 | mShaderList.push_back(&gWLSkyProgram); | ||
113 | mShaderList.push_back(&gWLCloudProgram); | ||
114 | mShaderList.push_back(&gAvatarProgram); | ||
115 | mShaderList.push_back(&gObjectShinyProgram); | ||
116 | mShaderList.push_back(&gWaterProgram); | ||
117 | mShaderList.push_back(&gAvatarEyeballProgram); | ||
118 | mShaderList.push_back(&gObjectSimpleProgram); | ||
119 | mShaderList.push_back(&gObjectFullbrightProgram); | ||
120 | mShaderList.push_back(&gObjectFullbrightShinyProgram); | ||
121 | mShaderList.push_back(&gTerrainProgram); | ||
122 | mShaderList.push_back(&gTerrainWaterProgram); | ||
123 | mShaderList.push_back(&gObjectSimpleWaterProgram); | ||
124 | mShaderList.push_back(&gObjectFullbrightWaterProgram); | ||
125 | mShaderList.push_back(&gAvatarWaterProgram); | ||
126 | mShaderList.push_back(&gObjectShinyWaterProgram); | ||
127 | mShaderList.push_back(&gUnderWaterProgram); | ||
128 | } | ||
129 | |||
130 | LLViewerShaderMgr::~LLViewerShaderMgr() | ||
131 | { | ||
132 | mVertexShaderLevel.clear(); | ||
133 | mShaderList.clear(); | ||
134 | } | ||
135 | |||
136 | // static | ||
137 | LLViewerShaderMgr * LLViewerShaderMgr::instance() | ||
138 | { | ||
139 | if(NULL == sInstance) | ||
140 | { | ||
141 | sInstance = new LLViewerShaderMgr(); | ||
142 | } | ||
143 | |||
144 | return static_cast<LLViewerShaderMgr*>(sInstance); | ||
145 | } | ||
146 | |||
147 | void LLViewerShaderMgr::initAttribsAndUniforms(void) | ||
148 | { | ||
149 | if (mReservedAttribs.empty()) | ||
150 | { | ||
151 | mReservedAttribs.push_back("materialColor"); | ||
152 | mReservedAttribs.push_back("specularColor"); | ||
153 | mReservedAttribs.push_back("binormal"); | ||
154 | |||
155 | mAvatarAttribs.reserve(5); | ||
156 | mAvatarAttribs.push_back("weight"); | ||
157 | mAvatarAttribs.push_back("clothing"); | ||
158 | mAvatarAttribs.push_back("gWindDir"); | ||
159 | mAvatarAttribs.push_back("gSinWaveParams"); | ||
160 | mAvatarAttribs.push_back("gGravity"); | ||
161 | |||
162 | mAvatarUniforms.push_back("matrixPalette"); | ||
163 | |||
164 | mReservedUniforms.reserve(24); | ||
165 | mReservedUniforms.push_back("diffuseMap"); | ||
166 | mReservedUniforms.push_back("specularMap"); | ||
167 | mReservedUniforms.push_back("bumpMap"); | ||
168 | mReservedUniforms.push_back("environmentMap"); | ||
169 | mReservedUniforms.push_back("cloude_noise_texture"); | ||
170 | mReservedUniforms.push_back("fullbright"); | ||
171 | mReservedUniforms.push_back("lightnorm"); | ||
172 | mReservedUniforms.push_back("sunlight_color"); | ||
173 | mReservedUniforms.push_back("ambient"); | ||
174 | mReservedUniforms.push_back("blue_horizon"); | ||
175 | mReservedUniforms.push_back("blue_density"); | ||
176 | mReservedUniforms.push_back("haze_horizon"); | ||
177 | mReservedUniforms.push_back("haze_density"); | ||
178 | mReservedUniforms.push_back("cloud_shadow"); | ||
179 | mReservedUniforms.push_back("density_multiplier"); | ||
180 | mReservedUniforms.push_back("distance_multiplier"); | ||
181 | mReservedUniforms.push_back("max_y"); | ||
182 | mReservedUniforms.push_back("glow"); | ||
183 | mReservedUniforms.push_back("cloud_color"); | ||
184 | mReservedUniforms.push_back("cloud_pos_density1"); | ||
185 | mReservedUniforms.push_back("cloud_pos_density2"); | ||
186 | mReservedUniforms.push_back("cloud_scale"); | ||
187 | mReservedUniforms.push_back("gamma"); | ||
188 | mReservedUniforms.push_back("scene_light_strength"); | ||
189 | |||
190 | mWLUniforms.push_back("camPosLocal"); | ||
191 | |||
192 | mTerrainUniforms.reserve(5); | ||
193 | mTerrainUniforms.push_back("detail_0"); | ||
194 | mTerrainUniforms.push_back("detail_1"); | ||
195 | mTerrainUniforms.push_back("detail_2"); | ||
196 | mTerrainUniforms.push_back("detail_3"); | ||
197 | mTerrainUniforms.push_back("alpha_ramp"); | ||
198 | |||
199 | mGlowUniforms.push_back("glowDelta"); | ||
200 | mGlowUniforms.push_back("glowStrength"); | ||
201 | |||
202 | mGlowExtractUniforms.push_back("minLuminance"); | ||
203 | mGlowExtractUniforms.push_back("maxExtractAlpha"); | ||
204 | mGlowExtractUniforms.push_back("lumWeights"); | ||
205 | mGlowExtractUniforms.push_back("warmthWeights"); | ||
206 | mGlowExtractUniforms.push_back("warmthAmount"); | ||
207 | |||
208 | mShinyUniforms.push_back("origin"); | ||
209 | |||
210 | mWaterUniforms.reserve(12); | ||
211 | mWaterUniforms.push_back("screenTex"); | ||
212 | mWaterUniforms.push_back("screenDepth"); | ||
213 | mWaterUniforms.push_back("refTex"); | ||
214 | mWaterUniforms.push_back("eyeVec"); | ||
215 | mWaterUniforms.push_back("time"); | ||
216 | mWaterUniforms.push_back("d1"); | ||
217 | mWaterUniforms.push_back("d2"); | ||
218 | mWaterUniforms.push_back("lightDir"); | ||
219 | mWaterUniforms.push_back("specular"); | ||
220 | mWaterUniforms.push_back("lightExp"); | ||
221 | mWaterUniforms.push_back("fogCol"); | ||
222 | mWaterUniforms.push_back("kd"); | ||
223 | mWaterUniforms.push_back("refScale"); | ||
224 | mWaterUniforms.push_back("waterHeight"); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | |||
229 | //============================================================================ | ||
230 | // Set Levels | ||
231 | |||
232 | S32 LLViewerShaderMgr::getVertexShaderLevel(S32 type) | ||
233 | { | ||
234 | return LLPipeline::sDisableShaders ? 0 : mVertexShaderLevel[type]; | ||
235 | } | ||
236 | |||
237 | //============================================================================ | ||
238 | // Shader Management | ||
239 | |||
240 | void LLViewerShaderMgr::setShaders() | ||
241 | { | ||
242 | if (!gPipeline.mInitialized) | ||
243 | { | ||
244 | return; | ||
245 | } | ||
246 | // Make sure the compiled shader map is cleared before we recompile shaders. | ||
247 | mShaderObjects.clear(); | ||
248 | |||
249 | initAttribsAndUniforms(); | ||
250 | gPipeline.releaseGLBuffers(); | ||
251 | |||
252 | if (gSavedSettings.getBOOL("VertexShaderEnable")) | ||
253 | { | ||
254 | LLPipeline::sWaterReflections = gGLManager.mHasCubeMap; | ||
255 | LLPipeline::sRenderGlow = gSavedSettings.getBOOL("RenderGlow"); | ||
256 | } | ||
257 | else | ||
258 | { | ||
259 | LLPipeline::sRenderGlow = | ||
260 | LLPipeline::sWaterReflections = FALSE; | ||
261 | } | ||
262 | |||
263 | //hack to reset buffers that change behavior with shaders | ||
264 | gPipeline.resetVertexBuffers(); | ||
265 | |||
266 | if (gViewerWindow) | ||
267 | { | ||
268 | gViewerWindow->setCursor(UI_CURSOR_WAIT); | ||
269 | } | ||
270 | |||
271 | // Lighting | ||
272 | gPipeline.setLightingDetail(-1); | ||
273 | |||
274 | // Shaders | ||
275 | LL_INFOS("ShaderLoading") << "\n~~~~~~~~~~~~~~~~~~\n Loading Shaders:\n~~~~~~~~~~~~~~~~~~" << LL_ENDL; | ||
276 | for (S32 i = 0; i < SHADER_COUNT; i++) | ||
277 | { | ||
278 | mVertexShaderLevel[i] = 0; | ||
279 | } | ||
280 | mMaxAvatarShaderLevel = 0; | ||
281 | |||
282 | if (LLFeatureManager::getInstance()->isFeatureAvailable("VertexShaderEnable") | ||
283 | && gSavedSettings.getBOOL("VertexShaderEnable")) | ||
284 | { | ||
285 | S32 light_class = 2; | ||
286 | S32 env_class = 2; | ||
287 | S32 obj_class = 2; | ||
288 | S32 effect_class = 2; | ||
289 | S32 wl_class = 2; | ||
290 | S32 water_class = 2; | ||
291 | S32 deferred_class = 0; | ||
292 | if (!gSavedSettings.getBOOL("WindLightUseAtmosShaders")) | ||
293 | { | ||
294 | // user has disabled WindLight in their settings, downgrade | ||
295 | // windlight shaders to stub versions. | ||
296 | wl_class = 1; | ||
297 | |||
298 | // if class one or less, turn off more shaders | ||
299 | // since higher end cards won't see any real gain | ||
300 | // from turning off most of the shaders, | ||
301 | // but class one would | ||
302 | // TODO: Make water on class one cards color things | ||
303 | // beneath it properly | ||
304 | if(LLFeatureManager::getInstance()->getGPUClass() < GPU_CLASS_2) | ||
305 | { | ||
306 | // use lesser water and other stuff | ||
307 | light_class = 2; | ||
308 | env_class = 0; | ||
309 | obj_class = 0; | ||
310 | effect_class = 1; | ||
311 | water_class = 1; | ||
312 | } | ||
313 | } | ||
314 | |||
315 | if (gSavedSettings.getBOOL("RenderDeferred")) | ||
316 | { | ||
317 | light_class = 1; | ||
318 | env_class = 0; | ||
319 | obj_class = 0; | ||
320 | water_class = 1; | ||
321 | effect_class = 1; | ||
322 | deferred_class = 1; | ||
323 | } | ||
324 | |||
325 | if(!gSavedSettings.getBOOL("EnableRippleWater")) | ||
326 | { | ||
327 | water_class = 0; | ||
328 | } | ||
329 | |||
330 | // Trigger a full rebuild of the fallback skybox / cubemap if we've toggled windlight shaders | ||
331 | if (mVertexShaderLevel[SHADER_WINDLIGHT] != wl_class && gSky.mVOSkyp.notNull()) | ||
332 | { | ||
333 | gSky.mVOSkyp->forceSkyUpdate(); | ||
334 | } | ||
335 | |||
336 | // Load lighting shaders | ||
337 | mVertexShaderLevel[SHADER_LIGHTING] = light_class; | ||
338 | mVertexShaderLevel[SHADER_INTERFACE] = light_class; | ||
339 | mVertexShaderLevel[SHADER_ENVIRONMENT] = env_class; | ||
340 | mVertexShaderLevel[SHADER_WATER] = water_class; | ||
341 | mVertexShaderLevel[SHADER_OBJECT] = obj_class; | ||
342 | mVertexShaderLevel[SHADER_EFFECT] = effect_class; | ||
343 | mVertexShaderLevel[SHADER_WINDLIGHT] = wl_class; | ||
344 | mVertexShaderLevel[SHADER_DEFERRED] = deferred_class; | ||
345 | |||
346 | BOOL loaded = loadBasicShaders(); | ||
347 | |||
348 | if (loaded) | ||
349 | { | ||
350 | gPipeline.mVertexShadersEnabled = TRUE; | ||
351 | gPipeline.mVertexShadersLoaded = 1; | ||
352 | |||
353 | // Load all shaders to set max levels | ||
354 | loadShadersEnvironment(); | ||
355 | loadShadersWater(); | ||
356 | loadShadersObject(); | ||
357 | loadShadersWindLight(); | ||
358 | loadShadersEffects(); | ||
359 | loadShadersInterface(); | ||
360 | loadShadersDeferred(); | ||
361 | |||
362 | // Load max avatar shaders to set the max level | ||
363 | mVertexShaderLevel[SHADER_AVATAR] = 3; | ||
364 | mMaxAvatarShaderLevel = 3; | ||
365 | loadShadersAvatar(); | ||
366 | |||
367 | #if 0 && LL_DARWIN // force avatar shaders off for mac | ||
368 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
369 | sMaxAvatarShaderLevel = 0; | ||
370 | #else | ||
371 | if (gSavedSettings.getBOOL("RenderAvatarVP")) | ||
372 | { | ||
373 | BOOL avatar_cloth = gSavedSettings.getBOOL("RenderAvatarCloth"); | ||
374 | S32 avatar_class = 1; | ||
375 | |||
376 | // cloth is a class3 shader | ||
377 | if(avatar_cloth) | ||
378 | { | ||
379 | avatar_class = 3; | ||
380 | } | ||
381 | |||
382 | // Set the actual level | ||
383 | mVertexShaderLevel[SHADER_AVATAR] = avatar_class; | ||
384 | loadShadersAvatar(); | ||
385 | if (mVertexShaderLevel[SHADER_AVATAR] != avatar_class) | ||
386 | { | ||
387 | if (mVertexShaderLevel[SHADER_AVATAR] == 0) | ||
388 | { | ||
389 | gSavedSettings.setBOOL("RenderAvatarVP", FALSE); | ||
390 | } | ||
391 | if(llmax(mVertexShaderLevel[SHADER_AVATAR]-1,0) >= 3) | ||
392 | { | ||
393 | avatar_cloth = true; | ||
394 | } | ||
395 | else | ||
396 | { | ||
397 | avatar_cloth = false; | ||
398 | } | ||
399 | gSavedSettings.setBOOL("RenderAvatarCloth", avatar_cloth); | ||
400 | } | ||
401 | } | ||
402 | else | ||
403 | { | ||
404 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
405 | gSavedSettings.setBOOL("RenderAvatarCloth", FALSE); | ||
406 | loadShadersAvatar(); // unloads | ||
407 | } | ||
408 | #endif | ||
409 | } | ||
410 | else | ||
411 | { | ||
412 | gPipeline.mVertexShadersEnabled = FALSE; | ||
413 | gPipeline.mVertexShadersLoaded = 0; | ||
414 | mVertexShaderLevel[SHADER_LIGHTING] = 0; | ||
415 | mVertexShaderLevel[SHADER_INTERFACE] = 0; | ||
416 | mVertexShaderLevel[SHADER_ENVIRONMENT] = 0; | ||
417 | mVertexShaderLevel[SHADER_WATER] = 0; | ||
418 | mVertexShaderLevel[SHADER_OBJECT] = 0; | ||
419 | mVertexShaderLevel[SHADER_EFFECT] = 0; | ||
420 | mVertexShaderLevel[SHADER_WINDLIGHT] = 0; | ||
421 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
422 | } | ||
423 | } | ||
424 | else | ||
425 | { | ||
426 | gPipeline.mVertexShadersEnabled = FALSE; | ||
427 | gPipeline.mVertexShadersLoaded = 0; | ||
428 | mVertexShaderLevel[SHADER_LIGHTING] = 0; | ||
429 | mVertexShaderLevel[SHADER_INTERFACE] = 0; | ||
430 | mVertexShaderLevel[SHADER_ENVIRONMENT] = 0; | ||
431 | mVertexShaderLevel[SHADER_WATER] = 0; | ||
432 | mVertexShaderLevel[SHADER_OBJECT] = 0; | ||
433 | mVertexShaderLevel[SHADER_EFFECT] = 0; | ||
434 | mVertexShaderLevel[SHADER_WINDLIGHT] = 0; | ||
435 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
436 | } | ||
437 | |||
438 | if (gViewerWindow) | ||
439 | { | ||
440 | gViewerWindow->setCursor(UI_CURSOR_ARROW); | ||
441 | } | ||
442 | gPipeline.createGLBuffers(); | ||
443 | } | ||
444 | |||
445 | void LLViewerShaderMgr::unloadShaders() | ||
446 | { | ||
447 | gObjectSimpleProgram.unload(); | ||
448 | gObjectSimpleWaterProgram.unload(); | ||
449 | gObjectFullbrightProgram.unload(); | ||
450 | gObjectFullbrightWaterProgram.unload(); | ||
451 | |||
452 | gObjectShinyProgram.unload(); | ||
453 | gObjectFullbrightShinyProgram.unload(); | ||
454 | gObjectShinyWaterProgram.unload(); | ||
455 | gWaterProgram.unload(); | ||
456 | gUnderWaterProgram.unload(); | ||
457 | gTerrainProgram.unload(); | ||
458 | gTerrainWaterProgram.unload(); | ||
459 | gGlowProgram.unload(); | ||
460 | gGlowExtractProgram.unload(); | ||
461 | gAvatarProgram.unload(); | ||
462 | gAvatarWaterProgram.unload(); | ||
463 | gAvatarEyeballProgram.unload(); | ||
464 | gAvatarPickProgram.unload(); | ||
465 | gHighlightProgram.unload(); | ||
466 | |||
467 | gWLSkyProgram.unload(); | ||
468 | gWLCloudProgram.unload(); | ||
469 | |||
470 | gPostColorFilterProgram.unload(); | ||
471 | gPostNightVisionProgram.unload(); | ||
472 | |||
473 | gDeferredDiffuseProgram.unload(); | ||
474 | |||
475 | mVertexShaderLevel[SHADER_LIGHTING] = 0; | ||
476 | mVertexShaderLevel[SHADER_OBJECT] = 0; | ||
477 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
478 | mVertexShaderLevel[SHADER_ENVIRONMENT] = 0; | ||
479 | mVertexShaderLevel[SHADER_WATER] = 0; | ||
480 | mVertexShaderLevel[SHADER_INTERFACE] = 0; | ||
481 | mVertexShaderLevel[SHADER_EFFECT] = 0; | ||
482 | mVertexShaderLevel[SHADER_WINDLIGHT] = 0; | ||
483 | |||
484 | gPipeline.mVertexShadersLoaded = 0; | ||
485 | } | ||
486 | |||
487 | BOOL LLViewerShaderMgr::loadBasicShaders() | ||
488 | { | ||
489 | // Load basic dependency shaders first | ||
490 | // All of these have to load for any shaders to function | ||
491 | |||
492 | #if LL_DARWIN // Mac can't currently handle all 8 lights, | ||
493 | S32 sum_lights_class = 2; | ||
494 | #else | ||
495 | S32 sum_lights_class = 3; | ||
496 | |||
497 | // class one cards will get the lower sum lights | ||
498 | // class zero we're not going to think about | ||
499 | // since a class zero card COULD be a ridiculous new card | ||
500 | // and old cards should have the features masked | ||
501 | if(LLFeatureManager::getInstance()->getGPUClass() == GPU_CLASS_1) | ||
502 | { | ||
503 | sum_lights_class = 2; | ||
504 | } | ||
505 | #endif | ||
506 | |||
507 | // If we have sun and moon only checked, then only sum those lights. | ||
508 | if (gPipeline.getLightingDetail() == 0) | ||
509 | { | ||
510 | sum_lights_class = 1; | ||
511 | } | ||
512 | |||
513 | // Load the Basic Vertex Shaders at the appropriate level. | ||
514 | // (in order of shader function call depth for reference purposes, deepest level first) | ||
515 | |||
516 | vector< pair<string, S32> > shaders; | ||
517 | shaders.reserve(10); | ||
518 | shaders.push_back( make_pair( "windlight/atmosphericsVarsV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
519 | shaders.push_back( make_pair( "windlight/atmosphericsHelpersV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
520 | shaders.push_back( make_pair( "lighting/lightFuncV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
521 | shaders.push_back( make_pair( "lighting/sumLightsV.glsl", sum_lights_class ) ); | ||
522 | shaders.push_back( make_pair( "lighting/lightV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
523 | shaders.push_back( make_pair( "lighting/lightFuncSpecularV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
524 | shaders.push_back( make_pair( "lighting/sumLightsSpecularV.glsl", sum_lights_class ) ); | ||
525 | shaders.push_back( make_pair( "lighting/lightSpecularV.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
526 | shaders.push_back( make_pair( "windlight/atmosphericsV.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
527 | shaders.push_back( make_pair( "avatar/avatarSkinV.glsl", 1 ) ); | ||
528 | |||
529 | // We no longer have to bind the shaders to global glhandles, they are automatically added to a map now. | ||
530 | for (U32 i = 0; i < shaders.size(); i++) | ||
531 | { | ||
532 | // Note usage of GL_VERTEX_SHADER_ARB | ||
533 | if (loadShaderFile(shaders[i].first, shaders[i].second, GL_VERTEX_SHADER_ARB) == 0) | ||
534 | { | ||
535 | return FALSE; | ||
536 | } | ||
537 | } | ||
538 | |||
539 | // Load the Basic Fragment Shaders at the appropriate level. | ||
540 | // (in order of shader function call depth for reference purposes, deepest level first) | ||
541 | |||
542 | shaders.clear(); | ||
543 | shaders.reserve(12); | ||
544 | shaders.push_back( make_pair( "windlight/atmosphericsVarsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
545 | shaders.push_back( make_pair( "windlight/gammaF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT]) ); | ||
546 | shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
547 | shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); | ||
548 | shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); | ||
549 | shaders.push_back( make_pair( "lighting/lightF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
550 | shaders.push_back( make_pair( "lighting/lightFullbrightF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
551 | shaders.push_back( make_pair( "lighting/lightWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
552 | shaders.push_back( make_pair( "lighting/lightFullbrightWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
553 | shaders.push_back( make_pair( "lighting/lightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
554 | shaders.push_back( make_pair( "lighting/lightFullbrightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
555 | shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); | ||
556 | |||
557 | for (U32 i = 0; i < shaders.size(); i++) | ||
558 | { | ||
559 | // Note usage of GL_FRAGMENT_SHADER_ARB | ||
560 | if (loadShaderFile(shaders[i].first, shaders[i].second, GL_FRAGMENT_SHADER_ARB) == 0) | ||
561 | { | ||
562 | return FALSE; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | return TRUE; | ||
567 | } | ||
568 | |||
569 | BOOL LLViewerShaderMgr::loadShadersEnvironment() | ||
570 | { | ||
571 | BOOL success = TRUE; | ||
572 | |||
573 | if (mVertexShaderLevel[SHADER_ENVIRONMENT] == 0) | ||
574 | { | ||
575 | gTerrainProgram.unload(); | ||
576 | return FALSE; | ||
577 | } | ||
578 | |||
579 | if (success) | ||
580 | { | ||
581 | gTerrainProgram.mName = "Terrain Shader"; | ||
582 | gTerrainProgram.mFeatures.calculatesLighting = true; | ||
583 | gTerrainProgram.mFeatures.calculatesAtmospherics = true; | ||
584 | gTerrainProgram.mFeatures.hasAtmospherics = true; | ||
585 | gTerrainProgram.mFeatures.hasGamma = true; | ||
586 | gTerrainProgram.mShaderFiles.clear(); | ||
587 | gTerrainProgram.mShaderFiles.push_back(make_pair("environment/terrainV.glsl", GL_VERTEX_SHADER_ARB)); | ||
588 | gTerrainProgram.mShaderFiles.push_back(make_pair("environment/terrainF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
589 | gTerrainProgram.mShaderLevel = mVertexShaderLevel[SHADER_ENVIRONMENT]; | ||
590 | success = gTerrainProgram.createShader(NULL, &mTerrainUniforms); | ||
591 | } | ||
592 | |||
593 | if (!success) | ||
594 | { | ||
595 | mVertexShaderLevel[SHADER_ENVIRONMENT] = 0; | ||
596 | return FALSE; | ||
597 | } | ||
598 | |||
599 | LLWorld::getInstance()->updateWaterObjects(); | ||
600 | |||
601 | return TRUE; | ||
602 | } | ||
603 | |||
604 | BOOL LLViewerShaderMgr::loadShadersWater() | ||
605 | { | ||
606 | BOOL success = TRUE; | ||
607 | BOOL terrainWaterSuccess = TRUE; | ||
608 | |||
609 | if (mVertexShaderLevel[SHADER_WATER] == 0) | ||
610 | { | ||
611 | gWaterProgram.unload(); | ||
612 | gUnderWaterProgram.unload(); | ||
613 | gTerrainWaterProgram.unload(); | ||
614 | return FALSE; | ||
615 | } | ||
616 | |||
617 | if (success) | ||
618 | { | ||
619 | // load water shader | ||
620 | gWaterProgram.mName = "Water Shader"; | ||
621 | gWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
622 | gWaterProgram.mFeatures.hasGamma = true; | ||
623 | gWaterProgram.mFeatures.hasTransport = true; | ||
624 | gWaterProgram.mShaderFiles.clear(); | ||
625 | gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER_ARB)); | ||
626 | gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
627 | gWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER]; | ||
628 | success = gWaterProgram.createShader(NULL, &mWaterUniforms); | ||
629 | } | ||
630 | |||
631 | if (success) | ||
632 | { | ||
633 | //load under water vertex shader | ||
634 | gUnderWaterProgram.mName = "Underwater Shader"; | ||
635 | gUnderWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
636 | gUnderWaterProgram.mShaderFiles.clear(); | ||
637 | gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER_ARB)); | ||
638 | gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
639 | gUnderWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER]; | ||
640 | gUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
641 | |||
642 | success = gUnderWaterProgram.createShader(NULL, &mWaterUniforms); | ||
643 | } | ||
644 | |||
645 | if (success) | ||
646 | { | ||
647 | //load terrain water shader | ||
648 | gTerrainWaterProgram.mName = "Terrain Water Shader"; | ||
649 | gTerrainWaterProgram.mFeatures.calculatesLighting = true; | ||
650 | gTerrainWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
651 | gTerrainWaterProgram.mFeatures.hasAtmospherics = true; | ||
652 | gTerrainWaterProgram.mFeatures.hasWaterFog = true; | ||
653 | gTerrainWaterProgram.mShaderFiles.clear(); | ||
654 | gTerrainWaterProgram.mShaderFiles.push_back(make_pair("environment/terrainV.glsl", GL_VERTEX_SHADER_ARB)); | ||
655 | gTerrainWaterProgram.mShaderFiles.push_back(make_pair("environment/terrainWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
656 | gTerrainWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_ENVIRONMENT]; | ||
657 | gTerrainWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
658 | terrainWaterSuccess = gTerrainWaterProgram.createShader(NULL, &mTerrainUniforms); | ||
659 | } | ||
660 | |||
661 | /// Keep track of water shader levels | ||
662 | if (gWaterProgram.mShaderLevel != mVertexShaderLevel[SHADER_WATER] | ||
663 | || gUnderWaterProgram.mShaderLevel != mVertexShaderLevel[SHADER_WATER]) | ||
664 | { | ||
665 | mVertexShaderLevel[SHADER_WATER] = llmin(gWaterProgram.mShaderLevel, gUnderWaterProgram.mShaderLevel); | ||
666 | } | ||
667 | |||
668 | if (!success) | ||
669 | { | ||
670 | mVertexShaderLevel[SHADER_WATER] = 0; | ||
671 | return FALSE; | ||
672 | } | ||
673 | |||
674 | // if we failed to load the terrain water shaders and we need them (using class2 water), | ||
675 | // then drop down to class1 water. | ||
676 | if (mVertexShaderLevel[SHADER_WATER] > 1 && !terrainWaterSuccess) | ||
677 | { | ||
678 | mVertexShaderLevel[SHADER_WATER]--; | ||
679 | return loadShadersWater(); | ||
680 | } | ||
681 | |||
682 | LLWorld::getInstance()->updateWaterObjects(); | ||
683 | |||
684 | return TRUE; | ||
685 | } | ||
686 | |||
687 | BOOL LLViewerShaderMgr::loadShadersEffects() | ||
688 | { | ||
689 | BOOL success = TRUE; | ||
690 | |||
691 | if (mVertexShaderLevel[SHADER_EFFECT] == 0) | ||
692 | { | ||
693 | gGlowProgram.unload(); | ||
694 | gGlowExtractProgram.unload(); | ||
695 | gPostColorFilterProgram.unload(); | ||
696 | gPostNightVisionProgram.unload(); | ||
697 | return FALSE; | ||
698 | } | ||
699 | |||
700 | if (success) | ||
701 | { | ||
702 | gGlowProgram.mName = "Glow Shader (Post)"; | ||
703 | gGlowProgram.mShaderFiles.clear(); | ||
704 | gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowV.glsl", GL_VERTEX_SHADER_ARB)); | ||
705 | gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
706 | gGlowProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT]; | ||
707 | success = gGlowProgram.createShader(NULL, &mGlowUniforms); | ||
708 | if (!success) | ||
709 | { | ||
710 | LLPipeline::sRenderGlow = FALSE; | ||
711 | } | ||
712 | } | ||
713 | |||
714 | if (success) | ||
715 | { | ||
716 | gGlowExtractProgram.mName = "Glow Extract Shader (Post)"; | ||
717 | gGlowExtractProgram.mShaderFiles.clear(); | ||
718 | gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractV.glsl", GL_VERTEX_SHADER_ARB)); | ||
719 | gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
720 | gGlowExtractProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT]; | ||
721 | success = gGlowExtractProgram.createShader(NULL, &mGlowExtractUniforms); | ||
722 | if (!success) | ||
723 | { | ||
724 | LLPipeline::sRenderGlow = FALSE; | ||
725 | } | ||
726 | } | ||
727 | |||
728 | #if 0 | ||
729 | // disabling loading of postprocess shaders until we fix | ||
730 | // ATI sampler2DRect compatibility. | ||
731 | |||
732 | //load Color Filter Shader | ||
733 | if (success) | ||
734 | { | ||
735 | vector<string> shaderUniforms; | ||
736 | shaderUniforms.reserve(7); | ||
737 | shaderUniforms.push_back("RenderTexture"); | ||
738 | shaderUniforms.push_back("gamma"); | ||
739 | shaderUniforms.push_back("brightness"); | ||
740 | shaderUniforms.push_back("contrast"); | ||
741 | shaderUniforms.push_back("contrastBase"); | ||
742 | shaderUniforms.push_back("saturation"); | ||
743 | shaderUniforms.push_back("lumWeights"); | ||
744 | |||
745 | gPostColorFilterProgram.mName = "Color Filter Shader (Post)"; | ||
746 | gPostColorFilterProgram.mShaderFiles.clear(); | ||
747 | gPostColorFilterProgram.mShaderFiles.push_back(make_pair("effects/colorFilterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
748 | gPostColorFilterProgram.mShaderFiles.push_back(make_pair("effects/drawQuadV.glsl", GL_VERTEX_SHADER_ARB)); | ||
749 | gPostColorFilterProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT]; | ||
750 | success = gPostColorFilterProgram.createShader(NULL, &shaderUniforms); | ||
751 | } | ||
752 | |||
753 | //load Night Vision Shader | ||
754 | if (success) | ||
755 | { | ||
756 | vector<string> shaderUniforms; | ||
757 | shaderUniforms.reserve(5); | ||
758 | shaderUniforms.push_back("RenderTexture"); | ||
759 | shaderUniforms.push_back("NoiseTexture"); | ||
760 | shaderUniforms.push_back("brightMult"); | ||
761 | shaderUniforms.push_back("noiseStrength"); | ||
762 | shaderUniforms.push_back("lumWeights"); | ||
763 | |||
764 | gPostNightVisionProgram.mName = "Night Vision Shader (Post)"; | ||
765 | gPostNightVisionProgram.mShaderFiles.clear(); | ||
766 | gPostNightVisionProgram.mShaderFiles.push_back(make_pair("effects/nightVisionF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
767 | gPostNightVisionProgram.mShaderFiles.push_back(make_pair("effects/drawQuadV.glsl", GL_VERTEX_SHADER_ARB)); | ||
768 | gPostNightVisionProgram.mShaderLevel = mVertexShaderLevel[SHADER_EFFECT]; | ||
769 | success = gPostNightVisionProgram.createShader(NULL, &shaderUniforms); | ||
770 | } | ||
771 | #endif | ||
772 | |||
773 | return success; | ||
774 | |||
775 | } | ||
776 | |||
777 | BOOL LLViewerShaderMgr::loadShadersDeferred() | ||
778 | { | ||
779 | if (mVertexShaderLevel[SHADER_DEFERRED] == 0) | ||
780 | { | ||
781 | gDeferredDiffuseProgram.unload(); | ||
782 | return FALSE; | ||
783 | } | ||
784 | |||
785 | BOOL success = TRUE; | ||
786 | |||
787 | if (success) | ||
788 | { | ||
789 | gDeferredDiffuseProgram.mName = "Deffered Diffuse Shader"; | ||
790 | gDeferredDiffuseProgram.mShaderFiles.clear(); | ||
791 | gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); | ||
792 | gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
793 | gDeferredDiffuseProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; | ||
794 | success = gDeferredDiffuseProgram.createShader(NULL, NULL); | ||
795 | } | ||
796 | |||
797 | return success; | ||
798 | } | ||
799 | |||
800 | BOOL LLViewerShaderMgr::loadShadersObject() | ||
801 | { | ||
802 | BOOL success = TRUE; | ||
803 | |||
804 | if (mVertexShaderLevel[SHADER_OBJECT] == 0) | ||
805 | { | ||
806 | gObjectShinyProgram.unload(); | ||
807 | gObjectFullbrightShinyProgram.unload(); | ||
808 | gObjectShinyWaterProgram.unload(); | ||
809 | gObjectSimpleProgram.unload(); | ||
810 | gObjectSimpleWaterProgram.unload(); | ||
811 | gObjectFullbrightProgram.unload(); | ||
812 | gObjectFullbrightWaterProgram.unload(); | ||
813 | return FALSE; | ||
814 | } | ||
815 | |||
816 | if (success) | ||
817 | { | ||
818 | gObjectSimpleProgram.mName = "Simple Shader"; | ||
819 | gObjectSimpleProgram.mFeatures.calculatesLighting = true; | ||
820 | gObjectSimpleProgram.mFeatures.calculatesAtmospherics = true; | ||
821 | gObjectSimpleProgram.mFeatures.hasGamma = true; | ||
822 | gObjectSimpleProgram.mFeatures.hasAtmospherics = true; | ||
823 | gObjectSimpleProgram.mFeatures.hasLighting = true; | ||
824 | gObjectSimpleProgram.mShaderFiles.clear(); | ||
825 | gObjectSimpleProgram.mShaderFiles.push_back(make_pair("objects/simpleV.glsl", GL_VERTEX_SHADER_ARB)); | ||
826 | gObjectSimpleProgram.mShaderFiles.push_back(make_pair("objects/simpleF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
827 | gObjectSimpleProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
828 | success = gObjectSimpleProgram.createShader(NULL, NULL); | ||
829 | } | ||
830 | |||
831 | if (success) | ||
832 | { | ||
833 | gObjectSimpleWaterProgram.mName = "Simple Water Shader"; | ||
834 | gObjectSimpleWaterProgram.mFeatures.calculatesLighting = true; | ||
835 | gObjectSimpleWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
836 | gObjectSimpleWaterProgram.mFeatures.hasWaterFog = true; | ||
837 | gObjectSimpleWaterProgram.mFeatures.hasAtmospherics = true; | ||
838 | gObjectSimpleWaterProgram.mFeatures.hasLighting = true; | ||
839 | gObjectSimpleWaterProgram.mShaderFiles.clear(); | ||
840 | gObjectSimpleWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleV.glsl", GL_VERTEX_SHADER_ARB)); | ||
841 | gObjectSimpleWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
842 | gObjectSimpleWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
843 | gObjectSimpleWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
844 | success = gObjectSimpleWaterProgram.createShader(NULL, NULL); | ||
845 | } | ||
846 | |||
847 | if (success) | ||
848 | { | ||
849 | gObjectFullbrightProgram.mName = "Fullbright Shader"; | ||
850 | gObjectFullbrightProgram.mFeatures.calculatesAtmospherics = true; | ||
851 | gObjectFullbrightProgram.mFeatures.hasGamma = true; | ||
852 | gObjectFullbrightProgram.mFeatures.hasTransport = true; | ||
853 | gObjectFullbrightProgram.mFeatures.isFullbright = true; | ||
854 | gObjectFullbrightProgram.mShaderFiles.clear(); | ||
855 | gObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); | ||
856 | gObjectFullbrightProgram.mShaderFiles.push_back(make_pair("objects/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
857 | gObjectFullbrightProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
858 | success = gObjectFullbrightProgram.createShader(NULL, NULL); | ||
859 | } | ||
860 | |||
861 | if (success) | ||
862 | { | ||
863 | gObjectFullbrightWaterProgram.mName = "Fullbright Water Shader"; | ||
864 | gObjectFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
865 | gObjectFullbrightWaterProgram.mFeatures.isFullbright = true; | ||
866 | gObjectFullbrightWaterProgram.mFeatures.hasWaterFog = true; | ||
867 | gObjectFullbrightWaterProgram.mFeatures.hasTransport = true; | ||
868 | gObjectFullbrightWaterProgram.mShaderFiles.clear(); | ||
869 | gObjectFullbrightWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); | ||
870 | gObjectFullbrightWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
871 | gObjectFullbrightWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
872 | gObjectFullbrightWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
873 | success = gObjectFullbrightWaterProgram.createShader(NULL, NULL); | ||
874 | } | ||
875 | |||
876 | if (success) | ||
877 | { | ||
878 | gObjectShinyProgram.mName = "Shiny Shader"; | ||
879 | gObjectShinyProgram.mFeatures.calculatesAtmospherics = true; | ||
880 | gObjectShinyProgram.mFeatures.calculatesLighting = true; | ||
881 | gObjectShinyProgram.mFeatures.hasGamma = true; | ||
882 | gObjectShinyProgram.mFeatures.hasAtmospherics = true; | ||
883 | gObjectShinyProgram.mFeatures.isShiny = true; | ||
884 | gObjectShinyProgram.mShaderFiles.clear(); | ||
885 | gObjectShinyProgram.mShaderFiles.push_back(make_pair("objects/shinyV.glsl", GL_VERTEX_SHADER_ARB)); | ||
886 | gObjectShinyProgram.mShaderFiles.push_back(make_pair("objects/shinyF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
887 | gObjectShinyProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
888 | success = gObjectShinyProgram.createShader(NULL, &mShinyUniforms); | ||
889 | } | ||
890 | |||
891 | if (success) | ||
892 | { | ||
893 | gObjectShinyWaterProgram.mName = "Shiny Water Shader"; | ||
894 | gObjectShinyWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
895 | gObjectShinyWaterProgram.mFeatures.calculatesLighting = true; | ||
896 | gObjectShinyWaterProgram.mFeatures.isShiny = true; | ||
897 | gObjectShinyWaterProgram.mFeatures.hasWaterFog = true; | ||
898 | gObjectShinyWaterProgram.mFeatures.hasAtmospherics = true; | ||
899 | gObjectShinyWaterProgram.mShaderFiles.clear(); | ||
900 | gObjectShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/shinyWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
901 | gObjectShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/shinyV.glsl", GL_VERTEX_SHADER_ARB)); | ||
902 | gObjectShinyWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
903 | gObjectShinyWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
904 | success = gObjectShinyWaterProgram.createShader(NULL, &mShinyUniforms); | ||
905 | } | ||
906 | |||
907 | if (success) | ||
908 | { | ||
909 | gObjectFullbrightShinyProgram.mName = "Fullbright Shiny Shader"; | ||
910 | gObjectFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true; | ||
911 | gObjectFullbrightShinyProgram.mFeatures.isFullbright = true; | ||
912 | gObjectFullbrightShinyProgram.mFeatures.isShiny = true; | ||
913 | gObjectFullbrightShinyProgram.mFeatures.hasGamma = true; | ||
914 | gObjectFullbrightShinyProgram.mFeatures.hasTransport = true; | ||
915 | gObjectFullbrightShinyProgram.mShaderFiles.clear(); | ||
916 | gObjectFullbrightShinyProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyV.glsl", GL_VERTEX_SHADER_ARB)); | ||
917 | gObjectFullbrightShinyProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
918 | gObjectFullbrightShinyProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; | ||
919 | success = gObjectFullbrightShinyProgram.createShader(NULL, &mShinyUniforms); | ||
920 | } | ||
921 | |||
922 | |||
923 | if( !success ) | ||
924 | { | ||
925 | mVertexShaderLevel[SHADER_OBJECT] = 0; | ||
926 | return FALSE; | ||
927 | } | ||
928 | |||
929 | return TRUE; | ||
930 | } | ||
931 | |||
932 | BOOL LLViewerShaderMgr::loadShadersAvatar() | ||
933 | { | ||
934 | BOOL success = TRUE; | ||
935 | |||
936 | if (mVertexShaderLevel[SHADER_AVATAR] == 0) | ||
937 | { | ||
938 | gAvatarProgram.unload(); | ||
939 | gAvatarWaterProgram.unload(); | ||
940 | gAvatarEyeballProgram.unload(); | ||
941 | gAvatarPickProgram.unload(); | ||
942 | return FALSE; | ||
943 | } | ||
944 | |||
945 | if (success) | ||
946 | { | ||
947 | gAvatarProgram.mName = "Avatar Shader"; | ||
948 | gAvatarProgram.mFeatures.hasSkinning = true; | ||
949 | gAvatarProgram.mFeatures.calculatesAtmospherics = true; | ||
950 | gAvatarProgram.mFeatures.calculatesLighting = true; | ||
951 | gAvatarProgram.mFeatures.hasGamma = true; | ||
952 | gAvatarProgram.mFeatures.hasAtmospherics = true; | ||
953 | gAvatarProgram.mFeatures.hasLighting = true; | ||
954 | gAvatarProgram.mShaderFiles.clear(); | ||
955 | gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER_ARB)); | ||
956 | gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
957 | gAvatarProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR]; | ||
958 | success = gAvatarProgram.createShader(&mAvatarAttribs, &mAvatarUniforms); | ||
959 | |||
960 | if (success) | ||
961 | { | ||
962 | gAvatarWaterProgram.mName = "Avatar Water Shader"; | ||
963 | gAvatarWaterProgram.mFeatures.hasSkinning = true; | ||
964 | gAvatarWaterProgram.mFeatures.calculatesAtmospherics = true; | ||
965 | gAvatarWaterProgram.mFeatures.calculatesLighting = true; | ||
966 | gAvatarWaterProgram.mFeatures.hasWaterFog = true; | ||
967 | gAvatarWaterProgram.mFeatures.hasAtmospherics = true; | ||
968 | gAvatarWaterProgram.mFeatures.hasLighting = true; | ||
969 | gAvatarWaterProgram.mShaderFiles.clear(); | ||
970 | gAvatarWaterProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER_ARB)); | ||
971 | gAvatarWaterProgram.mShaderFiles.push_back(make_pair("objects/simpleWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
972 | // Note: no cloth under water: | ||
973 | gAvatarWaterProgram.mShaderLevel = llmin(mVertexShaderLevel[SHADER_AVATAR], 1); | ||
974 | gAvatarWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; | ||
975 | success = gAvatarWaterProgram.createShader(&mAvatarAttribs, &mAvatarUniforms); | ||
976 | } | ||
977 | |||
978 | /// Keep track of avatar levels | ||
979 | if (gAvatarProgram.mShaderLevel != mVertexShaderLevel[SHADER_AVATAR]) | ||
980 | { | ||
981 | mMaxAvatarShaderLevel = mVertexShaderLevel[SHADER_AVATAR] = gAvatarProgram.mShaderLevel; | ||
982 | } | ||
983 | } | ||
984 | |||
985 | if (success) | ||
986 | { | ||
987 | gAvatarPickProgram.mName = "Avatar Pick Shader"; | ||
988 | gAvatarPickProgram.mFeatures.hasSkinning = true; | ||
989 | gAvatarPickProgram.mShaderFiles.clear(); | ||
990 | gAvatarPickProgram.mShaderFiles.push_back(make_pair("avatar/pickAvatarV.glsl", GL_VERTEX_SHADER_ARB)); | ||
991 | gAvatarPickProgram.mShaderFiles.push_back(make_pair("avatar/pickAvatarF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
992 | gAvatarPickProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR]; | ||
993 | success = gAvatarPickProgram.createShader(&mAvatarAttribs, &mAvatarUniforms); | ||
994 | } | ||
995 | |||
996 | if (success) | ||
997 | { | ||
998 | gAvatarEyeballProgram.mName = "Avatar Eyeball Program"; | ||
999 | gAvatarEyeballProgram.mFeatures.calculatesLighting = true; | ||
1000 | gAvatarEyeballProgram.mFeatures.isSpecular = true; | ||
1001 | gAvatarEyeballProgram.mFeatures.calculatesAtmospherics = true; | ||
1002 | gAvatarEyeballProgram.mFeatures.hasGamma = true; | ||
1003 | gAvatarEyeballProgram.mFeatures.hasAtmospherics = true; | ||
1004 | gAvatarEyeballProgram.mFeatures.hasLighting = true; | ||
1005 | gAvatarEyeballProgram.mShaderFiles.clear(); | ||
1006 | gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballV.glsl", GL_VERTEX_SHADER_ARB)); | ||
1007 | gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
1008 | gAvatarEyeballProgram.mShaderLevel = mVertexShaderLevel[SHADER_AVATAR]; | ||
1009 | success = gAvatarEyeballProgram.createShader(NULL, NULL); | ||
1010 | } | ||
1011 | |||
1012 | if( !success ) | ||
1013 | { | ||
1014 | mVertexShaderLevel[SHADER_AVATAR] = 0; | ||
1015 | mMaxAvatarShaderLevel = 0; | ||
1016 | return FALSE; | ||
1017 | } | ||
1018 | |||
1019 | return TRUE; | ||
1020 | } | ||
1021 | |||
1022 | BOOL LLViewerShaderMgr::loadShadersInterface() | ||
1023 | { | ||
1024 | BOOL success = TRUE; | ||
1025 | |||
1026 | if (mVertexShaderLevel[SHADER_INTERFACE] == 0) | ||
1027 | { | ||
1028 | gHighlightProgram.unload(); | ||
1029 | return FALSE; | ||
1030 | } | ||
1031 | |||
1032 | if (success) | ||
1033 | { | ||
1034 | gHighlightProgram.mName = "Highlight Shader"; | ||
1035 | gHighlightProgram.mShaderFiles.clear(); | ||
1036 | gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER_ARB)); | ||
1037 | gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
1038 | gHighlightProgram.mShaderLevel = mVertexShaderLevel[SHADER_INTERFACE]; | ||
1039 | success = gHighlightProgram.createShader(NULL, NULL); | ||
1040 | } | ||
1041 | |||
1042 | if( !success ) | ||
1043 | { | ||
1044 | mVertexShaderLevel[SHADER_INTERFACE] = 0; | ||
1045 | return FALSE; | ||
1046 | } | ||
1047 | |||
1048 | return TRUE; | ||
1049 | } | ||
1050 | |||
1051 | BOOL LLViewerShaderMgr::loadShadersWindLight() | ||
1052 | { | ||
1053 | BOOL success = TRUE; | ||
1054 | |||
1055 | if (mVertexShaderLevel[SHADER_WINDLIGHT] < 2) | ||
1056 | { | ||
1057 | gWLSkyProgram.unload(); | ||
1058 | gWLCloudProgram.unload(); | ||
1059 | return FALSE; | ||
1060 | } | ||
1061 | |||
1062 | if (success) | ||
1063 | { | ||
1064 | gWLSkyProgram.mName = "Windlight Sky Shader"; | ||
1065 | //gWLSkyProgram.mFeatures.hasGamma = true; | ||
1066 | gWLSkyProgram.mShaderFiles.clear(); | ||
1067 | gWLSkyProgram.mShaderFiles.push_back(make_pair("windlight/skyV.glsl", GL_VERTEX_SHADER_ARB)); | ||
1068 | gWLSkyProgram.mShaderFiles.push_back(make_pair("windlight/skyF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
1069 | gWLSkyProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT]; | ||
1070 | gWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY; | ||
1071 | success = gWLSkyProgram.createShader(NULL, &mWLUniforms); | ||
1072 | } | ||
1073 | |||
1074 | if (success) | ||
1075 | { | ||
1076 | gWLCloudProgram.mName = "Windlight Cloud Program"; | ||
1077 | //gWLCloudProgram.mFeatures.hasGamma = true; | ||
1078 | gWLCloudProgram.mShaderFiles.clear(); | ||
1079 | gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsV.glsl", GL_VERTEX_SHADER_ARB)); | ||
1080 | gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB)); | ||
1081 | gWLCloudProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT]; | ||
1082 | gWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY; | ||
1083 | success = gWLCloudProgram.createShader(NULL, &mWLUniforms); | ||
1084 | } | ||
1085 | |||
1086 | return success; | ||
1087 | } | ||
1088 | |||
1089 | std::string LLViewerShaderMgr::getShaderDirPrefix(void) | ||
1090 | { | ||
1091 | return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/class"); | ||
1092 | } | ||
1093 | |||
1094 | void LLViewerShaderMgr::updateShaderUniforms(LLGLSLShader * shader) | ||
1095 | { | ||
1096 | LLWLParamManager::instance()->updateShaderUniforms(shader); | ||
1097 | LLWaterParamManager::instance()->updateShaderUniforms(shader); | ||
1098 | } | ||