Forward+ semi working

This commit is contained in:
viktorljung
2015-12-17 17:55:44 +01:00
parent 6a3c14540d
commit 4a817613e3
5 changed files with 30 additions and 24 deletions
+1 -1
View File
@@ -15,7 +15,7 @@
#define TILE_SIZE 16
#define NUM_LIGHTS 3
#define NUM_LIGHTS 25
#include "../Core/EventBroker.h"
+3 -3
View File
@@ -49,7 +49,7 @@ in VertexData{
out vec4 fragmentColor;
vec4 scene_ambient = vec4(0.0,0.0,0.0,1);
vec4 scene_ambient = vec4(0.3,0.3,0.3,1);
struct LightResult {
vec4 Diffuse;
@@ -115,11 +115,11 @@ void main()
}
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
fragmentColor += vec4(LightGrids.Data[currentTile].Amount/3.0, 0, 0, 1);
fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
//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);
fragmentColor += vec4(0.5, 0, 0, 0);
} else {
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);
+6 -6
View File
@@ -24,7 +24,7 @@ vec4 ConvertToView(vec4 ScreenCoords)
vec2 normalizedScreenCoords = ScreenCoords.xy / ScreenDimensions;
vec4 clipSpace = vec4( vec2(normalizedScreenCoords.x, normalizedScreenCoords.y) * 2.0 - 1.0, ScreenCoords.z, ScreenCoords.w);
vec4 view = inverse(P) * clipSpace;
view = view / view.w;
//view = view / view.w;
return view;
}
@@ -46,7 +46,7 @@ void main ()
//Top-Left = 0 | Top-Right = 1
//Bottom-Left = 2 | Bottom-Right = 3
vec4 ScreenCoords[4];
ScreenCoords[0] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y + 1 ) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[0] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[1] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[2] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
ScreenCoords[3] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
@@ -59,10 +59,10 @@ void main ()
vec3 EyePos = vec3(0,0,0);
Frustum f;
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]);
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]);
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]);
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]);
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]); // left plane
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]); // right plane
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]); // top plane
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]); // bottom plane
+9 -7
View File
@@ -8,7 +8,7 @@
#define NUM_LIGHTS 3
#define NUM_LIGHTS 25
#define MAX_LIGHTS_PER_TILE 1024
#define NUM_TILES 3600
#define TILE_SIZE 16
@@ -71,12 +71,11 @@ int GroupIndex;
bool SphereInsidePlane(vec3 center, float radius, Plane plane)
{
return dot(plane.Normal, center) - plane.d < -radius;
return dot(plane.Normal, center) + plane.d > -radius;
}
bool SphereInsideFrustrum(vec3 center, float radius, Frustum frustum/*, float zNear, float zFar*/)
{
bool result = true;
//Check depth here
//if ( sphere.c.z - sphere.r > zNear || sphere.c.z + sphere.r < zFar )
@@ -84,14 +83,14 @@ bool SphereInsideFrustrum(vec3 center, float radius, Frustum frustum/*, float zN
// result = false;
//}
for (int i =0; i < 4 && result; i++)
for (int i =0; i < 4; i++)
{
if(SphereInsidePlane(center, radius, frustum.Planes[i]))
if(! SphereInsidePlane(center, radius, frustum.Planes[i]))
{
result = false;
return false;
}
}
return result;
return true;
}
void AppendLight(int li)
@@ -115,6 +114,7 @@ void main ()
}
barrier();
memoryBarrierShared();
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
{
@@ -136,6 +136,7 @@ void main ()
}
barrier();
memoryBarrierShared();
if(gl_LocalInvocationIndex == 0)
{
@@ -145,6 +146,7 @@ void main ()
}
barrier();
for (uint i = gl_LocalInvocationIndex; i < GroupLightCount; i += TILE_SIZE * TILE_SIZE )
{
+11 -7
View File
@@ -5,7 +5,7 @@ void Renderer::Initialize()
InitializeWindow();
// Create default camera
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
m_DefaultCamera->SetPosition(glm::vec3(0, 1, 10));
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera;
}
@@ -254,6 +254,8 @@ void Renderer::CalculateFrustum()
m_CalculateFrustumProgram->Bind();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(m_Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Resolution.Width, m_Resolution.Height);
@@ -264,11 +266,13 @@ void Renderer::CalculateFrustum()
void Renderer::TEMPCreateLights()
{
for (int i = 0; i < NUM_LIGHTS; i++) {
m_PointLights[i].Position = glm::vec4(5.f * (i-1), 1.f, 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 = 2.f;
}
for (int z = 0; z < 5; z++)
for (int x = 0; x < 5; x++)
{
m_PointLights[x + z*5].Position = glm::vec4(x*2.f, 0.2f, z * 2.f, 1.f);
m_PointLights[x + z*5].Color = glm::vec4(1.f, 0.5f, 1.f, 1.f);
m_PointLights[x + z*5].Radius = 0.5f;
}
}
void Renderer::CullLights()
@@ -282,7 +286,7 @@ void Renderer::CullLights()
m_LightCullProgram->Bind();
glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "V"), 1, false, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_LightCullProgram->GetHandle(), "V"), 1, false, glm::value_ptr(m_Camera->ViewMatrix()));
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);