💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
8.2 KiB

7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef RENDER_PASSES_HPP
  20. #define RENDER_PASSES_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. #include "material-loader.hpp"
  24. #include "model-loader.hpp"
  25. #include <cstdint>
  26. /**
  27. * Clears framebuffers
  28. */
  29. class ClearRenderPass: public RenderPass
  30. {
  31. public:
  32. ClearRenderPass();
  33. virtual bool load(const RenderContext* renderContext);
  34. virtual void unload();
  35. virtual void render(RenderContext* renderContext);
  36. void setClear(bool color, bool depth, bool stencil);
  37. void setClearColor(const Vector4& color);
  38. void setClearDepth(float depth);
  39. void setClearStencil(int index);
  40. private:
  41. bool clearColor;
  42. bool clearDepth;
  43. bool clearStencil;
  44. Vector4 color;
  45. float depth;
  46. int index;
  47. };
  48. /**
  49. * Blurs a texture
  50. */
  51. class BlurRenderPass: public RenderPass
  52. {
  53. public:
  54. BlurRenderPass();
  55. virtual bool load(const RenderContext* renderContext);
  56. virtual void unload();
  57. virtual void render(RenderContext* renderContext);
  58. inline void setGammaCorrect(bool gammaCorrect) { this->gammaCorrect = gammaCorrect; }
  59. /**
  60. * Sets the texture to blur.
  61. */
  62. inline void setTexture(const Texture2D* texture) { textureParam.setValue(texture); }
  63. /**
  64. * Sets the direction of the blur.
  65. */
  66. inline void setDirection(const Vector2& direction) { directionParam.setValue(direction); }
  67. private:
  68. bool gammaCorrect;
  69. Shader shader;
  70. std::uint32_t permutation;
  71. ShaderTexture2D textureParam;
  72. ShaderVector2 resolutionParam;
  73. ShaderVector2 directionParam;
  74. int quadVertexCount;
  75. int quadIndexCount;
  76. GLuint quadVAO;
  77. GLuint quadVBO;
  78. GLuint quadIBO;
  79. };
  80. /**
  81. * Renders the distance from the view frustum's near clipping plane to scene geometry. The render target should have a depth only framebuffer.
  82. */
  83. class ShadowMapRenderPass: public RenderPass
  84. {
  85. public:
  86. ShadowMapRenderPass();
  87. virtual bool load(const RenderContext* renderContext);
  88. virtual void unload();
  89. virtual void render(RenderContext* renderContext);
  90. inline void setViewCamera(const Camera* camera) { this->viewCamera = camera; }
  91. inline void setLightCamera(Camera* camera) { this->lightCamera = camera; }
  92. inline const SplitViewFrustum& getSplitViewFrustum() const { return *splitViewFrustum; }
  93. inline const Matrix4& getCropMatrix(std::size_t index) const { return cropMatrices[index]; }
  94. inline const Matrix4& getTileMatrix(std::size_t index) const { return tileMatrices[index]; }
  95. private:
  96. class RenderOpCompare
  97. {
  98. public:
  99. // Sort render opations
  100. bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
  101. };
  102. Shader shader;
  103. std::uint32_t unskinnedPermutation;
  104. std::uint32_t skinnedPermutation;
  105. ShaderMatrix4 modelViewProjectionParam;
  106. ShaderMatrix4* matrixPaletteParam; // data not used, just getConnectedInput() then pass pose matrix palette pointer directly
  107. int maxBoneCount;
  108. int shadowMapResolution;
  109. int croppedShadowMapResolution;
  110. Vector4* croppedShadowMapViewports;
  111. Matrix4* cropMatrices;
  112. Matrix4* tileMatrices;
  113. const Camera* viewCamera;
  114. Camera* lightCamera;
  115. SplitViewFrustum* splitViewFrustum;
  116. };
  117. /**
  118. * Renders scene geometry.
  119. */
  120. class LightingRenderPass: public RenderPass
  121. {
  122. public:
  123. LightingRenderPass();
  124. virtual bool load(const RenderContext* renderContext);
  125. virtual void unload();
  126. virtual void render(RenderContext* renderContext);
  127. inline void setShadowMap(const Texture2D* shadowMap) { this->shadowMap = shadowMap; }
  128. inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
  129. inline void setShadowMapPass(const ShadowMapRenderPass* shadowMapPass) { this->shadowMapPass = shadowMapPass; }
  130. inline void setDiffuseCubemap(const TextureCube* cubemap) { this->diffuseCubemap = cubemap; }
  131. inline void setSpecularCubemap(const TextureCube* cubemap) { this->specularCubemap = cubemap; }
  132. private:
  133. class RenderOpCompare
  134. {
  135. public:
  136. // Sort render opations
  137. bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
  138. };
  139. struct ParameterSet
  140. {
  141. ShaderMatrix4* matrixPalette;
  142. ShaderMatrix4 modelMatrix;
  143. ShaderMatrix4 modelViewMatrix;
  144. ShaderMatrix4 modelViewProjectionMatrix;
  145. ShaderMatrix3 normalModelViewMatrix;
  146. ShaderMatrix3 normalModelMatrix;
  147. ShaderMatrix4* lightViewProjectionMatrices;
  148. ShaderVector4 splitDistances;
  149. ShaderTexture2D shadowMap;
  150. ShaderVector3 cameraPosition;
  151. ShaderTextureCube diffuseCubemap;
  152. ShaderTextureCube specularCubemap;
  153. ShaderInt directionalLightCount;
  154. ShaderVector3* directionalLightColors;
  155. ShaderVector3* directionalLightDirections;
  156. ShaderInt spotlightCount;
  157. ShaderVector3 spotlightColors;
  158. ShaderVector3 spotlightPositions;
  159. ShaderVector3 spotlightAttenuations;
  160. ShaderVector3 spotlightDirections;
  161. ShaderFloat spotlightCutoffs;
  162. ShaderFloat spotlightExponents;
  163. ShaderTexture2D albedoOpacityMap;
  164. ShaderTexture2D metalnessRoughnessMap;
  165. ShaderTexture2D normalOcclusionMap;
  166. // Material shader parameters (uploaded by material directly)
  167. //ShaderTexture2D albedoOpacityMap;
  168. //ShaderTexture2D metalnessRoughnessMap;
  169. //ShaderTexture2D normalOcclusionMap;
  170. };
  171. //std::map<Shader* shader, ParameterSet> parameterSets;
  172. Shader shader;
  173. ParameterSet parameters;
  174. std::uint32_t unskinnedPermutation;
  175. std::uint32_t skinnedPermutation;
  176. int maxBoneCount;
  177. int maxDirectionalLightCount;
  178. int maxSpotlightCount;
  179. Matrix4 biasMatrix;
  180. const Texture2D* shadowMap;
  181. const TextureCube* diffuseCubemap;
  182. const TextureCube* specularCubemap;
  183. const Camera* shadowCamera;
  184. float time;
  185. const ShadowMapRenderPass* shadowMapPass;
  186. };
  187. /**
  188. * Renders bounding boxes, skeletons
  189. */
  190. class DebugRenderPass: public RenderPass
  191. {
  192. public:
  193. DebugRenderPass();
  194. virtual bool load(const RenderContext* renderContext);
  195. virtual void unload();
  196. virtual void render(RenderContext* renderContext);
  197. //void setDrawBounds(bool enabled);
  198. //void setDrawSkeletons(bool enabled);
  199. //void setDrawCameras(bool enabled);
  200. //void setDrawLights(bool enabled);
  201. private:
  202. Shader shader;
  203. std::uint32_t permutation;
  204. ShaderMatrix4 modelViewProjectionMatrixParam;
  205. int aabbVertexCount;
  206. int aabbIndexCount;
  207. GLuint aabbVAO;
  208. GLuint aabbVBO;
  209. GLuint aabbIBO;
  210. };
  211. /**
  212. * Renders the user interface
  213. */
  214. class UIRenderPass: public RenderPass
  215. {
  216. public:
  217. UIRenderPass();
  218. virtual bool load(const RenderContext* renderContext);
  219. virtual void unload();
  220. virtual void render(RenderContext* renderContext);
  221. private:
  222. Shader shader;
  223. std::uint32_t texturedPermutation;
  224. std::uint32_t untexturedPermutation;
  225. ShaderMatrix4 modelViewProjectionMatrixParam;
  226. ShaderTexture2D textureParam;
  227. ShaderVector2 textureOffsetParam;
  228. ShaderVector2 textureScaleParam;
  229. };
  230. /**
  231. * Renders a vignette
  232. */
  233. /*
  234. class VignetteRenderPass: public RenderPass
  235. {
  236. public:
  237. VignetteRenderPass();
  238. virtual bool load(const RenderContext* renderContext);
  239. virtual void unload();
  240. virtual void render(RenderContext* renderContext);
  241. private:
  242. ShaderParameterSet parameterSet;
  243. const ShaderParameter* modelViewProjectionParam;
  244. const ShaderParameter* bayerTextureParam;
  245. ShaderLoader shaderLoader;
  246. Shader* shader;
  247. GLuint bayerTextureID;
  248. };
  249. */
  250. /**
  251. * Renders a skybox
  252. */
  253. class SkyboxRenderPass: public RenderPass
  254. {
  255. public:
  256. SkyboxRenderPass();
  257. inline void setCubemap(TextureCube* cubemap) { this->cubemap = cubemap; }
  258. virtual bool load(const RenderContext* renderContext);
  259. virtual void unload();
  260. virtual void render(RenderContext* renderContext);
  261. private:
  262. Shader shader;
  263. std::uint32_t permutation;
  264. ShaderMatrix4 matrixParam;
  265. ShaderTextureCube cubemapParam;
  266. TextureCube* cubemap;
  267. int quadVertexCount;
  268. int quadIndexCount;
  269. GLuint quadVAO;
  270. GLuint quadVBO;
  271. GLuint quadIBO;
  272. };
  273. #endif // RENDER_PASSES_HPP