Merge pull request #163 from teamfisk/revert-145-Shadows
Revert "Shadows"
This commit is contained in:
@@ -11,12 +11,11 @@
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
#include "Texture.h"
|
||||
#include "ShadowPass.h"
|
||||
|
||||
class DrawFinalPass
|
||||
{
|
||||
public:
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass);
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass);
|
||||
~DrawFinalPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
@@ -66,7 +65,6 @@ private:
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
const CubeMapPass* m_CubeMapPass;
|
||||
const SSAOPass* m_SSAOPass;
|
||||
const ShadowPass* m_ShadowPass;
|
||||
|
||||
ShaderProgram* m_ForwardPlusProgram;
|
||||
ShaderProgram* m_ExplosionEffectProgram;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "TextPass.h"
|
||||
#include "Util/CommonFunctions.h"
|
||||
#include "Core/PerformanceTimer.h"
|
||||
#include "ShadowPass.h"
|
||||
|
||||
class Renderer : public IRenderer
|
||||
{
|
||||
@@ -76,7 +75,6 @@ private:
|
||||
DrawColorCorrectionPass* m_DrawColorCorrectionPass;
|
||||
SSAOPass* m_SSAOPass;
|
||||
CubeMapPass* m_CubeMapPass;
|
||||
ShadowPass* m_ShadowPass;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
#ifndef ShadowPass_h__
|
||||
#define ShadowPass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/World.h"
|
||||
#include "ShadowPassState.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
enum NearFar { NEAR = 0, FAR = 1 };
|
||||
enum LRBT { LEFT = 0, RIGHT = 1, BOTTOM = 2, TOP = 3 };
|
||||
|
||||
struct ShadowFrustum
|
||||
{
|
||||
float NearClip;
|
||||
float FarClip;
|
||||
float FOV;
|
||||
float AspectRatio;
|
||||
glm::vec3 MiddlePoint;
|
||||
float Radius;
|
||||
std::array<float, 4> LRBT;
|
||||
std::array<glm::vec3, 8> CornerPoint;
|
||||
};
|
||||
|
||||
class ShadowPass
|
||||
{
|
||||
public:
|
||||
ShadowPass(IRenderer* renderer);
|
||||
ShadowPass(IRenderer * renderer, int ShadowResX, int ShadowResY);
|
||||
~ShadowPass();
|
||||
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
void ClearBuffer();
|
||||
void Draw(RenderScene& scene);
|
||||
|
||||
void DebugGUI();
|
||||
|
||||
GLuint DepthMap() const { return m_DepthMap; }
|
||||
std::array<glm::mat4, MAX_SPLITS> LightP() const { return m_LightProjection; }
|
||||
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; }
|
||||
|
||||
void SetSplitWeight(float split_weight) { m_SplitWeight = split_weight; };
|
||||
private:
|
||||
void InitializeCameras(RenderScene & scene);
|
||||
void UpdateSplitDist(std::array<ShadowFrustum, MAX_SPLITS>& frusta, float near_distance, float far_distance);
|
||||
void UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir);
|
||||
void UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v);
|
||||
|
||||
void PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v);
|
||||
|
||||
float FindRadius(ShadowFrustum& frustum);
|
||||
void RadiusToLightspace(ShadowFrustum& frustum);
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
GLuint m_DepthMap;
|
||||
FrameBuffer m_DepthBuffer;
|
||||
ShaderProgram* m_ShadowProgram;
|
||||
|
||||
std::array<glm::mat4, MAX_SPLITS> m_LightProjection;
|
||||
std::array<glm::mat4, MAX_SPLITS> m_LightView;
|
||||
|
||||
GLfloat m_NearFarPlane[2] = { -34.f, 27.f };
|
||||
GLuint m_ResolutionSizeWidth = 1024 * 2;
|
||||
GLuint m_ResolutionSizeHeight = 1024 * 2;
|
||||
|
||||
bool m_TransparentObjects = false;
|
||||
bool m_TexturedShadows = false;
|
||||
bool m_EnableShadows = true;
|
||||
|
||||
int m_CurrentNrOfSplits = 4;
|
||||
float m_SplitWeight = 0.962f;
|
||||
|
||||
std::array<ShadowFrustum, MAX_SPLITS> m_shadowFrusta;
|
||||
|
||||
Texture* m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef ShadowPassState_h_
|
||||
#define ShadowPassState_h_
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class ShadowPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
ShadowPassState(GLuint frameBuffer);
|
||||
~ShadowPassState();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -245,13 +245,6 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="Ambient">
|
||||
<Components>
|
||||
<c:SceneLight/>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -559,8 +559,8 @@
|
||||
<Entity name="Cube1">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>Models/BushAlive.mesh</Resource>
|
||||
<Color A="1" B="0" G="1" R="0"/>
|
||||
<Resource>Models/Core/UnitCube.mesh</Resource>
|
||||
<Color A="0.505882382" B="0" G="1" R="0"/>
|
||||
<Transparent>true</Transparent>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#version 430
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -24,7 +22,6 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Input[];
|
||||
|
||||
out VertexData{
|
||||
@@ -35,7 +32,6 @@ out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Output;
|
||||
|
||||
layout(triangles) in;
|
||||
@@ -149,7 +145,6 @@ void main()
|
||||
Output.TextureCoordinate = Input[i].TextureCoordinate;
|
||||
Output.Tangent = Input[i].Tangent;
|
||||
Output.BiTangent = Input[i].BiTangent;
|
||||
Output.PositionLightSpace = Input[i].PositionLightSpace;
|
||||
|
||||
// convert to model space for the gravity to always be in -y
|
||||
vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0);
|
||||
@@ -191,7 +186,6 @@ void main()
|
||||
Output.TextureCoordinate = Input[i].TextureCoordinate;
|
||||
Output.Tangent = Input[i].Tangent;
|
||||
Output.BiTangent = Input[i].BiTangent;
|
||||
Output.PositionLightSpace = Input[i].PositionLightSpace;
|
||||
|
||||
// no change in position, pass through vertex
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#version 430
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
@@ -15,7 +14,6 @@ uniform float FillPercentage;
|
||||
uniform float GlowIntensity = 10;
|
||||
uniform vec3 CameraPosition;
|
||||
uniform int SSAOQuality;
|
||||
uniform float FarDistance[MAX_SPLITS];
|
||||
|
||||
uniform vec2 DiffuseUVRepeat;
|
||||
uniform vec2 NormalUVRepeat;
|
||||
@@ -27,7 +25,6 @@ layout (binding = 2) uniform sampler2D NormalMapTexture;
|
||||
layout (binding = 3) uniform sampler2D SpecularMapTexture;
|
||||
layout (binding = 4) uniform sampler2D GlowMapTexture;
|
||||
layout (binding = 5) uniform samplerCube CubeMap;
|
||||
layout (binding = 13) uniform sampler2DArrayShadow DepthMap;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
@@ -62,6 +59,7 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
float LightIndex[];
|
||||
};
|
||||
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
@@ -70,7 +68,6 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Input;
|
||||
|
||||
out vec4 sceneColor;
|
||||
@@ -81,25 +78,6 @@ struct LightResult {
|
||||
vec4 Specular;
|
||||
};
|
||||
|
||||
vec2 poissonDisk[16] = vec2[](
|
||||
vec2( -0.94201624, -0.39906216 ),
|
||||
vec2( 0.94558609, -0.76890725 ),
|
||||
vec2( -0.094184101, -0.92938870 ),
|
||||
vec2( 0.34495938, 0.29387760 ),
|
||||
vec2( -0.91588581, 0.45771432 ),
|
||||
vec2( -0.81544232, -0.87912464 ),
|
||||
vec2( -0.38277543, 0.27676845 ),
|
||||
vec2( 0.97484398, 0.75648379 ),
|
||||
vec2( 0.44323325, -0.97511554 ),
|
||||
vec2( 0.53742981, -0.47373420 ),
|
||||
vec2( -0.26496911, -0.41893023 ),
|
||||
vec2( 0.79197514, 0.19090188 ),
|
||||
vec2( -0.24188840, 0.99706507 ),
|
||||
vec2( -0.81409955, 0.91437590 ),
|
||||
vec2( 0.19984126, 0.78641367 ),
|
||||
vec2( 0.14383161, -0.14100790 )
|
||||
);
|
||||
|
||||
float CalcAttenuation(float radius, float dist, float falloff) {
|
||||
return 1.0 - smoothstep(radius * falloff, radius, dist);
|
||||
}
|
||||
@@ -146,154 +124,6 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
|
||||
return vec4(TBN * normalize(NormalMap), 0.0);
|
||||
}
|
||||
|
||||
// Returns a "random" value.
|
||||
float Random(vec3 seed, int i)
|
||||
{
|
||||
vec4 seed4 = vec4(seed, i);
|
||||
float dot_product = dot(seed4, vec4(12.9898, 78.233, 45.164, 94.673));
|
||||
return fract(sin(dot_product) * 43758.5453);
|
||||
}
|
||||
|
||||
int getShadowIndex(float far_distance[1])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getShadowIndex(float far_distance[2])
|
||||
{
|
||||
float depth = gl_FragCoord.z / gl_FragCoord.w;
|
||||
|
||||
int index = 1;
|
||||
if ( depth < far_distance[0] )
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
int getShadowIndex(float far_distance[3])
|
||||
{
|
||||
float depth = gl_FragCoord.z / gl_FragCoord.w;
|
||||
|
||||
int index = 2;
|
||||
if ( depth < far_distance[0] )
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
else if ( depth < far_distance[1] && depth > far_distance[0] )
|
||||
{
|
||||
index = 1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
int getShadowIndex(float far_distance[4])
|
||||
{
|
||||
float depth = gl_FragCoord.z / gl_FragCoord.w;
|
||||
|
||||
int index = 3;
|
||||
if ( depth < far_distance[0] )
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
else if ( depth < far_distance[1] && depth > far_distance[0] )
|
||||
{
|
||||
index = 1;
|
||||
}
|
||||
else if ( depth < far_distance[2] && depth > far_distance[1] )
|
||||
{
|
||||
index = 2;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
// Standard hardware-calculated PCF method
|
||||
float PCFShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index)
|
||||
{
|
||||
return texture(depth_texture_array, vec4(projection_coords.xy, layer_index, projection_coords.z));
|
||||
}
|
||||
|
||||
// PCF + Poisson model method
|
||||
float PoissonShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
|
||||
{
|
||||
int loop;
|
||||
float multiplier = 1.0 / float(taps);
|
||||
float shadowMapDepth;
|
||||
|
||||
for (int i = 0; i < taps; i++)
|
||||
{
|
||||
loop = i;
|
||||
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
|
||||
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
|
||||
}
|
||||
|
||||
return shadowMapDepth;
|
||||
}
|
||||
|
||||
// PCF + Poisson + RandomSample model method
|
||||
float PoissonDotShadow(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, int taps, float spread)
|
||||
{
|
||||
int loop;
|
||||
float multiplier = 1.0 / float(taps);
|
||||
float shadowMapDepth;
|
||||
|
||||
for (int i = 0; i < taps; i++)
|
||||
{
|
||||
loop = int(16.0 * Random(gl_FragCoord.xyy, i)) % 16;
|
||||
vec3 newProjCoords = projection_coords + vec3(poissonDisk[loop], 0.0) / (spread * (1.0 + layer_index));
|
||||
shadowMapDepth += multiplier * texture(depth_texture_array, vec4(newProjCoords.xy, layer_index, newProjCoords.z));
|
||||
}
|
||||
|
||||
return shadowMapDepth;
|
||||
}
|
||||
|
||||
// Hardware PCF + Additional software PCF method
|
||||
float SoftwarePCF(sampler2DArrayShadow depth_texture_array, vec3 projection_coords, int layer_index, float bias)
|
||||
{
|
||||
float shadow = 0.0;
|
||||
|
||||
vec3 texelSize = 1.0 / textureSize(depth_texture_array, 0);
|
||||
for(int x = -1; x <= 1; x++)
|
||||
{
|
||||
for(int y = -1; y <= 1; y++)
|
||||
{
|
||||
shadow += texture(depth_texture_array, vec4(projection_coords.xy + vec2(x, y) * texelSize.xy / (1.0 + layer_index), layer_index, projection_coords.z));
|
||||
}
|
||||
}
|
||||
|
||||
return shadow / 9.0;
|
||||
}
|
||||
|
||||
float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler2DArrayShadow depth_texture_array, int layer_index)
|
||||
{
|
||||
float shadowMapDepth;
|
||||
float bias = 0.005;
|
||||
|
||||
// Various bias methods.
|
||||
|
||||
//bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias);
|
||||
//bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
|
||||
bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
|
||||
|
||||
// Calculate coordinates in projection space.
|
||||
|
||||
vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
//projCoords = (floor(projCoords * 255.0)) / 255.0;
|
||||
|
||||
// Various methods for shadow calculation in fastest to slowest order.
|
||||
|
||||
//shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index);
|
||||
//shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
|
||||
//shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
|
||||
shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias);
|
||||
|
||||
return shadowMapDepth;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float ao = texelFetch(AOTexture, ivec2(gl_FragCoord.xy) >> int(SSAOQuality), 0).r;
|
||||
@@ -321,8 +151,6 @@ void main()
|
||||
|
||||
int start = int(LightGrids.Data[currentTile].Start);
|
||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||
|
||||
float shadowFactor = 0.0;
|
||||
|
||||
for(int i = start; i < start + amount; i++) {
|
||||
|
||||
@@ -334,16 +162,11 @@ void main()
|
||||
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
|
||||
int DepthMapIndex = getShadowIndex(FarDistance);
|
||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||
shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap, DepthMapIndex);
|
||||
}
|
||||
totalLighting.Diffuse += vec4(light_result.Diffuse.rgb * ao, light_result.Diffuse.a);
|
||||
totalLighting.Specular += vec4(light_result.Specular.rgb * ao, light_result.Specular.a);
|
||||
}
|
||||
|
||||
totalLighting.Diffuse *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
|
||||
totalLighting.Specular *= vec4(min(vec3(shadowFactor) + AmbientColor.xyz, vec3(1.0)), 1.0);
|
||||
|
||||
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
|
||||
color_result = color_result * (totalLighting.Diffuse + (totalLighting.Specular * specularTexel));
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#version 430
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 LightV[MAX_SPLITS];
|
||||
uniform mat4 LightP[MAX_SPLITS];
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
@@ -22,7 +18,6 @@ out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Output;
|
||||
|
||||
void main()
|
||||
@@ -36,9 +31,4 @@ void main()
|
||||
Output.BiTangent = vec3(TIM * vec4(BiTangent, 0.0));
|
||||
Output.ExplosionColor = vec4(1.0);
|
||||
Output.ExplosionPercentageElapsed = 0.0;
|
||||
|
||||
for(int i = 0; i < MAX_SPLITS; i++)
|
||||
{
|
||||
Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * vec4(Position, 1.0);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#version 430
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
@@ -70,7 +69,6 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Input;
|
||||
|
||||
out vec4 sceneColor;
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
#version 430
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
uniform mat4 LightV[MAX_SPLITS];
|
||||
uniform mat4 LightP[MAX_SPLITS];
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
@@ -25,7 +21,6 @@ out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Output;
|
||||
|
||||
void main()
|
||||
@@ -48,9 +43,4 @@ void main()
|
||||
Output.BiTangent = vec3(M * vec4(BiTangent, 0.0));
|
||||
Output.ExplosionColor = vec4(1.0);
|
||||
Output.ExplosionPercentageElapsed = 0.0;
|
||||
|
||||
for(int i = 0; i < MAX_SPLITS; i++)
|
||||
{
|
||||
Output.PositionLightSpace[i] = LightP[i] * LightV[i] * M * boneTransform * vec4(Position, 1.0);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#version 430
|
||||
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
@@ -97,7 +95,6 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Input;
|
||||
|
||||
out vec4 sceneColor;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#version 430
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
@@ -84,7 +83,6 @@ in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
vec4 ExplosionColor;
|
||||
float ExplosionPercentageElapsed;
|
||||
vec4 PositionLightSpace[MAX_SPLITS];
|
||||
}Input;
|
||||
|
||||
out vec4 sceneColor;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#version 430
|
||||
|
||||
#define ALPHA_CUTOFF 0.3
|
||||
|
||||
layout (binding = 24) uniform sampler2D DiffuseTexture;
|
||||
uniform float Alpha;
|
||||
|
||||
in VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
}Input;
|
||||
|
||||
layout (location = 0) out float ShadowMap;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoordinate) * Alpha;
|
||||
|
||||
if (diffuseTexel.a < ALPHA_CUTOFF)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 4) in vec2 TextureCoords;
|
||||
|
||||
out VertexData{
|
||||
vec2 TextureCoordinate;
|
||||
}Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = P * V * M * vec4(Position, 1.0);
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "Rendering/DrawFinalPass.h"
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass)
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass)
|
||||
: m_Renderer(renderer)
|
||||
, m_LightCullingPass(lightCullingPass)
|
||||
, m_CubeMapPass(cubeMapPass)
|
||||
, m_SSAOPass(ssaoPass)
|
||||
, m_ShadowPass(shadowPass)
|
||||
{
|
||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||
m_ShieldPixelRate = 8;
|
||||
@@ -344,14 +343,6 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOPass->SSAOTexture());
|
||||
|
||||
glActiveTexture(GL_TEXTURE13);
|
||||
if (m_ShadowPass->DepthMap() != NULL) {
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_ShadowPass->DepthMap());
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
for (auto &job : jobs) {
|
||||
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
|
||||
if (explosionEffectJob) {
|
||||
@@ -1092,10 +1083,6 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind 20 uniform");
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntensity);
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data()));
|
||||
glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data());
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
@@ -1134,11 +1121,8 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
|
||||
|
||||
GLERROR("Bind 10 uniform");
|
||||
GLint Location_GlowIntensity = glGetUniformLocation(shaderHandle, "GlowIntensity");
|
||||
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightP"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightP().data()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "LightV"), MAX_SPLITS, GL_FALSE, glm::value_ptr(*m_ShadowPass->LightV().data()));
|
||||
glUniform1fv(glGetUniformLocation(shaderHandle, "FarDistance"), MAX_SPLITS, m_ShadowPass->FarDistance().data());
|
||||
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
|
||||
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
@@ -53,20 +53,16 @@ void FrameBuffer::Generate()
|
||||
case GL_TEXTURE_2D:
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
|
||||
|
||||
break;
|
||||
case GL_RENDERBUFFER:
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
|
||||
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
|
||||
break;
|
||||
case GL_TEXTURE_2D_ARRAY:
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2DArray");
|
||||
break;
|
||||
}
|
||||
GLERROR("2");
|
||||
|
||||
// Need GL_DEPTH_ATTACHMENT for shadows
|
||||
if (/*(*it)->m_Attachment != GL_DEPTH_ATTACHMENT &&*/ (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) {
|
||||
if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT && (*it)->m_Attachment != GL_STENCIL_ATTACHMENT && (*it)->m_Attachment != GL_DEPTH_STENCIL_ATTACHMENT) {
|
||||
attachments.push_back((*it)->m_Attachment);
|
||||
}
|
||||
GLERROR("Attachment");
|
||||
|
||||
@@ -133,8 +133,6 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
m_DrawFinalPass->ClearBuffer();
|
||||
m_DrawBloomPass->ClearBuffer();
|
||||
m_SSAOPass->ClearBuffer();
|
||||
m_ShadowPass->ClearBuffer();
|
||||
m_ShadowPass->DebugGUI();
|
||||
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
||||
GLERROR("ClearBuffers");
|
||||
for (auto scene : frame.RenderScenes) {
|
||||
@@ -150,9 +148,6 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||
SortRenderJobsByDepth(*scene);
|
||||
GLERROR("SortByDepth");
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Draw shadow maps");
|
||||
m_ShadowPass->Draw(*scene);
|
||||
GLERROR("Draw shadow maps");
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
|
||||
m_LightCullingPass->GenerateNewFrustum(*scene);
|
||||
GLERROR("Generate frustums");
|
||||
@@ -249,8 +244,7 @@ void Renderer::InitializeRenderPasses()
|
||||
m_LightCullingPass = new LightCullingPass(this);
|
||||
m_CubeMapPass = new CubeMapPass(this);
|
||||
m_SSAOPass = new SSAOPass(this, m_Config);
|
||||
m_ShadowPass = new ShadowPass(this);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass);
|
||||
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
||||
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
|
||||
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
#include "Rendering/ShadowPass.h"
|
||||
|
||||
ShadowPass::ShadowPass(IRenderer * renderer, int shadow_res_x, int shadow_res_y)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
m_ResolutionSizeWidth = shadow_res_x;
|
||||
m_ResolutionSizeHeight = shadow_res_y;
|
||||
|
||||
InitializeFrameBuffers();
|
||||
InitializeShaderPrograms();
|
||||
}
|
||||
|
||||
ShadowPass::ShadowPass(IRenderer * renderer)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
|
||||
InitializeFrameBuffers();
|
||||
InitializeShaderPrograms();
|
||||
}
|
||||
|
||||
ShadowPass::~ShadowPass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
ImGui::Checkbox("ShadowOnTextureAlphas", &m_TexturedShadows);
|
||||
}
|
||||
|
||||
void ShadowPass::InitializeCameras(RenderScene & scene)
|
||||
{
|
||||
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
|
||||
m_shadowFrusta[i].AspectRatio = scene.Camera->AspectRatio();
|
||||
m_shadowFrusta[i].FOV = scene.Camera->FOV();
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateSplitDist computes the near and far distances for every frustum slice
|
||||
// in camera eye space - that is, at what distance does a slice start and end
|
||||
void ShadowPass::UpdateSplitDist(std::array<ShadowFrustum, MAX_SPLITS>& frusta, float near_distance, float far_distance)
|
||||
{
|
||||
float lambda = m_SplitWeight;
|
||||
float ratio = far_distance / near_distance;
|
||||
|
||||
frusta[0].NearClip = near_distance;
|
||||
|
||||
for (int i = 1; i < m_CurrentNrOfSplits; i++) {
|
||||
float si = i / static_cast<float>(m_CurrentNrOfSplits);
|
||||
|
||||
frusta[i].NearClip = lambda * (near_distance * powf(ratio, si)) + (1 - lambda) * (near_distance + (far_distance - near_distance) * si);
|
||||
frusta[i - 1].FarClip = frusta[i].NearClip * 1.005f;
|
||||
}
|
||||
|
||||
frusta[m_CurrentNrOfSplits - 1].FarClip = far_distance;
|
||||
}
|
||||
|
||||
void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::mat4 p, glm::mat4 v)
|
||||
{
|
||||
std::array<glm::vec4, 8> CornerPoint = {
|
||||
glm::vec4(-1.f, -1.f, -1.f, 1.f),
|
||||
glm::vec4(-1.f, 1.f, -1.f, 1.f),
|
||||
glm::vec4(1.f, 1.f, -1.f, 1.f),
|
||||
glm::vec4(1.f, -1.f, -1.f, 1.f),
|
||||
glm::vec4(-1.f, -1.f, 1.f, 1.f),
|
||||
glm::vec4(-1.f, 1.f, 1.f, 1.f),
|
||||
glm::vec4(1.f, 1.f, 1.f, 1.f),
|
||||
glm::vec4(1.f, -1.f, 1.f, 1.f)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
glm::vec4 NDC = glm::inverse(p) * CornerPoint[i];
|
||||
NDC = NDC / NDC.w;
|
||||
frustum.CornerPoint[i] = glm::vec3(glm::inverse(v) * NDC);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the 8 corner points of the current view frustum in world space
|
||||
void ShadowPass::UpdateFrustumPoints(ShadowFrustum& frustum, glm::vec3 camera_position, glm::vec3 view_dir)
|
||||
{
|
||||
glm::vec3 up = glm::vec3(0.f, 1.f, 0.f);
|
||||
glm::vec3 right = glm::normalize(glm::cross(view_dir, up));
|
||||
|
||||
glm::vec3 far_center = camera_position + glm::normalize(view_dir) * frustum.FarClip;
|
||||
glm::vec3 near_center = camera_position + glm::normalize(view_dir) * frustum.NearClip;
|
||||
frustum.MiddlePoint = near_center + (far_center - near_center) * 0.5f;
|
||||
|
||||
up = glm::normalize(glm::cross(right, view_dir));
|
||||
|
||||
// these heights and widths are half the heights and widths of the near and far plane rectangles.
|
||||
float near_height = tan(frustum.FOV / 2.f) * frustum.NearClip;
|
||||
float near_width = near_height * frustum.AspectRatio;
|
||||
float far_height = tan(frustum.FOV / 2.f) * frustum.FarClip;
|
||||
float far_width = far_height * frustum.AspectRatio;
|
||||
|
||||
frustum.CornerPoint[0] = near_center - up * near_height - right * near_width;
|
||||
frustum.CornerPoint[1] = near_center + up * near_height - right * near_width;
|
||||
frustum.CornerPoint[2] = near_center + up * near_height + right * near_width;
|
||||
frustum.CornerPoint[3] = near_center - up * near_height + right * near_width;
|
||||
|
||||
frustum.CornerPoint[4] = far_center - up * far_height - right * far_width;
|
||||
frustum.CornerPoint[5] = far_center + up * far_height - right * far_width;
|
||||
frustum.CornerPoint[6] = far_center + up * far_height + right * far_width;
|
||||
frustum.CornerPoint[7] = far_center - up * far_height + right * far_width;
|
||||
}
|
||||
|
||||
float ShadowPass::FindRadius(ShadowFrustum& frustum)
|
||||
{
|
||||
float radius = 0.f;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
float distance = glm::distance(frustum.MiddlePoint, frustum.CornerPoint[i]);
|
||||
if (distance > radius) {
|
||||
radius = distance;
|
||||
}
|
||||
}
|
||||
|
||||
frustum.Radius = radius;
|
||||
return radius;
|
||||
}
|
||||
|
||||
void ShadowPass::InitializeFrameBuffers()
|
||||
{
|
||||
// Depth texture
|
||||
glGenTextures(1, &m_DepthMap);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_DepthMap);
|
||||
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits);
|
||||
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight, m_CurrentNrOfSplits, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, glm::vec4(1.f).data);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
|
||||
m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT)));
|
||||
m_DepthBuffer.Generate();
|
||||
|
||||
GLERROR("depthMap failed END");
|
||||
}
|
||||
|
||||
void ShadowPass::InitializeShaderPrograms()
|
||||
{
|
||||
m_ShadowProgram = ResourceManager::Load<ShaderProgram>("#ShadowProgram");
|
||||
m_ShadowProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Shadow.vert.glsl")));
|
||||
m_ShadowProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Shadow.frag.glsl")));
|
||||
m_ShadowProgram->Compile();
|
||||
m_ShadowProgram->BindFragDataLocation(0, "ShadowMap");
|
||||
m_ShadowProgram->Link();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ShadowPass::ClearBuffer()
|
||||
{
|
||||
m_DepthBuffer.Bind();
|
||||
|
||||
for (int i = 0; i < m_CurrentNrOfSplits; i++) {
|
||||
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
m_DepthBuffer.Unbind();
|
||||
}
|
||||
|
||||
void ShadowPass::PointsToLightspace(ShadowFrustum& frustum, glm::mat4 v)
|
||||
{
|
||||
float left = INFINITY;
|
||||
float right = -INFINITY;
|
||||
float bottom = INFINITY;
|
||||
float top = -INFINITY;
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
glm::vec3 tempPoint = glm::vec3(v * glm::vec4(frustum.CornerPoint[i], 1.f));
|
||||
|
||||
if (tempPoint.x < left) { left = tempPoint.x; }
|
||||
if (tempPoint.x > right) { right = tempPoint.x; }
|
||||
if (tempPoint.y < bottom) { bottom = tempPoint.y; }
|
||||
if (tempPoint.y > top) { top = tempPoint.y; }
|
||||
}
|
||||
|
||||
frustum.LRBT = { left, right, bottom, top };
|
||||
}
|
||||
|
||||
void ShadowPass::RadiusToLightspace(ShadowFrustum& frustum)
|
||||
{
|
||||
float quantizationStep = 1.0f / m_ResolutionSizeHeight;
|
||||
|
||||
float left = -frustum.Radius;
|
||||
float right = frustum.Radius;
|
||||
float bottom = -frustum.Radius;
|
||||
float top = frustum.Radius;
|
||||
|
||||
frustum.LRBT = { left, right, bottom, top };
|
||||
}
|
||||
|
||||
void ShadowPass::Draw(RenderScene & scene)
|
||||
{
|
||||
if (m_EnableShadows) {
|
||||
InitializeCameras(scene);
|
||||
UpdateSplitDist(m_shadowFrusta, scene.Camera->NearClip(), scene.Camera->FarClip());
|
||||
|
||||
ShadowPassState* state = new ShadowPassState(m_DepthBuffer.GetHandle());
|
||||
|
||||
m_ShadowProgram->Bind();
|
||||
GLuint shaderHandle = m_ShadowProgram->GetHandle();
|
||||
glViewport(0, 0, m_ResolutionSizeWidth, m_ResolutionSizeHeight);
|
||||
|
||||
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);
|
||||
|
||||
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]);
|
||||
|
||||
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]));
|
||||
|
||||
GLERROR("ShadowLight ERROR");
|
||||
|
||||
for (auto &objectJob : scene.Jobs.OpaqueObjects) {
|
||||
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob)) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
state->CullFace(GL_FRONT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
m_DepthBuffer.Unbind();
|
||||
delete state;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "Rendering/ShadowPassState.h"
|
||||
|
||||
ShadowPassState::ShadowPassState(GLuint frameBuffer)
|
||||
{
|
||||
BindFramebuffer(frameBuffer);
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
Disable(GL_BLEND);
|
||||
Disable(GL_TEXTURE_2D);
|
||||
CullFace(GL_FRONT);
|
||||
ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f));
|
||||
//Enable(GL_ALPHA_TEST);
|
||||
//glAlphaFunc(GL_GREATER, 0.9f);
|
||||
}
|
||||
|
||||
ShadowPassState::~ShadowPassState()
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user