Added spot lights

dev
Shariq Shah 9 years ago
parent c9cdfb5fff
commit b53dcf287e
  1. 20
      assets/shaders/blinn_phong.frag
  2. 12
      src/game.c

@ -92,6 +92,24 @@ vec4 calc_dir_light(in Light dir_light)
return (dir_light.intensity * (diffuse_comp + specular_comp)); return (dir_light.intensity * (diffuse_comp + specular_comp));
} }
vec4 calc_spot_light(in Light spot_light)
{
vec4 color = vec4(0.0);
vec3 light_to_surface = vertex - spot_light.position;
float angle = dot(spot_light.direction, normalize(light_to_surface));
if(acos(angle) < spot_light.outer_angle)
{
color = calc_point_light(spot_light);
color *= smoothstep(cos(spot_light.outer_angle), cos(spot_light.inner_angle), angle);
// if(light.cast_shadow != 0)
// {
// float shadow_factor = calc_shadow_factor(vert_light_space.xyz / vert_light_space.w);
// color *= shadow_factor;
// }
}
return color;// * shadowFactor;
}
void main() void main()
{ {
@ -106,6 +124,8 @@ void main()
light_contribution += calc_point_light(lights[i]); light_contribution += calc_point_light(lights[i]);
else if(lights[i].type == LT_DIR) else if(lights[i].type == LT_DIR)
light_contribution += calc_dir_light(lights[i]); light_contribution += calc_dir_light(lights[i]);
else
light_contribution += calc_spot_light(lights[i]);
} }
frag_color = (albedo_color * vec4(0.1, 0.1, 0.1, 1.0)) + frag_color = (albedo_color * vec4(0.1, 0.1, 0.1, 1.0)) +

@ -151,7 +151,7 @@ void scene_setup(void)
/* model_set_material_param(screen_model, "diffuse_color", &color); */ /* model_set_material_param(screen_model, "diffuse_color", &color); */
/* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */ /* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */
const int MAX_LIGHTS = 5; const int MAX_LIGHTS = 2;
for(int i = 0; i < MAX_LIGHTS; i++) for(int i = 0; i < MAX_LIGHTS; i++)
{ {
int x = rand() % MAX_LIGHTS; int x = rand() % MAX_LIGHTS;
@ -161,14 +161,14 @@ void scene_setup(void)
struct Transform* light_tran = entity_component_get(light_ent, C_TRANSFORM); struct Transform* light_tran = entity_component_get(light_ent, C_TRANSFORM);
vec3 lt_pos = {x * 10, 3, z * 10}; vec3 lt_pos = {x * 10, 3, z * 10};
transform_set_position(light_tran, &lt_pos); transform_set_position(light_tran, &lt_pos);
struct Light* light_comp = entity_component_add(light_ent, C_LIGHT, LT_POINT); struct Light* light_comp = entity_component_add(light_ent, C_LIGHT, LT_SPOT);
vec4_fill(&light_comp->color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z, 1); vec4_fill(&light_comp->color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z, 1);
light_comp->intensity = 0.2f; light_comp->intensity = 1.f;
} }
struct Entity* sun = scene_add_new("Sun", NULL); /* struct Entity* sun = scene_add_new("Sun", NULL); */
struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); /* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */
sun_light->intensity = 0.8f; /* sun_light->intensity = 0.8f; */
} }
void debug(float dt) void debug(float dt)

Loading…
Cancel
Save