]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
back to eye positions
authorPeter Schaefer <schaeferpm@gmail.com>
Sat, 9 May 2015 23:00:30 +0000 (01:00 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Sat, 9 May 2015 23:00:30 +0000 (01:00 +0200)
shader/basicTexture_VS.hlsl
shader/lightingTexture_FS.hlsl

index 2b83c337a95683e2ef6534041616cefa8204f5b2..4e614d9812741aea9de4849ebde0c234df03525e 100644 (file)
@@ -7,22 +7,26 @@ in vec2 aUV;
 out vec3 world_Position, worldNormal;
 out vec2 fUVs;
 
+out vec3  PointLightPosition1, DirectionalLightDirection1;
+
 //uniform vec3 PointLightPosition1, DirectionalLightDirection1;
 uniform mat4 uProjection, uView, uModel;
 
-
 uniform int uEnableBloom = 1;
 uniform int uEnableTransp = 1;
 
 void main()
 {
+       PointLightPosition1 = (uView * vec4(0.0f, 1.0f, 0.0f, 0.f)).xyz;
+       DirectionalLightDirection1 = normalize((uView * vec4(-1.f, -0.f, -0.f, 0.f)).xyz);
+
        fUVs = aUV;
-       vec4 world_Position = uModel * vec4(aPosition, 1);
+       vec4 world_Position = uView * uModel * vec4(aPosition, 1);
        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);
 
-       gl_Position = uProjection * uView * world_Position;
+       gl_Position = uProjection * world_Position;
 }
\ No newline at end of file
index 5fd496427b8761a0d6ca641a620aea8453ce7195..e281291d788b85139f249ef93a104417fd069e3f 100644 (file)
@@ -3,6 +3,8 @@
 in vec3 world_Position, worldNormal;
 in vec2 fUVs;
 
+in vec3 PointLightPosition1, DirectionalLightDirection1;
+
 out vec4 FragmentColor;
 
 uniform vec3 cameraPos;
@@ -12,33 +14,28 @@ uniform vec4 material;                                      //vec4 in the form (ambient, point, directional, glos
 void main()
 {
        float specularConst = material[3];
-       vec3 normal = normalize(worldNormal);
        vec4 uvColor = texture(uColorTexture, fUVs);
 
 
        vec3 AmbientLightColor = 0 * vec3(0.2f, 0.2f, 0.2f);
-
-       vec3 PointLightPosition1 = vec3(0.0f, 1.0f, 0.0f);
-       vec3 PointLightColor1 = 1 * vec3(1.0f, 1.0f, 1.0f);
-
-       vec3 DirectionalLightDirection1 = normalize(vec3(-1.0f, -1.0f, -1.0f));
-       vec3 DirectionalLightColor1 = 0 * vec3(0.6f, 0.6f, 0.6f);
+       vec3 PointLightColor1 = 0 * vec3(1.0f, 1.0f, 1.0f);
+       vec3 DirectionalLightColor1 = 1 * vec3(0.6f, 0.6f, 0.6f);
 
 
-       vec3 cameraVec = normalize(cameraPos - world_Position.xyz);
+       vec3 cameraVec = normalize(-world_Position.xyz);
        vec3 worldPointLightDir1 = PointLightPosition1 - world_Position.xyz;
        vec3 PointLightDirection1 = normalize(worldPointLightDir1);
 
-       float SpecularCosPoint1 = clamp(dot(cameraVec, normalize(reflect(PointLightDirection1, normal))), 0, 1);
-       float SpecularCosDirection1 = clamp(dot(cameraVec, normalize(reflect(-DirectionalLightDirection1, normal))), 0, 1);
-       //float SpecularCosPoint1 = 0;
-       //float SpecularCosDirection1 = 0;
+       float SpecularCosPoint1 = clamp(dot(cameraVec, normalize(reflect(PointLightDirection1, worldNormal))), 0, 1);
+       float SpecularCosDirection1 = clamp(dot(cameraVec, -normalize(reflect(-DirectionalLightDirection1, worldNormal))), 0, 1);
+       SpecularCosPoint1 = 0;
+       //SpecularCosDirection1 = 0;
 
 
-       //float cosThetaPoint1 = clamp(dot(normal, PointLightDirection1), 0, 1);
-       //float cosThetaDirection1 = clamp(dot(normal, -DirectionalLightDirection1), 0, 1);
-       float cosThetaPoint1 = 0;
-       float cosThetaDirection1 = 0;
+       float cosThetaPoint1 = clamp(dot(worldNormal, PointLightDirection1), 0, 1);
+       float cosThetaDirection1 = clamp(dot(worldNormal, -DirectionalLightDirection1), 0, 1);
+       cosThetaPoint1 = 0;
+       cosThetaDirection1 = 0;
 
        float squaredist1 = worldPointLightDir1.x * worldPointLightDir1.x + worldPointLightDir1.y * worldPointLightDir1.y + worldPointLightDir1.z * worldPointLightDir1.z;
 
@@ -49,7 +46,7 @@ void main()
                ), uvColor.a);
 
 
-       //FragmentColor = vec4(worldNormal, 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;