Point lights

This commit is contained in:
Confideo-IOM
2026-08-28 16:36:25 +01:00
parent 30538ae7ab
commit e3d37e3f8a
60 changed files with 458 additions and 184 deletions
@@ -232,7 +232,7 @@ vec3 DirectionalShading(vec3 normal,
{
float distance = length(light_pos - world_pos);
float attenuation = 1.0;
float attenuation = 3.5;
vec3 radiance = diffuse * attenuation;
@@ -251,10 +251,12 @@ vec3 PointShading(vec3 normal,
float light_constant,
float light_linear,
float light_quadratic,
vec3 light_colour,
vec3 world_pos,
vec3 view_pos,
float shadow_val)
{
float distance = length(light_pos - world_pos);
float attenuation = 1.0;
@@ -263,7 +265,7 @@ vec3 PointShading(vec3 normal,
vec3 light_dir = normalize(light_pos - world_pos);
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, light_dir, diffuse, radiance, roughness, metallic);
Lo = Lo * light_colour;
return Lo;
}
vec3 SpotShading(vec3 normal,
@@ -339,9 +341,17 @@ float SampleCascadeShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_ma
// check whether current frag pos is in shadow
// float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
// PCF
if(shadow_trans_idx < 3)
if(shadow_trans_idx < 1)
{
bias = 0.00001;
bias = 0.0000005;
}
if(shadow_trans_idx < 2)
{
bias = 0.00005;
}
else if(shadow_trans_idx < 3)
{
bias = 0.00005;
}
else if(shadow_trans_idx == 3)
{
@@ -351,9 +361,6 @@ float SampleCascadeShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_ma
{
bias = 0.0005;
}
float shadow = 0.0;
vec2 texel_size = 1.0 / textureSize(sampler_shadow_map, 0).xy;
if((frag_light_space.x >= 0.0)&&(frag_light_space.y >= 0.0)
@@ -418,6 +425,12 @@ vec3 CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, ve
//measure the distance of the fragment from the light
float frag_distance = abs(length(viewer_pos - world_pos.xyz));
float back_face = dot(normal, light_dir);
if(back_face < 0)
{
return vec3(1);
}
uint shadow_trans_idx = 5;
uint ignore_shadow = 0;
//Work out which shadowmap is appropriate for this distance
@@ -548,14 +561,22 @@ void main()
float ao = 1;
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
vec3 Lo = ambient;
if(metal_rough[0] > 0)
{
uFragColor = vec4(diffuse.xyz * metal_rough[0], diffuse.a);
}
else
{
for(int i = 0; i < ubo_per_frame.light_count; i ++)
{
mat4 model = model_matrix[lights[i].entity_id];
mat3 rot_mat = GetRotationOnlyMatrix(model);
vec3 light_direction = normalize(rot_mat * vec3(0,0,1));
vec3 light_pos = GetPositionFromView(model);
light_pos = model[3].xyx;
vec4 light_pos_model_space = vec4(0,0,0,1);
light_pos_model_space = model * light_pos_model_space;
vec3 light_pos = light_pos_model_space.xyz;
//vec3 light_pos = GetPositionFromView(model);
//light_pos = model[3].xyx;
if(lights[i].light_type == HYDRA_LIGHT_DIRECTIONAL)
{
Lo += DirectionalShading(normal, diffuse.xyz, rough, metal, lights[i].intensity, light_direction, light_pos, world_pos, ubo_per_frame.viewer_pos);
@@ -563,6 +584,7 @@ void main()
if(lights[i].shadow_caster == 1)
{
vec3 shadow = CalculateDirectionalShadow(vec4(world_pos, 1.0), lights[i].shadow_map_id, normal, light_direction, ubo_per_frame.viewer_pos);
Lo = Lo * shadow;
}
@@ -586,6 +608,7 @@ void main()
lights[i].constant,
lights[i].linear,
lights[i].quadratic,
lights[i].diffuse.xyz,
world_pos,
ubo_per_frame.viewer_pos,
shadow);
@@ -626,11 +649,13 @@ void main()
vec3 output_color = Lo;
// HDR tonemapping
output_color = output_color / (output_color + vec3(1.0));
// gamma correct
output_color = pow(output_color, vec3(1.0/2.1));
uFragColor = vec4(output_color, 1.0);
output_color = output_color / (output_color + vec3(1.0));
// gamma correct
output_color = pow(output_color, vec3(1.0/2.1));
uFragColor = vec4(output_color, 1.0);
}
// float light = dot(lights[0].light_direction, normal);
// uFragColor = vec4(diffuse.xyz * light,1);
@@ -73,7 +73,7 @@ void main()
}
diffuse_out = diffuse_val;
metalic_rough_out = mat_rough_val;
metalic_rough_out = mat_rough_val;
normal_out = vec4(normal_val,1);
position_out = vs_out.vsWorldPos;
}