]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Directional Lights sind jetzt fertig:
authorLockedLunatic <locked.lunatic@aon.at>
Tue, 7 Jun 2016 01:23:49 +0000 (03:23 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Tue, 7 Jun 2016 01:23:49 +0000 (03:23 +0200)
PCF fertig
frontface culling für Schatten hinzugefügt
Directional Light bewegt sich mit dem player mit

point lights halb fertig (derzeit auskommentiert, damit es kompiliert)

18 files changed:
CGUE2015_Weave.sln
Weave/Graphix/Lights/DirectionalLight.cpp
Weave/Graphix/Lights/DirectionalLight.h
Weave/Graphix/Lights/PointLight.cpp
Weave/Graphix/Lights/PointLight.h
Weave/Graphix/Shader.cpp
Weave/Graphix/Shader.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/Textures/Texture.h
Weave/Graphix/Textures/dBufferObject.cpp
Weave/Graphix/Textures/tImage.cpp
Weave/Graphix/Textures/tImage.h
Weave/Scene/Scene.cpp
Weave/Scene/Scene.h
shader/basicTexture_VS.hlsl
shader/lightingTexture_FS.hlsl
shader/pointlight_FS.hlsl [new file with mode: 0644]
shader/pointlight_VS.hlsl [new file with mode: 0644]

index f5a4387b50d15b09e381873101e5bf441903c69e..f35b4cfb4d6943d04c97511c1e7ab1a1588065bc 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
@@ -15,6 +15,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\pointlight_FS.hlsl = shader\pointlight_FS.hlsl
+               shader\pointlight_VS.hlsl = shader\pointlight_VS.hlsl
                shader\shadowmapDir_FS.hlsl = shader\shadowmapDir_FS.hlsl
                shader\shadowmapDir_VS.hlsl = shader\shadowmapDir_VS.hlsl
                shader\skyplane_color_FS.hlsl = shader\skyplane_color_FS.hlsl
index 806242ad806d3414c5e1d678514aa1fc68f9ea2e..fafd1d7aa9b80e3d935a3ca1c836b1d3ebaa4a7d 100644 (file)
@@ -2,12 +2,14 @@
 #include "../Shader.h"
 #include "../../GLM.h"
 
-DirectionalLight::DirectionalLight(const vec3& _color, const float _size, const vec3& _direction) :
+DirectionalLight::DirectionalLight(const vec3& _color, const float _size, const vec3& _direction, SceneObject* _player) :
        Light(_color),
        size(_size),
-       direction(normalize(_direction))
+       direction(normalize(_direction)),
+       player(_player)
 {
-       lightview = lookAt(direction, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
+       lightview = lookAt(direction, vec3(0.0f), vec3(0.0f, 1.0f, 0.0f));
+       center = vec3(0.0f);
        proj = scale(vec3(1 / size));
        invproj = scale(vec3(size));
        
@@ -35,12 +37,30 @@ void DirectionalLight::changeDirection(const vec3& _direction)
 {
        direction = normalize(_direction);
 
-       lightview = lookAt(direction, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
+       lightview = lookAt(direction, vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)) * translate(-center);
 }
 
 void DirectionalLight::useLight()
 {
+       center = player->getPosition();
+       lightview = lookAt(direction, vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)) * translate(-center);
+
        Shader::getShader(SH_ACTIVE)->setUniformLocation("uView", lightview);
        Shader::getShader(SH_ACTIVE)->setUniformLocation("uProjection", proj);
        Shader::getShader(SH_ACTIVE)->setUniformLocation("uInvProjection", invproj);
+}
+
+void DirectionalLight::useCenter(SceneObject* _player)
+{
+       player = _player;
+       center = player->getPosition();
+}
+
+void DirectionalLight::updateDirLightView()
+{
+       center = player->getPosition();
+       lightview = lookAt(direction, vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)) * translate(-center);
+
+       Shader::getShader(SH_LIGHTING)->useShader();
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("dirLightView", lightview);
 }
\ No newline at end of file
index 05d6966250c626f2499ce75449dd2c7ec601d48e..a1a5ef89984d9c2a9d87d16d8585819103bf1868 100644 (file)
@@ -3,11 +3,13 @@
 #include "../../GLM.h"
 #include "Light.h"
 
+#include "../../Scene/SceneObject.h"
+
 class DirectionalLight
        : public Light
 {
 public:
-       DirectionalLight(const vec3& _color, const float size, const vec3& _direction);
+       DirectionalLight(const vec3& _color, const float size, const vec3& _direction, SceneObject* _player);
 
        virtual ~DirectionalLight();
 
@@ -17,10 +19,17 @@ public:
 
        void useLight();
 
+       void useCenter(SceneObject* _player);
+
+       void updateDirLightView();
+
 protected:
        float size;
        vec3 direction;
        mat4 lightview;
        mat4 proj;
        mat4 invproj;
+
+       SceneObject* player;
+       vec3 center;
 };
\ No newline at end of file
index a042be5630dc49f47ab4c324b2801b6a6cc65068..f72a3452ebdb9e171d64f428c746bb6c9ad6abb8 100644 (file)
@@ -1,5 +1,7 @@
 #include "PointLight.h"
 #include "../Graphix.h"
+#include "../Shader.h"
+#include "../../GLM.h"
 
 
 
@@ -29,7 +31,14 @@ PointLight::PointLight(const vec3& _position,const vec3& _color) :
        Light(_color),
        position(_position)
 {
-       
+       lightview = mat4(1.0f);
+       proj = glm::perspective(90.0f * (float)M_D2R, 1.0f, zNear, zFar);
+
+       Shader::getShader(SH_LIGHTING)->useShader();
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightPosition", position);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightColor", color);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightView", lightview);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightProj", proj);
 }
 
 PointLight::~PointLight()
@@ -41,3 +50,14 @@ void PointLight::changePosition(const vec3& _position)
 {
        position = _position;
 }
+
+void PointLight::useLight(int i)
+{
+       lightview = lookAt(gCameraDirections[i].Target, position, gCameraDirections[i].Up);
+
+       Shader::getShader(SH_LIGHTING)->useShader();
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightPosition", position);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightColor", color);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightView", lightview);
+       Shader::getShader(SH_ACTIVE)->setUniformLocation("LightProj", proj);
+}
\ No newline at end of file
index 8da602955fe9ed754db1dbc8b48018a0f714a5fb..6f3c797bf0f799ac3ff8f6ce57f0c1dfa4a28713 100644 (file)
@@ -15,6 +15,13 @@ public:
        /*Change Light*/
        virtual void changePosition(const vec3& position);
 
+       void useLight(int i);
+
 protected:
+       float zNear = 0.1f;
+       float zFar = 40.0f;
+
        vec3 position;
+       mat4 lightview;
+       mat4 proj;
 };
\ No newline at end of file
index 5812bd121532e0702b2216a6037eae62342c2566..cf31301c60d177686cd3afc30dd828a1c09d9453 100644 (file)
@@ -6,7 +6,7 @@
 
 using namespace std;
 
-#define SHADER_NUM 7
+#define SHADER_NUM 8
 
 Shader::Shader(string _shader1, string _shader2)
 {
@@ -239,6 +239,7 @@ void Shader::init()
                shList[SH_BLUR] = new Shader("basic_VS.hlsl", "blur_FS.hlsl");
                shList[SH_BLEND] = new Shader("basic_VS.hlsl", "blend_FS.hlsl");
                shList[SH_SHADOWDIR] = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl");
+               shList[SH_POINTLIGHT] = new Shader("pointlight_VS.hlsl", "pointlight_FS.hlsl");
        }
 
        initShader = true;
index 46bcc3064175901089745f11b0582985a3c40459..7358697f7c57d1e07611011aba3a34b66401e3dd 100644 (file)
@@ -16,7 +16,8 @@ enum ShaderTarget {
        SH_LIGHTING = 3,
        SH_BLUR = 4,
        SH_BLEND = 5,
-       SH_SHADOWDIR = 6
+       SH_SHADOWDIR = 6,
+       SH_POINTLIGHT = 7
 }; //Don't forget to resize the shList Array at the begining of shader.cpp!
 
 class Shader
index fd3edd4da1f88f6dd5cf908febe3933fddb03348..bfda1fcfdb7f7c86b59c2309dd2f9775db507ead 100644 (file)
@@ -89,7 +89,7 @@ Texture::operator unsigned int() const
        return handle;
 }
 
-void Texture::bindTexture(unsigned int _width, unsigned int _height)
+void Texture::bindTexture(unsigned int _width, unsigned int _height, bool shadow)
 {
        if (_width != 0 && _height != 0)
        {
@@ -106,9 +106,17 @@ void Texture::bindTexture(unsigned int _width, unsigned int _height)
 
        glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
-       glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-       glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-       //glTexParameteri(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+       if (shadow)
+       {
+               glTexParameteri(texture_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
+               glTexParameteri(texture_target, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
+       }
+       else
+       {
+               glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+               glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+               //glTexParameteri(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+       }
 
        glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
 }
index 14c76f0cb135ba8042f8ecaec6c0ced6e68154ac..0f22aa8ae6dcfbf53a9a0b3bb7743ea7b70e6427 100644 (file)
@@ -21,7 +21,7 @@ enum bindTarget {
        uPLightYP = 4,
        uPLightYM = 5,
        uPLightZP = 6,
-       uPLightZM = 7,
+       uPLightZM = 7
 }; //Don't forget to assign the correct name in bindTargets at the beginning of Texture.cpp!
 
 class Texture
@@ -33,7 +33,7 @@ public:
        Texture(texTarget = texT_COLORBUFFER);
        ~Texture();
 
-       virtual void bindTexture(unsigned int width = 0, unsigned int height = 0);
+       virtual void bindTexture(unsigned int width = 0, unsigned int height = 0, bool shadow=false);
        virtual void unbindTexture();
        virtual void useTexture(bindTarget = uCOLOR) const;
 
index 962360294c5e44d6354bafe0f3d5390ede5d166a..02099719ec259a3a906bfb55fed737d6460d7a6a 100644 (file)
@@ -47,7 +47,7 @@ void dBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
        glBindFramebuffer(buffer_target, handle);
 
        /*Bind Texture Buffers (RENDER)*/
-       textures->bindTexture(_width, _height);
+       textures->bindTexture(_width, _height, true);
        glFramebufferTexture2D(buffer_target, GL_DEPTH_ATTACHMENT, textures->getTTarget(), *textures, 0);
 
        glDrawBuffer(GL_NONE);
index ea09699a26ed34fa0d7b65773156ddd4a2ca2649..f2304225be9708b9fed2c5e4225916b8b30a0aff 100644 (file)
@@ -37,7 +37,7 @@ tImage::~tImage()
        FreeImage_Unload((FIBITMAP*)data);
 }
 
-void tImage::bindTexture(unsigned int _width, unsigned int _height)
+void tImage::bindTexture(unsigned int _width, unsigned int _height, bool shadow)
 {      
        
        Texture::bindTexture();
index dce65bfa2d414f2991ddfc29b4f07998b300eba4..2eade550672ebd2c6f0599163d379d1e56604245 100644 (file)
@@ -15,7 +15,7 @@ public:
        tImage(const std::string& path, const vec4& material);
        virtual ~tImage();
 
-       virtual void bindTexture(unsigned int width = 0, unsigned int height = 0) override;
+       virtual void bindTexture(unsigned int width = 0, unsigned int height = 0, bool shadow = false) override;
        virtual void useTexture(bindTarget = uCOLOR) const override;
 
        operator std::string() const;
index e30e9ea0824f91e51006078331174fbe92a6af8c..6645c6a5c8d64a1b41975b7b98d7849ffce92d95 100644 (file)
@@ -42,9 +42,12 @@ lookat(_lookat)
 {
        //Lights
        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(0.4f), 20.0f, vec3(1.f, -0.5f, -0.5f), lookat);
        //dirLight = new DirectionalLight(vec3(1.2f), 0.2f, vec3(0.0f, 0.0f, -1.0f));
 
+       //pointlights.push_back(new PointLight(vec3(0.0f, 1.0f, 0.0f), vec3(2.0f)));
+       //pointlights.push_back(new PointLight(vec3(-10.0f, 1.0f, 5.0f), vec3(1.0f)));
+
 
        currenttime = 0.0f;
        if (lookat != nullptr)
@@ -106,6 +109,10 @@ Scene::~Scene()
                delete (*i);
        }
        timestamps.empty();
+       for (auto i = pointlights.begin(); i != pointlights.end(); ++i)
+       {
+               delete (*i);
+       }
 
        //Bullet
        delete bt_collision_world;
@@ -236,19 +243,31 @@ void Scene::draw() const
                return;
        }
 
+
+
        //Directional Light Shadow
+       glCullFace(GL_FRONT);
+       glEnable(GL_POLYGON_OFFSET_FILL);
+       glPolygonOffset(4.f, 0.f);
+
        shadowdir->useBuffer();
        glClear(GL_DEPTH_BUFFER_BIT);
        Shader::getShader(SH_SHADOWDIR)->useShader();
        dirLight->useLight();
        drawSceneObjects(DRAW_Model,false);
+
+
+       glCullFace(GL_BACK);
+       glDisable(GL_POLYGON_OFFSET_FILL);
+
        camera.useCamera();
        render->useBuffer();
+       dirLight->updateDirLightView();
        Shader::getShader(SH_LIGHTING)->useShader();
        fBufferObject::clearBuffer();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        shadowdir->getTexture()->useTexture(uPLightXP);
-
+       
 
 
        /* DRAW SCENE */
@@ -271,6 +290,47 @@ void Scene::draw() const
        drawSceneObjects();
 
 
+       //Pointlights & their shadows
+       //for (auto i = pointlights.begin(); i != pointlights.end(); ++i)
+       //{
+       //      postRender->useBuffer();
+       //      glClear(GL_COLOR_BUFFER_BIT);
+       //      Shader::getShader(SH_POINTLIGHT)->useShader();
+       //      render->getTexture()->useTexture();
+       //      for (int j = 0; j < 6; j++)
+       //      {
+       //              shadowdir->useBuffer();
+       //              glClear(GL_DEPTH_BUFFER_BIT);
+       //              Shader::getShader(SH_SHADOWDIR)->useShader();
+       //              (*i)->useLight(j);
+
+       //              drawSceneObjects(DRAW_Model, false);
+
+       //              postRender->useBuffer();
+       //              Shader::getShader(SH_POINTLIGHT)->useShader();
+       //              //shadowdir->getTexture()->useTexture(uPLightXP + j);
+       //              switch (j)
+       //              {
+       //              case 0: shadowdir->getTexture()->useTexture(uPLightXP);
+       //              case 1: shadowdir->getTexture()->useTexture(uPLightXM);
+       //              case 2: shadowdir->getTexture()->useTexture(uPLightYP);
+       //              case 3: shadowdir->getTexture()->useTexture(uPLightYM);
+       //              case 4: shadowdir->getTexture()->useTexture(uPLightZP);
+       //              case 5: shadowdir->getTexture()->useTexture(uPLightZM);
+       //              }
+       //      }
+
+       //      camera.useCamera();
+       //      fBufferObject::clearBuffer();
+       //      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       //      drawSceneObjects();
+       //      render->useBuffer();
+       //      //TODO copy the texture from postrender to render
+       //      //render->getTexture()->
+       //}
+
+
        GLboolean horizontal = true, firstit = true;
        if (Graphix::testEffect(EF_BLOOM))
        {
@@ -374,6 +434,8 @@ list<SceneObject*>* Scene::getSceneObjects()
 void Scene::setLookAt(SceneObject* _lookat)
 {
        lookat = _lookat;
+
+       dirLight->useCenter(_lookat);
 }
 
 //ViewPort& Scene::getViewport()
index 5693503c541ef05016aedb9e5916177ab8f84e5f..96abd01ab5a32cc6c709a27b593b45719d822bb2 100644 (file)
@@ -82,4 +82,5 @@ protected:
 
        DirectionalLight* dirLight;
        AmbientLight* ambLight;
+       std::list<PointLight*> pointlights;
 };
index de9ea7bfe156b0e0e937799bf3c75e6d05b5c4d8..86752b1eecee26bef9c1f36fb66109a513f6e8cb 100644 (file)
@@ -26,7 +26,9 @@ void main()
        PointLightPosition1 = (uView * vec4(0.0f, 1.0f, 0.0f, 1.f)).xyz;
        DirectionalLightDirection1 = normalize((uView * vec4(DirectionalLightDirection, 0.0f)).xyz);
 
-       DirLightSpacePos = dirLightProj * dirLightView * uModel * vec4(aPosition, 1.0);
+       mat4 L = mat4(0.5f);
+       L[3] = vec4(0.5f, 0.5f, 0.5f, 1.0f);
+       DirLightSpacePos = L * dirLightProj * dirLightView * uModel * vec4(aPosition, 1.0);
 
 
        fUVs = aUV;
@@ -40,6 +42,5 @@ void main()
        gl_Position = uProjection * vec4(eyePosition,1.f);
 
 
-       //fPosition = aPosition;
        //gl_Position = vec4(aPosition, 1.0f);
 }
\ No newline at end of file
index 9c55e8ff7df42df8647083332b01b26581d6a2ef..f6921f595931f7d1e45f3b839182237b09143868 100644 (file)
@@ -12,25 +12,18 @@ in vec4 DirLightSpacePos;
 layout(location = 0) out vec4 FragColor;
 
 uniform sampler2D uColorTexture;
-uniform sampler2D uPointLightXP;
+uniform sampler2DShadow 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)
 {
-       vec3 ProjCoords = LightSpacePos.xyz / LightSpacePos.w;
-       vec2 UVCoords = vec2(0.5f * ProjCoords.x + 0.5f, 0.5f * ProjCoords.y + 0.5f);
-       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)
+       vec3 pos = LightSpacePos.xyz / LightSpacePos.w;
+       if (pos.x < 0 || pos.x > 1 || pos.y < 0 || pos.y > 1 || pos.z < 0 || pos.z > 1)
                return 1.0f;
+       return textureProj(uPointLightXP, LightSpacePos);
 
-       float Depth = texture(uPointLightXP, UVCoords).x;
-       if (Depth < (z + 0.00001f))
-               return 0.0f;
-       else
-               return 1.0f;
 }
  
 void main()
@@ -71,6 +64,6 @@ void main()
        //FragColor = vec4(uvColor, 1.0);
        
        //vec3 uvColor = vec3(1.0 - (1.0 - texture(uPointLightXP, fUVs).x) * 25.0);
-       //vec3 uvColor = vec3(texture(uPointLightXP, vec2(fPosition.x / 2 + 0.5f, fPosition.y / 2 + 0.5f)).x);
+       //vec3 uvColor = vec3(textureProj(uPointLightXP, DirLightSpacePos));
        //FragColor = vec4(uvColor, 1.0);
 }
\ No newline at end of file
diff --git a/shader/pointlight_FS.hlsl b/shader/pointlight_FS.hlsl
new file mode 100644 (file)
index 0000000..acd5fcc
--- /dev/null
@@ -0,0 +1,63 @@
+//Fragment Shader
+#version 330
+in vec3 eyePosition, worldNormal;
+in vec2 fUVs;
+
+//in vec3 fPosition;
+
+
+layout(location = 0) out vec4 FragColor;
+
+uniform sampler2D uColorTexture;
+uniform sampler2DShadow uPointLightXP;
+uniform vec4 material;                                 //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3)
+
+uniform vec3 LightColor;
+uniform vec3 LightPosition;
+
+float DirLightCalcShadowFactor(vec4 LightSpacePos)
+{
+       return textureProj(uPointLightXP, LightSpacePos);
+
+
+       /*vec3 ProjCoords = LightSpacePos.xyz / LightSpacePos.w;
+       vec2 UVCoords = vec2(0.5f * ProjCoords.x + 0.5f, 0.5f * ProjCoords.y + 0.5f);
+       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 1.0f;
+
+       float Depth = texture(uPointLightXP, UVCoords).x;
+       if (Depth < (z + 0.00001f))
+               return 0.0f;
+       else
+               return 1.0f;*/
+}
+void main()
+{
+       float specularConst = material[3];
+       vec4 uvColor = texture(uColorTexture, fUVs);
+
+       vec3 cameraVec = normalize(eyePosition);
+       vec3 worldPointLightDir = LightPosition - eyePosition;
+       vec3 PointLightDirection = normalize(worldPointLightDir);
+
+       float SpecularCosPoint = clamp(dot(cameraVec, normalize(reflect(PointLightDirection, worldNormal))), 0, 1);
+       float cosThetaPoint1 = clamp(dot(worldNormal, PointLightDirection), 0, 1);
+
+       float squaredist = worldPointLightDir.x * worldPointLightDir.x + worldPointLightDir.y * worldPointLightDir.y + worldPointLightDir.z * worldPointLightDir.z;
+
+
+       FragColor = vec4(LightColor * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint, specularConst)) / squaredist, uvColor.a);
+       
+       //FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f);
+       //FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f);
+
+       //vec3 uvColor = texture(uColorTexture, fUVs).rgb;
+       //FragColor = vec4(uvColor, 1.0);
+       
+       //vec3 uvColor = vec3(1.0 - (1.0 - texture(uPointLightXP, fUVs).x) * 25.0);
+       //vec3 uvColor = vec3(texture(uPointLightXP, vec2(fPosition.x / 2 + 0.5f, fPosition.y / 2 + 0.5f)).x);
+       //FragColor = vec4(uvColor, 1.0);
+}
\ No newline at end of file
diff --git a/shader/pointlight_VS.hlsl b/shader/pointlight_VS.hlsl
new file mode 100644 (file)
index 0000000..6a33512
--- /dev/null
@@ -0,0 +1,32 @@
+//Vertex Shader
+#version 330 core
+
+in vec3 aNormal, aPosition;
+in vec2 aUV;
+
+out vec3 eyePosition, worldNormal;
+out vec2 fUVs;
+
+//out vec3 fPosition;
+
+
+//uniform vec3 PointLightPosition, DirectionalLightDirection1;
+uniform mat4 uProjection, uView, uModel=mat4(1.f);
+
+
+void main()
+{
+       fUVs = aUV;
+       eyePosition = (uView * uModel * vec4(aPosition, 1.f)).xyz;
+       mat3 scale = transpose(mat3(uModel))*mat3(uModel);
+       vec3 Normal;
+       for (int i = 0; i < 3; ++i)
+               Normal[i] = 1/(scale[i][i])*aNormal[i];
+       worldNormal = normalize((uView * uModel * vec4(Normal, 0.0f)).xyz);
+
+       gl_Position = uProjection * vec4(eyePosition,1.f);
+
+
+       //fPosition = aPosition;
+       //gl_Position = vec4(aPosition, 1.0f);
+}
\ No newline at end of file