Addressed review comments

This commit is contained in:
Joshua Barretto 2022-10-23 23:54:55 +01:00
parent 1521b6165f
commit 428816c65e
10 changed files with 26 additions and 17 deletions

View File

@ -86,7 +86,8 @@ void main() {
vec3 wpos = wpos_at(uv);
float dist = distance(wpos, cam_pos.xyz);
vec3 dir = (wpos - cam_pos.xyz) / dist;
vec3 cam_dir = (wpos - cam_pos.xyz) / dist;
vec3 dir = cam_dir;
// Apply clouds
float cloud_blend = 1.0;
@ -201,7 +202,7 @@ void main() {
if (medium.x == MEDIUM_AIR && rain_density > 0.001) {
vec3 cam_wpos = cam_pos.xyz + focus_off.xyz;
vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz;
vec3 adjusted_dir = (vec4(cam_dir, 0) * rain_dir_mat).xyz;
vec2 dir2d = adjusted_dir.xy;
vec3 rorigin = cam_pos.xyz + focus_off.xyz + 0.5;

View File

@ -227,8 +227,8 @@ void main() {
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
#if (FLUID_MODE >= FLUID_MODE_MEDIUM)
cam_attenuation =
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz + focus_off.xyz, view_dir, mu, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos + focus_off.xyz)
: compute_attenuation_point(f_pos + focus_off.xyz, -view_dir, mu, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz + focus_off.xyz);
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
#endif
// Prevent the sky affecting light when underground

View File

@ -229,7 +229,7 @@ void main() {
float min_refl = 0.0;
float opacity = (1.0 - passthrough) * 1.0 / (1.0 + min_refl);
if (medium.x == MEDIUM_WATER) {
// Hack to make the opacity of the surface fade when underwater to avoid artifacts
// Hack to make the transparency of the surface fade when underwater to avoid artifacts
opacity = min(sqrt(max(opacity, clamp((f_pos.z - cam_pos.z) * 0.05, 0.0, 1.0))), 0.99);
}

View File

@ -409,7 +409,7 @@ void main() {
if (medium.x != MEDIUM_WATER) {
min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
} else {
// Hack to make the opacity of the surface fade when underwater to avoid artifacts
// Hack to make the transparency of the surface fade when underwater to avoid artifacts
if (dot(refract_ray_dir, cam_to_frag) > 0.0) {
opacity = 0.99;
} else {

View File

@ -579,9 +579,9 @@ void main() {
vec3 emitted_light, reflected_light;
vec3 mu = false/* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
// NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water.
vec3 cam_attenuation = compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos);
vec3 cam_attenuation = compute_attenuation_point(f_pos, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
// Use f_norm here for better shadows.
// vec3 light_frac = light_reflection_factor(f_norm/*l_norm*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(/*1.0*/R_s), alpha);

View File

@ -90,8 +90,8 @@ void main() {
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
#if (FLUID_MODE >= FLUID_MODE_MEDIUM)
cam_attenuation =
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz + focus_off.xyz, view_dir, MU_WATER, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos + focus_off.xyz)
: compute_attenuation_point(f_pos + focus_off.xyz, -view_dir, vec3(0), fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz + focus_off.xyz);
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
: compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
#endif
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);

View File

@ -96,8 +96,8 @@ void main() {
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
#if (FLUID_MODE >= FLUID_MODE_MEDIUM)
cam_attenuation =
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz + focus_off.xyz, view_dir, mu, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos + focus_off.xyz)
: compute_attenuation_point(f_pos + focus_off.xyz, -view_dir, mu, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz + focus_off.xyz);
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
#endif
// Prevent the sky affecting light when underground

View File

@ -366,8 +366,8 @@ void main() {
// NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water.
// Computing light attenuation from water.
vec3 cam_attenuation =
false/*medium.x == MEDIUM_WATER*/ ? compute_attenuation_point(cam_pos.xyz + focus_off.xyz, view_dir, MU_WATER, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos + focus_off.xyz)
: compute_attenuation_point(f_pos + focus_off.xyz, -view_dir, mu, fluid_alt + focus_off.z, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz + focus_off.xyz);
false/*medium.x == MEDIUM_WATER*/ ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
// Prevent the sky affecting light when underground
float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0);

View File

@ -391,6 +391,14 @@ pub fn generate_mesh<'a>(
let create_opaque =
|atlas_pos, pos, norm, meta| TerrainVertex::new(atlas_pos, pos + mesh_delta, norm, meta);
let create_transparent = |_atlas_pos, pos: Vec3<f32>, norm| {
// TODO: It *should* be possible to pull most of this code out of this function
// and compute it per-chunk. For some reason, this doesn't work! If you,
// dear reader, feel like giving it a go then feel free. For now
// it's been kept as-is because I'm lazy and water vertices aren't nearly common
// enough for this to matter much. If you want to test whether your
// change works, look carefully at how waves interact between water
// polygons in different chunks. If the join is smooth, you've solved the
// problem!
let key = vol.pos_key(range.min + pos.as_());
let v00 = vol
.get_key(key + Vec2::new(0, 0))

View File

@ -12,7 +12,7 @@ const FIRST_PERSON_INTERP_TIME: f32 = 0.1;
const THIRD_PERSON_INTERP_TIME: f32 = 0.1;
const FREEFLY_INTERP_TIME: f32 = 0.0;
const LERP_ORI_RATE: f32 = 15.0;
const CLIPPING_MODE_DISTANCE: Range<f32> = 2.0..20.0;
const CLIPPING_MODE_RANGE: Range<f32> = 2.0..20.0;
pub const MIN_ZOOM: f32 = 0.1;
// Possible TODO: Add more modes
@ -368,7 +368,7 @@ impl Camera {
) {
span!(_guard, "compute_dependents", "Camera::compute_dependents");
// TODO: More intelligent function to decide on which strategy to use
if self.tgt_dist < CLIPPING_MODE_DISTANCE.end {
if self.tgt_dist < CLIPPING_MODE_RANGE.end {
self.compute_dependents_near(terrain, is_transparent)
} else {
self.compute_dependents_far(terrain, is_transparent)
@ -426,7 +426,7 @@ impl Camera {
};
// If the camera ends up being too close to the focus point, switch policies.
if dist < CLIPPING_MODE_DISTANCE.start {
if dist < CLIPPING_MODE_RANGE.start {
self.compute_dependents_far(terrain, is_transparent);
} else {
if self.dist >= dist {