From 6cf7c12d3447b2f8418af505362a300119f93814 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Fri, 18 Dec 2015 11:09:54 +0100 Subject: [PATCH] Forward+ working --- include/Engine/Rendering/Renderer.h | 2 +- resources/Schema/Entities/Test.xml | 2 +- resources/Shaders/ForwardPlus.frag.glsl | 6 +++--- resources/Shaders/GridFrustum.comp.glsl | 6 ++++-- resources/Shaders/cullLights.comp.glsl | 3 +-- src/Engine/Rendering/Renderer.cpp | 16 ++++++++-------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 82471c6d..2f0dae08 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -15,7 +15,7 @@ #define TILE_SIZE 16 -#define NUM_LIGHTS 25 +#define NUM_LIGHTS 5000 #include "../Core/EventBroker.h" diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index f8be48a7..cf428a77 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -10,7 +10,7 @@ - + Models/Core/UnitPlane.obj diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 59456322..568195ce 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -57,7 +57,7 @@ struct LightResult { }; float CalcAttenuation(float radius, float dist) { - return 1.0 - smoothstep(radius * 1.0, radius, dist); + return 1.0 - smoothstep(radius * 0.3, radius, dist); } vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) { @@ -115,11 +115,11 @@ void main() } fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; - fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.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); diff --git a/resources/Shaders/GridFrustum.comp.glsl b/resources/Shaders/GridFrustum.comp.glsl index 6e567e14..bb2a4fb7 100644 --- a/resources/Shaders/GridFrustum.comp.glsl +++ b/resources/Shaders/GridFrustum.comp.glsl @@ -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; } @@ -51,12 +51,14 @@ void main () 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); + + vec3 ViewVectors[4]; for(int i = 0; i < 4; i++) { ViewVectors[i] = vec3(ConvertToView(ScreenCoords[i])); } - vec3 EyePos = vec3(0,0,0); + vec3 EyePos = vec3(0.0, 0.0 ,0.0); Frustum f; f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]); // left plane diff --git a/resources/Shaders/cullLights.comp.glsl b/resources/Shaders/cullLights.comp.glsl index a0da2520..69eb5903 100644 --- a/resources/Shaders/cullLights.comp.glsl +++ b/resources/Shaders/cullLights.comp.glsl @@ -8,7 +8,6 @@ -#define NUM_LIGHTS 25 #define MAX_LIGHTS_PER_TILE 1024 #define NUM_TILES 3600 #define TILE_SIZE 16 @@ -71,7 +70,7 @@ 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*/) diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index e048b082..c32fc4f8 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -4,7 +4,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 = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(90.0f), 0.01f, 5000.f); m_DefaultCamera->SetPosition(glm::vec3(0, 1, 10)); if (m_Camera == nullptr) { m_Camera = m_DefaultCamera; @@ -266,13 +266,13 @@ void Renderer::CalculateFrustum() void Renderer::TEMPCreateLights() { - 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; - } + for (int i = 0; i < NUM_LIGHTS; i++) + { + glm::vec3 pos = glm::vec3(cos(i) * i/10.f , 0.5f, sin(i) * i/10.f); + m_PointLights[i].Position = glm::vec4(pos, 1.f); + m_PointLights[i].Color = glm::vec4(rand()%255 / 255.f, rand()%255 / 255.f, rand()%255 / 255.f, 1.f); + m_PointLights[i].Radius = 5.0f; + } } void Renderer::CullLights()