ho3/resources/shaders/directlight.fragment

36 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-06-06 13:25:38 +00:00
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
uniform float FogBeginDistance;
uniform float FogEndDistance;
uniform vec4 FogColor;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
varying vec3 vertexPos;
void main()
{
vec3 lVec = lightVec;
vec3 cVec = normalize(camVec);
//go-go-go
vec3 TexRGB = texture2D(Texture, texCoord.xy).xyz;
vec3 norm = vec3(0.0,0.0,1.0);
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
float light_coef = 1.0;
vec4 ambient = gl_LightSource[0].ambient;
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lVec,norm),0.0), light_coef);
vec4 specular = gl_LightSource[0].specular * min(shineFactor, light_coef);
float fogFactor = min(max(max(abs(vertexPos.x)-FogBeginDistance, abs(vertexPos.z)-FogBeginDistance),0.0)/(FogEndDistance - FogBeginDistance),1.0);
gl_FragColor = mix(vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular), FogColor, fogFactor);
}