diff --git a/assets/shaders/blinn_phong.frag b/assets/shaders/blinn_phong.frag index e5a108e..2f5416e 100644 --- a/assets/shaders/blinn_phong.frag +++ b/assets/shaders/blinn_phong.frag @@ -92,6 +92,24 @@ vec4 calc_dir_light(in Light dir_light) 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() { @@ -106,6 +124,8 @@ void main() light_contribution += calc_point_light(lights[i]); else if(lights[i].type == LT_DIR) 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)) + diff --git a/src/game.c b/src/game.c index bf4c0ce..5b3994c 100644 --- a/src/game.c +++ b/src/game.c @@ -151,7 +151,7 @@ void scene_setup(void) /* model_set_material_param(screen_model, "diffuse_color", &color); */ /* 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++) { int x = rand() % MAX_LIGHTS; @@ -161,14 +161,14 @@ void scene_setup(void) struct Transform* light_tran = entity_component_get(light_ent, C_TRANSFORM); vec3 lt_pos = {x * 10, 3, z * 10}; transform_set_position(light_tran, <_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); - light_comp->intensity = 0.2f; + light_comp->intensity = 1.f; } - struct Entity* sun = scene_add_new("Sun", NULL); - struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); - sun_light->intensity = 0.8f; + /* struct Entity* sun = scene_add_new("Sun", NULL); */ + /* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */ + /* sun_light->intensity = 0.8f; */ } void debug(float dt)