From: LockedLunatic Date: Tue, 7 Jun 2016 01:23:49 +0000 (+0200) Subject: Directional Lights sind jetzt fertig: X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=acb63d09fade34f984b7bf5c2b384dee920e605d;p=cgue_weave.git Directional Lights sind jetzt fertig: 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) --- diff --git a/CGUE2015_Weave.sln b/CGUE2015_Weave.sln index f5a4387..f35b4cf 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 @@ -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 diff --git a/Weave/Graphix/Lights/DirectionalLight.cpp b/Weave/Graphix/Lights/DirectionalLight.cpp index 806242a..fafd1d7 100644 --- a/Weave/Graphix/Lights/DirectionalLight.cpp +++ b/Weave/Graphix/Lights/DirectionalLight.cpp @@ -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 diff --git a/Weave/Graphix/Lights/DirectionalLight.h b/Weave/Graphix/Lights/DirectionalLight.h index 05d6966..a1a5ef8 100644 --- a/Weave/Graphix/Lights/DirectionalLight.h +++ b/Weave/Graphix/Lights/DirectionalLight.h @@ -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 diff --git a/Weave/Graphix/Lights/PointLight.cpp b/Weave/Graphix/Lights/PointLight.cpp index a042be5..f72a345 100644 --- a/Weave/Graphix/Lights/PointLight.cpp +++ b/Weave/Graphix/Lights/PointLight.cpp @@ -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 diff --git a/Weave/Graphix/Lights/PointLight.h b/Weave/Graphix/Lights/PointLight.h index 8da6029..6f3c797 100644 --- a/Weave/Graphix/Lights/PointLight.h +++ b/Weave/Graphix/Lights/PointLight.h @@ -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 diff --git a/Weave/Graphix/Shader.cpp b/Weave/Graphix/Shader.cpp index 5812bd1..cf31301 100644 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@ -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; diff --git a/Weave/Graphix/Shader.h b/Weave/Graphix/Shader.h index 46bcc30..7358697 100644 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@ -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 diff --git a/Weave/Graphix/Textures/Texture.cpp b/Weave/Graphix/Textures/Texture.cpp index fd3edd4..bfda1fc 100644 --- a/Weave/Graphix/Textures/Texture.cpp +++ b/Weave/Graphix/Textures/Texture.cpp @@ -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); } diff --git a/Weave/Graphix/Textures/Texture.h b/Weave/Graphix/Textures/Texture.h index 14c76f0..0f22aa8 100644 --- a/Weave/Graphix/Textures/Texture.h +++ b/Weave/Graphix/Textures/Texture.h @@ -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; diff --git a/Weave/Graphix/Textures/dBufferObject.cpp b/Weave/Graphix/Textures/dBufferObject.cpp index 9623602..0209971 100644 --- a/Weave/Graphix/Textures/dBufferObject.cpp +++ b/Weave/Graphix/Textures/dBufferObject.cpp @@ -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); diff --git a/Weave/Graphix/Textures/tImage.cpp b/Weave/Graphix/Textures/tImage.cpp index ea09699..f230422 100644 --- a/Weave/Graphix/Textures/tImage.cpp +++ b/Weave/Graphix/Textures/tImage.cpp @@ -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(); diff --git a/Weave/Graphix/Textures/tImage.h b/Weave/Graphix/Textures/tImage.h index dce65bf..2eade55 100644 --- a/Weave/Graphix/Textures/tImage.h +++ b/Weave/Graphix/Textures/tImage.h @@ -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; diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index e30e9ea..6645c6a 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -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* Scene::getSceneObjects() void Scene::setLookAt(SceneObject* _lookat) { lookat = _lookat; + + dirLight->useCenter(_lookat); } //ViewPort& Scene::getViewport() diff --git a/Weave/Scene/Scene.h b/Weave/Scene/Scene.h index 5693503..96abd01 100644 --- a/Weave/Scene/Scene.h +++ b/Weave/Scene/Scene.h @@ -82,4 +82,5 @@ protected: DirectionalLight* dirLight; AmbientLight* ambLight; + std::list pointlights; }; diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index de9ea7b..86752b1 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -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 diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 9c55e8f..f6921f5 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -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 index 0000000..acd5fcc --- /dev/null +++ b/shader/pointlight_FS.hlsl @@ -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 index 0000000..6a33512 --- /dev/null +++ b/shader/pointlight_VS.hlsl @@ -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