KP3Dii/Data/resources/shaders/basic_light_f.glsl
2024-07-22 02:48:42 -05:00

85 lines
1.9 KiB
GLSL

#version 330 core
uniform vec3 u_campos;
in vec3 v_position;
in vec3 v_normal;
in vec3 v_proj_normal;
in vec2 v_texcoord;
layout (location=0) out vec4 v_output;
uniform sampler2D u_texture;
float get_fog_factor(float d)
{
const float FogMax = 10.0;
const float FogMin = 0.0;
if (d >= FogMax) return 1.0;
if (d <= FogMin) return 0.0;
return 1 - (FogMax - d) / (FogMax - FogMin);
}
struct Light
{
vec3 position;
vec3 diffuse;
};
float lambert(vec3 n, vec3 l)
{
vec3 nrmn = normalize(n);
vec3 nrml = normalize(l);
float res = dot(nrmn, nrml);
return max(res, 0.5);
}
float dist(vec2 p0, vec2 pf){return sqrt((pf.x-p0.x)*(pf.x-p0.x)+(pf.y-p0.y)*(pf.y-p0.y));}
void main()
{
Light light;
light.position = vec3(3.0, -4.0, 5.0);
light.diffuse = vec3(1.0, 1.0, 1.0);
vec4 tex = texture(u_texture, v_texcoord);
vec3 norm = normalize(v_normal);
vec3 res = vec3(1.0, 0.0, 1.0) * lambert(normalize(v_normal), light.position);
float a = dist(v_position.xy, vec2(0.0, 0.0)) * 2.0f;
// vec4 res2 = texture2D(u_texture, v_texcoord) * ((dot(-light.position, v_normal) * 0.5)+2.5);
vec4 texv = texture2D(u_texture, v_texcoord);
vec4 res2 = texv * (abs(dot(-light.position, v_normal) * 0.5));
res2.xyz *= 0.2;
res2.a = texv.a;
v_output = res2;
/*
vec3 col;
vec4 tex = texture(u_texture, v_texcoord);
vec3 norm = normalize(v_normal);
vec3 dir = normalize(vec3(5.0, 0.25, -5.0) - v_position);
float diff = max(dot(norm, dir), 0.0);
float alpha = get_fog_factor(distance(u_campos, v_position));
vec3 diffuse = diff * vec3(0.8, 0.75, 0.7);
float ff = 1.75;
if (diffuse.x > 0.0) diffuse.x *= ff;
if (diffuse.y > 0.0) diffuse.y *= ff;
if (diffuse.z > 0.0) diffuse.z *= ff;
vec3 ambient = vec3(0.3, 0.3, 0.3);
col = (ambient + diffuse) * tex.rgb;
col *= mix(vec4(1.0), vec4(0.0f, 0.0, 0.0, 1.0), alpha-0.2).xyz;
*/
// vec4 tex = texture(u_texture, v_texcoord);
// v_output = tex * vec4(vec3(1.5), 1.0);
}