Guest User

lit.glsl

a guest
Jul 4th, 2020
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform vec3 color_value = vec3(1.0,0.1,0.1);
  2. //uniform sampler2D color_texture;
  3.  
  4. MAIN_PASS
  5. {
  6.     //vec4 albedo = texture(color_texture, uv[0]) * vec4(color_value, 1);
  7.     vec4 albedo = vec4(color_value, 1);
  8.  
  9.     for (int i = 0; i < scene_lights.sun_lights_count; i++)
  10.     {
  11.         SunLight sun_light = scene_lights.sun_lights[i];
  12.         COLOR += (albedo * vec4(sun_light.color,1)) * max(0, dot(-sun_light.direction, normal));
  13.     }
  14.     for (int i = 0; i < scene_lights.point_lights_count; i++)
  15.     {
  16.         PointLight point = scene_lights.point_lights[i];
  17.         float normalized_distance = distance(position, point.position) / point.radius;
  18.         normalized_distance = clamp(normalized_distance, 0, 1);
  19.         float d = dot(normalize(point.position - position), normal);
  20.         d = clamp(d,0,1);
  21.         COLOR += (albedo * vec4(point.color,1)) * (1.0 - normalized_distance) * d;
  22.     }
  23.     for (int i = 0; i < scene_lights.spot_lights_count; i++)
  24.     {
  25.         SpotLight spot = scene_lights.spot_lights[i];
  26.         float spot_angle = dot(spot.direction, normalize(position - spot.position));
  27.         spot.angle /= 2.0;
  28.         spot_angle = acos(spot_angle);
  29.         float normalized_distance = distance(position, spot.position) / spot.radius;
  30.         normalized_distance = clamp(normalized_distance, 0, 1);
  31.         float d = dot(-spot.direction, normal);
  32.         d = clamp(d,0,1);
  33.         if(spot_angle < spot.angle)
  34.         {
  35.             COLOR += (albedo * vec4(spot.color,1)) * (1.0 - normalized_distance) * d;
  36.         }
  37.     }
  38. }
RAW Paste Data