llshadermgr.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /**
  2. * @file llshadermgr.h
  3. * @brief Shader Manager
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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_SHADERMGR_H
  33. #define LL_SHADERMGR_H
  34. #include "llglslshader.h"
  35. class LLShaderMgr
  36. {
  37. protected:
  38. LOG_CLASS(LLShaderMgr);
  39. LLShaderMgr();
  40. virtual ~LLShaderMgr();
  41. public:
  42. typedef enum
  43. {
  44. MODELVIEW_MATRIX = 0,
  45. PROJECTION_MATRIX,
  46. INVERSE_PROJECTION_MATRIX,
  47. MODELVIEW_PROJECTION_MATRIX,
  48. INVERSE_MODELVIEW_MATRIX,
  49. NORMAL_MATRIX,
  50. TEXTURE_MATRIX0,
  51. // Actually never used by shaders, but currently needed by the C++ code
  52. // due to NUM_MATRIX_MODES.
  53. // *TODO: cleanup the code and get rid of this. HB
  54. TEXTURE_MATRIX1,
  55. TEXTURE_MATRIX2,
  56. TEXTURE_MATRIX3,
  57. OBJECT_PLANE_S,
  58. OBJECT_PLANE_T,
  59. TEXTURE_BASE_COLOR_TRANSFORM, // For PBR shaders only
  60. TEXTURE_NORMAL_TRANSFORM, // For PBR shaders only
  61. TEXTURE_ROUGHNESS_TRANSFORM, // For PBR shaders only
  62. TEXTURE_EMISSIVE_TRANSFORM, // For PBR shaders only
  63. BASE_COLOR_TEXCOORD, // For PBR shaders only
  64. EMISSIVE_TEXCOORD, // For PBR shaders only
  65. NORMAL_TEXCOORD, // For PBR shaders only
  66. METALLIC_ROUGHNESS_TEXCOORD, // For PBR shaders only
  67. OCCLUSION_TEXCOORD, // For PBR shaders only
  68. GLTF_NODE_ID, // For PBR shaders only
  69. GLTF_MATERIAL_ID, // For PBR shaders only
  70. TERRAIN_TEXTURE_TRANSFORMS, // For PBR shaders only
  71. VIEWPORT,
  72. LIGHT_POSITION,
  73. LIGHT_DIRECTION,
  74. LIGHT_ATTENUATION,
  75. LIGHT_DEFERRED_ATTENUATION, // For PBR shaders only
  76. LIGHT_DIFFUSE,
  77. LIGHT_AMBIENT,
  78. MULTI_LIGHT_COUNT,
  79. MULTI_LIGHT,
  80. MULTI_LIGHT_COL,
  81. MULTI_LIGHT_FAR_Z,
  82. PROJECTOR_MATRIX,
  83. PROJECTOR_P,
  84. PROJECTOR_N,
  85. PROJECTOR_ORIGIN,
  86. PROJECTOR_RANGE,
  87. PROJECTOR_AMBIANCE,
  88. PROJECTOR_SHADOW_INDEX,
  89. PROJECTOR_SHADOW_FADE,
  90. PROJECTOR_FOCUS,
  91. PROJECTOR_LOD,
  92. DIFFUSE_COLOR,
  93. EMISSIVE_COLOR, // For PBR shaders only
  94. METALLIC_FACTOR, // For PBR shaders only
  95. ROUGHNESS_FACTOR, // For PBR shaders only
  96. MIRROR_FLAG, // For PBR shaders only
  97. CLIP_PLANE, // For PBR shaders only
  98. DIFFUSE_MAP,
  99. ALTERNATE_DIFFUSE_MAP,
  100. SPECULAR_MAP,
  101. EMISSIVE_MAP, // For PBR shaders only
  102. BUMP_MAP,
  103. BUMP_MAP2,
  104. ENVIRONMENT_MAP,
  105. SCENE_MAP, // For PBR shaders only
  106. SCENE_DEPTH, // For PBR shaders only
  107. REFLECTION_PROBES, // For PBR shaders only
  108. IRRADIANCE_PROBES, // For PBR shaders only
  109. HERO_PROBE, // For PBR shaders only
  110. CLOUD_NOISE_MAP,
  111. CLOUD_NOISE_MAP_NEXT,
  112. FULLBRIGHT, // For EE shaders only
  113. LIGHTNORM,
  114. SUNLIGHT_COLOR,
  115. AMBIENT,
  116. SKY_HDR_SCALE, // For PBR shaders only
  117. SKY_SUNLIGHT_SCALE, // For PBR shaders only
  118. SKY_AMBIENT_SCALE, // For PBR shaders only
  119. BLUE_HORIZON,
  120. BLUE_DENSITY,
  121. HAZE_HORIZON,
  122. HAZE_DENSITY,
  123. CLOUD_SHADOW,
  124. DENSITY_MULTIPLIER,
  125. DISTANCE_MULTIPLIER,
  126. MAX_Y,
  127. GLOW,
  128. CLOUD_COLOR,
  129. CLOUD_POS_DENSITY1,
  130. CLOUD_POS_DENSITY2,
  131. CLOUD_SCALE,
  132. GAMMA,
  133. SCENE_LIGHT_STRENGTH,
  134. LIGHT_CENTER,
  135. LIGHT_SIZE,
  136. LIGHT_FALLOFF,
  137. BOX_CENTER,
  138. BOX_SIZE,
  139. GLOW_MIN_LUMINANCE,
  140. GLOW_MAX_EXTRACT_ALPHA,
  141. GLOW_LUM_WEIGHTS,
  142. GLOW_WARMTH_WEIGHTS,
  143. GLOW_WARMTH_AMOUNT,
  144. GLOW_STRENGTH,
  145. GLOW_DELTA,
  146. GLOW_NOISE_MAP, // For PBR shaders only
  147. MINIMUM_ALPHA,
  148. EMISSIVE_BRIGHTNESS,
  149. DEFERRED_SHADOW_MATRIX,
  150. DEFERRED_ENV_MAT,
  151. DEFERRED_SHADOW_CLIP,
  152. DEFERRED_SUN_WASH,
  153. DEFERRED_SHADOW_NOISE,
  154. DEFERRED_BLUR_SIZE,
  155. DEFERRED_SSAO_RADIUS,
  156. DEFERRED_SSAO_MAX_RADIUS,
  157. DEFERRED_SSAO_FACTOR,
  158. DEFERRED_SSAO_EFFECT_MAT,
  159. DEFERRED_SCREEN_RES,
  160. DEFERRED_NEAR_CLIP,
  161. DEFERRED_SHADOW_OFFSET,
  162. DEFERRED_SHADOW_BIAS,
  163. DEFERRED_SPOT_SHADOW_BIAS,
  164. DEFERRED_SPOT_SHADOW_OFFSET,
  165. DEFERRED_SUN_DIR,
  166. DEFERRED_MOON_DIR,
  167. DEFERRED_SHADOW_RES,
  168. DEFERRED_PROJ_SHADOW_RES,
  169. DEFERRED_SHADOW_TARGET_WIDTH,
  170. DEFERRED_SSR_ITR_COUNT, // For PBR shaders only
  171. DEFERRED_SSR_RAY_STEP, // For PBR shaders only
  172. DEFERRED_SSR_DIST_BIAS, // For PBR shaders only
  173. DEFERRED_SSR_REJECT_BIAS, // For PBR shaders only
  174. DEFERRED_SSR_GLOSSY_SAMPLES, // For PBR shaders only
  175. DEFERRED_SSR_NOISE_SINE, // For PBR shaders only
  176. DEFERRED_SSR_ADAPTIVE_STEP_MULT,// For PBR shaders only
  177. MODELVIEW_DELTA_MATRIX, // For PBR shaders only
  178. INVERSE_MODELVIEW_DELTA_MATRIX, // For PBR shaders only
  179. CUBE_SNAPSHOT, // For PBR shaders only
  180. FXAA_TC_SCALE,
  181. FXAA_RCP_SCREEN_RES,
  182. FXAA_RCP_FRAME_OPT,
  183. FXAA_RCP_FRAME_OPT2,
  184. DOF_FOCAL_DISTANCE,
  185. DOF_BLUR_CONSTANT,
  186. DOF_TAN_PIXEL_ANGLE,
  187. DOF_MAGNIFICATION,
  188. DOF_MAX_COF,
  189. DOF_RES_SCALE,
  190. DOF_WIDTH,
  191. DOF_HEIGHT,
  192. DEFERRED_DEPTH,
  193. DEFERRED_SHADOW0,
  194. DEFERRED_SHADOW1,
  195. DEFERRED_SHADOW2,
  196. DEFERRED_SHADOW3,
  197. DEFERRED_SHADOW4,
  198. DEFERRED_SHADOW5,
  199. DEFERRED_NORMAL,
  200. DEFERRED_POSITION,
  201. DEFERRED_DIFFUSE,
  202. DEFERRED_SPECULAR,
  203. DEFERRED_EMISSIVE, // For PBR shaders only
  204. EXPOSURE_MAP, // For PBR shaders only
  205. DEFERRED_BRDF_LUT, // For PBR shaders only
  206. DEFERRED_NOISE,
  207. DEFERRED_LIGHTFUNC,
  208. DEFERRED_LIGHT,
  209. DEFERRED_BLOOM, // For EE shaders only
  210. DEFERRED_PROJECTION,
  211. DEFERRED_NORM_MATRIX,
  212. TEXTURE_GAMMA, // For EE shaders only
  213. SPECULAR_COLOR,
  214. ENVIRONMENT_INTENSITY,
  215. AVATAR_MATRIX,
  216. WATER_SCREENTEX,
  217. WATER_SCREENDEPTH, // For PBR shaders only
  218. WATER_REFTEX,
  219. WATER_EYEVEC,
  220. WATER_TIME,
  221. WATER_WAVE_DIR1,
  222. WATER_WAVE_DIR2,
  223. WATER_LIGHT_DIR,
  224. WATER_SPECULAR,
  225. WATER_FOGCOLOR,
  226. WATER_FOGCOLOR_LINEAR, // For PBR shaders only
  227. WATER_FOGDENSITY,
  228. WATER_FOGKS,
  229. WATER_REFSCALE,
  230. WATER_WATERHEIGHT,
  231. WATER_WATERPLANE,
  232. WATER_NORM_SCALE,
  233. WATER_FRESNEL_SCALE,
  234. WATER_FRESNEL_OFFSET,
  235. WATER_BLUR_MULTIPLIER,
  236. WATER_SUN_ANGLE,
  237. WL_CAMPOSLOCAL,
  238. AVATAR_WIND, // For EE shaders only
  239. AVATAR_SINWAVE, // For EE shaders only
  240. AVATAR_GRAVITY, // For EE shaders only
  241. TERRAIN_DETAIL0,
  242. TERRAIN_DETAIL1,
  243. TERRAIN_DETAIL2,
  244. TERRAIN_DETAIL3,
  245. TERRAIN_ALPHARAMP,
  246. TERRAIN_DETAIL0_BASE_COLOR, // For PBR shaders only
  247. TERRAIN_DETAIL1_BASE_COLOR, // For PBR shaders only
  248. TERRAIN_DETAIL2_BASE_COLOR, // For PBR shaders only
  249. TERRAIN_DETAIL3_BASE_COLOR, // For PBR shaders only
  250. TERRAIN_DETAIL0_NORMAL, // For PBR shaders only
  251. TERRAIN_DETAIL1_NORMAL, // For PBR shaders only
  252. TERRAIN_DETAIL2_NORMAL, // For PBR shaders only
  253. TERRAIN_DETAIL3_NORMAL, // For PBR shaders only
  254. TERRAIN_DETAIL0_MROUGHNESS, // For PBR shaders only
  255. TERRAIN_DETAIL1_MROUGHNESS, // For PBR shaders only
  256. TERRAIN_DETAIL2_MROUGHNESS, // For PBR shaders only
  257. TERRAIN_DETAIL3_MROUGHNESS, // For PBR shaders only
  258. TERRAIN_DETAIL0_EMISSIVE, // For PBR shaders only
  259. TERRAIN_DETAIL1_EMISSIVE, // For PBR shaders only
  260. TERRAIN_DETAIL2_EMISSIVE, // For PBR shaders only
  261. TERRAIN_DETAIL3_EMISSIVE, // For PBR shaders only
  262. TERRAIN_BASE_COLOR_FACTORS, // For PBR shaders only
  263. TERRAIN_METALLIC_FACTORS, // For PBR shaders only
  264. TERRAIN_ROUGHNESS_FACTORS, // For PBR shaders only
  265. TERRAIN_EMISSIVE_COLORS, // For PBR shaders only
  266. TERRAIN_MINIMUM_ALPHAS, // For PBR shaders only
  267. SHINY_ORIGIN,
  268. DISPLAY_GAMMA,
  269. SUN_SIZE,
  270. FOG_COLOR,
  271. BLEND_FACTOR,
  272. NO_ATMO, // For EE shaders only
  273. MOISTURE_LEVEL,
  274. DROPLET_RADIUS,
  275. ICE_LEVEL,
  276. RAINBOW_MAP,
  277. HALO_MAP,
  278. MOON_BRIGHTNESS,
  279. CLOUD_VARIANCE,
  280. REFLECTION_PROBE_AMBIANCE, // For PBR shaders only
  281. REFLECTION_PROBE_MAX_LOD, // For PBR shaders only
  282. REFLECTION_PROBE_STRENGTH, // For PBR shaders only
  283. // Used only be the EE shaders, but not in the C++ renderer code.
  284. // *TODO: check for a possible bug or eliminate if actually useless. HB
  285. SH_INPUT_L1R,
  286. SH_INPUT_L1G,
  287. SH_INPUT_L1B,
  288. SUN_MOON_GLOW_FACTOR,
  289. SUN_UP_FACTOR,
  290. MOONLIGHT_COLOR,
  291. DEBUG_NORMAL_DRAW_LENGTH, // For PBR shaders only
  292. END_RESERVED_UNIFORMS
  293. } eGLSLReservedUniforms;
  294. // Singleton pattern implementation
  295. static LLShaderMgr* getInstance();
  296. virtual void initAttribsAndUniforms();
  297. bool attachShaderFeatures(LLGLSLShader* shader);
  298. bool linkProgramObject(GLuint obj, bool suppress_errors = false);
  299. GLuint loadShaderFile(const std::string& filename, S32& shader_level,
  300. U32 type,
  301. LLGLSLShader::defines_map_t* defines = NULL,
  302. S32 texture_index_channels = -1);
  303. // Implemented in the application to actually point to the shader directory
  304. virtual const std::string& getShaderDirPrefix() const = 0;
  305. // Implemented in the application to actually update out of date uniforms
  306. // for a particular shader
  307. virtual void updateShaderUniforms(LLGLSLShader* shader) = 0;
  308. private:
  309. #if 0 // Not used
  310. bool validateProgramObject(GLuint obj);
  311. #endif
  312. void dumpObjectLog(bool is_program, GLuint ret, bool warns = true);
  313. void dumpShaderSource(U32 shader_count, GLchar** shader_text);
  314. protected:
  315. // Our parameter manager singleton instance
  316. static LLShaderMgr* sInstance;
  317. public:
  318. // Map of shader names to compiled
  319. typedef std::map<std::string, GLuint> shaders_map_t;
  320. typedef std::map<std::string, GLuint>::const_iterator map_citer_t;
  321. static shaders_map_t sVertexShaderObjects;
  322. static shaders_map_t sFragmentShaderObjects;
  323. // Global (reserved slot) shader parameters
  324. typedef std::vector<std::string> reserved_strings_t;
  325. static reserved_strings_t sReservedAttribs;
  326. static reserved_strings_t sReservedUniforms;
  327. static S32 sIndexedTextureChannels;
  328. static bool sMirrorsEnabled;
  329. };
  330. #endif // LL_SHADERMGR_H