From b89c974c7cf173422a8f7a109a024b1ed9d8825d Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Sun, 10 May 2015 01:00:30 +0200 Subject: [PATCH] back to eye positions --- shader/basicTexture_VS.hlsl | 10 +++++++--- shader/lightingTexture_FS.hlsl | 31 ++++++++++++++----------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index 2b83c33..4e614d9 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -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 diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 5fd4964..e281291 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -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; -- 2.47.3