Forward+ Fixes
This commit is contained in:
@@ -18,14 +18,6 @@
|
||||
#define NUM_LIGHTS 3
|
||||
|
||||
|
||||
enum lightType
|
||||
{
|
||||
Point,
|
||||
Spot,
|
||||
Directional,
|
||||
Area
|
||||
};
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "EPicking.h"
|
||||
|
||||
@@ -94,22 +86,22 @@ private:
|
||||
PointLight m_PointLights[NUM_LIGHTS];
|
||||
|
||||
struct LightGrid {
|
||||
int Amount;
|
||||
int Start;
|
||||
float Start;
|
||||
float Amount;
|
||||
glm::vec2 Padding;
|
||||
};
|
||||
LightGrid m_LightGrid[80*45];
|
||||
|
||||
int m_LightOffset = 0;
|
||||
|
||||
int m_LightIndex[80*45*200];
|
||||
float m_LightIndex[80*45*200];
|
||||
|
||||
//-------------------------SSBO------------------------//
|
||||
GLuint m_FrustumSSBO = 0;
|
||||
GLuint m_LightSSBO = 1;
|
||||
GLuint m_LightGridSSBO = 2;
|
||||
GLuint m_LightOffsetSSBO = 3;
|
||||
GLuint m_LightIndexSSBO = 4;
|
||||
GLuint m_LightSSBO = 0;
|
||||
GLuint m_LightGridSSBO = 0;
|
||||
GLuint m_LightOffsetSSBO = 0;
|
||||
GLuint m_LightIndexSSBO = 0;
|
||||
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||
//--------------------ShaderPrograms-------------------//
|
||||
|
||||
@@ -23,8 +23,8 @@ layout (std430, binding = 1) buffer LightBuffer
|
||||
} PointLights;
|
||||
|
||||
struct LightGrid {
|
||||
int Amount;
|
||||
int Start;
|
||||
float Start;
|
||||
float Amount;
|
||||
vec2 Padding;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ layout (std430, binding = 2) buffer LightGridBuffer
|
||||
|
||||
layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
{
|
||||
int LightIndex[];
|
||||
float LightIndex[];
|
||||
};
|
||||
|
||||
|
||||
@@ -98,11 +98,14 @@ void main()
|
||||
|
||||
LightResult totalLighting;
|
||||
totalLighting.Diffuse = scene_ambient;
|
||||
|
||||
|
||||
|
||||
int start = int(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Start);
|
||||
int amount = int(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount);
|
||||
//for(int i = 0; i < 3; i++)
|
||||
for(int i = LightGrids.Data[int(tilePos.x + tilePos.y*80)].Start; i < LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount; i++)
|
||||
for(int i = start; i < start + amount; i++)
|
||||
{
|
||||
int l = LightIndex[i];
|
||||
int l = int(LightIndex[i]);
|
||||
|
||||
LightResult result = CalcPointLight(V * PointLights.List[l].Position, PointLights.List[l].Radius, PointLights.List[l].Color, PointLights.List[l].Intensity, viewVec, position, normal);
|
||||
|
||||
@@ -111,12 +114,15 @@ void main()
|
||||
}
|
||||
|
||||
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
||||
|
||||
//fragmentColor = texel * Input.DiffuseColor * Color;
|
||||
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 )
|
||||
{
|
||||
fragmentColor = vec4(0.5, 0, 0, 0);
|
||||
} else {
|
||||
//fragmentColor = vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Start/3600, 0, 0, 1);
|
||||
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,12 @@ void main ()
|
||||
|
||||
|
||||
|
||||
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
|
||||
if ( gl_GlobalInvocationID.x < ScreenDimensions.x / TILE_SIZE && gl_GlobalInvocationID.y < ScreenDimensions.y / TILE_SIZE ) { // innanför skärmen?
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,8 @@ layout (std430, binding = 1) buffer LightBuffer
|
||||
} PointLights;
|
||||
|
||||
struct LightGrid {
|
||||
int Amount;
|
||||
int Start;
|
||||
float Start;
|
||||
float Amount;
|
||||
vec2 Padding;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ layout (std430, binding = 3) buffer LightOffsetBuffer
|
||||
|
||||
layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
{
|
||||
int LightIndex[];
|
||||
float LightIndex[];
|
||||
};
|
||||
|
||||
shared int GroupLightCount;
|
||||
@@ -107,7 +107,7 @@ void AppendLight(int li)
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
GroupIndex = int(gl_WorkGroupID.x + gl_WorkGroupID.y * gl_NumWorkGroups.y);
|
||||
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * 80));
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
GroupLightCount = 0;
|
||||
@@ -146,6 +146,15 @@ void main ()
|
||||
LightGrid g;
|
||||
g.Start = GroupLightIndexStartOffset;
|
||||
g.Amount = GroupLightCount;
|
||||
LightGrids.Data[GroupIndex];
|
||||
g.Padding = vec2(1111, 1111);
|
||||
LightGrids.Data[GroupIndex] = g;
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
for (uint i = gl_LocalInvocationIndex; i < GroupLightCount; i += TILE_SIZE * TILE_SIZE )
|
||||
{
|
||||
LightIndex[GroupLightIndexStartOffset + i] = GroupLightIndex[i];
|
||||
}
|
||||
}
|
||||
@@ -209,44 +209,35 @@ void Renderer::InitializeSSBOs()
|
||||
glGenBuffers(1, &m_FrustumSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_Frustums), &m_Frustums, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
GLERROR("m_FrustumSSBO");
|
||||
|
||||
glGenBuffers(1, &m_LightSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_PointLights), &m_PointLights, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
GLERROR("m_LightSSBO");
|
||||
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightGridSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightGrid), &m_LightGrid, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
GLERROR("m_LightGridSSBO");
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightOffsetSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
GLERROR("m_LightOffsetSSBO");
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightIndexSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightIndexSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightIndex), &m_LightIndex, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
GLERROR("m_LightIndexSSBO");
|
||||
|
||||
}
|
||||
@@ -274,9 +265,9 @@ void Renderer::CalculateFrustum()
|
||||
void Renderer::TEMPCreateLights()
|
||||
{
|
||||
for (int i = 0; i < NUM_LIGHTS; i++) {
|
||||
m_PointLights[i].Position = glm::vec4(5.f * (i-1), 0.f, 0.f, 1.f);
|
||||
m_PointLights[i].Position = glm::vec4(5.f * (i-1), -1.5f, 0.f, 1.f);
|
||||
m_PointLights[i].Color = glm::vec4(1.f, 0.5f, 0.f + i*0.1f, 1.f);
|
||||
m_PointLights[i].Radius = 10.f;
|
||||
m_PointLights[i].Radius = 2.f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +278,18 @@ void Renderer::CullLights()
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightGrid), &m_LightGrid, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightIndexSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightIndex), &m_LightIndex, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
m_LightCullProgram->Bind();
|
||||
|
||||
Reference in New Issue
Block a user