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
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
#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));
{
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
#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();
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
#include "PointLight.h"
#include "../Graphix.h"
+#include "../Shader.h"
+#include "../../GLM.h"
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()
{
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
/*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
using namespace std;
-#define SHADER_NUM 7
+#define SHADER_NUM 8
Shader::Shader(string _shader1, string _shader2)
{
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;
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
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)
{
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);
}
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
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;
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);
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();
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;
{
//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)
delete (*i);
}
timestamps.empty();
+ for (auto i = pointlights.begin(); i != pointlights.end(); ++i)
+ {
+ delete (*i);
+ }
//Bullet
delete bt_collision_world;
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 */
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))
{
void Scene::setLookAt(SceneObject* _lookat)
{
lookat = _lookat;
+
+ dirLight->useCenter(_lookat);
}
//ViewPort& Scene::getViewport()
DirectionalLight* dirLight;
AmbientLight* ambLight;
+ std::list<PointLight*> pointlights;
};
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;
gl_Position = uProjection * vec4(eyePosition,1.f);
- //fPosition = aPosition;
//gl_Position = vec4(aPosition, 1.0f);
}
\ No newline at end of file
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()
//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
--- /dev/null
+//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
--- /dev/null
+//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