ho3/resources/shaders/directlight3.fragment

54 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2024-06-09 18:42:23 +00:00
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform float FogBeginDistance;
uniform float FogEndDistance;
varying vec2 texCoord;
varying vec3 vertexPos;
varying vec3 absoluteVertexPos;
2024-06-10 19:17:41 +00:00
varying vec3 normal;
varying vec3 tangent;
varying vec3 bitangent;
2024-06-09 18:42:23 +00:00
void main()
{
2024-06-10 19:17:41 +00:00
vec3 norm1 = normalize(normal);
vec3 norm2 = texture2D(NormalMap, texCoord).rgb * 2.0 - 1.0;
mat3 TBN = mat3(tangent, bitangent, norm1);
vec3 transformedNormal = normalize(TBN * norm2);
//gl_FragColor = vec4(transformedNormal*0.5+ vec3(0.5, 0.5, 0.5), 1.0);
2024-06-09 18:42:23 +00:00
vec3 lightPos = vec3(-2, 5, 0);
vec3 lightVec = absoluteVertexPos - lightPos;
2024-06-10 19:17:41 +00:00
float coef = max(dot(-normalize(lightVec),transformedNormal),0.2);
2024-06-09 18:42:23 +00:00
float coef2 = clamp((15.0 - length(lightVec))/10.0, 0.2, 1.0);
2024-06-10 19:17:41 +00:00
vec4 texColor = texture2D(Texture,texCoord).rgba;
2024-06-09 18:42:23 +00:00
gl_FragColor = vec4(texColor.rgb*coef2*coef, 1.0);
/*
//Night
//vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0);
vec4 fogColor = vec4(0.05, 0.05, 0.1, 1.0);
float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance);
fogDistCoef = clamp(fogDistCoef, 0.0, 1.0);
vec4 resultColor = mix(texColor*coef2, fogColor, fogDistCoef);
gl_FragColor = vec4(resultColor.rgb, 1.0);*/
}