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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llviewershadermgr.h
  3.  * @brief Viewer Shader Manager
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-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. #ifndef LL_VIEWER_SHADER_MGR_H
  33. #define LL_VIEWER_SHADER_MGR_H
  34. #include "llshadermgr.h"
  35. class LLViewerShaderMgr: public LLShaderMgr
  36. {
  37. public:
  38. static BOOL sInitialized;
  39. LLViewerShaderMgr();
  40. /* virtual */ ~LLViewerShaderMgr();
  41. // singleton pattern implementation
  42. static LLViewerShaderMgr * instance();
  43. void initAttribsAndUniforms(void);
  44. void setShaders();
  45. void unloadShaders();
  46. S32 getVertexShaderLevel(S32 type);
  47. BOOL loadBasicShaders();
  48. BOOL loadShadersEffects();
  49. BOOL loadShadersDeferred();
  50. BOOL loadShadersObject();
  51. BOOL loadShadersAvatar();
  52. BOOL loadShadersEnvironment();
  53. BOOL loadShadersWater();
  54. BOOL loadShadersInterface();
  55. BOOL loadShadersWindLight();
  56. std::vector<S32> mVertexShaderLevel;
  57. S32 mMaxAvatarShaderLevel;
  58. enum EShaderClass
  59. {
  60. SHADER_LIGHTING,
  61. SHADER_OBJECT,
  62. SHADER_AVATAR,
  63. SHADER_ENVIRONMENT,
  64. SHADER_INTERFACE,
  65. SHADER_EFFECT,
  66. SHADER_WINDLIGHT,
  67. SHADER_WATER,
  68. SHADER_DEFERRED,
  69. SHADER_COUNT
  70. };
  71. typedef enum 
  72. {
  73. MATERIAL_COLOR = 0,
  74. SPECULAR_COLOR,
  75. BINORMAL,
  76. END_RESERVED_ATTRIBS
  77. } eGLSLReservedAttribs;
  78. typedef enum
  79. {
  80. DIFFUSE_MAP = 0,
  81. SPECULAR_MAP,
  82. BUMP_MAP,
  83. ENVIRONMENT_MAP,
  84. CLOUD_NOISE_MAP,
  85. FULLBRIGHT,
  86. LIGHTNORM,
  87. SUNLIGHT_COLOR,
  88. AMBIENT,
  89. BLUE_HORIZON,
  90. BLUE_DENSITY,
  91. HAZE_HORIZON,
  92. HAZE_DENSITY,
  93. CLOUD_SHADOW,
  94. DENSITY_MULTIPLIER,
  95. DISTANCE_MULTIPLIER,
  96. MAX_Y,
  97. GLOW,
  98. CLOUD_COLOR,
  99. CLOUD_POS_DENSITY1,
  100. CLOUD_POS_DENSITY2,
  101. CLOUD_SCALE,
  102. GAMMA,
  103. SCENE_LIGHT_STRENGTH,
  104. DEFERRED_DEPTH,
  105. DEFERRED_SHADOW0,
  106. DEFERRED_SHADOW1,
  107. DEFERRED_SHADOW2,
  108. DEFERRED_SHADOW3,
  109. DEFERRED_SHADOW4,
  110. DEFERRED_SHADOW5,
  111. DEFERRED_NORMAL,
  112. DEFERRED_POSITION,
  113. DEFERRED_DIFFUSE,
  114. DEFERRED_SPECULAR,
  115. DEFERRED_NOISE,
  116. DEFERRED_LIGHTFUNC,
  117. DEFERRED_LIGHT,
  118. DEFERRED_LUMINANCE,
  119. DEFERRED_GI_LIGHT,
  120. DEFERRED_GI_MIP,
  121. DEFERRED_EDGE,
  122. DEFERRED_BLOOM,
  123. DEFERRED_SUN_LIGHT,
  124. DEFERRED_LOCAL_LIGHT,
  125. DEFERRED_PROJECTION,
  126. DEFERRED_GI_DIFFUSE,
  127. DEFERRED_GI_SPECULAR,
  128. DEFERRED_GI_NORMAL,
  129. DEFERRED_GI_MIN_POS,
  130. DEFERRED_GI_MAX_POS,
  131. DEFERRED_GI_DEPTH,
  132. DEFERRED_GI_LAST_DIFFUSE,
  133. DEFERRED_GI_LAST_NORMAL,
  134. DEFERRED_GI_LAST_MIN_POS,
  135. DEFERRED_GI_LAST_MAX_POS,
  136. END_RESERVED_UNIFORMS
  137. } eGLSLReservedUniforms;
  138. typedef enum
  139. {
  140. SHINY_ORIGIN = END_RESERVED_UNIFORMS
  141. } eShinyUniforms;
  142. typedef enum
  143. {
  144. WATER_SCREENTEX = END_RESERVED_UNIFORMS,
  145. WATER_SCREENDEPTH,
  146. WATER_REFTEX,
  147. WATER_EYEVEC,
  148. WATER_TIME,
  149. WATER_WAVE_DIR1,
  150. WATER_WAVE_DIR2,
  151. WATER_LIGHT_DIR,
  152. WATER_SPECULAR,
  153. WATER_SPECULAR_EXP,
  154. WATER_FOGCOLOR,
  155. WATER_FOGDENSITY,
  156. WATER_REFSCALE,
  157. WATER_WATERHEIGHT,
  158. } eWaterUniforms;
  159. typedef enum
  160. {
  161. WL_CAMPOSLOCAL = END_RESERVED_UNIFORMS,
  162. WL_WATERHEIGHT
  163. } eWLUniforms;
  164. typedef enum
  165. {
  166. TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS,
  167. TERRAIN_DETAIL1,
  168. TERRAIN_DETAIL2,
  169. TERRAIN_DETAIL3,
  170. TERRAIN_ALPHARAMP
  171. } eTerrainUniforms;
  172. typedef enum
  173. {
  174. GLOW_DELTA = END_RESERVED_UNIFORMS
  175. } eGlowUniforms;
  176. typedef enum
  177. {
  178. AVATAR_WEIGHT = END_RESERVED_ATTRIBS,
  179. AVATAR_CLOTHING,
  180. AVATAR_WIND,
  181. AVATAR_SINWAVE,
  182. AVATAR_GRAVITY
  183. } eAvatarAttribs;
  184. typedef enum
  185. {
  186. AVATAR_MATRIX = END_RESERVED_UNIFORMS
  187. } eAvatarUniforms;
  188. // simple model of forward iterator
  189. // http://www.sgi.com/tech/stl/ForwardIterator.html
  190. class shader_iter
  191. {
  192. private:
  193. friend bool operator == (shader_iter const & a, shader_iter const & b);
  194. friend bool operator != (shader_iter const & a, shader_iter const & b);
  195. typedef std::vector<LLGLSLShader *>::const_iterator base_iter_t;
  196. public:
  197. shader_iter()
  198. {
  199. }
  200. shader_iter(base_iter_t iter) : mIter(iter)
  201. {
  202. }
  203. LLGLSLShader & operator * () const
  204. {
  205. return **mIter;
  206. }
  207. LLGLSLShader * operator -> () const
  208. {
  209. return *mIter;
  210. }
  211. shader_iter & operator++ ()
  212. {
  213. ++mIter;
  214. return *this;
  215. }
  216. shader_iter operator++ (int)
  217. {
  218. return mIter++;
  219. }
  220. private:
  221. base_iter_t mIter;
  222. };
  223. shader_iter beginShaders() const
  224. {
  225. return mShaderList.begin();
  226. }
  227. shader_iter endShaders() const
  228. {
  229. return mShaderList.end();
  230. }
  231. /* virtual */ std::string getShaderDirPrefix(void); // Virtual
  232. /* virtual */ void updateShaderUniforms(LLGLSLShader * shader); // Virtual
  233. private:
  234. std::vector<std::string> mShinyUniforms;
  235. //water parameters
  236. std::vector<std::string> mWaterUniforms;
  237. std::vector<std::string> mWLUniforms;
  238. //terrain parameters
  239. std::vector<std::string> mTerrainUniforms;
  240. //glow parameters
  241. std::vector<std::string> mGlowUniforms;
  242. std::vector<std::string> mGlowExtractUniforms;
  243. //avatar shader parameter tables
  244. std::vector<std::string> mAvatarAttribs;
  245. std::vector<std::string> mAvatarUniforms;
  246. // the list of shaders we need to propagate parameters to.
  247. std::vector<LLGLSLShader *> mShaderList;
  248. }; //LLViewerShaderMgr
  249. inline bool operator == (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
  250. {
  251. return a.mIter == b.mIter;
  252. }
  253. inline bool operator != (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
  254. {
  255. return a.mIter != b.mIter;
  256. }
  257. extern LLVector4 gShinyOrigin;
  258. //object shaders
  259. extern LLGLSLShader gObjectSimpleProgram;
  260. extern LLGLSLShader gObjectSimpleWaterProgram;
  261. extern LLGLSLShader gObjectFullbrightProgram;
  262. extern LLGLSLShader gObjectFullbrightWaterProgram;
  263. extern LLGLSLShader gObjectSimpleLODProgram;
  264. extern LLGLSLShader gObjectFullbrightLODProgram;
  265. extern LLGLSLShader gObjectFullbrightShinyProgram;
  266. extern LLGLSLShader gObjectShinyProgram;
  267. extern LLGLSLShader gObjectShinyWaterProgram;
  268. //environment shaders
  269. extern LLGLSLShader gTerrainProgram;
  270. extern LLGLSLShader gTerrainWaterProgram;
  271. extern LLGLSLShader gWaterProgram;
  272. extern LLGLSLShader gUnderWaterProgram;
  273. extern LLGLSLShader gGlowProgram;
  274. extern LLGLSLShader gGlowExtractProgram;
  275. //interface shaders
  276. extern LLGLSLShader gHighlightProgram;
  277. // avatar shader handles
  278. extern LLGLSLShader gAvatarProgram;
  279. extern LLGLSLShader gAvatarWaterProgram;
  280. extern LLGLSLShader gAvatarEyeballProgram;
  281. extern LLGLSLShader gAvatarPickProgram;
  282. // WindLight shader handles
  283. extern LLGLSLShader gWLSkyProgram;
  284. extern LLGLSLShader gWLCloudProgram;
  285. // Post Process Shaders
  286. extern LLGLSLShader gPostColorFilterProgram;
  287. extern LLGLSLShader gPostNightVisionProgram;
  288. // Deferred rendering shaders
  289. extern LLGLSLShader gDeferredImpostorProgram;
  290. extern LLGLSLShader gDeferredEdgeProgram;
  291. extern LLGLSLShader gDeferredWaterProgram;
  292. extern LLGLSLShader gDeferredDiffuseProgram;
  293. extern LLGLSLShader gDeferredBumpProgram;
  294. extern LLGLSLShader gDeferredTerrainProgram;
  295. extern LLGLSLShader gDeferredTreeProgram;
  296. extern LLGLSLShader gDeferredLightProgram;
  297. extern LLGLSLShader gDeferredMultiLightProgram;
  298. extern LLGLSLShader gDeferredSpotLightProgram;
  299. extern LLGLSLShader gDeferredMultiSpotLightProgram;
  300. extern LLGLSLShader gDeferredSunProgram;
  301. extern LLGLSLShader gDeferredGIProgram;
  302. extern LLGLSLShader gDeferredGIFinalProgram;
  303. extern LLGLSLShader gDeferredBlurLightProgram;
  304. extern LLGLSLShader gDeferredAvatarProgram;
  305. extern LLGLSLShader gDeferredSoftenProgram;
  306. extern LLGLSLShader gDeferredShadowProgram;
  307. extern LLGLSLShader gDeferredPostGIProgram;
  308. extern LLGLSLShader gDeferredPostProgram;
  309. extern LLGLSLShader gDeferredAvatarShadowProgram;
  310. extern LLGLSLShader gDeferredAlphaProgram;
  311. extern LLGLSLShader gDeferredFullbrightProgram;
  312. extern LLGLSLShader gDeferredAvatarAlphaProgram;
  313. extern LLGLSLShader gLuminanceGatherProgram;
  314. //current avatar shader parameter pointer
  315. extern GLint gAvatarMatrixParam;
  316. #endif