]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
mid shader change
authorLockedLunatic <locked.lunatic@aon.at>
Sat, 9 May 2015 19:41:35 +0000 (21:41 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Sat, 9 May 2015 19:41:35 +0000 (21:41 +0200)
Weave/Graphix/ViewPort.cpp
Weave/Graphix/ViewPort.h
shader/basicTexture_VS.hlsl
shader/lightingTexture_FS.hlsl

index d252aa0780215d31ff55360668a4c7bd5049ef2f..ebb112785302aadb9e8713884f7c7ea4fda03563 100644 (file)
@@ -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)));
        }
 
 }
index fdb0a4ecea16c1c31d7291c5385dfac40a4e577e..baf7c328f0f97c9592bbf55aa0077cc969e05242 100644 (file)
@@ -34,6 +34,8 @@ protected:
        unsigned int xpos;
        unsigned int ypos;
 
+       vec3 cameraPosition;
+
        mat4 projection;
        mat4 view;
 
index 370d418cd4f52a265c50c1db7f099f6ecf81ebba..26f907a8b1a4e75ed0faf4ce17d7ff173043bd75 100644 (file)
@@ -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
index 10ec95f92b8359e93819735c26e7b541e9d04dae..8a2599fe301254ce09277bbf892b0e2330b68384 100644 (file)
@@ -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;