Pixel-Composer/shaders/sh_d3d_default/sh_d3d_default.fsh

64 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-08-14 19:22:04 +02:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec3 v_vNormal;
varying vec3 v_worldPosition;
2023-08-16 20:16:31 +02:00
#region ---- light ----
uniform vec4 light_ambient;
#define LIGHT_DIR_LIMIT 16
uniform int light_dir_count;
uniform vec3 light_dir_direction[LIGHT_DIR_LIMIT];
uniform vec4 light_dir_color[LIGHT_DIR_LIMIT];
uniform float light_dir_intensity[LIGHT_DIR_LIMIT];
#define LIGHT_PNT_LIMIT 16
uniform int light_pnt_count;
uniform vec3 light_pnt_position[LIGHT_PNT_LIMIT];
uniform vec4 light_pnt_color[LIGHT_PNT_LIMIT];
uniform float light_pnt_intensity[LIGHT_PNT_LIMIT];
uniform float light_pnt_radius[LIGHT_PNT_LIMIT];
#endregion
2023-08-14 19:22:04 +02:00
void main() {
vec4 final_color = texture2D( gm_BaseTexture, v_vTexcoord );
final_color *= v_vColour;
2023-08-16 20:16:31 +02:00
#region ++++ light ++++
vec3 light_effect = light_ambient.rgb;
for(int i = 0; i < light_dir_count; i++) {
float light_dir_strength = dot(normalize(v_vNormal), normalize(light_dir_direction[i]));
if(light_dir_strength < 0.)
continue;
light_dir_strength = max(light_dir_strength * light_dir_intensity[i], 0.);
light_effect += light_dir_color[i].rgb * light_dir_strength;
}
for(int i = 0; i < light_pnt_count; i++) {
float light_pnt_strength = dot(normalize(v_vNormal), normalize(light_pnt_position[i] - v_worldPosition));
if(light_pnt_strength < 0.)
continue;
float light_distance = distance(light_pnt_position[i], v_worldPosition);
if(light_distance > light_pnt_radius[i])
continue;
float light_attenuation = 1. - pow(light_distance / light_pnt_radius[i], 2.);
light_pnt_strength = max(light_pnt_strength * light_pnt_intensity[i] * light_attenuation, 0.);
light_effect += light_pnt_color[i].rgb * light_pnt_strength;
}
2023-08-14 19:22:04 +02:00
2023-08-16 20:16:31 +02:00
light_effect = max(light_effect, 0.);
final_color.rgb *= light_effect;
#endregion
2023-08-14 19:22:04 +02:00
gl_FragColor = final_color;
}