From bb40477d86233840ffea3e8c1b3edb42f8e94e2f Mon Sep 17 00:00:00 2001 From: s473621 Date: Wed, 7 Feb 2024 15:31:46 +0100 Subject: [PATCH] upd shader_tex 2 --- .../cw 6/shaders/shader_5_1_tex.frag | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/PlanetCreator/cw 6/shaders/shader_5_1_tex.frag b/PlanetCreator/cw 6/shaders/shader_5_1_tex.frag index e51baab..b36ea0a 100644 --- a/PlanetCreator/cw 6/shaders/shader_5_1_tex.frag +++ b/PlanetCreator/cw 6/shaders/shader_5_1_tex.frag @@ -1,23 +1,36 @@ #version 430 core -float AMBIENT = 0.1; +float AMBIENT = 0.2; uniform vec3 color; uniform vec3 lightPos; uniform sampler2D colorTexture; +const float PI = 3.14159265359; + in vec3 vecNormal; in vec3 worldPos; in vec2 texCoord; out vec4 outColor; -vec3 textureColorTemp; + void main() { - vec3 lightDir = normalize(lightPos-worldPos); - vec3 normal = normalize(vecNormal); - float diffuse=max(0,dot(normal,lightDir)); - - vec4 textureColor = texture2D(colorTexture,texCoord); - textureColorTemp=vec3(textureColor.r,textureColor.g,textureColor.b); - outColor = vec4(textureColorTemp*min(1,AMBIENT+diffuse), 1.0); + + vec3 lightDir = normalize(lightPos - worldPos); + vec3 normal = normalize(vecNormal); + + + float diffuse = max(0.0, dot(normal, lightDir)); + diffuse = clamp(diffuse + 0.2, 0.0, 1.0); + + + vec3 viewDir = normalize(-worldPos); + vec3 halfwayDir = normalize(lightDir + viewDir); + float specularStrength = 0.7; // Increase specular strength + float specular = pow(max(0.0, dot(normal, halfwayDir)), 32); + + vec4 textureColor = texture(colorTexture, texCoord); + vec3 finalColor = textureColor.rgb * (AMBIENT + diffuse) + specularStrength * specular; + + outColor = vec4(finalColor, textureColor.a); }