From e8ba1c0bae3aa1788cd9132179d618d1ba30aecd Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Sat, 9 May 2015 21:41:35 +0200 Subject: [PATCH] mid shader change --- Weave/Graphix/ViewPort.cpp | 9 +++++++-- Weave/Graphix/ViewPort.h | 2 ++ shader/basicTexture_VS.hlsl | 22 ++++++---------------- shader/lightingTexture_FS.hlsl | 11 +++++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index d252aa0..ebb1127 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -18,7 +18,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), + cameraPosition(vec3(0.0f, 0.0f, -2.0f)) { rotateView(0.f, -.5f); } @@ -65,6 +66,10 @@ void ViewPort::bindView(Shader* shader, vec3 pos) const{ tmp = shader->getUniformLocation("uView"); if (tmp >= 0) glUniformMatrix4fv(tmp, 1, false, value_ptr(translate(view,-pos))); + + tmp = shader->getUniformLocation("cameraPos"); + if (tmp >= 0) + glUniform3fv(tmp, 1, value_ptr(cameraPosition)); } void ViewPort::rotateView(float angle_x, float angle_y){ @@ -82,7 +87,7 @@ void ViewPort::rotateView(float angle_x, float angle_y){ view_angle_y = VIEW_BOT_LIM; view = translate(vec3(0.f, 0.f, -view_dist))*rotate(view_angle_y *(float)M_PI_2, vec3(1.f, 0.f, 0.f))*rotate(view_angle_x * (float)M_PI_2, vec3(0.f, 1.f, 0.f)); - + cameraPosition = vec3(((rotate(view_angle_x * (float)M_PI_2, vec3(0.f, 1.f, 0.f)) * rotate(view_angle_y *(float)M_PI_2, vec3(1.f, 0.f, 0.f))) * vec4(0.f, 0.f, view_dist, 1.0f))); } } diff --git a/Weave/Graphix/ViewPort.h b/Weave/Graphix/ViewPort.h index fdb0a4e..baf7c32 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -34,6 +34,8 @@ protected: unsigned int xpos; unsigned int ypos; + vec3 cameraPosition; + mat4 projection; mat4 view; diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index 370d418..26f907a 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -2,40 +2,30 @@ #version 330 in vec3 aNormal, aPosition; -//in vec3 lightPosition in vec2 aUV; -out vec3 worldNormal, worldLightPoint1, DirectionalLightDirection1;// , cameraVec; +out vec3 worldNormal, worldPointLightDir1, DirectionalLightDirection1, cameraVec; out vec2 fUVs; -out float SpecularCosPoint1, SpecularCosDirection1; +uniform vec3 cameraPos; +//uniform vec3 PointLightPosition1, DirectionalLightDirection1; uniform mat4 uProjection, uView, uModel; -//uniform vec3 cameraPos; + uniform int uEnableBloom = 1; uniform int uEnableTransp = 1; void main() { - //for every point light source define PointLightPosition and SpecularCos - //for every directional light source define Direction and SpecularCos - //everything else is in the Fragment Shader - vec3 PointLightPosition1 = vec3(0.0f, 1.0f, 0.0f); vec3 DirectionalLightDirection1 = normalize(vec3(-1.0f, -1.0f, -1.0f)); fUVs = aUV; vec4 world_Position = uModel * vec4(aPosition, 1); - worldLightPoint1 = PointLightPosition1 - world_Position.xyz; + worldPointLightDir1 = PointLightPosition1 - world_Position.xyz; gl_Position = uProjection * uView * world_Position; worldNormal = (uModel * vec4(aNormal, 0.0f)).xyz; - - SpecularCosPoint1 = clamp(dot(vec3(0.0f, 0.0f, -1.0f), normalize((uProjection * uView * vec4(reflect(PointLightPosition1 - world_Position.xyz, worldNormal), 0.0f)).xyz)), 0, 1); - SpecularCosDirection1 = clamp(dot(vec3(0.0f, 0.0f, -1.0f), normalize((uProjection * uView * vec4(reflect(-DirectionalLightDirection1, worldNormal), 0.0f)).xyz)), 0, 1); - //cameraVec = normalize(cameraPos - world_Position.xyz); - - - //worldnormal = vec3(SpecularCos, SpecularCos, SpecularCos); + cameraVec = normalize(cameraPos - world_Position.xyz); } \ No newline at end of file diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 10ec95f..8a2599f 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -1,8 +1,7 @@ //Fragment Shader #version 330 -in vec3 worldNormal, worldLightPoint1, DirectionalLightDirection1;// , cameraVec; +in vec3 worldNormal, worldPointLightDir1, DirectionalLightDirection1, cameraVec; in vec2 fUVs; -in float visNormal, SpecularCosPoint1, SpecularCosDirection1; out vec4 FragmentColor; @@ -19,18 +18,22 @@ void main() vec3 AmbientLightColor = 0 * vec3(0.2f, 0.2f, 0.2f); - vec3 PointLightDirection1 = normalize(worldLightPoint1); + vec3 PointLightDirection1 = normalize(worldPointLightDir1); vec3 PointLightColor1 = 1 * vec3(1.0f, 1.0f, 1.0f); vec3 DirectionalLightColor1 = 0 * vec3(0.6f, 0.6f, 0.6f); + float SpecularCosPoint1 = clamp(dot(cameraVec, normalize(reflect(PointLightDirection1, normal))), 0, 1); + float SpecularCosDirection1 = clamp(dot(cameraVec, normalize(reflect(-DirectionalLightDirection1, normal))), 0, 1); + + float cosThetaPoint1 = clamp(dot(normal, PointLightDirection1), 0, 1); float cosThetaDirection1 = clamp(dot(normal, DirectionalLightDirection1), 0, 1); //float cosThetaPoint1 = clamp(dot(cameraVec, PointLightDirection1), 0, 1); //float cosThetaDirection1 = clamp(dot(cameraVec, DirectionalLightDirection1), 0, 1); - float squaredist1 = worldLightPoint1.x * worldLightPoint1.x + worldLightPoint1.y * worldLightPoint1.y + worldLightPoint1.z * worldLightPoint1.z; + float squaredist1 = worldPointLightDir1.x * worldPointLightDir1.x + worldPointLightDir1.y * worldPointLightDir1.y + worldPointLightDir1.z * worldPointLightDir1.z; //if (uvColor.a < 0.3) // discard; -- 2.47.3