verus/Verus/src/CGI/DeferredShading.h

112 lines
2.6 KiB
C
Raw Normal View History

2019-09-01 13:49:15 +02:00
#pragma once
namespace verus
{
namespace CGI
{
enum class LightType : int
{
none,
dir,
omni,
spot
};
class DeferredShading : public Object
{
2019-10-02 19:35:07 +02:00
#include "../Shaders/DS.inc.hlsl"
#include "../Shaders/DS_Compose.inc.hlsl"
2019-09-01 13:49:15 +02:00
enum S
{
S_LIGHT,
S_COMPOSE,
S_MAX
};
2019-10-02 19:35:07 +02:00
enum PIPE
2019-09-01 13:49:15 +02:00
{
2019-10-02 19:35:07 +02:00
PIPE_INSTANCED_DIR,
PIPE_INSTANCED_OMNI,
PIPE_INSTANCED_SPOT,
PIPE_COMPOSE,
PIPE_QUAD,
PIPE_MAX
2019-09-01 13:49:15 +02:00
};
enum TEX
{
TEX_GBUFFER_0, // Albedo RGB, A = motion blur.
TEX_GBUFFER_1, // Depth.
TEX_GBUFFER_2, // RG - Normals in screen space, Emission, Metallicity.
TEX_GBUFFER_3, // LamScale, LamBias, Specular, Gloss.
TEX_LIGHT_ACC_DIFF,
TEX_LIGHT_ACC_SPEC,
TEX_MAX
};
2019-11-03 09:31:18 +01:00
static UB_PerFrame s_ubPerFrame;
static UB_TexturesFS s_ubTexturesFS;
static UB_PerMeshVS s_ubPerMeshVS;
static UB_ShadowFS s_ubShadowFS;
static UB_PerObject s_ubPerObject;
static UB_ComposeVS s_ubComposeVS;
static UB_ComposeFS s_ubComposeFS;
2019-10-02 19:35:07 +02:00
ShaderPwns<S_MAX> _shader;
PipelinePwns<PIPE_MAX> _pipe;
TexturePwns<TEX_MAX> _tex;
UINT64 _frame = 0;
int _width = 0;
int _height = 0;
int _rp = -1;
int _fb = -1;
int _csidLight = -1;
int _csidCompose = -1;
int _csidQuad[6];
bool _activeGeometryPass = false;
bool _activeLightingPass = false;
bool _async_initPipe = false;
2019-09-01 13:49:15 +02:00
public:
DeferredShading();
~DeferredShading();
void Init();
void InitGBuffers(int w, int h);
2019-11-03 09:31:18 +01:00
void InitByAtmosphere(TexturePtr texShadow);
2019-09-01 13:49:15 +02:00
void Done();
2019-10-02 19:35:07 +02:00
static bool IsLoaded();
2019-09-01 13:49:15 +02:00
void Draw(int gbuffer);
int GetWidth() const { return _width; }
int GetHeight() const { return _height; }
bool IsActiveGeometryPass() const { return _activeGeometryPass; }
bool IsActiveLightingPass() const { return _activeLightingPass; }
2019-10-02 19:35:07 +02:00
int GetRenderPassID() const { return _rp; }
2019-09-01 13:49:15 +02:00
void BeginGeometryPass(bool onlySetRT = false, bool spriteBaking = false);
void EndGeometryPass(bool resetRT = false);
2019-10-02 19:35:07 +02:00
bool BeginLightingPass();
2019-09-01 13:49:15 +02:00
void EndLightingPass();
void Compose();
void AntiAliasing();
static bool IsLightUrl(CSZ url);
2019-11-03 09:31:18 +01:00
static UB_PerMeshVS& GetUbPerMeshVS() { return s_ubPerMeshVS; }
2019-09-01 13:49:15 +02:00
void OnNewLightType(LightType type, bool wireframe = false);
2019-10-02 19:35:07 +02:00
void UpdateUniformBufferPerFrame();
2019-11-03 09:31:18 +01:00
void BindDescriptorsPerMeshVS();
2019-09-01 13:49:15 +02:00
void Load();
TexturePtr GetGBuffer(int index);
};
VERUS_TYPEDEFS(DeferredShading);
}
}