diff --git a/CHANGELOG.md b/CHANGELOG.md index e8892deeba..07e1ee751a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made the hotbar link to items by item definition id and component composition instead of specific inventory slots. - Made loot boxes drop items instead of doing nothing in order to loot forcing - Refactored agent code file structure +- Changed the way light strength is rendered by moving processing from shader code (GPU) to CPU code ### Removed diff --git a/assets/voxygen/shaders/include/light.glsl b/assets/voxygen/shaders/include/light.glsl index 3918b9b4e4..576b7a8460 100644 --- a/assets/voxygen/shaders/include/light.glsl +++ b/assets/voxygen/shaders/include/light.glsl @@ -84,8 +84,7 @@ vec3 light_at(vec3 wpos, vec3 wnorm) { float strength = attenuation_strength(difference); - // Multiply the vec3 only once - vec3 color = srgb_to_linear(L.light_col.rgb) * (strength * L.light_col.a); + vec3 color = srgb_to_linear(L.light_col.rgb); light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIANCE); } @@ -194,12 +193,12 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve is_direct = true; #endif vec3 lrf = light_reflection_factor(/*direct_norm_dir*/wnorm, /*cam_to_frag*/view_dir, direct_light_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting); - vec3 direct_light = PI * color * strength * square_factor * lrf; + vec3 direct_light = PI * color * square_factor * lrf; /* is_direct = true; */ float computed_shadow = ShadowCalculationPoint(i, -difference, wnorm, wpos/*, light_distance*/); // directed_light += is_direct ? max(computed_shadow, /*LIGHT_AMBIANCE*/0.0) * direct_light * square_factor : vec3(0.0); // Non-physically emulate ambient light nearby - float ambiance = (dot(-wnorm, direct_light_dir) * 0.5 + 0.5) * strength * square_factor; + float ambiance = (dot(-wnorm, direct_light_dir) * 0.5 + 0.5) * square_factor; #ifdef FIGURE_SHADER // Non-physical hack. Subtle, but allows lanterns to glow nicely // TODO: Make lanterns use glowing cells instead diff --git a/assets/voxygen/shaders/include/point_glow.glsl b/assets/voxygen/shaders/include/point_glow.glsl index 10127966d3..e30c67b4ca 100644 --- a/assets/voxygen/shaders/include/point_glow.glsl +++ b/assets/voxygen/shaders/include/point_glow.glsl @@ -30,7 +30,7 @@ vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) { float strength = pow(attenuation_strength_real(difference), spread); - vec3 light_color = srgb_to_linear(L.light_col.rgb) * strength * L.light_col.a; + vec3 light_color = srgb_to_linear(L.light_col.rgb) * L.light_col.a; const float LIGHT_AMBIANCE = 0.025; color += light_color diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 7ca4caf4f8..dd9d8dc8c8 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -204,7 +204,8 @@ impl Light { pub fn new(pos: Vec3, col: Rgb, strength: f32) -> Self { Self { pos: Vec4::from(pos).into_array(), - col: Rgba::new(col.r, col.g, col.b, strength).into_array(), + col: (Rgba::new(strength * col.r, strength * col.g, strength * col.b, 0.0) * strength) + .into_array(), } } diff --git a/voxygen/src/scene/debug.rs b/voxygen/src/scene/debug.rs index 747e80c364..b25da57f0f 100644 --- a/voxygen/src/scene/debug.rs +++ b/voxygen/src/scene/debug.rs @@ -186,7 +186,7 @@ impl Debug { if let Some(model) = renderer.create_model(&shape.mesh()) { let locals = renderer.create_debug_bound_locals(&[DebugLocals { pos: [0.0; 4], - color: [1.0, 0.0, 0.0, 1.0], + color: [1.0 * 1.0, 0.0, 0.0, 0.0], ori: [0.0, 0.0, 0.0, 1.0], }]); self.models.insert(id, (model, locals)); @@ -202,7 +202,7 @@ impl Debug { let lc = srgba_to_linear(color.into()); let new_locals = [DebugLocals { pos, - color: [lc.r, lc.g, lc.b, lc.a], + color: [lc.a * lc.r, lc.a * lc.g, lc.a * lc.b, 0.0], ori, }]; renderer.update_consts(locals, &new_locals); diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 336356d9d5..518d9e2ef2 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -1188,11 +1188,11 @@ impl Scene { }); let hb_pos = [pos.0.x, pos.0.y, pos.0.z + *z_min, 0.0]; let color = if group == Some(&comp::group::ENEMY) { - [1.0, 0.0, 0.0, 0.5] + [0.5 * 1.0, 0.0, 0.0, 0.0] } else if group == Some(&comp::group::NPC) { - [0.0, 0.0, 1.0, 0.5] + [0.0, 0.0, 1.0 * 0.5, 0.0] } else { - [0.0, 1.0, 0.0, 0.5] + [0.0, 1.0 * 0.5, 0.0, 0.0] }; let ori = ori.to_quat(); let hb_ori = [ori.x, ori.y, ori.z, ori.w];