Merge remote-tracking branch 'origin/master' into FixNetworkBugs
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
class DrawBloomPass
|
||||
{
|
||||
public:
|
||||
DrawBloomPass(IRenderer* renderer /* ,Texture or finalpass*/ );
|
||||
DrawBloomPass(IRenderer* renderer, ConfigFile* config);
|
||||
~DrawBloomPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
@@ -23,26 +23,33 @@ public:
|
||||
void FillGaussianBuffer(FrameBuffer* fb);
|
||||
|
||||
void Draw(GLuint texture);
|
||||
void ChangeQuality(int quality);
|
||||
|
||||
void OnWindowResize();
|
||||
|
||||
//Getters
|
||||
//Return the blurred result of the texture that was sent into draw
|
||||
GLuint GaussianTexture() const { return m_GaussianTexture_vert; }
|
||||
GLuint GaussianTexture() const {
|
||||
if (m_Quality == 0) {
|
||||
return m_BlackTexture->m_Texture;
|
||||
} else {
|
||||
return m_GaussianTexture_vert;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
Texture* m_WhiteTexture;
|
||||
Texture* m_BlackTexture;
|
||||
Model* m_ScreenQuad;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
ConfigFile* m_Config;
|
||||
//const LightCullingPass* m_LightCullingPass
|
||||
GLuint m_iterations = 9;
|
||||
int m_Iterations;
|
||||
int m_Quality = 0;
|
||||
|
||||
GLuint m_GaussianTexture_horiz;
|
||||
GLuint m_GaussianTexture_vert;
|
||||
GLuint m_GaussianTexture_horiz = 0;
|
||||
GLuint m_GaussianTexture_vert = 0;
|
||||
|
||||
FrameBuffer m_GaussianFrameBuffer_horiz;
|
||||
FrameBuffer m_GaussianFrameBuffer_vert;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "DrawFinalPassState.h"
|
||||
#include "LightCullingPass.h"
|
||||
#include "CubeMapPass.h"
|
||||
#include "SSAOPass.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
@@ -14,12 +15,12 @@
|
||||
class DrawFinalPass
|
||||
{
|
||||
public:
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass);
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer);
|
||||
~DrawFinalPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
void Draw(RenderScene& scene, GLuint SSAOTexture);
|
||||
void Draw(RenderScene& scene);
|
||||
void ClearBuffer();
|
||||
void OnWindowResize();
|
||||
|
||||
@@ -34,11 +35,8 @@ public:
|
||||
FrameBuffer* FinalPassFrameBufferLowRes() { return &m_FinalPassFrameBufferLowRes; }
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const;
|
||||
|
||||
void DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, RenderScene& scene);
|
||||
void DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene, GLuint SSAOTexture);
|
||||
void DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawShieldToStencilBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawShieldedModelRenderQueue(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
void DrawToDepthBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene);
|
||||
@@ -61,7 +59,7 @@ private:
|
||||
GLuint m_SceneTexture;
|
||||
GLuint m_BloomTextureLowRes;
|
||||
GLuint m_SceneTextureLowRes;
|
||||
GLuint m_DepthBuffer;
|
||||
GLuint* m_DepthBuffer;
|
||||
GLuint m_DepthBufferLowRes;
|
||||
GLuint m_CubeMapTexture;
|
||||
|
||||
@@ -71,6 +69,7 @@ private:
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
const CubeMapPass* m_CubeMapPass;
|
||||
const SSAOPass* m_SSAOPass;
|
||||
|
||||
ShaderProgram* m_ForwardPlusProgram;
|
||||
ShaderProgram* m_ExplosionEffectProgram;
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
#include "../OpenGL.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
#include "Util/ScreenCoords.h"
|
||||
#include "Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Model.h"
|
||||
#include "../Core/World.h" //So temp
|
||||
#include "Util/CommonFunctions.h"
|
||||
|
||||
|
||||
struct PickData
|
||||
|
||||
@@ -28,15 +28,13 @@ public:
|
||||
const ShaderProgram& PickingProgram() const { return *m_PickingProgram; }
|
||||
//const std::unordered_map<glm::ivec2, EntityID>& PickingColorsToEntity() const { return m_PickingColorsToEntity; }
|
||||
GLuint PickingTexture() const { return m_PickingTexture; }
|
||||
GLuint DepthBuffer() const { return m_DepthBuffer; }
|
||||
GLuint* DepthBuffer() { return &m_DepthBuffer; }
|
||||
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
|
||||
|
||||
|
||||
PickData Pick(glm::vec2 screenCoord);
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
bool StencilFunc(GLenum func, GLint ref, GLuint mask);
|
||||
bool StencilMask(GLuint mask);
|
||||
bool DepthMask(GLboolean flag);
|
||||
bool DepthFunc(GLenum func);
|
||||
bool AlphaFunc(GLenum func, GLclampf thresholder);
|
||||
|
||||
private:
|
||||
std::vector<std::function<void(void)>> m_ResetFunctions;
|
||||
|
||||
@@ -32,8 +32,9 @@ class Renderer : public IRenderer
|
||||
static void glfwFrameBufferCallback(GLFWwindow* window, int width, int height);
|
||||
|
||||
public:
|
||||
Renderer(EventBroker* eventBroker)
|
||||
Renderer(EventBroker* eventBroker, ConfigFile* config)
|
||||
: m_EventBroker(eventBroker)
|
||||
, m_Config(config)
|
||||
{ }
|
||||
|
||||
virtual void Initialize() override;
|
||||
@@ -47,6 +48,7 @@ private:
|
||||
//----------------------Variables----------------------//
|
||||
|
||||
static std::unordered_map <GLFWwindow*, Renderer*> m_WindowToRenderer;
|
||||
ConfigFile* m_Config;
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
TextPass* m_TextPass;
|
||||
@@ -61,12 +63,8 @@ private:
|
||||
int m_DebugTextureToDraw = 0;
|
||||
int m_CubeMapTexture = 0;
|
||||
bool m_ResizeWindow = false;
|
||||
float m_SSAO_Radius = 1.0f;
|
||||
float m_SSAO_Bias = 0.05f;
|
||||
float m_SSAO_Contrast = 1.5f;
|
||||
float m_SSAO_IntensityScale = 1.0f;
|
||||
int m_SSAO_NumOfSamples = 24;
|
||||
int m_SSAO_NumOfTurns = 7;
|
||||
int m_SSAO_Quality = 0;
|
||||
int m_GLOW_Quality = 2;
|
||||
|
||||
PickingPass* m_PickingPass;
|
||||
LightCullingPass* m_LightCullingPass;
|
||||
|
||||
@@ -13,18 +13,32 @@
|
||||
class SSAOPass
|
||||
{
|
||||
public:
|
||||
SSAOPass(IRenderer* rendere);
|
||||
~SSAOPass() {
|
||||
delete m_DrawBloomPass;
|
||||
};
|
||||
SSAOPass(IRenderer* renderer, ConfigFile* config);
|
||||
~SSAOPass() { };
|
||||
|
||||
void ChangeQuality(int quality);
|
||||
|
||||
void Draw(GLuint depthBuffer, Camera* camera);
|
||||
void Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int NumOfTurns);
|
||||
void Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int numOfTurns, int iterations, int quality);
|
||||
void ClearBuffer();
|
||||
void OnWindowResize();
|
||||
|
||||
//Return the SSAO of the texture sent to Draw
|
||||
GLuint SSAOTexture() const { return m_DrawBloomPass->GaussianTexture(); }
|
||||
GLuint SSAOTexture() const {
|
||||
if (m_Quality == 0) {
|
||||
return m_WhiteTexture->m_Texture;
|
||||
} else {
|
||||
return m_Gaussian_vert;
|
||||
}
|
||||
}
|
||||
|
||||
int TextureQuality() const {
|
||||
if (m_Quality == 0) {
|
||||
return 13;
|
||||
} else {
|
||||
return m_TextureQuality;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void InitializeTexture();
|
||||
@@ -32,14 +46,13 @@ private:
|
||||
void InitializeShaderProgram();
|
||||
void InitializeBuffer();
|
||||
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
//void blurHorizontal(GLuint depthBuffer);
|
||||
//void blurVertical(GLuint depthBuffer);
|
||||
|
||||
Model* m_ScreenQuad;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
ConfigFile* m_Config;
|
||||
|
||||
float m_Radius;
|
||||
float m_Bias;
|
||||
@@ -47,17 +60,28 @@ private:
|
||||
float m_IntensityScale;
|
||||
int m_NumOfSamples;
|
||||
int m_NumOfTurns;
|
||||
int m_Iterations;
|
||||
int m_TextureQuality;
|
||||
int m_Quality = 0;
|
||||
|
||||
GLuint m_SSAOTexture;
|
||||
Texture* m_WhiteTexture;
|
||||
|
||||
GLuint m_SSAOTexture = 0;
|
||||
FrameBuffer m_SSAOFramBuffer;
|
||||
|
||||
GLuint m_SSAOViewSpaceZTexture;
|
||||
GLuint m_SSAOViewSpaceZTexture = 0;
|
||||
FrameBuffer m_SSAOViewSpaceZFramBuffer;
|
||||
|
||||
GLuint m_Gaussian_horiz = 0;
|
||||
GLuint m_Gaussian_vert = 0;
|
||||
|
||||
FrameBuffer m_GaussianFrameBuffer_horiz;
|
||||
FrameBuffer m_GaussianFrameBuffer_vert;
|
||||
|
||||
ShaderProgram* m_SSAOProgram;
|
||||
ShaderProgram* m_SSAOViewSpaceZProgram;
|
||||
|
||||
DrawBloomPass* m_DrawBloomPass;
|
||||
ShaderProgram* m_GaussianProgram_horiz;
|
||||
ShaderProgram* m_GaussianProgram_vert;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,10 @@
|
||||
namespace CommonFunctions
|
||||
{
|
||||
Texture* LoadTexture(std::string path, bool threaded);
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||
void GenerateMultiSampleTexture(GLuint* texture, int numSamples, glm::vec2 dimensions, GLint internalFormat);
|
||||
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps);
|
||||
void DeleteTexture(GLuint* texture);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,8 +14,6 @@ public:
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
static void SetRespawnTime(float respawnTime) { m_RespawnTime = respawnTime; };
|
||||
|
||||
private:
|
||||
struct SpawnRequest
|
||||
{
|
||||
@@ -31,8 +29,8 @@ private:
|
||||
//EntityWrapper ID -> Player ID.
|
||||
std::map<EntityID, int> m_PlayerIDs;
|
||||
|
||||
static float m_RespawnTime;
|
||||
float m_Timer;
|
||||
float m_ForcedRespawnTime;
|
||||
bool m_DbgConfigForceRespawn;
|
||||
|
||||
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
||||
bool OnInputCommand(Events::InputCommand& e);
|
||||
|
||||
@@ -37,3 +37,36 @@ ResourceLoading=true
|
||||
BGMVolume=1.0
|
||||
SFXVolume=1.0
|
||||
Announcer=female
|
||||
|
||||
[SSAO]
|
||||
Quality=0
|
||||
|
||||
[SSAO1]
|
||||
Radius=1.0
|
||||
Bias=0.02
|
||||
Contrast=1.5
|
||||
Intensity=1.0
|
||||
NumSamples=8
|
||||
NumTurns=3
|
||||
NumIterations=5
|
||||
TextureQuality=2
|
||||
|
||||
[SSAO2]
|
||||
Radius=1.0
|
||||
Bias=0.02
|
||||
Contrast=1.5
|
||||
Intensity=1.0
|
||||
NumSamples=16
|
||||
NumTurns=13
|
||||
NumIterations=9
|
||||
TextureQuality=1
|
||||
|
||||
[SSAO3]
|
||||
Radius=1.0
|
||||
Bias=0.02
|
||||
Contrast=1.5
|
||||
Intensity=1.0
|
||||
NumSamples=24
|
||||
NumTurns=17
|
||||
NumIterations=13
|
||||
TextureQuality=0
|
||||
@@ -46,6 +46,8 @@
|
||||
<xs:include schemaLocation="Components/Page.xsd"/>
|
||||
<xs:include schemaLocation="Components/SpriteIndicator.xsd"/>
|
||||
<xs:include schemaLocation="Components/Button.xsd"/>
|
||||
<xs:include schemaLocation="Components/DoubleJump.xsd"/>
|
||||
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
|
||||
<xs:include schemaLocation="Components/DefenderWeapon.xsd"/>
|
||||
<xs:include schemaLocation="Components/CapturePointGameMode.xsd"/>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<CapturePointGameMode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePointGameMode.xsd">
|
||||
<RespawnTime>0.0</RespawnTime>
|
||||
<MaxRespawnTime>8.0</MaxRespawnTime>
|
||||
</CapturePointGameMode>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="CapturePointGameMode">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="RespawnTime" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>The time since the last respawn wave. Players will be spawned when this reaches MaxRespawnTime.</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="MaxRespawnTime" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Players will be spawned when RespawnTime reaches this.</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<DoubleJump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DoubleJump.xsd">
|
||||
<DoubleJumpSpeed>4.0</DoubleJumpSpeed>
|
||||
</DoubleJump>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="DoubleJump">
|
||||
<xs:annotation><xs:documentation>Enables a Player to double jump.</xs:documentation></xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="DoubleJumpSpeed" type="t:float" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Vertical velocity set on double jump.</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -2,6 +2,7 @@
|
||||
<Player xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Player.xsd">
|
||||
<MovementSpeed>3</MovementSpeed>
|
||||
<CrouchSpeed>1.5</CrouchSpeed>
|
||||
<JumpSpeed>4.0</JumpSpeed>
|
||||
<CurrentWishDirection X="0" Y="0" Z="0"/>
|
||||
<CurrentWeapon></CurrentWeapon>
|
||||
</Player>
|
||||
@@ -11,6 +11,9 @@
|
||||
<xs:all>
|
||||
<xs:element name="MovementSpeed" type="t:float" minOccurs="0"/>
|
||||
<xs:element name="CrouchSpeed" type="t:float" minOccurs="0"/>
|
||||
<xs:element name="JumpSpeed" type="t:float" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Vertical velocity set when jumping.</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="CurrentWishDirection" type="t:Vector" minOccurs="0"/>
|
||||
<xs:element name="CurrentWeapon" type="t:string" minOccurs="0"/>
|
||||
</xs:all>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<c:DefenderWeapon>
|
||||
<TimeSinceLastFire>1.6944730461160304</TimeSinceLastFire>
|
||||
</c:DefenderWeapon>
|
||||
<c:DoubleJump/>
|
||||
<c:Health/>
|
||||
<c:Physics>
|
||||
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
|
||||
|
||||
Executable → Regular
+1
@@ -15,6 +15,7 @@
|
||||
<c:DefenderWeapon>
|
||||
<TimeSinceLastFire>1.6944730461160304</TimeSinceLastFire>
|
||||
</c:DefenderWeapon>
|
||||
<c:DoubleJump/>
|
||||
<c:Health/>
|
||||
<c:Physics>
|
||||
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
|
||||
|
||||
@@ -13,6 +13,7 @@ uniform vec4 AmbientColor;
|
||||
uniform float FillPercentage;
|
||||
uniform float GlowIntensity = 10;
|
||||
uniform vec3 CameraPosition;
|
||||
uniform int SSAOQuality;
|
||||
|
||||
uniform vec2 DiffuseUVRepeat;
|
||||
uniform vec2 NormalUVRepeat;
|
||||
@@ -125,7 +126,7 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
|
||||
|
||||
void main()
|
||||
{
|
||||
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy), 0).r;
|
||||
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r;
|
||||
ao = (clamp(1.0 - (1.0 - ao), 0.0, 1.0) + MIN_AMBIENT_LIGHT) / (1.0 + MIN_AMBIENT_LIGHT);
|
||||
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
|
||||
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
|
||||
@@ -170,7 +171,8 @@ void main()
|
||||
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
|
||||
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
|
||||
float specularResult = (specularTexel.r + specularTexel.g + specularTexel.b)/3.0;
|
||||
color_result = color_result * clamp(1/specularTexel, 0, 1)*2 + reflectionColor * clamp(specularTexel, 0, 1)/2;
|
||||
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a;
|
||||
color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal;
|
||||
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
|
||||
|
||||
|
||||
@@ -181,9 +183,9 @@ void main()
|
||||
}
|
||||
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
||||
//sceneColor = vec4(reflectionColor.xyz, 1);
|
||||
color_result += glowTexel*GlowIntensity;
|
||||
color_result.xyz += glowTexel.xyz*GlowIntensity;
|
||||
|
||||
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), clamp(color_result.a, 0, 1));
|
||||
bloomColor = vec4(max(color_result.xyz - 1.0, 0.0), clamp(color_result.a, 0, 1));
|
||||
|
||||
//Tiled Debug Code
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,7 @@ uniform vec4 DiffuseColor;
|
||||
uniform vec4 FillColor;
|
||||
uniform vec4 Color;
|
||||
uniform vec4 AmbientColor;
|
||||
uniform int SSAOQuality;
|
||||
|
||||
//Get bineded at the same time as the textures
|
||||
uniform vec2 DiffuseUVRepeat1;
|
||||
@@ -177,7 +178,7 @@ vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B,
|
||||
|
||||
void main()
|
||||
{
|
||||
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy), 0).r;
|
||||
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r;
|
||||
ao = (clamp(1.0 - (1.0 - ao), 0.0, 1.0) + MIN_AMBIENT_LIGHT) / (1.0 + MIN_AMBIENT_LIGHT);
|
||||
|
||||
vec4 splatTexel = texture2D(SplatMapTexture, Input.TextureCoordinate);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
//Number of samples per pixel
|
||||
uniform int uNumOfSamples;
|
||||
//#define NUM_SAMPLES (11)
|
||||
//#define uNumOfSamples (11)
|
||||
|
||||
//Number of turns around the cirle
|
||||
uniform int uNumOfTurns;
|
||||
//#define NUM_TURNS (7)
|
||||
//#define uNumOfTurns (7)
|
||||
|
||||
layout (binding = 0) uniform sampler2D ViewSpaceZ;
|
||||
|
||||
@@ -16,15 +16,16 @@ uniform float uProjScale;
|
||||
//#define ProjScale 500
|
||||
|
||||
uniform float uRadius;
|
||||
//#define Radius 1.0f
|
||||
//#define uRadius 1.0f
|
||||
|
||||
uniform float uBias;
|
||||
//#define Bias 0.012f
|
||||
//#define uBias 0.05f
|
||||
|
||||
uniform float uContrast;
|
||||
//#define IntensityDivR6 1
|
||||
//#define uContrast 1.5f
|
||||
|
||||
uniform float uIntensityScale;
|
||||
//#define uIntensityScale 1.0f
|
||||
|
||||
out float AO;
|
||||
|
||||
@@ -88,13 +89,7 @@ void main() {
|
||||
|
||||
vec3 origin = getVSPosition(originScreenCoord);
|
||||
|
||||
float radius;
|
||||
if(origin.z < uRadius){
|
||||
radius = origin.z;
|
||||
} else {
|
||||
radius = uRadius;
|
||||
}
|
||||
|
||||
float radius = min(origin.z, uRadius);
|
||||
|
||||
vec3 originNormal = getVSFaceNormal(origin);
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
}Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
Output.TextureCoordinate = (vec2(Position) + 1) / 2;
|
||||
}
|
||||
@@ -3,11 +3,15 @@
|
||||
layout (binding = 0) uniform sampler2D DepthBuffer;
|
||||
uniform vec3 ClipInfo;
|
||||
|
||||
in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
}Input;
|
||||
|
||||
out float depthLinear;
|
||||
//Just for Debug, should be depthLinear
|
||||
//out vec4 fragmentColor;
|
||||
void main() {
|
||||
float depthSample = texelFetch(DepthBuffer, ivec2(gl_FragCoord.xy), 0).r;
|
||||
float depthSample = texture2D(DepthBuffer, Input.TextureCoordinate).r;
|
||||
depthLinear = ClipInfo[0] / (ClipInfo[1] * depthSample + ClipInfo[2]);
|
||||
//float depthLinear = (NearClip) / ( -depthSample + 1.0f);
|
||||
//fragmentColor = vec4(depthLinear, depthLinear, depthLinear, 1.0f);
|
||||
|
||||
@@ -12,6 +12,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
if (!boundingBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentWrapper& cTransform = entity["Transform"];
|
||||
EntityAABB& boxA = *boundingBox;
|
||||
bool everHitTheGround = false;
|
||||
@@ -86,10 +87,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
||||
|
||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||
bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end();
|
||||
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
||||
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
||||
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
||||
(glm::vec3&)cTransform["Position"] += resolutionVector;
|
||||
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
|
||||
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
|
||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||
cPhysics["Velocity"] = inOutVelocity;
|
||||
if (isOnGround) {
|
||||
|
||||
@@ -580,6 +580,11 @@ void EditorGUI::createWidgetToolButton(WidgetMode mode)
|
||||
|
||||
bool EditorGUI::OnKeyDown(const Events::KeyDown& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.WantCaptureKeyboard) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.ModCtrl && e.KeyCode == GLFW_KEY_S) {
|
||||
if (m_CurrentSelection.Valid()) {
|
||||
EntityWrapper baseParent = m_CurrentSelection;
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
#include "Rendering/DrawBloomPass.h"
|
||||
|
||||
DrawBloomPass::DrawBloomPass(IRenderer* renderer)
|
||||
DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config)
|
||||
: m_Renderer(renderer)
|
||||
, m_Config(config)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
|
||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
|
||||
|
||||
InitializeTextures();
|
||||
InitializeBuffers();
|
||||
InitializeShaderPrograms();
|
||||
|
||||
ChangeQuality(m_Config->Get<int>("GLOW.Quality", 2));
|
||||
}
|
||||
|
||||
void DrawBloomPass::InitializeTextures()
|
||||
{
|
||||
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
|
||||
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
|
||||
}
|
||||
|
||||
void DrawBloomPass::ChangeQuality(int quality)
|
||||
{
|
||||
if (m_Quality == quality) {
|
||||
return;
|
||||
}
|
||||
m_Quality = quality;
|
||||
|
||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
|
||||
|
||||
if (m_Quality == 0) {
|
||||
CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz);
|
||||
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
|
||||
m_GaussianTexture_horiz = 0;
|
||||
m_GaussianTexture_vert = 0;
|
||||
return;
|
||||
}
|
||||
InitializeTextures();
|
||||
|
||||
InitializeBuffers();
|
||||
InitializeShaderPrograms();
|
||||
std::string qStr = std::to_string(m_Quality);
|
||||
m_Iterations = m_Config->Get<float>("GLOW" + qStr + ".NumIterations", 0);
|
||||
}
|
||||
|
||||
void DrawBloomPass::InitializeShaderPrograms()
|
||||
@@ -35,37 +57,45 @@ void DrawBloomPass::InitializeShaderPrograms()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawBloomPass::InitializeBuffers()
|
||||
{
|
||||
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
|
||||
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
|
||||
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_GaussianFrameBuffer_horiz.Generate();
|
||||
|
||||
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
|
||||
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
|
||||
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_GaussianFrameBuffer_vert.Generate();
|
||||
}
|
||||
|
||||
|
||||
void DrawBloomPass::ClearBuffer()
|
||||
{
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
GLERROR("PRE");
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_horiz.Unbind();
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
void DrawBloomPass::Draw(GLuint texture)
|
||||
{
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
GLERROR("DrawBloomPass::Draw: Pre");
|
||||
|
||||
DrawBloomPassState state;
|
||||
@@ -84,11 +114,12 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
//Iterate some times to make it more gaussian.
|
||||
for (int i = 1; i < m_iterations; i++) {
|
||||
for (int i = 1; i < m_Iterations; i++) {
|
||||
//Vertical pass
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
m_GaussianProgram_vert->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
@@ -96,16 +127,19 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
//horizontal pass
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
m_GaussianProgram_horiz->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
m_GaussianFrameBuffer_horiz.Unbind();
|
||||
}
|
||||
|
||||
//final vertical gaussian after the iterations are done
|
||||
@@ -113,6 +147,7 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
m_GaussianProgram_vert->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
@@ -125,20 +160,11 @@ void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
void DrawBloomPass::OnWindowResize()
|
||||
{
|
||||
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
m_GaussianFrameBuffer_vert.Generate();
|
||||
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
m_GaussianFrameBuffer_horiz.Generate();
|
||||
}
|
||||
|
||||
void DrawBloomPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "Rendering/DrawFinalPass.h"
|
||||
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass)
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer)
|
||||
: m_Renderer(renderer)
|
||||
, m_LightCullingPass(lightCullingPass)
|
||||
, m_CubeMapPass(cubeMapPass)
|
||||
, m_SSAOPass(ssaoPass)
|
||||
, m_DepthBuffer(depthBuffer)
|
||||
{
|
||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||
m_ShieldPixelRate = 8;
|
||||
@@ -23,19 +24,13 @@ void DrawFinalPass::InitializeTextures()
|
||||
|
||||
void DrawFinalPass::InitializeFrameBuffers()
|
||||
{
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("RenderBuffer generation");
|
||||
|
||||
|
||||
GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||
//GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT);
|
||||
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
//m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
@@ -47,9 +42,9 @@ void DrawFinalPass::InitializeFrameBuffers()
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, (int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate));
|
||||
GLERROR("RenderBufferLowRes generation");
|
||||
|
||||
GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||
//GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT);
|
||||
|
||||
@@ -162,27 +157,26 @@ void DrawFinalPass::InitializeShaderPrograms()
|
||||
|
||||
m_FillDepthBufferProgram = ResourceManager::Load<ShaderProgram>("#FillDepthBufferProgram");
|
||||
m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBuffer.vert.glsl")));
|
||||
m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
|
||||
//m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
|
||||
m_FillDepthBufferProgram->Compile();
|
||||
m_FillDepthBufferProgram->Link();
|
||||
GLERROR("Creating DepthFill program");
|
||||
|
||||
m_FillDepthBufferSkinnedProgram = ResourceManager::Load<ShaderProgram>("#FillDepthBufferProgramSkinned");
|
||||
m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBufferSkinned.vert.glsl")));
|
||||
m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
|
||||
//m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
|
||||
m_FillDepthBufferSkinnedProgram->Compile();
|
||||
m_FillDepthBufferSkinnedProgram->Link();
|
||||
GLERROR("Creating DepthFill program");
|
||||
}
|
||||
|
||||
void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
||||
void DrawFinalPass::Draw(RenderScene& scene)
|
||||
{
|
||||
GLERROR("Pre");
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
if (scene.ClearDepth) {
|
||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||
state->Disable(GL_DEPTH_TEST);
|
||||
state->DepthMask(GL_FALSE);
|
||||
}
|
||||
//TODO: Do we need check for this or will it be per scene always?
|
||||
glClearStencil(0x00);
|
||||
@@ -191,12 +185,15 @@ void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
||||
//Fill depth buffer
|
||||
|
||||
state->StencilMask(0x00);
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene, SSAOTexture);
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
|
||||
GLERROR("OpaqueObjects");
|
||||
state->BlendFunc(GL_ONE, GL_ONE);
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene, SSAOTexture);
|
||||
GLERROR("TransparentObjects");
|
||||
//state->BlendFunc(GL_ONE, GL_ONE);
|
||||
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
|
||||
GLERROR("TransparentObjects");
|
||||
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
DrawSprites(scene.Jobs.SpriteJob, scene);
|
||||
GLERROR("SpriteJobs");
|
||||
|
||||
@@ -210,11 +207,11 @@ void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
||||
//Draw Opaque shielded objects
|
||||
state->StencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
||||
state->StencilMask(0x00);
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueShieldedObjects, scene, SSAOTexture); //might need changing
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueShieldedObjects, scene); //might need changing
|
||||
GLERROR("Shielded Opaque object");
|
||||
|
||||
//Draw Transparen Shielded objects
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentShieldedObjects, scene, SSAOTexture); //might need changing
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentShieldedObjects, scene); //might need changing
|
||||
GLERROR("Shielded Transparent objects");
|
||||
|
||||
GLERROR("END");
|
||||
@@ -250,9 +247,9 @@ void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
||||
stateLowRes->Enable(GL_DEPTH_TEST);
|
||||
stateLowRes->StencilFunc(GL_LEQUAL, 1, 0xFF);
|
||||
stateLowRes->StencilMask(0x00);
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene, SSAOTexture);
|
||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
|
||||
GLERROR("OpaqueObjects");
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene, SSAOTexture);
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
|
||||
GLERROR("TransparentObjects");
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
@@ -273,7 +270,7 @@ void DrawFinalPass::ClearBuffer()
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
GLERROR("1");
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
GLERROR("2");
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
@@ -288,7 +285,7 @@ void DrawFinalPass::ClearBuffer()
|
||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("ViewPort,Scissor LowRes");
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
@@ -297,50 +294,22 @@ void DrawFinalPass::ClearBuffer()
|
||||
void DrawFinalPass::OnWindowResize()
|
||||
{
|
||||
//InitializeFrameBuffers();
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
|
||||
GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
m_FinalPassFrameBuffer.Generate();
|
||||
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBufferLowRes);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, (int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate));
|
||||
|
||||
GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SceneTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_BloomTextureLowRes, GL_CLAMP_TO_EDGE, GL_NEAREST, glm::vec2((int)(m_Renderer->GetViewportSize().Width/m_ShieldPixelRate), (int)(m_Renderer->GetViewportSize().Height/m_ShieldPixelRate)), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
m_FinalPassFrameBufferLowRes.Generate();
|
||||
GLERROR("Error changing texture resolutions");
|
||||
}
|
||||
|
||||
void DrawFinalPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
void DrawFinalPass::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
GLERROR("MipMap Texture initialization failed");
|
||||
}
|
||||
|
||||
void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene, GLuint SSAOTexture)
|
||||
void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
|
||||
{
|
||||
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
|
||||
GLERROR("forwardHandle");
|
||||
@@ -364,7 +333,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, SSAOTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture());
|
||||
|
||||
for (auto &job : jobs) {
|
||||
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
|
||||
@@ -383,7 +352,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
glUniform3fv(glGetUniformLocation(explosionSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (explosionEffectJob->AnimationOffset.animation != nullptr) {
|
||||
@@ -401,7 +370,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindExplosionTextures(explosionHandle, explosionEffectJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
glUniform3fv(glGetUniformLocation(explosionHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -463,7 +432,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindModelTextures(forwardSkinnedHandle, modelJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
glUniform3fv(glGetUniformLocation(forwardHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
glUniform3fv(glGetUniformLocation(forwardSkinnedHandle, "CameraPosition"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->AnimationOffset.animation != nullptr) {
|
||||
@@ -753,6 +722,7 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
|
||||
|
||||
void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene)
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
GLERROR("Bind 1 uniform");
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
|
||||
GLERROR("Bind 2 uniform");
|
||||
@@ -801,6 +771,7 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
|
||||
|
||||
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
GLERROR("Bind 1 uniform");
|
||||
GLint Location_M = glGetUniformLocation(shaderHandle, "M");
|
||||
glUniformMatrix4fv(Location_M, 1, GL_FALSE, glm::value_ptr(job->Matrix));
|
||||
|
||||
@@ -8,6 +8,8 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
|
||||
Enable(GL_BLEND);
|
||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Enable(GL_DEPTH_TEST);
|
||||
DepthMask(GL_FALSE);
|
||||
DepthFunc(GL_LEQUAL);
|
||||
Enable(GL_CULL_FACE);
|
||||
Enable(GL_STENCIL_TEST);
|
||||
StencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
||||
|
||||
@@ -42,8 +42,9 @@ void FrameBuffer::Generate()
|
||||
GLERROR("PRE");
|
||||
|
||||
std::vector<GLenum> attachments;
|
||||
|
||||
if (m_BufferHandle == 0) {
|
||||
glGenFramebuffers(1, &m_BufferHandle);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferHandle);
|
||||
GLERROR("1");
|
||||
|
||||
@@ -69,7 +70,6 @@ void FrameBuffer::Generate()
|
||||
}
|
||||
GLERROR("3");
|
||||
|
||||
|
||||
GLenum* bufferTextures = &attachments[0];
|
||||
glDrawBuffers(attachments.size(), bufferTextures);
|
||||
if (GLERROR("GLBufferAttachement error")) {
|
||||
|
||||
@@ -19,10 +19,10 @@ PickingPass::~PickingPass()
|
||||
|
||||
void PickingPass::InitializeTextures()
|
||||
{
|
||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||
CommonFunctions::GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||
|
||||
GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ void PickingPass::ClearPicking()
|
||||
|
||||
m_PickingBuffer.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
@@ -407,16 +407,3 @@ PickData PickingPass::Pick(glm::vec2 screenCoord)
|
||||
pickData.World = pickInfo.World;
|
||||
return pickData;
|
||||
}
|
||||
|
||||
void PickingPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
//TODO: Renderer: Make this in a sparate class
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
Disable(GL_BLEND);
|
||||
|
||||
glm::vec4 clearColor = glm::vec4(0.f);
|
||||
//ClearColor(clearColor);
|
||||
//Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLERROR("END");
|
||||
|
||||
}
|
||||
|
||||
PickingPassState::~PickingPassState()
|
||||
|
||||
@@ -135,6 +135,26 @@ bool RenderState::DepthMask(GLboolean flag)
|
||||
return !GLERROR("DepthMask");
|
||||
}
|
||||
|
||||
bool RenderState::DepthFunc(GLenum func)
|
||||
{
|
||||
GLint original;
|
||||
glGetIntegerv(GL_DEPTH_FUNC, &original);
|
||||
m_ResetFunctions.push_back(std::bind(glDepthFunc, original));
|
||||
glDepthFunc(func);
|
||||
return !GLERROR("DepthFunc");
|
||||
}
|
||||
|
||||
bool RenderState::AlphaFunc(GLenum func, GLclampf thresholder)
|
||||
{
|
||||
GLint originalFunc;
|
||||
glGetIntegerv(GL_ALPHA_TEST_FUNC, &originalFunc);
|
||||
GLint originalRef;
|
||||
glGetIntegerv(GL_ALPHA_TEST_REF, &originalRef);
|
||||
m_ResetFunctions.push_back(std::bind(glAlphaFunc, originalFunc, originalRef));
|
||||
glAlphaFunc(func, thresholder);
|
||||
return !GLERROR("AlphaFunc");
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
{
|
||||
for (auto& f : boost::adaptors::reverse(m_ResetFunctions)) {
|
||||
|
||||
@@ -4,6 +4,8 @@ std::unordered_map<GLFWwindow*, Renderer*> Renderer::m_WindowToRenderer;
|
||||
|
||||
void Renderer::Initialize()
|
||||
{
|
||||
m_SSAO_Quality = m_Config->Get<int>("SSAO.Quality", 0);
|
||||
m_GLOW_Quality = m_Config->Get<int>("GLOW.Quality", 0);
|
||||
InitializeWindow();
|
||||
|
||||
InitializeRenderPasses();
|
||||
@@ -26,9 +28,9 @@ void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height
|
||||
glViewport(0, 0, width, height);
|
||||
Renderer* currentRenderer = m_WindowToRenderer[window];
|
||||
currentRenderer->m_ViewportSize = Rectangle(width, height);
|
||||
currentRenderer->m_PickingPass->OnWindowResize();
|
||||
currentRenderer->m_DrawFinalPass->OnWindowResize();
|
||||
currentRenderer->m_LightCullingPass->OnWindowResize();
|
||||
currentRenderer->m_PickingPass->OnWindowResize();
|
||||
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
||||
currentRenderer->m_SSAOPass->OnWindowResize();
|
||||
}
|
||||
@@ -107,6 +109,7 @@ void Renderer::Update(double dt)
|
||||
void Renderer::Draw(RenderFrame& frame)
|
||||
{
|
||||
GLERROR("PRE");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0SceneLowRes\0BloomLowRes\0Gaussian\0Picking\0Ambient Occlusion");
|
||||
ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)");
|
||||
if(m_CubeMapTexture == 0) {
|
||||
@@ -115,13 +118,10 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
m_CubeMapPass->LoadTextures("Sky");
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("SSAO sample radius", &m_SSAO_Radius, 0.01f, 5.0f);
|
||||
ImGui::SliderFloat("SSAO bias", &m_SSAO_Bias, 0.0f, 0.1f);
|
||||
ImGui::SliderFloat("SSAO contrast", &m_SSAO_Contrast, 0.0f, 10.0f);
|
||||
ImGui::SliderFloat("SSAO IntensityScale", &m_SSAO_IntensityScale, 0.0f, 10.0f);
|
||||
ImGui::SliderInt("SSAO Number of Samples", &m_SSAO_NumOfSamples, 2, 100);
|
||||
ImGui::SliderInt("SSAO Number of Turns", &m_SSAO_NumOfTurns, 0, 50);
|
||||
m_SSAOPass->Setting(m_SSAO_Radius, m_SSAO_Bias, m_SSAO_Contrast, m_SSAO_IntensityScale, m_SSAO_NumOfSamples, m_SSAO_NumOfTurns);
|
||||
ImGui::SliderInt("SSAO Quality", &m_SSAO_Quality, 0, 3);
|
||||
ImGui::SliderInt("Glow Quality", &m_GLOW_Quality, 0, 3);
|
||||
m_SSAOPass->ChangeQuality(m_SSAO_Quality);
|
||||
m_DrawBloomPass->ChangeQuality(m_GLOW_Quality);
|
||||
GLERROR("SSAO Settings");
|
||||
//clear buffer 0
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
@@ -136,18 +136,16 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
||||
GLERROR("ClearBuffers");
|
||||
for (auto scene : frame.RenderScenes) {
|
||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||
PerformanceTimer::StartTimer("Renderer-PickingPass");
|
||||
m_PickingPass->Draw(*scene);
|
||||
GLERROR("Drawing pickingpass");
|
||||
PerformanceTimer::StopTimer("Renderer-Depth");
|
||||
PerformanceTimer::StopTimer("Renderer-PickingPass");
|
||||
}
|
||||
PerformanceTimer::StartTimer("AO generation");
|
||||
m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
|
||||
GLuint ao = m_SSAOPass->SSAOTexture();
|
||||
PerformanceTimer::StopTimer("AO generation");
|
||||
PerformanceTimer::StartTimer("Renderer-AO generation");
|
||||
m_SSAOPass->Draw(*m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
|
||||
PerformanceTimer::StopTimer("Renderer-AO generation");
|
||||
for (auto scene : frame.RenderScenes){
|
||||
|
||||
PerformanceTimer::StartTimer("Renderer-Drawing PickingPass");
|
||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||
SortRenderJobsByDepth(*scene);
|
||||
GLERROR("SortByDepth");
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
|
||||
@@ -159,8 +157,8 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
|
||||
m_LightCullingPass->CullLights(*scene);
|
||||
GLERROR("LightCulling");
|
||||
m_DrawFinalPass->Draw(*scene, ao);
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
|
||||
m_DrawFinalPass->Draw(*scene);
|
||||
GLERROR("Draw Geometry+Light");
|
||||
//m_DrawScenePass->Draw(*scene);
|
||||
|
||||
@@ -207,8 +205,11 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
|
||||
m_ImGuiRenderPass->Draw();
|
||||
GLERROR("Imgui draw");
|
||||
glfwSwapBuffers(m_Window);
|
||||
PerformanceTimer::StopTimer("Renderer-ImGuiRenderPass");
|
||||
|
||||
PerformanceTimer::StartTimer("Renderer-SwapBuffer");
|
||||
glfwSwapBuffers(m_Window);
|
||||
PerformanceTimer::StopTimer("Renderer-SwapBuffer");
|
||||
}
|
||||
|
||||
PickData Renderer::Pick(glm::vec2 screenCoord)
|
||||
@@ -248,9 +249,10 @@ void Renderer::InitializeRenderPasses()
|
||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||
m_LightCullingPass = new LightCullingPass(this);
|
||||
m_CubeMapPass = new CubeMapPass(this);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass);
|
||||
m_SSAOPass = new SSAOPass(this, m_Config);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_PickingPass->DepthBuffer());
|
||||
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
||||
m_DrawBloomPass = new DrawBloomPass(this);
|
||||
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
|
||||
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
||||
m_SSAOPass = new SSAOPass(this);
|
||||
|
||||
}
|
||||
@@ -1,84 +1,168 @@
|
||||
#include "Rendering/SSAOPass.h"
|
||||
|
||||
SSAOPass::SSAOPass(IRenderer* renderer)
|
||||
SSAOPass::SSAOPass(IRenderer* renderer, ConfigFile* config)
|
||||
: m_Renderer(renderer)
|
||||
, m_Config(config)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
|
||||
|
||||
ChangeQuality(m_Config->Get<int>("SSAO.Quality", 0));
|
||||
|
||||
}
|
||||
|
||||
void SSAOPass::ChangeQuality(int quality)
|
||||
{
|
||||
if (m_Quality == quality) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Quality = quality;
|
||||
|
||||
if (m_Quality == 0) {
|
||||
CommonFunctions::DeleteTexture(&m_SSAOTexture);
|
||||
CommonFunctions::DeleteTexture(&m_SSAOViewSpaceZTexture);
|
||||
CommonFunctions::DeleteTexture(&m_Gaussian_horiz);
|
||||
CommonFunctions::DeleteTexture(&m_Gaussian_vert);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string qStr = std::to_string(m_Quality);
|
||||
Setting(
|
||||
m_Config->Get<float>("SSAO" + qStr + ".Radius", 0.01),
|
||||
m_Config->Get<float>("SSAO" + qStr + ".Bias", 0.012),
|
||||
m_Config->Get<float>("SSAO" + qStr + ".Contrast", 1.0),
|
||||
m_Config->Get<float>("SSAO" + qStr + ".Intensity", 1.0),
|
||||
m_Config->Get<int>("SSAO" + qStr + ".NumSamples", 0),
|
||||
m_Config->Get<int>("SSAO" + qStr + ".NumTurns", 0),
|
||||
m_Config->Get<int>("SSAO" + qStr + ".NumIterations", 0),
|
||||
m_Config->Get<int>("SSAO" + qStr + ".TextureQuality", 4)
|
||||
);
|
||||
|
||||
|
||||
|
||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
|
||||
|
||||
InitializeTexture();
|
||||
InitializeBuffer();
|
||||
InitializeShaderProgram();
|
||||
Setting(0.1f, 0.012f, 1.0f, 1.0f, 13, 7);
|
||||
|
||||
m_DrawBloomPass = new DrawBloomPass(renderer);
|
||||
|
||||
}
|
||||
|
||||
void SSAOPass::InitializeShaderProgram()
|
||||
{
|
||||
m_SSAOProgram = ResourceManager::Load<ShaderProgram>("##SSAOProgram");
|
||||
if (m_SSAOProgram->GetHandle() == 0) {
|
||||
m_SSAOProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SSAO.vert.glsl")));
|
||||
m_SSAOProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SSAO.frag.glsl")));
|
||||
m_SSAOProgram->Compile();
|
||||
m_SSAOProgram->Link();
|
||||
}
|
||||
|
||||
m_SSAOViewSpaceZProgram = ResourceManager::Load<ShaderProgram>("##SSAOViewSpaceZProgram");
|
||||
if (m_SSAOViewSpaceZProgram->GetHandle() == 0) {
|
||||
m_SSAOViewSpaceZProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SSAO.vert.glsl")));
|
||||
m_SSAOViewSpaceZProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SSAOViewSpaceZ.frag.glsl")));
|
||||
m_SSAOViewSpaceZProgram->Compile();
|
||||
m_SSAOViewSpaceZProgram->Link();
|
||||
}
|
||||
|
||||
m_GaussianProgram_horiz = ResourceManager::Load<ShaderProgram>("##GaussianProgramHoriz");
|
||||
if (m_GaussianProgram_horiz->GetHandle() == 0) {
|
||||
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_horiz.vert.glsl")));
|
||||
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl")));
|
||||
m_GaussianProgram_horiz->Compile();
|
||||
m_GaussianProgram_horiz->Link();
|
||||
}
|
||||
|
||||
m_GaussianProgram_vert = ResourceManager::Load<ShaderProgram>("##GaussianProgramVert");
|
||||
if (m_GaussianProgram_vert->GetHandle() == 0) {
|
||||
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_vert.vert.glsl")));
|
||||
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_vert.frag.glsl")));
|
||||
m_GaussianProgram_vert->Compile();
|
||||
m_GaussianProgram_vert->Link();
|
||||
}
|
||||
}
|
||||
|
||||
void SSAOPass::InitializeTexture() {
|
||||
GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R8, GL_RED, GL_FLOAT);
|
||||
GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R32F, GL_RED, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R32F, GL_RED, GL_FLOAT);
|
||||
|
||||
CommonFunctions::GenerateTexture(&m_Gaussian_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||
CommonFunctions::GenerateTexture(&m_Gaussian_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||
}
|
||||
|
||||
void SSAOPass::InitializeBuffer()
|
||||
{
|
||||
if (m_SSAOFramBuffer.GetHandle() == 0) {
|
||||
m_SSAOFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOTexture, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_SSAOFramBuffer.Generate();
|
||||
|
||||
|
||||
if (m_SSAOViewSpaceZFramBuffer.GetHandle() == 0) {
|
||||
m_SSAOViewSpaceZFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOViewSpaceZTexture, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_SSAOViewSpaceZFramBuffer.Generate();
|
||||
|
||||
|
||||
|
||||
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
|
||||
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_Gaussian_horiz, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_GaussianFrameBuffer_horiz.Generate();
|
||||
|
||||
|
||||
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
|
||||
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_Gaussian_vert, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_GaussianFrameBuffer_vert.Generate();
|
||||
|
||||
}
|
||||
|
||||
void SSAOPass::ClearBuffer()
|
||||
{
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
m_SSAOFramBuffer.Bind();
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_SSAOFramBuffer.Unbind();
|
||||
|
||||
m_SSAOViewSpaceZFramBuffer.Bind();
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_SSAOViewSpaceZFramBuffer.Unbind();
|
||||
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_horiz.Unbind();
|
||||
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
}
|
||||
|
||||
void SSAOPass::Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int NumOfTurns) {
|
||||
void SSAOPass::Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int numOfTurns, int iterations, int quality) {
|
||||
m_Radius = radius;
|
||||
m_Bias = bias;
|
||||
m_Contrast = contrast;
|
||||
m_IntensityScale = intensityScale;
|
||||
m_NumOfSamples = numOfSamples;
|
||||
m_NumOfTurns = NumOfTurns;
|
||||
}
|
||||
|
||||
void SSAOPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);
|
||||
GLERROR("Texture initialization failed");
|
||||
m_NumOfTurns = numOfTurns;
|
||||
m_Iterations = iterations;
|
||||
m_TextureQuality = quality;
|
||||
}
|
||||
|
||||
void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
{
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSAOPassState state;
|
||||
GLuint viewSpaceZPShaderHandle = m_SSAOViewSpaceZProgram->GetHandle();
|
||||
GLuint SSAOShaderHandle = m_SSAOProgram->GetHandle();
|
||||
@@ -98,6 +182,7 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
(-1.0f),
|
||||
(+1.0f)
|
||||
);*/
|
||||
glViewport(0, 0, (m_Renderer->GetViewportSize().Width >> m_TextureQuality), (m_Renderer->GetViewportSize().Height >> m_TextureQuality)); //JOHAN TODO: Get this into state
|
||||
glUniform3fv(glGetUniformLocation(viewSpaceZPShaderHandle, "ClipInfo"), 1, glm::value_ptr(clipInfo));
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
@@ -107,9 +192,9 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
|
||||
glm::vec4 projInfo = glm::vec4(
|
||||
((1.0 - camera->ProjectionMatrix()[0][2]) / camera->ProjectionMatrix()[0][0]),
|
||||
(-2.0 / (m_Renderer->GetViewportSize().Width * camera->ProjectionMatrix()[0][0])),
|
||||
(-2.0 / ((m_Renderer->GetViewportSize().Width >> m_TextureQuality) * camera->ProjectionMatrix()[0][0])),
|
||||
((1.0 + camera->ProjectionMatrix()[1][2]) / camera->ProjectionMatrix()[1][1]),
|
||||
(-2.0 / (m_Renderer->GetViewportSize().Height * camera->ProjectionMatrix()[1][1]))
|
||||
(-2.0 / ((m_Renderer->GetViewportSize().Height >> m_TextureQuality) * camera->ProjectionMatrix()[1][1]))
|
||||
);
|
||||
|
||||
|
||||
@@ -120,26 +205,84 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOViewSpaceZTexture);
|
||||
|
||||
// How many pixel there are in a 1m long object 1m away from the camera
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uProjScale"), m_Renderer->GetViewportSize().Height / (-2.0f * glm::tan(camera->FOV() * 0.5f)));
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uProjScale"), (m_Renderer->GetViewportSize().Height >> m_TextureQuality) / (-2.0f * glm::tan(camera->FOV() * 0.5f)));
|
||||
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uRadius"), m_Radius);
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uBias"), m_Bias);
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uContrast"), m_Contrast);
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uIntensityScale"), m_IntensityScale);
|
||||
glUniform1i(glGetUniformLocation(SSAOShaderHandle, "uNumOfSamples"), m_NumOfSamples);
|
||||
glUniform1i(glGetUniformLocation(SSAOShaderHandle, "uNumOfTurns"), m_NumOfTurns);;
|
||||
glUniform1i(glGetUniformLocation(SSAOShaderHandle, "uNumOfTurns"), m_NumOfTurns);
|
||||
|
||||
glUniform4fv(glGetUniformLocation(SSAOShaderHandle, "uProjInfo"), 1, glm::value_ptr(projInfo));
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
|
||||
m_DrawBloomPass->ClearBuffer();
|
||||
m_DrawBloomPass->Draw(m_SSAOTexture);
|
||||
DrawBloomPassState BloomState;
|
||||
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
|
||||
GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle();
|
||||
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
m_GaussianProgram_horiz->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOTexture);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
//Iterate some times to make it more gaussian.
|
||||
for (int i = 1; i < m_Iterations; i++) {
|
||||
//Vertical pass
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
m_GaussianProgram_vert->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
//horizontal pass
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
m_GaussianProgram_horiz->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gaussian_vert);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
m_GaussianFrameBuffer_horiz.Unbind();
|
||||
}
|
||||
|
||||
//final vertical gaussian after the iterations are done
|
||||
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
m_GaussianProgram_vert->Bind();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz);
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
||||
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
|
||||
glViewport(0, 0, (m_Renderer->GetViewportSize().Width), (m_Renderer->GetViewportSize().Height));
|
||||
}
|
||||
|
||||
void SSAOPass::OnWindowResize() {
|
||||
m_DrawBloomPass->OnWindowResize();
|
||||
if (m_Quality == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
InitializeTexture();
|
||||
m_SSAOFramBuffer.Generate();
|
||||
m_SSAOViewSpaceZFramBuffer.Generate();
|
||||
InitializeBuffer();
|
||||
}
|
||||
@@ -17,3 +17,46 @@ Texture* CommonFunctions::LoadTexture(std::string path, bool threaded)
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
void CommonFunctions::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples, glm::vec2 dimensions, GLint internalFormat)
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, *texture);
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, false);
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
|
||||
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps)
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
GLERROR("MipMap Texture initialization failed");
|
||||
}
|
||||
|
||||
void CommonFunctions::DeleteTexture(GLuint* texture)
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
*texture = 0;
|
||||
}
|
||||
@@ -31,22 +31,27 @@ glm::vec3 ScreenCoords::ToWorldPos(glm::vec2 screenCoord, float depth, float scr
|
||||
|
||||
ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||
{
|
||||
GLERROR("Pre");
|
||||
PickDataBuffer->Bind();
|
||||
unsigned char pdata[3];
|
||||
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata);
|
||||
GLERROR("glReadPixels(pdata) Error");
|
||||
PickDataBuffer->Unbind();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
||||
GLERROR("glBindFramebuffer(DepthBuffer) Error");
|
||||
float depthData;
|
||||
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
|
||||
GLERROR("glReadPixels(depthData) Error");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
GLERROR("glBindFramebuffer(0) Error");
|
||||
|
||||
PixelData p;
|
||||
p.Color[0] = (int)pdata[0];
|
||||
p.Color[1] = (int)pdata[1];
|
||||
p.Depth = depthData;
|
||||
|
||||
GLERROR("ScreenCoords::ToPixelData Error");
|
||||
GLERROR("End");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
+4
-3
@@ -48,13 +48,12 @@ Game::Game(int argc, char* argv[])
|
||||
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
||||
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
PlayerSpawnSystem::SetRespawnTime(m_Config->Get<float>("Debug.RespawnTime", 15.0f));
|
||||
|
||||
// Create the core event broker
|
||||
m_EventBroker = new EventBroker();
|
||||
|
||||
// Create the renderer
|
||||
m_Renderer = new Renderer(m_EventBroker);
|
||||
m_Renderer = new Renderer(m_EventBroker, m_Config);
|
||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||
m_Renderer->SetResolution(Rectangle::Rectangle(
|
||||
@@ -139,7 +138,6 @@ Game::Game(int argc, char* argv[])
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeTrigger, "Player");
|
||||
m_SystemPipeline->AddSystem<FillFrustumOctreeSystem>(updateOrderLevel, m_OctreeFrustrumCulling);
|
||||
m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<UniformScaleSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<HealthHUDSystem>(updateOrderLevel);
|
||||
@@ -149,6 +147,9 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline->AddSystem<BoneAttachmentSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
|
||||
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeTrigger);
|
||||
// Octree for frustum culling must be updated after collisions, otherwise players frustum may be moved after tree is filled, and wrong things are culled.
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillFrustumOctreeSystem>(updateOrderLevel, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
|
||||
@@ -116,12 +116,18 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
|
||||
}
|
||||
|
||||
//you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air
|
||||
if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (isOnGround || !controller->DoubleJumping())) {
|
||||
(bool)cPhysics["IsOnGround"] = false;
|
||||
if (isOnGround) {
|
||||
controller->SetDoubleJumping(false);
|
||||
} else {
|
||||
}
|
||||
//If player presses Jump and is not crouching.
|
||||
if (controller->Jumping() && !controller->Crouching()) {
|
||||
if (isOnGround) {
|
||||
(bool)cPhysics["IsOnGround"] = false;
|
||||
velocity.y = player["Player"]["JumpSpeed"];
|
||||
} else if (player.HasComponent("DoubleJump") && !controller->DoubleJumping()) {
|
||||
//Enter here if player can double jump and is doing so.
|
||||
(bool)cPhysics["IsOnGround"] = false;
|
||||
velocity.y = player["DoubleJump"]["DoubleJumpSpeed"];
|
||||
// If IsServer and network is off this will not work
|
||||
if (IsClient) {
|
||||
//put a hexagon at the players feet
|
||||
@@ -133,7 +139,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
velocity.y = 4.f;
|
||||
}
|
||||
|
||||
if (player.HasComponent("AABB")) {
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
#include "Systems/PlayerSpawnSystem.h"
|
||||
|
||||
//This should be set by the config anyway.
|
||||
float PlayerSpawnSystem::m_RespawnTime = 15.0f;
|
||||
|
||||
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
||||
: System(params)
|
||||
, m_Timer(0.f)
|
||||
, m_DbgConfigForceRespawn(false)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerSpawnerd, &PlayerSpawnSystem::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerSpawnSystem::OnPlayerDeath);
|
||||
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
|
||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_NetworkEnabled = config->Get("Networking.StartNetwork", false);
|
||||
m_ForcedRespawnTime = config->Get("Debug.RespawnTime", -1.0f);
|
||||
m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0;
|
||||
}
|
||||
|
||||
void PlayerSpawnSystem::Update(double dt)
|
||||
{
|
||||
//Increase timer.
|
||||
m_Timer += dt;
|
||||
if (m_Timer < m_RespawnTime) {
|
||||
// If there are no CapturePointGameMode components we will just spawn immediately.
|
||||
// Should be able to support older maps with this.
|
||||
// TODO: In the future we might want to return instead, to avoid spawning in the menu for instance.
|
||||
auto pool = m_World->GetComponents("CapturePointGameMode");
|
||||
if (pool != nullptr && pool->size() > 0)
|
||||
{
|
||||
// Take the first CapturePointGameMode component found.
|
||||
ComponentWrapper& modeComponent = *pool->begin();
|
||||
// Increase timer.
|
||||
double& timer = (double&)modeComponent["RespawnTime"];
|
||||
timer += dt;
|
||||
double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"];
|
||||
if (timer < maxRespawnTime) {
|
||||
return;
|
||||
}
|
||||
//If respawn time has passed, we spawn all players that have requested to be spawned.
|
||||
m_Timer = 0.f;
|
||||
// If respawn time has passed, we spawn all players that have requested to be spawned.
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
//If there are no spawn requests, return immediately, if we are client the SpawnRequests should always be empty.
|
||||
// If there are no spawn requests, return immediately, if we are client the SpawnRequests should always be empty.
|
||||
if (m_SpawnRequests.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ int main(int argc, char* argv[])
|
||||
|
||||
Game game(argc, argv);
|
||||
while (game.Running()) {
|
||||
PerformanceTimer::StartTimer("Game-Tick");
|
||||
game.Tick();
|
||||
PerformanceTimer::StopTimer("Game-Tick");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user