From: LockedLunatic Date: Wed, 13 Apr 2016 15:44:35 +0000 (+0200) Subject: pointlights (hopefully) almost done X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=f939c0164cee1dec4a43b5460e9ff2bedbc03d41;p=cgue_weave.git pointlights (hopefully) almost done --- diff --git a/CGUE2015_Weave.sln b/CGUE2015_Weave.sln index e715e71..6e1ae8e 100644 --- a/CGUE2015_Weave.sln +++ b/CGUE2015_Weave.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25029.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Weave", "Weave\Weave.vcxproj", "{A2F0B06D-880C-4B90-9D4B-8B174418E1BE}" EndProject @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shader", "shader", "{75179E shader\blur_FS.hlsl = shader\blur_FS.hlsl shader\lightingTexture_FS.hlsl = shader\lightingTexture_FS.hlsl shader\perspective_VS.hlsl = shader\perspective_VS.hlsl + shader\shadowmapDir_FS.hlsl = shader\shadowmapDir_FS.hlsl + shader\shadowmapDir_VS.hlsl = shader\shadowmapDir_VS.hlsl shader\skybox_VS.hlsl = shader\skybox_VS.hlsl shader\skyplane_color_FS.hlsl = shader\skyplane_color_FS.hlsl shader\skyplane_FS.hlsl = shader\skyplane_FS.hlsl diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index d0b064e..a3118c9 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -146,6 +146,7 @@ void Graphix::init() glClear(GL_ACCUM_BUFFER_BIT); shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); + shadow_dir = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl"); } void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution) @@ -227,6 +228,7 @@ void Graphix::swap() void Graphix::cleanup() { delete shader_BBox; + delete shadow_dir; //SDL_SetWindowGrab(sdl_window, SDL_FALSE); @@ -285,3 +287,4 @@ SDL_GLContext Graphix::sdl_glcontext; short Graphix::effects = EF_TRANSPARENCY; Shader* Graphix::shader_BBox; +Shader* Graphix::shadow_dir; diff --git a/Weave/Graphix/Graphix.h b/Weave/Graphix/Graphix.h index bde1f6a..9159d07 100644 --- a/Weave/Graphix/Graphix.h +++ b/Weave/Graphix/Graphix.h @@ -43,6 +43,7 @@ public: static unsigned int getGlError(); static Shader* shader_BBox; + static Shader* shadow_dir; private: diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index 80f68b8..9f05ecb 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -21,7 +21,8 @@ ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsign view_angle_x(0), view_angle_y(0), view_dist(2), - view(0.f) + view(0.f), + shadow_dist(2) { rotateView(0.f, -.5f); } @@ -70,6 +71,24 @@ void ViewPort::bindView(Shader* shader, vec3 pos) const{ glUniformMatrix4fv(tmp, 1, false, value_ptr(translate(view,-pos))); } +void ViewPort::bindViewShadowDir(Shader* shader) const { + shader->useShader(); + int tmp = -1; + + tmp = shader->getUniformLocation("uProjection"); + if (tmp >= 0) + glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(1 / shadow_dist))); + + tmp = shader->getUniformLocation("uInvProjection"); + if (tmp >= 0) + glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(shadow_dist))); + + tmp = shader->getUniformLocation("uView"); + if (tmp >= 0) + //TODO the real thing + glUniformMatrix4fv(tmp, 1, false, value_ptr(view)); +} + void ViewPort::rotateView(float angle_x, float angle_y){ if (angle_y || angle_x){ diff --git a/Weave/Graphix/ViewPort.h b/Weave/Graphix/ViewPort.h index 1ea3588..fdf8bdf 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -17,6 +17,7 @@ public: void bindView(Shader* shader) const; void bindView(Shader* shader, vec3 lookat) const; + void bindViewShadowDir(Shader* shader) const; void rotateView(float angle_x, float angle_y); vec3 rotateDirection(const vec3 & direction) const; @@ -45,5 +46,6 @@ protected: float view_angle_x; float view_angle_y; + float shadow_dist; }; diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 7871ed4..848be43 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -165,6 +165,8 @@ void Scene::draw() const { viewPort.useViewPort(); + //Directional Light Shadow + viewPort.bindViewShadowDir(Graphix::shadow_dir); //Skybox viewPort.bindView(SkyBox.getShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f)); //BBox diff --git a/shader/shadowmapDir_FS.hlsl b/shader/shadowmapDir_FS.hlsl new file mode 100644 index 0000000..28d5b58 --- /dev/null +++ b/shader/shadowmapDir_FS.hlsl @@ -0,0 +1,8 @@ +//Fragment Shader +#version 330 + +void main() +{ + gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); +} + diff --git a/shader/shadowmapDir_VS.hlsl b/shader/shadowmapDir_VS.hlsl new file mode 100644 index 0000000..34001b6 --- /dev/null +++ b/shader/shadowmapDir_VS.hlsl @@ -0,0 +1,12 @@ +//Vertex Shader +#version 330 + +in vec3 aNormal, aPosition; +in vec2 aUV; + +uniform mat4 uProjection, uView, uModel = mat4(1.f); + +void main() +{ + gl_Position = uProjection * uView * uModel * vec4(aPosition, 1); +}