Compare commits

..

2 Commits

Author SHA1 Message Date
FakeShemp 8e150da7ff Use CommonFunctions::DeleteTexture() instead 2016-03-13 21:25:04 +01:00
FakeShemp 9b5e4c10fd Shadow will actually shut itself off and delete itself now 2016-03-13 16:19:17 +01:00
43 changed files with 10556 additions and 12866 deletions
+1 -1
Submodule assets updated: 6ffc1ab82a...504752c949
-5
View File
@@ -2,11 +2,8 @@
#define PerformanceTimer_h__
#include "../Common.h"
#ifdef DEBUG
#include <boost/timer/timer.hpp>
using boost::timer::cpu_timer;
#endif //DEBUG
class PerformanceTimer
{
@@ -20,11 +17,9 @@ public:
static void CreateExcelData();
private:
#ifdef DEBUG
static std::map<std::string, cpu_timer> timers;
static cpu_timer m_Timer;
static std::string currentTimerRunning;
#endif //DEBUG
};
#endif
+15 -16
View File
@@ -10,31 +10,30 @@
#include <boost/asio.hpp>
#include <boost/shared_array.hpp>
#include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h"
#include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Core/EPlayerDamage.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Game/Events/EDoubleJump.h"
#include "Game/Events/EDashAbility.h"
#include "Game/Events/EReset.h"
#include "Input/EInputCommand.h"
#include "imgui/imgui.h"
#include "Network/Network.h"
#include "Network/MessageType.h"
#include "Network/PlayerDefinition.h"
#include "Network/UDPClient.h"
#include "Network/TCPClient.h"
#include "Network/SnapshotDefinitions.h"
#include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h"
#include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Input/EInputCommand.h"
#include "Core/EPlayerDamage.h"
#include "../Game/Events/EDoubleJump.h"
#include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Network/ESearchForServers.h"
#include "../Game/Events/EDashAbility.h"
#include "Network/EDisplayServerlist.h"
#include "Network/EConnectRequest.h"
#include "Network/EPlayerDisconnected.h"
#include "Network/ESearchForServers.h"
#include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h"
#include "Game/Events/EReset.h"
class Client : public Network
{
+11 -73
View File
@@ -17,7 +17,7 @@
class DrawFinalPass
{
public:
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass, ConfigFile* config);
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass);
~DrawFinalPass();
void InitializeTextures();
void InitializeFrameBuffers();
@@ -25,77 +25,17 @@ public:
void Draw(RenderScene& scene, BlurHUD* blurHUDPass);
void ClearBuffer();
void OnWindowResize();
void setMSAA(unsigned int numberOfSamples);
//Return the texture that is used in later stages to apply the bloom effect
GLuint BloomTexture() {
if (m_MSAA){
m_AntiAliasedFrameBuffer->Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_AntiAliasedFrameBuffer->Unbind();
m_FinalPassFrameBuffer->Read();
glReadBuffer(GL_COLOR_ATTACHMENT1);
m_AntiAliasedFrameBuffer->Draw();
glBlitFramebuffer(
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
return m_AntiAliasedTexture;
}
return m_BloomTexture; }
GLuint BloomTexture() const { return m_BloomTexture; }
//Return the texture with diffuse and lighting of the scene.
GLuint DrawFinalPass::SceneTexture() {
if (m_MSAA) {
m_AntiAliasedFrameBuffer->Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_AntiAliasedFrameBuffer->Unbind();
m_FinalPassFrameBuffer->Read();
glReadBuffer(GL_COLOR_ATTACHMENT0);
m_AntiAliasedFrameBuffer->Draw();
glBlitFramebuffer(
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
return m_AntiAliasedTexture;
}
return m_SceneTexture;
}
GLuint SceneTexture() const { return m_SceneTexture; }
//Return the SceneTexture with the blurred HUD bits.
GLuint CombinedSceneTexture() {
if (m_MSAA) {
m_AntiAliasedFrameBuffer->Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_AntiAliasedFrameBuffer->Unbind();
m_FinalPassFrameBuffer->Read();
m_AntiAliasedFrameBuffer->Draw();
glBlitFramebuffer(
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
return m_AntiAliasedTexture;
}
return m_CombinedTexture; }
GLuint CombinedSceneTexture() const { return m_CombinedTexture; }
//Return the blurred scene texture.
GLuint FullBlurredTexture() {
if (m_MSAA) {
m_AntiAliasedFrameBuffer->Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_AntiAliasedFrameBuffer->Unbind();
m_FinalPassFrameBuffer->Read();
m_AntiAliasedFrameBuffer->Draw();
glBlitFramebuffer(
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
return m_AntiAliasedTexture;
}
return m_FullBlurredTexture; }
GLuint FullBlurredTexture() const { return m_FullBlurredTexture; }
//Return the framebuffer used in the scene rendering stage.
FrameBuffer* FinalPassFrameBuffer() { return m_FinalPassFrameBuffer; }
FrameBuffer* FinalPassFrameBuffer() { return &m_FinalPassFrameBuffer; }
private:
void DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, RenderScene& scene);
@@ -116,21 +56,18 @@ private:
Texture* m_GreyTexture;
Texture* m_ErrorTexture;
FrameBuffer* m_FinalPassFrameBuffer = nullptr;
FrameBuffer* m_ShieldDepthFrameBuffer = nullptr;
FrameBuffer* m_AntiAliasedFrameBuffer = nullptr;
FrameBuffer m_FinalPassFrameBuffer;
FrameBuffer m_ShieldDepthFrameBuffer;
GLuint m_BloomTexture = 0;
GLuint m_SceneTexture = 0;
GLuint m_DepthBuffer = 0;
GLuint m_ShieldBuffer = 0;
GLuint m_CubeMapTexture = 0;
GLuint m_FullBlurredTexture = 0;
GLuint m_CombinedTexture = 0; //This can be removed for less memory usage, just set m_sceneTexture to the return from m_BlurHUDPass.CombineTextures
GLuint m_AntiAliasedTexture = 0; //Is only used when MSAA is active;
GLuint m_FullBlurredTexture;
GLuint m_CombinedTexture; //This can be removed for less memory usage, just set m_sceneTexture to the return from m_BlurHUDPass.CombineTextures
//maqke this component based i guess?
GLuint m_ShieldPixelRate = 16;
unsigned int m_MSAA = 0;
const IRenderer* m_Renderer;
const LightCullingPass* m_LightCullingPass;
@@ -139,6 +76,7 @@ private:
const ShadowPass* m_ShadowPass;
ShaderProgram* m_ForwardPlusProgram;
ShaderProgram* m_ForwardPlusNoShadowsProgram;
ShaderProgram* m_ExplosionEffectProgram;
ShaderProgram* m_ExplosionEffectSplatMapProgram;
ShaderProgram* m_SpriteProgram;
+7 -22
View File
@@ -7,13 +7,12 @@
class BufferResource
{
public:
BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod, bool multiSampling);
BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod);
GLuint* m_ResourceHandle;
GLenum m_ResourceType;
GLenum m_Attachment;
GLuint m_MipMapLod = 0;
bool m_MultiSampling = false;
private:
};
@@ -22,33 +21,24 @@ template <GLenum RESOURCETYPE>
class ResourceType : public BufferResource
{
public:
ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod, bool multiSampling)
: BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod, multiSampling) { }
ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod)
: BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod) { }
};
class Texture2D : public ResourceType<GL_TEXTURE_2D>
{
public:
Texture2D(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0)
: ResourceType(resourceHandle, attachment, mipMapLod, false) { };
: ResourceType(resourceHandle, attachment, mipMapLod) { };
~Texture2D();
};
class Texture2DMultiSample : public ResourceType<GL_TEXTURE_2D_MULTISAMPLE>
{
public:
Texture2DMultiSample(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0)
: ResourceType(resourceHandle, attachment, mipMapLod, true) { };
~Texture2DMultiSample();
};
class RenderBuffer : public ResourceType<GL_RENDERBUFFER>
{
public:
RenderBuffer(GLuint* resourceHandle, GLenum attachment, bool multiSampling = false)
: ResourceType(resourceHandle, attachment, 0, multiSampling)
RenderBuffer(GLuint* resourceHandle, GLenum attachment)
: ResourceType(resourceHandle, attachment, 0)
{ };
~RenderBuffer();
@@ -58,13 +48,12 @@ class Texture2DArray : public ResourceType<GL_TEXTURE_2D_ARRAY>
{
public:
Texture2DArray(GLuint* resourceHandle, GLenum attachment)
: ResourceType(resourceHandle, attachment, 0, false)
: ResourceType(resourceHandle, attachment, 0)
{ };
~Texture2DArray();
};
class FrameBuffer
{
public:
@@ -76,13 +65,9 @@ public:
void Generate();
void Bind();
void Unbind();
void Read();
void Draw();
GLuint GetHandle();
bool MultiSampling() { return m_MultiSampling; };
private:
bool m_MultiSampling = true;
GLuint m_BufferHandle;
std::vector<std::shared_ptr<BufferResource>> m_Resources;
};
+1 -1
View File
@@ -71,7 +71,7 @@ private:
bool m_ResizeWindow = false;
int m_SSAO_Quality = 0;
int m_GLOW_Quality = 2;
unsigned int m_MSAA_Level = 0;
bool m_Shadow_Enabled = true;
PickingPass* m_PickingPass;
LightCullingPass* m_LightCullingPass;
+6 -3
View File
@@ -38,6 +38,8 @@ public:
void ClearBuffer();
void Draw(RenderScene& scene);
void CheckStatus(bool status);
void DebugGUI();
GLuint DepthMap() const { return m_DepthMap; }
@@ -45,6 +47,7 @@ public:
std::array<glm::mat4, MAX_SPLITS> LightV() const { return m_LightView; }
std::array<float, MAX_SPLITS> FarDistance() const { std::array<float, MAX_SPLITS> f; for (int i = 0; i < MAX_SPLITS; i++) f[i] = m_shadowFrusta[i].FarClip; return f; }
int CurrentNrOfSplits() const { return m_CurrentNrOfSplits; }
bool EnableShadows() const { return m_EnableShadows; }
void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; };
private:
@@ -63,8 +66,8 @@ private:
GLuint m_DepthMap;
FrameBuffer m_DepthBuffer;
ShaderProgram* m_ShadowProgram;
ShaderProgram* m_ShadowProgramSkinned;
ShaderProgram* m_ShadowProgram;
ShaderProgram* m_ShadowProgramSkinned;
std::array<glm::mat4, MAX_SPLITS> m_LightProjection;
std::array<glm::mat4, MAX_SPLITS> m_LightView;
@@ -75,7 +78,7 @@ private:
bool m_TransparentObjects = false;
bool m_TexturedShadows = false;
bool m_EnableShadows = true;
bool m_EnableShadows = false;
int m_CurrentNrOfSplits = 4;
float m_SplitWeight = 0.962f;
+1 -4
View File
@@ -20,14 +20,11 @@ public:
, Parent(parent)
, Name(name)
, OffsetMatrix(offsetMatrix)
{
BindTransformMatrix = glm::inverse(offsetMatrix);
}
{ }
std::string Name;
glm::mat4 OffsetMatrix;
int ID;
glm::mat4 BindTransformMatrix;
Bone* Parent;
std::vector<Bone*> Children;
-2
View File
@@ -29,7 +29,6 @@ struct SpriteJob : RenderJob
IncandescenceTexture = CommonFunctions::TryLoadResource<TextureSprite, true>(cSprite["GlowMap"]);
Linear = (bool)cSprite["Linear"];
ClampToBorder = (bool)cSprite["ClampToBorder"];
StartIndex = matProp.material->StartIndex;
EndIndex = matProp.material->EndIndex;
@@ -94,7 +93,6 @@ struct SpriteJob : RenderJob
float ScaleX = 1;
float ScaleY = 1;
bool Linear = false;
bool ClampToBorder = false;
glm::vec4 FillColor = glm::vec4(0);
float FillPercentage = 0.0;
@@ -27,7 +27,7 @@ Texture* TryLoadResource(std::string path)
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 internalFormat, GLint format, GLenum type, GLint numMipMaps, GLint MAGFilter, GLint MINFilter);
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps);
void DeleteTexture(GLuint* texture);
};
+1 -3
View File
@@ -30,7 +30,6 @@
#include "../Engine/Core/EPause.h"
#include "../Engine/Core/EComponentAttached.h"
#include "../Core/EPlayerSpawned.h"
#include "../Rendering/ESetCamera.h"
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
@@ -92,6 +91,7 @@ private:
void matchBGMLoop();
Source* m_CurrentBGM = nullptr;
Source* m_CurrentBGMCombo = nullptr;
bool m_DrumLoopHasBeenStarted = false;
// Logic
World* m_World = nullptr;
@@ -139,8 +139,6 @@ private:
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
bool OnChangeBGM(const Events::ChangeBGM &e);
EventRelay<SoundManager, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(const Events::SetCamera& e);
};
+1 -4
View File
@@ -85,7 +85,4 @@ NumIterations=5
NumIterations=9
[GLOW3]
NumIterations=13
[MSAA]
Level = 0;
NumIterations=13
-1
View File
@@ -10,6 +10,5 @@
<KeepRatioY>false</KeepRatioY>
<KeepRatio>false</KeepRatio>
<Linear>true</Linear>
<ClampToBorder>false</ClampToBorder>
<BlurBackground>false</BlurBackground>
</Sprite>
-3
View File
@@ -39,9 +39,6 @@
<xs:element name="Linear" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>If it should use Linear or Nearest sampling method.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ClampToBorder" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>If it should clamp to border or repeat the texture.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="BlurBackground" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Wether the background should be blurred begind this sprite.</xs:documentation></xs:annotation>
</xs:element>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -1,11 +1,14 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec4 Color;
uniform sampler2D texture0;
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
+1 -5
View File
@@ -2,7 +2,6 @@
#define MAX_SPLITS 4
uniform mat4 PVM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -24,7 +23,6 @@ uniform float ColorDistanceScalar;
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -36,7 +34,6 @@ in VertexData{
out VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -104,7 +101,6 @@ void PassThingsThrough(int index)
// pass through vertex data
Output.Normal = Input[index].Normal;
Output.Position = Input[index].Position;
Output.ViewSpacePosition = Input[index].ViewSpacePosition;
Output.TextureCoordinate = Input[index].TextureCoordinate;
Output.Tangent = Input[index].Tangent;
Output.BiTangent = Input[index].BiTangent;
@@ -179,7 +175,7 @@ void main()
}
// convert to window space
gl_Position = PVM * vec4(ExplodedPosition, 1.0);
gl_Position = P * V * M * vec4(ExplodedPosition, 1.0);
EmitVertex();
}
}
+5 -3
View File
@@ -2,6 +2,8 @@
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -63,7 +65,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -301,10 +302,11 @@ void main()
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
vec4 position = VM * vec4(Input.Position, 1.0);
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-Input.ViewSpacePosition);
vec4 viewVec = normalize(-position);
vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition);
vec3 R = reflect(-I, Input.Normal);
//R = vec3(P * vec4(R, 1.0));
@@ -331,7 +333,7 @@ void main()
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
int DepthMapIndex = getShadowIndex(FarDistance);
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
-3
View File
@@ -1,6 +1,5 @@
#version 430
uniform mat4 PVM;
uniform mat4 VM;
#define MAX_SPLITS 4
uniform mat4 TIM;
@@ -18,7 +17,6 @@ layout(location = 4) in vec2 TextureCoords;
out VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -33,7 +31,6 @@ void main()
gl_Position = PVM * vec4(Position, 1.0);
//mat4 TIM = transpose(inverse(M));
Output.Position = Position;
Output.ViewSpacePosition = VM * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(TIM * vec4(Normal, 0.0));
Output.Tangent = vec3(TIM * vec4(Tangent, 0.0));
@@ -0,0 +1,204 @@
#version 430
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec4 Color;
uniform vec4 DiffuseColor;
uniform vec2 ScreenDimensions;
uniform vec4 FillColor;
uniform vec4 AmbientColor;
uniform float FillPercentage;
uniform float GlowIntensity;
uniform vec3 CameraPosition;
uniform int SSAOQuality;
uniform float FarDistance[MAX_SPLITS];
uniform vec2 DiffuseUVRepeat;
uniform vec2 NormalUVRepeat;
uniform vec2 SpecularUVRepeat;
uniform vec2 GlowUVRepeat;
layout (binding = 0) uniform sampler2D AOTexture;
layout (binding = 1) uniform sampler2D DiffuseTexture;
layout (binding = 2) uniform sampler2D NormalMapTexture;
layout (binding = 3) uniform sampler2D SpecularMapTexture;
layout (binding = 4) uniform sampler2D GlowMapTexture;
layout (binding = 5) uniform samplerCube CubeMap;
#define TILE_SIZE 16
struct LightSource {
vec4 Position;
vec4 Direction;
vec4 Color;
float Radius;
float Intensity;
float Falloff;
int Type;
};
layout (std430, binding = 1) buffer LightBuffer
{
LightSource List[];
} LightSources;
struct LightGrid {
float Start;
float Amount;
vec2 Padding;
};
layout (std430, binding = 2) buffer LightGridBuffer
{
LightGrid Data[];
} LightGrids;
layout (std430, binding = 4) buffer LightIndexBuffer
{
float LightIndex[];
};
in VertexData{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate;
vec4 ExplosionColor;
float ExplosionPercentageElapsed;
vec4 PositionLightSpace[MAX_SPLITS];
}Input;
out vec4 sceneColor;
out vec4 bloomColor;
struct LightResult {
vec4 Diffuse;
vec4 Specular;
};
float CalcAttenuation(float radius, float dist, float falloff) {
return 1.0 - smoothstep(radius * falloff, radius, dist);
}
vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) {
vec4 R = normalize( reflect(-lightVec, normal));
float RdotV = max( dot(R, viewVec), 0.0);
return lightColor * pow(RdotV, 90.0);
}
vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
float power = max( dot(normal, lightVec), 0.0);
return lightColor * power;
}
LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
{
vec4 L = lightPos - position;
float dist = length(L);
L = normalize(L);
float attenuation = CalcAttenuation(lightRadius, dist, falloff);
LightResult result;
result.Diffuse = CalcDiffuse(lightColor, L, normal) * attenuation * intensity;
result.Specular = CalcSpecular(lightColor, viewVec, L, normal) * attenuation * intensity;
return result;
}
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal)
{
vec4 L = normalize( -vec4(direction.xyz, 0) );
LightResult result;
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity;
return result;
}
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}
void main()
{
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);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
vec4 position = VM * vec4(Input.Position, 1.0);
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-position);
vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition);
vec3 R = reflect(-I, Input.Normal);
//R = vec3(P * vec4(R, 1.0));
vec4 reflectionColor = texture(CubeMap, R);
vec2 tilePos;
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
tilePos.y = int(gl_FragCoord.y/TILE_SIZE);
LightResult totalLighting;
totalLighting.Diffuse = vec4(AmbientColor.rgb * ao, 1.0);
int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * int(ScreenDimensions.x/TILE_SIZE)));
int start = int(LightGrids.Data[currentTile].Start);
int amount = int(LightGrids.Data[currentTile].Amount);
for(int i = start; i < start + amount; i++) {
int l = int(LightIndex[i]);
LightSource light = LightSources.List[l];
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
}
totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a);
totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a);
}
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;
vec4 reflectionTotal = reflectionColor * (1-specularTexel.a) * color_result.a * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
color_result = color_result * clamp(1/specularTexel.a, 0, 1) + reflectionTotal;
//vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel)) * diffuseTexel * Color;
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
if(pos <= FillPercentage) {
color_result += FillColor;
}
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//sceneColor = CommonUniforms.testColour;
//sceneColor = vec4(reflectionColor.xyz, 1);
color_result.xyz += glowTexel.xyz*GlowIntensity;
bloomColor = vec4(max(color_result.xyz - 1.0, 0.0), clamp(color_result.a, 0, 1));
//Tiled Debug Code
/*
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) {
sceneColor += vec4(0.5, 0, 0, 0);
} else {
sceneColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/LightSources.List.length(), 0, 0, 1);
}
*/
}
@@ -65,7 +65,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -142,10 +141,11 @@ void main()
vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat);
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
vec4 position = VM * vec4(Input.Position, 1.0);
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-Input.ViewSpacePosition);
vec4 viewVec = normalize(-position);
vec3 I = normalize(vec3(M * vec4(Input.Position, 1.0)) - CameraPosition);
vec3 R = reflect(-I, Input.Normal);
//R = vec3(P * vec4(R, 1.0));
@@ -170,7 +170,7 @@ void main()
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
}
@@ -3,7 +3,6 @@
#define MAX_SPLITS 4
uniform mat4 PVM;
uniform mat4 VM;
uniform mat4 TIM;
uniform mat4 M;
uniform mat4 V;
@@ -22,7 +21,6 @@ layout(location = 6) in vec4 BoneWeights;
out VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -36,15 +34,16 @@ void main()
{
mat4 boneTransform = mat4(1);
if(BoneWeights[0] > 0.0f){
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
Output.ViewSpacePosition = VM * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(M * boneTransform * vec4(Normal, 0.0));
Output.Tangent = vec3(M * vec4(Tangent, 0.0));
@@ -2,6 +2,8 @@
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -80,7 +82,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -361,12 +362,13 @@ void main()
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
vec4 position = VM * vec4(Input.Position, 1.0);
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-Input.ViewSpacePosition);
vec4 viewVec = normalize(-position);
vec2 tilePos;
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
@@ -389,7 +391,7 @@ void main()
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
int DepthMapIndex = getShadowIndex(FarDistance);
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
@@ -2,6 +2,8 @@
#define MIN_AMBIENT_LIGHT 0.3
#define MAX_SPLITS 4
uniform mat4 VM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
@@ -78,7 +80,6 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{
vec3 Position;
vec4 ViewSpacePosition;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
@@ -192,12 +193,13 @@ void main()
GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3);
vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3,
SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3);
vec4 position = VM * vec4(Input.Position, 1.0);
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
normal = normalize(normal);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-Input.ViewSpacePosition);
vec4 viewVec = normalize(-position);
vec2 tilePos;
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
@@ -218,7 +220,7 @@ void main()
LightResult light_result;
//These if statements should be removed.
if(light.Type == 1) { // point
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, Input.ViewSpacePosition, normal, light.Falloff);
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
} else if (light.Type == 2) { //Directional
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
}
@@ -17,10 +17,12 @@ out VertexData{
void main()
{
mat4 boneTransform = mat4(1);
if(BoneWeights[0] > 0.0f){
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = PVM*boneTransform * vec4(Position, 1.0);
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
+4 -2
View File
@@ -1,6 +1,8 @@
#version 430
uniform mat4 PVM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (location = 0) in vec3 Position;
layout (location = 4) in vec2 TextureCoords;
@@ -11,6 +13,6 @@ out VertexData{
void main()
{
gl_Position = PVM * vec4(Position, 1.0);
gl_Position = P * V * M * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
}
+6 -2
View File
@@ -1,6 +1,8 @@
#version 430
uniform mat4 PVM;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
layout (location = 0) in vec3 Position;
@@ -15,11 +17,13 @@ out VertexData{
void main()
{
mat4 boneTransform = mat4(1);
if(BoneWeights[0] > 0.0f){
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
}
gl_Position = PVM * boneTransform * vec4(Position, 1.0);
gl_Position = P * V * M * boneTransform * vec4(Position, 1.0);
Output.TextureCoordinate = TextureCoords;
}
-15
View File
@@ -1,10 +1,7 @@
#include "Core/PerformanceTimer.h"
#ifdef DEBUG
#include <ctime>
#include <fstream>
cpu_timer PerformanceTimer::m_Timer;
std::map<std::string, cpu_timer> PerformanceTimer::timers;
std::string PerformanceTimer::currentTimerRunning = "";
@@ -77,15 +74,3 @@ void PerformanceTimer::CreateExcelData()
}
someFileStream.close();
}
#else
void PerformanceTimer::StartTimer(std::string nameOfTimer) {};
void PerformanceTimer::StartTimerAndStopPrevious(std::string nameOfTimer) {};
void PerformanceTimer::StopTimer(std::string nameOfTimer) {};
void PerformanceTimer::SetFrameNumber(int frameNumber) {};
void PerformanceTimer::ResetAllTimers() {};
void PerformanceTimer::CreateExcelData() {};
#endif //DEBUG
+162
View File
@@ -0,0 +1,162 @@
#include "Core/TransformSystem.h"
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
int TransformSystem::RecalculatedPositions = 0;
int TransformSystem::RecalculatedOrientations = 0;
int TransformSystem::RecalculatedScales = 0;
TransformSystem::TransformSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
}
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
{
// Clean up deleted entity
PositionCache.erase(e.DeletedEntity);
OrientationCache.erase(e.DeletedEntity);
ScaleCache.erase(e.DeletedEntity);
MatrixCache.erase(e.DeletedEntity);
return true;
}
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
//{
// glm::mat4 t = glm::mat4(1.f);
//
// while (entity.Valid()) {
// t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
// entity = entity.Parent();
// }
//
// return t;
//}
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
{
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
}
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::vec3();
}
auto cacheIt = PositionCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformPosition = cTransform["Position"];
if (cacheIt != PositionCache.end() && !cTransformPosition.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate position
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
// Cache it
PositionCache[entity] = position;
RecalculatedPositions++;
// Unset dirty flag
cTransformPosition.SetDirty(DirtySetType::Transform, false);
return position;
}
}
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
{
glm::vec3 orientation;
while (entity.Valid()) {
ComponentWrapper transform = entity["Transform"];
orientation += (Field<glm::vec3>)transform["Orientation"];
entity = entity.Parent();
}
return orientation;
}
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
{
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
}
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::quat();
}
auto cacheIt = OrientationCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformOrientation = cTransform["Orientation"];
if (cacheIt != OrientationCache.end() && !cTransformOrientation.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate orientation
glm::quat orientation = AbsoluteOrientation(parent) * glm::quat((const glm::vec3&)cTransformOrientation);
// Cache it
OrientationCache[entity] = orientation;
RecalculatedOrientations++;
// Unset dirty flag
cTransformOrientation.SetDirty(DirtySetType::Transform, false);
return orientation;
}
}
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
{
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
}
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::vec3(1.f);
}
auto cacheIt = ScaleCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformScale = cTransform["Scale"];
if (cacheIt != ScaleCache.end() && !cTransformScale.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate scale
glm::vec3 scale = AbsoluteScale(parent) * (const glm::vec3&)cTransformScale;
// Cache it
ScaleCache[entity] = scale;
RecalculatedPositions++;
// Unset dirty flag
cTransformScale.SetDirty(DirtySetType::Transform, false);
return scale;
}
}
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
{
return ModelMatrix(EntityWrapper(world, entityID));
}
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
{
auto cacheIt = MatrixCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
if (cacheIt != MatrixCache.end() && !isDirty) {
return cacheIt->second;
} else {
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
MatrixCache[entity] = matrix;
return matrix;
}
}
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
{
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
}
+2 -11
View File
@@ -108,15 +108,7 @@ void Client::Update(double dt)
hasServerTimedOut();
}
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("You have been disconnected from server.\n\n");
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
if (ImGui::Button("OK", ImVec2(120, 0))) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
//Network::Update();
}
void Client::parseMessageType(Packet& packet)
@@ -204,7 +196,7 @@ void Client::parseTCPConnect(Packet& packet)
packet.WritePrimitive(m_PlayerID);
m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server");
// LOG_INFO("Sent UDP Connect Server");
}
void Client::parsePlayerConnected(Packet & packet)
@@ -684,7 +676,6 @@ void Client::hasServerTimedOut()
if (timeSincePing > m_TimeoutMs) {
// Clear everything and go to menu.
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
ImGui::OpenPopup("Disconnected");
disconnect();
}
}
+18 -18
View File
@@ -68,13 +68,13 @@ void BlurHUD::InitializeBuffers()
}
m_GaussianFrameBuffer_horiz.Generate();
//CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
// res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_horiz, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_vert, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_vert.Generate();
@@ -260,22 +260,22 @@ void BlurHUD::FillStencil(RenderScene& scene)
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
//state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
//for (auto& job : scene.Jobs.SpriteJob) {
// auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
// if (!spriteJob) {
// continue;
// }
// if(!spriteJob->BlurBackground) {
// continue;
// }
// glm::mat4 MVP = VP * spriteJob->Matrix;
// glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(MVP));
state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob) {
continue;
}
if(!spriteJob->BlurBackground) {
continue;
}
glm::mat4 MVP = VP * spriteJob->Matrix;
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(MVP));
// glBindVertexArray(spriteJob->Model->VAO);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
// glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
//}
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
}
+5 -5
View File
@@ -76,12 +76,12 @@ void DrawBloomPass::InitializeShaderPrograms()
void DrawBloomPass::InitializeBuffers()
{
CommonFunctions::GenerateMipMapTexture(
&m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height),
GL_RGB16F, GL_RGB, GL_FLOAT, m_BloomLod, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
&m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height)
, GL_RGB, GL_FLOAT, m_BloomLod);
CommonFunctions::GenerateMipMapTexture(
&m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height),
GL_RGB16F, GL_RGB, GL_FLOAT, m_BloomLod, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_BORDER, GL_NEAREST, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
&m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height)
, GL_RGB, GL_FLOAT, m_BloomLod);
CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
if (m_GaussianCombineBuffer.GetHandle() == 0) {
m_GaussianCombineBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0)));
+93 -162
View File
@@ -1,5 +1,5 @@
#include "Rendering/DrawFinalPass.h"
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass, ConfigFile* config)
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass)
: m_Renderer(renderer)
, m_LightCullingPass(lightCullingPass)
, m_CubeMapPass(cubeMapPass)
@@ -8,11 +8,6 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
{
//TODO: Make sure that uniforms are not sent into shader if not needed.
m_ShieldPixelRate = 8;
m_FinalPassFrameBuffer = new FrameBuffer();
m_ShieldDepthFrameBuffer = new FrameBuffer();
setMSAA(config->Get<int>("MSAA.Level", 0));
InitializeTextures();
InitializeShaderPrograms();
InitializeFrameBuffers();
@@ -24,9 +19,6 @@ DrawFinalPass::~DrawFinalPass(){
CommonFunctions::DeleteTexture(&m_DepthBuffer);
CommonFunctions::DeleteTexture(&m_ShieldBuffer);
CommonFunctions::DeleteTexture(&m_CubeMapTexture);
delete m_FinalPassFrameBuffer;
delete m_ShieldDepthFrameBuffer;
}
void DrawFinalPass::InitializeTextures()
@@ -40,88 +32,26 @@ void DrawFinalPass::InitializeTextures()
void DrawFinalPass::InitializeFrameBuffers()
{
if (m_MSAA) {
CommonFunctions::GenerateTexture(&m_AntiAliasedTexture, GL_CLAMP_TO_BORDER, GL_NEAREST,
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, 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);
if (m_AntiAliasedFrameBuffer == nullptr) {
m_AntiAliasedFrameBuffer = new FrameBuffer();
m_AntiAliasedFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_AntiAliasedTexture, GL_COLOR_ATTACHMENT0)));
}
m_AntiAliasedFrameBuffer->Generate();
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);
if (m_SceneTexture != 0) {
glDeleteRenderbuffers(1, &m_SceneTexture);
}
glGenRenderbuffers(1, &m_SceneTexture);
GLERROR("FBO 1");
glBindRenderbuffer(GL_RENDERBUFFER, m_SceneTexture);
GLERROR("FBO 11");
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("FBO 111");
if (m_BloomTexture != 0) {
glDeleteRenderbuffers(1, &m_BloomTexture);
}
glGenRenderbuffers(1, &m_BloomTexture);
GLERROR("FBO 2");
glBindRenderbuffer(GL_RENDERBUFFER, m_BloomTexture);
GLERROR("FBO 22");
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("FBO 222");
if (m_DepthBuffer != 0) {
glDeleteRenderbuffers(1, &m_DepthBuffer);
}
glGenRenderbuffers(1, &m_DepthBuffer);
GLERROR("FBO 3");
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
GLERROR("FBO 33");
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("FBO 333");
//CommonFunctions::GenerateMultiSampleTexture(&m_SceneTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
//CommonFunctions::GenerateMultiSampleTexture(&m_BloomTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
//CommonFunctions::GenerateMultiSampleTexture(&m_DepthBuffer, m_MSAA,
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8);
//CommonFunctions::GenerateMultiSampleTexture(&m_ShieldBuffer, m_MSAA,
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F);
} else {
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, 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);
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);
}
CommonFunctions::GenerateTexture(&m_ShieldBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
if (m_FinalPassFrameBuffer->GetHandle() == 0) {
if (m_MSAA) {
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_StencilTexture, GL_STENCIL_ATTACHMENT)));
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
} else {
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)));
}
}
m_FinalPassFrameBuffer->Generate();
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)));
m_FinalPassFrameBuffer.Generate();
GLERROR("FBO generation");
if (m_ShieldDepthFrameBuffer->GetHandle() == 0) {
m_ShieldDepthFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
}
m_ShieldDepthFrameBuffer->Generate();
CommonFunctions::GenerateTexture(&m_ShieldBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
m_ShieldDepthFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
m_ShieldDepthFrameBuffer.Generate();
}
void DrawFinalPass::InitializeShaderPrograms()
@@ -135,6 +65,15 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ForwardPlusProgram->Link();
GLERROR("Creating forward+ program");
m_ForwardPlusNoShadowsProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusNoShadowProgram");
m_ForwardPlusNoShadowsProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ForwardPlusNoShadowsProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusNoShadows.frag.glsl")));
m_ForwardPlusNoShadowsProgram->Compile();
m_ForwardPlusNoShadowsProgram->BindFragDataLocation(0, "sceneColor");
m_ForwardPlusNoShadowsProgram->BindFragDataLocation(1, "bloomColor");
m_ForwardPlusNoShadowsProgram->Link();
GLERROR("Creating forward+ program without shadows");
m_ExplosionEffectProgram = ResourceManager::Load<ShaderProgram>("#ExplosionEffectProgram");
m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/ExplosionEffect.geom.glsl")));
@@ -315,14 +254,14 @@ void DrawFinalPass::InitializeShaderPrograms()
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
{
GLERROR("Pre");
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer->GetHandle());
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
//Draw shields to stencil
DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene);
GLERROR("StencilPass");
delete stateDethp;
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if (scene.ClearDepth) {
//glClear(GL_DEPTH_BUFFER_BIT);
state->Disable(GL_DEPTH_TEST);
@@ -363,22 +302,17 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
delete state;
if (scene.ShouldBlur) {
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
GLuint sceneTexture = SceneTexture();
m_FullBlurredTexture = blurHUDPass->Draw(sceneTexture, scene);
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
}
DrawFinalPassState* stateSprite;
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
GLuint sceneTexture = SceneTexture();
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(sceneTexture, m_FullBlurredTexture);
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
} else {
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
}
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
@@ -400,70 +334,41 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
void DrawFinalPass::ClearBuffer()
{
GLERROR("PRE");
m_ShieldDepthFrameBuffer->Bind();
m_ShieldDepthFrameBuffer.Bind();
glClear(GL_DEPTH_BUFFER_BIT);
m_ShieldDepthFrameBuffer->Unbind();
m_FinalPassFrameBuffer->Bind();
m_ShieldDepthFrameBuffer.Unbind();
m_FinalPassFrameBuffer.Bind();
GLERROR("Bind HighRes");
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
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);
m_FinalPassFrameBuffer->Unbind();
m_FinalPassFrameBuffer.Unbind();
GLERROR("END");
}
void DrawFinalPass::OnWindowResize()
{
if (m_FinalPassFrameBuffer->MultiSampling() != (bool)m_MSAA) {
delete m_FinalPassFrameBuffer;
delete m_ShieldDepthFrameBuffer;
m_FinalPassFrameBuffer = new FrameBuffer();
m_ShieldDepthFrameBuffer = new FrameBuffer();
}
//InitializeFrameBuffers();
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);
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_FinalPassFrameBuffer.Generate();
if (m_MSAA) {
if (m_AntiAliasedFrameBuffer != nullptr) {
delete m_AntiAliasedFrameBuffer;
m_AntiAliasedFrameBuffer = nullptr;
}
}
InitializeFrameBuffers();
GLERROR("Error changing texture resolutions");
}
void DrawFinalPass::setMSAA(unsigned int numberOfSamples) {
if (m_MSAA == numberOfSamples) {
return;
}
if (!(bool)numberOfSamples) {
if (m_AntiAliasedFrameBuffer != nullptr) {
delete m_AntiAliasedFrameBuffer;
m_AntiAliasedFrameBuffer = nullptr;
}
delete m_FinalPassFrameBuffer;
m_FinalPassFrameBuffer = new FrameBuffer();
}
if ((bool)numberOfSamples && !(bool)m_MSAA) {
delete m_FinalPassFrameBuffer;
m_FinalPassFrameBuffer = new FrameBuffer();
}
m_MSAA = numberOfSamples;
InitializeFrameBuffers();
}
void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
{
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
GLuint forwardHandle;
if (m_ShadowPass->EnableShadows()) {
forwardHandle = m_ForwardPlusProgram->GetHandle();
} else {
forwardHandle = m_ForwardPlusNoShadowsProgram->GetHandle();
}
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
GLuint explosionSplatMapHandle = m_ExplosionEffectSplatMapProgram->GetHandle();
GLuint forwardSplatMapHandle = m_ForwardPlusSplatMapProgram->GetHandle();
@@ -645,9 +550,13 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
if (lastShader != forwardHandle) {
if (forwardHandle == m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
} else {
m_ForwardPlusNoShadowsProgram->Bind();
}
lastShader = forwardHandle;
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
@@ -732,7 +641,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
{
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
GLuint forwardHandle;
if (m_ShadowPass->EnableShadows()) {
forwardHandle = m_ForwardPlusProgram->GetHandle();
} else {
forwardHandle = m_ForwardPlusNoShadowsProgram->GetHandle();
}
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
GLuint explosionSplatMapHandle = m_ExplosionEffectSplatMapProgram->GetHandle();
GLuint forwardSplatMapHandle = m_ForwardPlusSplatMapProgram->GetHandle();
@@ -1133,9 +1047,14 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
if (lastShader != forwardHandle) {
if (forwardHandle == m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
}
else {
m_ForwardPlusNoShadowsProgram->Bind();
}
lastShader = forwardHandle;
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
@@ -1221,7 +1140,12 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
{
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
GLuint forwardHandle;
if (m_ShadowPass->EnableShadows()) {
forwardHandle = m_ForwardPlusProgram->GetHandle();
} else {
forwardHandle = m_ForwardPlusNoShadowsProgram->GetHandle();
}
GLERROR("forwardHandle");
GLuint explosionHandle = m_ExplosionEffectProgram->GetHandle();
GLERROR("explosionHandle");
@@ -1280,7 +1204,11 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
//bind forward program
m_ForwardPlusProgram->Bind();
if (m_ShadowPass->EnableShadows()) {
m_ForwardPlusProgram->Bind();
} else {
m_ForwardPlusNoShadowsProgram->Bind();
}
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
//bind uniforms
@@ -1324,6 +1252,11 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
if (lastShader != m_FillDepthStencilBufferSkinnedProgram->GetHandle()) {
m_FillDepthStencilBufferSkinnedProgram->Bind();
lastShader = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 1");
}
@@ -1342,6 +1275,11 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
m_FillDepthStencilBufferProgram->Bind();
lastShader = m_FillDepthStencilBufferProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 2");
}
@@ -1397,14 +1335,7 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
if (spriteJob->ClampToBorder) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
}
else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} else {
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
}
+7 -37
View File
@@ -2,13 +2,12 @@
#include "Rendering/FrameBuffer.h"
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod, bool multiSampling)
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod)
{
m_ResourceHandle = resourceHandle;
m_ResourceType = resourceType;
m_Attachment = attachment;
m_MipMapLod = mipMapLod;
m_MultiSampling = multiSampling;
}
Texture2D::~Texture2D()
@@ -16,23 +15,14 @@ Texture2D::~Texture2D()
if (m_ResourceHandle != 0) {
glDeleteTextures(1, m_ResourceHandle);
}
*m_ResourceHandle = 0;
}
Texture2DMultiSample::~Texture2DMultiSample()
{
if (m_ResourceHandle != 0) {
glDeleteTextures(1, m_ResourceHandle);
}
*m_ResourceHandle = 0;
}
RenderBuffer::~RenderBuffer()
{
if (m_ResourceHandle != 0) {
glDeleteRenderbuffers(1, m_ResourceHandle);
}
*m_ResourceHandle = 0;
}
Texture2DArray::~Texture2DArray()
@@ -40,7 +30,6 @@ Texture2DArray::~Texture2DArray()
if (m_ResourceHandle != 0) {
glDeleteTextures(1, m_ResourceHandle);
}
*m_ResourceHandle = 0;
}
@@ -53,14 +42,6 @@ FrameBuffer::~FrameBuffer()
void FrameBuffer::AddResource(std::shared_ptr<BufferResource> resource)
{
//m_MultiSampling is true when initialized
if (m_MultiSampling != resource->m_MultiSampling) {
if (m_MultiSampling == false) {
GLERROR("All renderbuffers is/is not using multisampling");
} else {
m_MultiSampling = false;
}
}
m_Resources.push_back(resource);
}
@@ -74,23 +55,20 @@ void FrameBuffer::Generate()
}
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferHandle);
GLERROR("1");
for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) {
switch ((*it)->m_ResourceType) {
case GL_TEXTURE_2D_MULTISAMPLE:
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, GL_TEXTURE_2D_MULTISAMPLE, 0, 0);
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_MULTISAMPLE");
break;
case GL_TEXTURE_2D:
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, (*it)->m_MipMapLod);
GLERROR("FrameBuffer generate: GL_TEXTURE_2D");
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
break;
case GL_RENDERBUFFER:
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
GLERROR("FrameBuffer generate: GL_RENDERBUFFER");
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
break;
case GL_TEXTURE_2D_ARRAY:
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0);
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY");
GLERROR("FrameBuffer generate: glFramebufferTexture2DArray");
break;
}
GLERROR("2");
@@ -99,8 +77,8 @@ void FrameBuffer::Generate()
attachments.push_back((*it)->m_Attachment);
}
GLERROR("Attachment");
}
}
GLERROR("3");
GLenum* bufferTextures = attachments.data();
@@ -111,7 +89,7 @@ void FrameBuffer::Generate()
if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
GLERROR("Framebuffer incomplete");
LOG_ERROR("FrameBuffer incomplete: 0x%x\n", glCheckFramebufferStatus(GL_FRAMEBUFFER));
//LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus);
exit(EXIT_FAILURE);
}
GLERROR("END");
@@ -132,11 +110,3 @@ GLuint FrameBuffer::GetHandle()
{
return m_BufferHandle;
}
void FrameBuffer::Read() {
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_BufferHandle);
}
void FrameBuffer::Draw() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_BufferHandle);
}
-5
View File
@@ -362,11 +362,6 @@ void RenderSystem::fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs,
continue;
}
EntityWrapper entity(world, pointlightC.EntityID);
if (!isEntityVisible(entity)) {
continue;
}
std::shared_ptr<PointLightJob> pointLightJob = std::shared_ptr<PointLightJob>(new PointLightJob(transformC, pointlightC, m_World));
jobs.push_back(pointLightJob);
}
+4 -5
View File
@@ -168,10 +168,10 @@ void Renderer::Draw(RenderFrame& frame)
ImGui::SliderInt("SSAO Quality", &m_SSAO_Quality, 0, 3);
ImGui::SliderInt("Glow Quality", &m_GLOW_Quality, 0, 3);
ImGui::SliderInt("MSAA Level", (int*)&m_MSAA_Level, 0, 16);
ImGui::Checkbox("EnableShadows", &m_Shadow_Enabled);
m_SSAOPass->ChangeQuality(m_SSAO_Quality);
m_DrawBloomPass->ChangeQuality(m_GLOW_Quality);
m_DrawFinalPass->setMSAA(m_MSAA_Level);
m_ShadowPass->CheckStatus(m_Shadow_Enabled);
GLERROR("SSAO Settings");
//clear buffer 0
glClearColor(0.f, 0.f, 0.f, 0.f);
@@ -230,8 +230,7 @@ void Renderer::Draw(RenderFrame& frame)
if (m_DebugTextureToDraw == 0) {
PerformanceTimer::StartTimer("Renderer-Color Correction Pass");
GLuint test = m_DrawFinalPass->SceneTexture();
m_DrawColorCorrectionPass->Draw(test, m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure);
m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure);
PerformanceTimer::StopTimer("Renderer-Color Correction Pass");
}
@@ -310,7 +309,7 @@ void Renderer::InitializeRenderPasses()
m_SSAOPass = new SSAOPass(this, m_Config);
m_ShadowPass = new ShadowPass(this);
m_BlurHUDPass = new BlurHUD(this);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass, m_Config);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass);
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
+151 -128
View File
@@ -6,7 +6,7 @@ ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y)
m_ResolutionSizeWidth = shadow_res_x;
m_ResolutionSizeHeight = shadow_res_y;
InitializeFrameBuffers();
CheckStatus(true);
InitializeShaderPrograms();
}
@@ -14,18 +14,17 @@ ShadowPass::ShadowPass(IRenderer * renderer)
{
m_Renderer = renderer;
InitializeFrameBuffers();
CheckStatus(true);
InitializeShaderPrograms();
}
ShadowPass::~ShadowPass()
{
CommonFunctions::DeleteTexture(&m_DepthMap);
}
void ShadowPass::DebugGUI()
{
ImGui::Checkbox("EnableShadows", &m_EnableShadows);
ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f);
ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f);
ImGui::Checkbox("ShadowTransparentObjects", &m_TransparentObjects);
@@ -126,6 +125,7 @@ float ShadowPass::FindRadius(ShadowFrustum& frustum)
void ShadowPass::InitializeFrameBuffers()
{
// Depth texture
glDeleteTextures(1, &m_DepthMap);
glGenTextures(1, &m_DepthMap);
glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap);
@@ -156,12 +156,12 @@ void ShadowPass::InitializeShaderPrograms()
m_ShadowProgram->BindFragDataLocation(0, "ShadowMap");
m_ShadowProgram->Link();
m_ShadowProgramSkinned = ResourceManager::Load<ShaderProgram>("#ShadowProgramSkinned");
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowSkinned.vert.glsl")));
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Shadow.frag.glsl")));
m_ShadowProgramSkinned->Compile();
m_ShadowProgramSkinned->BindFragDataLocation(0, "ShadowMap");
m_ShadowProgramSkinned->Link();
m_ShadowProgramSkinned = ResourceManager::Load<ShaderProgram>("#ShadowProgramSkinned");
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowSkinned.vert.glsl")));
m_ShadowProgramSkinned->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Shadow.frag.glsl")));
m_ShadowProgramSkinned->Compile();
m_ShadowProgramSkinned->BindFragDataLocation(0, "ShadowMap");
m_ShadowProgramSkinned->Link();
}
void ShadowPass::ClearBuffer()
@@ -209,40 +209,109 @@ void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum)
frustum.LRBT = { left, right, bottom, top };
}
void ShadowPass::CheckStatus(bool shadowStatus)
{
if (m_EnableShadows == shadowStatus) {
return;
}
m_EnableShadows = shadowStatus;
if (m_EnableShadows == false) {
CommonFunctions::DeleteTexture(&m_DepthMap);
return;
}
InitializeFrameBuffers();
}
void ShadowPass::Draw(RenderScene & scene)
{
if (m_EnableShadows) {
InitializeCameras(scene);
UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip());
if (!m_EnableShadows) {
return;
}
ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle());
InitializeCameras(scene);
UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip());
glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight);
ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle());
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward());
glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
UpdateFrustumPoints(m_shadowFrusta[i], scene.Camera->Position(), scene.Camera->Forward());
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
GLuint shaderHandle;
for (auto &job : scene.Jobs.DirectionalLight) {
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
if (directionalLightJob) {
m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f));
PointsToLightspace(m_shadowFrusta[i], m_LightView[i]);
//FindRadius(m_shadowFrusta[i]);
//RadiusToLightspace(m_shadowFrusta[i]);
m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]);
GLuint shaderHandle = 0;
GLuint lastModel = 0;
for (auto &job : scene.Jobs.DirectionalLight) {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
if (directionalLightJob) {
m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f));
PointsToLightspace(m_shadowFrusta[i], m_LightView[i]);
//FindRadius(m_shadowFrusta[i]);
//RadiusToLightspace(m_shadowFrusta[i]);
m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]);
GLERROR("ShadowLight ERROR");
GLERROR("ShadowLight ERROR");
for (auto &objectJob : scene.Jobs.OpaqueObjects) {
for (auto &objectJob : scene.Jobs.OpaqueObjects) {
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!modelJob->Shadow) {
continue;
}
if (modelJob->Model->IsSkinned()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
}
else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f);
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
}
if (m_TransparentObjects) {
state->CullFace(GL_BACK);
for (auto &objectJob : scene.Jobs.TransparentObjects) {
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
@@ -250,114 +319,68 @@ void ShadowPass::Draw(RenderScene & scene)
continue;
}
if(modelJob->Model->IsSkinned()) {
if (shaderHandle != m_ShadowProgramSkinned->GetHandle()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
if (modelJob->Model->IsSkinned()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
}
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
} else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
if (shaderHandle != m_ShadowProgram->GetHandle()) {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
else {
frameBones = modelJob->Skeleton->GetTPose();
}
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i] * m_LightView[i] * modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
}
else {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
if (m_TexturedShadows) {
switch (modelJob->Type) {
case RawModel::MaterialType::SingleTextures:
case RawModel::MaterialType::Basic:
{
glActiveTexture(GL_TEXTURE24);
if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat));
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
}
break;
}
case RawModel::MaterialType::SplatMapping:
{
glActiveTexture(GL_TEXTURE24);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
break;
}
}
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
}
if (m_TransparentObjects) {
state->CullFace(GL_BACK);
for (auto &objectJob : scene.Jobs.TransparentObjects) {
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!modelJob->Shadow) {
continue;
}
if (modelJob->Model->IsSkinned()) {
if (shaderHandle != m_ShadowProgramSkinned->GetHandle()) {
m_ShadowProgramSkinned->Bind();
shaderHandle = m_ShadowProgramSkinned->GetHandle();
}
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
frameBones = modelJob->BlendTree->GetFinalPose();
} else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
if (shaderHandle != m_ShadowProgram->GetHandle()) {
m_ShadowProgram->Bind();
shaderHandle = m_ShadowProgram->GetHandle();
}
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i] * m_LightView[i] * modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
if (m_TexturedShadows) {
switch (modelJob->Type) {
case RawModel::MaterialType::SingleTextures:
case RawModel::MaterialType::Basic:
{
glActiveTexture(GL_TEXTURE24);
if (modelJob->DiffuseTexture.size() > 0 && modelJob->DiffuseTexture[0]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture[0]->Texture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(modelJob->DiffuseTexture[0]->UVRepeat));
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
}
break;
}
case RawModel::MaterialType::SplatMapping:
{
glActiveTexture(GL_TEXTURE24);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
glUniform2fv(glGetUniformLocation(shaderHandle, "DiffuseUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
break;
}
}
}
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
}
state->CullFace(GL_FRONT);
}
state->CullFace(GL_FRONT);
}
}
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_DepthBuffer.Unbind();
delete state;
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_DepthBuffer.Unbind();
delete state;
}
+30 -30
View File
@@ -33,33 +33,33 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
PoseData poseData;
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
const std::vector<Animation::Keyframe>& boneKeyFrames = animation->JointAnimations.at(bone->ID);
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
const Animation::Keyframe* currentFrame;
const Animation::Keyframe* nextFrame;
Animation::Keyframe currentFrame;
Animation::Keyframe nextFrame;
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
if (time >= boneKeyFrames.at(index).Time) {
currentFrame = &boneKeyFrames.at(index);
nextFrame = &boneKeyFrames.at((index + 1) % boneKeyFrames.size());
currentFrame = boneKeyFrames.at(index);
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
break;
}
}
float progress;
if (nextFrame->Index == 0) {
if (nextFrame.Index == 0) {
nextFrame = currentFrame;
progress = (time - currentFrame->Time) / (animation->Duration - currentFrame->Time);
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
} else {
progress = (time - currentFrame->Time) / (nextFrame->Time - currentFrame->Time);
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
}
progress = glm::clamp(progress, 0.0f, 1.0f);
const Animation::Keyframe::BoneProperty& currentBoneProperty = currentFrame->BoneProperties;
const Animation::Keyframe::BoneProperty& nextBoneProperty = nextFrame->BoneProperties;
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
glm::quat rotation = glm::normalize(glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress));
@@ -77,10 +77,10 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
boneMatrices[bone->ID] = poseData;
} else { // 1 keyframes for the current bone
currentFrame = &boneKeyFrames.at(0);
poseData.Translation = currentFrame->BoneProperties.Position;
poseData.Orientation = currentFrame->BoneProperties.Rotation;
poseData.Scale = currentFrame->BoneProperties.Scale;
currentFrame = boneKeyFrames.at(0);
poseData.Translation = currentFrame.BoneProperties.Position;
poseData.Orientation = currentFrame.BoneProperties.Rotation;
poseData.Scale = currentFrame.BoneProperties.Scale;
boneMatrices[bone->ID] = poseData;
}
}
@@ -117,33 +117,33 @@ Skeleton::PoseData Skeleton::GetAdditiveBonePose(const Bone* bone, const Animati
glm::vec3 scale = glm::vec3(1);
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
const std::vector<Animation::Keyframe>& boneKeyFrames = animation->JointAnimations.at(bone->ID);
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
const Animation::Keyframe* currentFrame;
const Animation::Keyframe* nextFrame;
Animation::Keyframe currentFrame;
Animation::Keyframe nextFrame;
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
if (time >= boneKeyFrames.at(index).Time) {
currentFrame = &boneKeyFrames.at(index);
nextFrame = &boneKeyFrames.at((index + 1) % boneKeyFrames.size());
currentFrame = boneKeyFrames.at(index);
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
break;
}
}
float progress;
if (nextFrame->Index == 0) {
if (nextFrame.Index == 0) {
nextFrame = currentFrame;
progress = (time - currentFrame->Time) / (animation->Duration - currentFrame->Time);
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
} else {
progress = (time - currentFrame->Time) / (nextFrame->Time - currentFrame->Time);
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
}
progress = glm::clamp(progress, 0.0f, 1.0f);
const Animation::Keyframe::BoneProperty& currentBoneProperty = currentFrame->BoneProperties;
const Animation::Keyframe::BoneProperty& nextBoneProperty = nextFrame->BoneProperties;
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress);
@@ -151,10 +151,10 @@ Skeleton::PoseData Skeleton::GetAdditiveBonePose(const Bone* bone, const Animati
} else { // 1 keyframes for the current bone
currentFrame = &boneKeyFrames.at(0);
position = currentFrame->BoneProperties.Position;
rotation = currentFrame->BoneProperties.Rotation;
scale = currentFrame->BoneProperties.Scale;
currentFrame = boneKeyFrames.at(0);
position = currentFrame.BoneProperties.Position;
rotation = currentFrame.BoneProperties.Rotation;
scale = currentFrame.BoneProperties.Scale;
}
}
@@ -270,10 +270,10 @@ void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, std::
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
} else {
if (bone->Parent) {
boneMatrix = parentMatrix * bone->BindTransformMatrix * bone->Parent->OffsetMatrix;
boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix);
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
} else {
boneMatrix = bone->BindTransformMatrix;
boneMatrix = glm::inverse(bone->OffsetMatrix);
boneMatrices[bone->ID] = parentMatrix;
}
}
@@ -17,26 +17,25 @@ void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples
{
glDeleteTextures(1, texture);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
GLERROR("Texture initialization failed 1");
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, GL_FALSE);
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 internalFormat, GLint format, GLenum type, GLint numMipMaps, GLint MAGFilter, GLint MINFilter)
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps)
{
glDeleteTextures(1, texture);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, internalFormat, dimensions.x, dimensions.y);
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, NULL);
GLERROR("MipMap Texture glTexSubImage2D failed");
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, MAGFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MINFilter);
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");
}
+21 -38
View File
@@ -30,7 +30,10 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &SoundManager::OnSetCamera);
Events::ChangeBGM e;
e.FilePath = "Audio/bgm/MenuMusic.wav";
m_EventBroker->Publish(e);
}
SoundManager::~SoundManager()
@@ -64,7 +67,8 @@ void SoundManager::Update(double dt)
deleteInactiveEmitters();
updateEmitters(dt);
updateListener(dt);
matchBGMLoop();
if (m_DrumLoopHasBeenStarted)
matchBGMLoop();
}
void SoundManager::deleteInactiveEmitters()
@@ -359,6 +363,15 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
{
if (e.PlayerID == -1) { // Local player
m_LocalPlayer = e.Player;
if (m_DrumLoopHasBeenStarted) {
return true;
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
m_DrumLoopHasBeenStarted = true;
return true;
}
return false;
@@ -381,9 +394,7 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
{
if (m_CurrentBGM != nullptr) {
if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGM);
}
stopSound(m_CurrentBGM);
}
m_CurrentBGM = createSource(e.FilePath);
m_CurrentBGM->Type = SoundType::BGM;
@@ -392,34 +403,6 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
return true;
}
bool SoundManager::OnSetCamera(const Events::SetCamera& e)
{
if (e.CameraEntity.Name() == "Overview_Camera_Start_Menu") {
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/MenuMusic.wav";
m_EventBroker->Publish(changeBGM);
} else if (e.CameraEntity.Name() == "PickTeamCamera") {
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(changeBGM);
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
}
}
ALenum SoundManager::getSourceState(ALuint source)
{
ALenum state;
@@ -436,14 +419,14 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom
{
float gain;
switch (source->Type) {
case SoundType::SFX:
gain = m_SFXVolumeChannel;
case SoundType::SFX:
gain = m_SFXVolumeChannel;
break;
case SoundType::BGM:
case SoundType::BGM:
gain = m_BGMVolumeChannel;
break;
case SoundType::Announcer:
gain = m_AnnouncerVolumeChannel;
case SoundType::Announcer:
gain = m_AnnouncerVolumeChannel;
break;
default:
gain = 1.f;
+5
View File
@@ -30,6 +30,11 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
Events::PlayAnonuncerVoice go;
go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
m_EventBroker->Publish(go);
{
Events::ChangeBGM ev;
ev.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(ev);
}
}
return true;
}
+1 -5
View File
@@ -61,11 +61,7 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
// TODO: 1 Signifies spectator, should probably have real enum here later.
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
if (swapToClass && m_PickedTeam != 1) {
if (m_PickedTeam == 2) {
camName = "PickClassCameraRed";
} else if (m_PickedTeam == 3) {
camName = "PickClassCameraBlue";
}
camName = "PickClassCamera";
} else if (e.Command == "SwapToTeamPick") {
camName = "PickTeamCamera";
} else {