From 8e39880b76d1ac3fe08e34997fabba251ebb8ead Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Thu, 19 May 2016 20:17:20 +0200 Subject: [PATCH] parameter changes for directional and ambient light ambient light moved out of the shader --- Weave/Graphix/Lights/AmbientLight.cpp | 4 ++++ Weave/Graphix/Lights/DirectionalLight.cpp | 8 ++++---- Weave/Scene/Scene.cpp | 3 ++- Weave/Scene/Scene.h | 1 + shader/lightingTexture_FS.hlsl | 6 +++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Weave/Graphix/Lights/AmbientLight.cpp b/Weave/Graphix/Lights/AmbientLight.cpp index af8e60d..f49ea52 100644 --- a/Weave/Graphix/Lights/AmbientLight.cpp +++ b/Weave/Graphix/Lights/AmbientLight.cpp @@ -1,10 +1,14 @@ #include "AmbientLight.h" +#include "../Shader.h" AmbientLight::AmbientLight(const vec3 & _color) : Light(_color) { + Shader::getShader(SH_LIGHTING)->useShader(); + Shader::getShader(SH_ACTIVE)->setUniformLocation("AmbientLightColor", color); } AmbientLight::~AmbientLight() { + } \ No newline at end of file diff --git a/Weave/Graphix/Lights/DirectionalLight.cpp b/Weave/Graphix/Lights/DirectionalLight.cpp index 4789afc..806242a 100644 --- a/Weave/Graphix/Lights/DirectionalLight.cpp +++ b/Weave/Graphix/Lights/DirectionalLight.cpp @@ -8,8 +8,8 @@ DirectionalLight::DirectionalLight(const vec3& _color, const float _size, const direction(normalize(_direction)) { lightview = lookAt(direction, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); - proj = scale(vec3(size)); - invproj = scale(vec3(1 / size)); + proj = scale(vec3(1 / size)); + invproj = scale(vec3(size)); Shader::getShader(SH_LIGHTING)->useShader(); Shader::getShader(SH_ACTIVE)->setUniformLocation("DirectionalLightDirection", direction); @@ -27,8 +27,8 @@ void DirectionalLight::changeSize(const float _size) { size = _size; - proj = scale(vec3(size)); - invproj = scale(vec3(1 / size)); + proj = scale(vec3(1 / size)); + invproj = scale(vec3(size)); } void DirectionalLight::changeDirection(const vec3& _direction) diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 87051d8..37509b6 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -41,7 +41,8 @@ camera(fovy, (float)width/height, zNear, zFar), lookat(_lookat) { //Lights - dirLight = new DirectionalLight(vec3(1.2f), 0.2f, vec3(-1.f, -0.5f, -0.5f)); + ambLight = new AmbientLight(vec3(0.25f)); + dirLight = new DirectionalLight(vec3(0.4f), 30.0f, vec3(1.f, -0.5f, -0.5f)); //dirLight = new DirectionalLight(vec3(1.2f), 0.2f, vec3(0.0f, 0.0f, -1.0f)); diff --git a/Weave/Scene/Scene.h b/Weave/Scene/Scene.h index a3072b7..0b55132 100644 --- a/Weave/Scene/Scene.h +++ b/Weave/Scene/Scene.h @@ -81,4 +81,5 @@ protected: fBufferObject* shadowdir; DirectionalLight* dirLight; + AmbientLight* ambLight; }; diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index dc8f1e0..9c55e8f 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -15,6 +15,7 @@ uniform sampler2D uColorTexture; uniform sampler2D uPointLightXP; uniform vec4 material; //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3) uniform vec3 dirLightColor; +uniform vec3 AmbientLightColor; float DirLightCalcShadowFactor(vec4 LightSpacePos) { @@ -23,7 +24,7 @@ float DirLightCalcShadowFactor(vec4 LightSpacePos) float z = 0.5f * ProjCoords.z + 0.5f; if (UVCoords.x < 0 || UVCoords.x > 1 || UVCoords.y < 0 || UVCoords.y > 1 || z < 0 || z > 1) - return 0.0f; + return 1.0f; float Depth = texture(uPointLightXP, UVCoords).x; if (Depth < (z + 0.00001f)) @@ -38,8 +39,7 @@ void main() float specularConst = material[3]; vec4 uvColor = texture(uColorTexture, fUVs); - vec3 AmbientLightColor = .5f * vec3(0.1f, 0.1f, 0.1f); - vec3 PointLightColor1 = 2 * vec3(1.0f, 1.0f, 1.0f); + vec3 PointLightColor1 = vec3(2.0f, 2.0f, 2.0f); vec3 cameraVec = normalize(eyePosition); vec3 worldPointLightDir1 = PointLightPosition1 - eyePosition; -- 2.47.3