/*
|
|
* Copyright (C) 2017 Christopher J. Howard
|
|
*
|
|
* This file is part of Antkeeper Source Code.
|
|
*
|
|
* Antkeeper Source Code is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Antkeeper Source Code is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef RENDER_PASSES_HPP
|
|
#define RENDER_PASSES_HPP
|
|
|
|
#include <emergent/emergent.hpp>
|
|
using namespace Emergent;
|
|
|
|
#include "material-loader.hpp"
|
|
#include "model-loader.hpp"
|
|
#include <cstdint>
|
|
|
|
/**
|
|
* Clears framebuffers
|
|
*/
|
|
class ClearRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
ClearRenderPass();
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
void setClear(bool color, bool depth, bool stencil);
|
|
void setClearColor(const Vector4& color);
|
|
void setClearDepth(float depth);
|
|
void setClearStencil(int index);
|
|
|
|
private:
|
|
bool clearColor;
|
|
bool clearDepth;
|
|
bool clearStencil;
|
|
Vector4 color;
|
|
float depth;
|
|
int index;
|
|
};
|
|
|
|
/**
|
|
* Blurs a texture
|
|
*/
|
|
class BlurRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
BlurRenderPass();
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
inline void setGammaCorrect(bool gammaCorrect) { this->gammaCorrect = gammaCorrect; }
|
|
|
|
/**
|
|
* Sets the texture to blur.
|
|
*/
|
|
inline void setTexture(const Texture2D* texture) { textureParam.setValue(texture); }
|
|
|
|
/**
|
|
* Sets the direction of the blur.
|
|
*/
|
|
inline void setDirection(const Vector2& direction) { directionParam.setValue(direction); }
|
|
|
|
private:
|
|
bool gammaCorrect;
|
|
|
|
Shader shader;
|
|
std::uint32_t permutation;
|
|
ShaderTexture2D textureParam;
|
|
ShaderVector2 resolutionParam;
|
|
ShaderVector2 directionParam;
|
|
|
|
int quadVertexCount;
|
|
int quadIndexCount;
|
|
GLuint quadVAO;
|
|
GLuint quadVBO;
|
|
GLuint quadIBO;
|
|
};
|
|
|
|
/**
|
|
* Renders the distance from the view frustum's near clipping plane to scene geometry. The render target should have a depth only framebuffer.
|
|
*/
|
|
class ShadowMapRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
ShadowMapRenderPass();
|
|
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
inline void setViewCamera(const Camera* camera) { this->viewCamera = camera; }
|
|
inline void setLightCamera(Camera* camera) { this->lightCamera = camera; }
|
|
|
|
inline const SplitViewFrustum& getSplitViewFrustum() const { return *splitViewFrustum; }
|
|
inline const Matrix4& getCropMatrix(std::size_t index) const { return cropMatrices[index]; }
|
|
inline const Matrix4& getTileMatrix(std::size_t index) const { return tileMatrices[index]; }
|
|
|
|
private:
|
|
class RenderOpCompare
|
|
{
|
|
public:
|
|
// Sort render opations
|
|
bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
|
|
};
|
|
|
|
Shader shader;
|
|
std::uint32_t unskinnedPermutation;
|
|
std::uint32_t skinnedPermutation;
|
|
ShaderMatrix4 modelViewProjectionParam;
|
|
ShaderMatrix4* matrixPaletteParam; // data not used, just getConnectedInput() then pass pose matrix palette pointer directly
|
|
|
|
int maxBoneCount;
|
|
int shadowMapResolution;
|
|
int croppedShadowMapResolution;
|
|
Vector4* croppedShadowMapViewports;
|
|
Matrix4* cropMatrices;
|
|
Matrix4* tileMatrices;
|
|
const Camera* viewCamera;
|
|
Camera* lightCamera;
|
|
SplitViewFrustum* splitViewFrustum;
|
|
};
|
|
|
|
/**
|
|
* Renders scene geometry.
|
|
*/
|
|
class LightingRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
LightingRenderPass();
|
|
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
inline void setShadowMap(const Texture2D* shadowMap) { this->shadowMap = shadowMap; }
|
|
inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
|
|
inline void setShadowMapPass(const ShadowMapRenderPass* shadowMapPass) { this->shadowMapPass = shadowMapPass; }
|
|
inline void setDiffuseCubemap(const TextureCube* cubemap) { this->diffuseCubemap = cubemap; }
|
|
inline void setSpecularCubemap(const TextureCube* cubemap) { this->specularCubemap = cubemap; }
|
|
|
|
private:
|
|
class RenderOpCompare
|
|
{
|
|
public:
|
|
// Sort render opations
|
|
bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
|
|
};
|
|
|
|
struct ParameterSet
|
|
{
|
|
ShaderMatrix4* matrixPalette;
|
|
ShaderMatrix4 modelMatrix;
|
|
ShaderMatrix4 modelViewMatrix;
|
|
ShaderMatrix4 modelViewProjectionMatrix;
|
|
ShaderMatrix3 normalModelViewMatrix;
|
|
ShaderMatrix3 normalModelMatrix;
|
|
ShaderMatrix4* lightViewProjectionMatrices;
|
|
ShaderVector4 splitDistances;
|
|
ShaderTexture2D shadowMap;
|
|
ShaderVector3 cameraPosition;
|
|
|
|
ShaderTextureCube diffuseCubemap;
|
|
ShaderTextureCube specularCubemap;
|
|
|
|
ShaderInt directionalLightCount;
|
|
ShaderVector3* directionalLightColors;
|
|
ShaderVector3* directionalLightDirections;
|
|
|
|
ShaderInt spotlightCount;
|
|
ShaderVector3 spotlightColors;
|
|
ShaderVector3 spotlightPositions;
|
|
ShaderVector3 spotlightAttenuations;
|
|
ShaderVector3 spotlightDirections;
|
|
ShaderFloat spotlightCutoffs;
|
|
ShaderFloat spotlightExponents;
|
|
|
|
ShaderTexture2D albedoOpacityMap;
|
|
ShaderTexture2D metalnessRoughnessMap;
|
|
ShaderTexture2D normalOcclusionMap;
|
|
|
|
// Material shader parameters (uploaded by material directly)
|
|
//ShaderTexture2D albedoOpacityMap;
|
|
//ShaderTexture2D metalnessRoughnessMap;
|
|
//ShaderTexture2D normalOcclusionMap;
|
|
};
|
|
|
|
//std::map<Shader* shader, ParameterSet> parameterSets;
|
|
|
|
Shader shader;
|
|
ParameterSet parameters;
|
|
std::uint32_t unskinnedPermutation;
|
|
std::uint32_t skinnedPermutation;
|
|
|
|
int maxBoneCount;
|
|
int maxDirectionalLightCount;
|
|
int maxSpotlightCount;
|
|
|
|
|
|
Matrix4 biasMatrix;
|
|
const Texture2D* shadowMap;
|
|
const TextureCube* diffuseCubemap;
|
|
const TextureCube* specularCubemap;
|
|
const Camera* shadowCamera;
|
|
float time;
|
|
const ShadowMapRenderPass* shadowMapPass;
|
|
};
|
|
|
|
/**
|
|
* Renders bounding boxes, skeletons
|
|
*/
|
|
class DebugRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
DebugRenderPass();
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
//void setDrawBounds(bool enabled);
|
|
//void setDrawSkeletons(bool enabled);
|
|
//void setDrawCameras(bool enabled);
|
|
//void setDrawLights(bool enabled);
|
|
|
|
private:
|
|
Shader shader;
|
|
std::uint32_t permutation;
|
|
ShaderMatrix4 modelViewProjectionMatrixParam;
|
|
|
|
int aabbVertexCount;
|
|
int aabbIndexCount;
|
|
GLuint aabbVAO;
|
|
GLuint aabbVBO;
|
|
GLuint aabbIBO;
|
|
};
|
|
|
|
/**
|
|
* Renders the user interface
|
|
*/
|
|
class UIRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
UIRenderPass();
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
private:
|
|
Shader shader;
|
|
std::uint32_t texturedPermutation;
|
|
std::uint32_t untexturedPermutation;
|
|
|
|
ShaderMatrix4 modelViewProjectionMatrixParam;
|
|
ShaderTexture2D textureParam;
|
|
ShaderVector2 textureOffsetParam;
|
|
ShaderVector2 textureScaleParam;
|
|
};
|
|
|
|
/**
|
|
* Renders a vignette
|
|
*/
|
|
/*
|
|
class VignetteRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
VignetteRenderPass();
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
private:
|
|
ShaderParameterSet parameterSet;
|
|
const ShaderParameter* modelViewProjectionParam;
|
|
const ShaderParameter* bayerTextureParam;
|
|
|
|
ShaderLoader shaderLoader;
|
|
Shader* shader;
|
|
GLuint bayerTextureID;
|
|
};
|
|
*/
|
|
|
|
/**
|
|
* Renders a skybox
|
|
*/
|
|
class SkyboxRenderPass: public RenderPass
|
|
{
|
|
public:
|
|
SkyboxRenderPass();
|
|
|
|
inline void setCubemap(TextureCube* cubemap) { this->cubemap = cubemap; }
|
|
virtual bool load(const RenderContext* renderContext);
|
|
virtual void unload();
|
|
virtual void render(RenderContext* renderContext);
|
|
|
|
private:
|
|
Shader shader;
|
|
std::uint32_t permutation;
|
|
ShaderMatrix4 matrixParam;
|
|
ShaderTextureCube cubemapParam;
|
|
TextureCube* cubemap;
|
|
|
|
int quadVertexCount;
|
|
int quadIndexCount;
|
|
GLuint quadVAO;
|
|
GLuint quadVBO;
|
|
GLuint quadIBO;
|
|
};
|
|
|
|
#endif // RENDER_PASSES_HPP
|