]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
pointlights (hopefully) almost done
authorLockedLunatic <locked.lunatic@aon.at>
Wed, 13 Apr 2016 15:44:35 +0000 (17:44 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Wed, 13 Apr 2016 15:44:35 +0000 (17:44 +0200)
CGUE2015_Weave.sln
Weave/Graphix/Graphix.cpp
Weave/Graphix/Graphix.h
Weave/Graphix/ViewPort.cpp
Weave/Graphix/ViewPort.h
Weave/Scene/Scene.cpp
shader/shadowmapDir_FS.hlsl [new file with mode: 0644]
shader/shadowmapDir_VS.hlsl [new file with mode: 0644]

index e715e71ecd277edfc4f73eabef700200331ab73c..6e1ae8e364ffcb29039466e81b355d7838e80987 100644 (file)
@@ -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
index d0b064efd3f1b52e173fbf796d92ece39ac05e1c..a3118c9b111dd99b851a3ba484b70d06ff52a421 100644 (file)
@@ -146,6 +146,7 @@ void Graphix::init()
        glClear(GL_ACCUM_BUFFER_BIT);\r
 \r
        shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl");\r
+       shadow_dir = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl");\r
 }\r
 \r
 void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution)\r
@@ -227,6 +228,7 @@ void Graphix::swap()
 void Graphix::cleanup()\r
 {\r
        delete shader_BBox;\r
+       delete shadow_dir;\r
 \r
        //SDL_SetWindowGrab(sdl_window, SDL_FALSE);\r
 \r
@@ -285,3 +287,4 @@ SDL_GLContext Graphix::sdl_glcontext;
 short Graphix::effects = EF_TRANSPARENCY;\r
 \r
 Shader* Graphix::shader_BBox;\r
+Shader* Graphix::shadow_dir;\r
index bde1f6ad5bb3e8793e8bc3db8d8f1c93f16b74b1..9159d0751134a94c8418154c7c7a9104c5a58425 100644 (file)
@@ -43,6 +43,7 @@ public:
        static unsigned int getGlError();
 
        static Shader* shader_BBox;
+       static Shader* shadow_dir;
 
 private:
 
index 80f68b845297bbc6c923943f5d6943bb768375a3..9f05ecb907c906390a5e233f4270db18d653d584 100644 (file)
@@ -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){
index 1ea35884183d2207cadab831d74ff71c4ad5ee41..fdf8bdff2eecd80f330082c2930b1bab7412c86d 100644 (file)
@@ -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;
 };
 
index 7871ed4515b714790a369a4dc4e9bea55d1f865b..848be43ec1e5a2688eae50e78eb81023385e4a21 100644 (file)
@@ -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 (file)
index 0000000..28d5b58
--- /dev/null
@@ -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 (file)
index 0000000..34001b6
--- /dev/null
@@ -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);
+}