From 362740ad55fe63b4766fc4ee8c8ae80fa275fff6 Mon Sep 17 00:00:00 2001 From: LockedLunatic Date: Sat, 9 May 2015 22:22:34 +0200 Subject: [PATCH] mid shader change --- shader/basicTexture_VS.hlsl | 11 ++--------- shader/lightingTexture_FS.hlsl | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index 26f907a..29d73f0 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -4,10 +4,9 @@ in vec3 aNormal, aPosition; in vec2 aUV; -out vec3 worldNormal, worldPointLightDir1, DirectionalLightDirection1, cameraVec; +out vec3 world_Position, worldNormal; out vec2 fUVs; -uniform vec3 cameraPos; //uniform vec3 PointLightPosition1, DirectionalLightDirection1; uniform mat4 uProjection, uView, uModel; @@ -17,15 +16,9 @@ uniform int uEnableTransp = 1; void main() { - 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); - worldPointLightDir1 = PointLightPosition1 - world_Position.xyz; + worldNormal = (uModel * vec4(aNormal, 0.0f)).xyz; gl_Position = uProjection * uView * world_Position; - worldNormal = (uModel * vec4(aNormal, 0.0f)).xyz; - 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 8a2599f..5fd4964 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -1,16 +1,16 @@ //Fragment Shader #version 330 -in vec3 worldNormal, worldPointLightDir1, DirectionalLightDirection1, cameraVec; +in vec3 world_Position, worldNormal; in vec2 fUVs; 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) void main() { - float specularConst = material[3]; vec3 normal = normalize(worldNormal); vec4 uvColor = texture(uColorTexture, fUVs); @@ -18,32 +18,34 @@ void main() vec3 AmbientLightColor = 0 * vec3(0.2f, 0.2f, 0.2f); - vec3 PointLightDirection1 = normalize(worldPointLightDir1); + 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 cameraVec = normalize(cameraPos - 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 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 cosThetaPoint1 = clamp(dot(normal, PointLightDirection1), 0, 1); + //float cosThetaDirection1 = clamp(dot(normal, -DirectionalLightDirection1), 0, 1); + float cosThetaPoint1 = 0; + float cosThetaDirection1 = 0; float squaredist1 = worldPointLightDir1.x * worldPointLightDir1.x + worldPointLightDir1.y * worldPointLightDir1.y + worldPointLightDir1.z * worldPointLightDir1.z; - //if (uvColor.a < 0.3) - // discard; - FragmentColor = vec4(uvColor.rgb * (AmbientLightColor * material[0] + PointLightColor1 * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1 - //+ PointLightColor1 * material[1] * (pow(cosThetaPoint1, specularConst)) / squaredist1 + DirectionalLightColor1 * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst)) - //+ DirectionalLightColor1 * material[2] * (pow(cosThetaDirection1, specularConst)) ), uvColor.a); -- 2.47.3