From d68f2f7925fcb03b1f4a6b52ae35768b217dc562 Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Sun, 10 May 2015 01:16:07 +0200 Subject: [PATCH] shader stuff --- Weave/Game.cpp | 2 +- Weave/Graphix/ViewPort.cpp | 8 +------- Weave/Graphix/ViewPort.h | 2 -- shader/basicTexture_VS.hlsl | 8 ++++---- shader/lightingTexture_FS.hlsl | 13 ++++++------- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 0a6af33..861cf15 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -47,7 +47,7 @@ Game::Game() : playing(true) Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl"); // load LVL - SceneObject* tmp_world = new SceneObject(shader1, scale(3.f * vec3(1.f, .32f, 1.f)), vec4(4.0f, 1.0f, 1.0f, 2.0f), "level_test.dae", "model_levelTest_2D.png"); + SceneObject* tmp_world = new SceneObject(shader1, scale(vec3(3.f)), vec4(4.0f, 1.0f, 1.0f, 2.0f), "level_test.dae", "model_levelTest_2D.png"); tmp_world->ignore = true; current_world->addObject(tmp_world); diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index ebb1127..affc90a 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -18,8 +18,7 @@ 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), - cameraPosition(vec3(0.0f, 0.0f, -2.0f)) + view(0.f) { rotateView(0.f, -.5f); } @@ -66,10 +65,6 @@ 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){ @@ -87,7 +82,6 @@ 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 baf7c32..fdb0a4e 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -34,8 +34,6 @@ 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 4e614d9..a46f53e 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -17,16 +17,16 @@ uniform int uEnableTransp = 1; void main() { - PointLightPosition1 = (uView * vec4(0.0f, 1.0f, 0.0f, 0.f)).xyz; + PointLightPosition1 = (uView * vec4(0.0f, 1.0f, 0.0f, 1.f)).xyz; DirectionalLightDirection1 = normalize((uView * vec4(-1.f, -0.f, -0.f, 0.f)).xyz); fUVs = aUV; - vec4 world_Position = uView * uModel * vec4(aPosition, 1); + world_Position = (uView * uModel * vec4(aPosition, 1)).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((uModel * vec4(Normal, 0.0f)).xyz); + worldNormal = normalize((uView * uModel * vec4(Normal, 0.0f)).xyz); - gl_Position = uProjection * world_Position; + gl_Position = uProjection * vec4(world_Position, 1); } \ No newline at end of file diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index e281291..c394fe2 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -7,7 +7,6 @@ in vec3 PointLightPosition1, DirectionalLightDirection1; out vec4 FragmentColor; -uniform vec3 cameraPos; uniform sampler2D uColorTexture; uniform vec4 material; //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3) @@ -19,16 +18,16 @@ void main() vec3 AmbientLightColor = 0 * vec3(0.2f, 0.2f, 0.2f); vec3 PointLightColor1 = 0 * vec3(1.0f, 1.0f, 1.0f); - vec3 DirectionalLightColor1 = 1 * vec3(0.6f, 0.6f, 0.6f); + vec3 DirectionalLightColor1 = 10 * vec3(0.6f, 0.6f, 0.6f); - vec3 cameraVec = normalize(-world_Position.xyz); - vec3 worldPointLightDir1 = PointLightPosition1 - world_Position.xyz; + vec3 cameraVec = normalize(-world_Position); + vec3 worldPointLightDir1 = PointLightPosition1 - world_Position; vec3 PointLightDirection1 = normalize(worldPointLightDir1); float SpecularCosPoint1 = clamp(dot(cameraVec, normalize(reflect(PointLightDirection1, worldNormal))), 0, 1); float SpecularCosDirection1 = clamp(dot(cameraVec, -normalize(reflect(-DirectionalLightDirection1, worldNormal))), 0, 1); - SpecularCosPoint1 = 0; + //SpecularCosPoint1 = 0; //SpecularCosDirection1 = 0; @@ -46,9 +45,9 @@ void main() ), uvColor.a); - FragmentColor = vec4((normalize(worldNormal)+1)/2, 1.0f); + //FragmentColor = vec4((normalize(worldNormal)+1)/2, 1.0f); //FragmentColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f); //vec3 uvColor = texture(uColorTexture, fUVs).rgb; - //FragmentColor = vec4(uvColor, 1.0); + FragmentColor = vec4(SpecularCosDirection1, SpecularCosDirection1, SpecularCosDirection1, 1.0); } -- 2.47.3