Make LoD towns glow

This commit is contained in:
Joshua Barretto 2023-04-07 14:03:03 +01:00
parent d751a22af7
commit efbab102a5
4 changed files with 36 additions and 15 deletions

View File

@ -22,7 +22,10 @@ layout(location = 0) in vec3 f_pos;
layout(location = 1) in vec3 f_norm;
layout(location = 2) in vec4 f_col;
layout(location = 3) in vec3 model_pos;
layout(location = 4) in float snow_cover;
layout(location = 4) flat in uint f_flags;
const uint FLAG_SNOW_COVERED = 1;
const uint FLAG_IS_BUILDING = 2;
layout(location = 0) out vec4 tgt_color;
layout(location = 1) out uvec4 tgt_mat;
@ -117,11 +120,25 @@ void main() {
emitted_light *= f_ao;
reflected_light *= f_ao;
vec3 side_color = mix(surf_color, vec3(0.5, 0.6, 1.0), snow_cover);
vec3 top_color = mix(surf_color, surf_color * 0.3, 0.5 + snow_cover * 0.5);
vec3 glow = vec3(0);
if ((f_flags & FLAG_IS_BUILDING) > 0u && abs(f_norm.z) < 0.1) {
ivec3 wpos = ivec3((f_pos.xyz + focus_off.xyz) * 0.2);
if (((wpos.x & wpos.y & wpos.z) & 1) == 1) {
glow += vec3(1, 0.7, 0.3) * 2;
} else {
reflected_light += vec3(1, 0.7, 0.3) * 0.9;
}
}
vec3 side_color = surf_color;
vec3 top_color = surf_color;
if ((f_flags & FLAG_SNOW_COVERED) > 0u && f_norm.z > 0.0) {
side_color = mix(side_color, vec3(0.5, 0.6, 1.0), f_norm.z);
top_color = mix(top_color, surf_color * 0.3, 0.5 + f_norm.z * 0.5);
}
surf_color = mix(side_color, top_color, pow(fract(model_pos.z * 0.1), 2.0));
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light);
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light + glow, surf_color * reflected_light);
tgt_color = vec4(surf_color, 1.0);
tgt_mat = uvec4(uvec3((f_norm + 1.0) * 127.0), MAT_LOD);

View File

@ -24,13 +24,11 @@ layout(location = 3) in vec3 inst_pos;
layout(location = 4) in uvec3 inst_col;
layout(location = 5) in uint inst_flags;
const uint FLAG_SNOW_COVERED = 1;
layout(location = 0) out vec3 f_pos;
layout(location = 1) out vec3 f_norm;
layout(location = 2) out vec4 f_col;
layout(location = 3) out vec3 model_pos;
layout(location = 4) out float snow_cover;
layout(location = 4) flat out uint f_flags;
void main() {
vec3 obj_pos = inst_pos - focus_off.xyz;
@ -50,12 +48,7 @@ void main() {
f_norm = v_norm;
f_col = vec4(vec3(inst_col) * (1.0 / 255.0) * v_col * (hash(inst_pos.xyxy) * 0.35 + 0.65), 1.0);
if ((inst_flags & FLAG_SNOW_COVERED) > 0u && f_norm.z > 0.0) {
snow_cover = 1.0;
} else {
snow_cover = 0.0;
}
f_flags = inst_flags;
gl_Position =
all_mat *

View File

@ -10,6 +10,7 @@ bitflags::bitflags! {
#[derive(Serialize, Deserialize)]
pub struct Flags: u8 {
const SNOW_COVERED = 0b00000001;
const IS_BUILDING = 0b00000010;
}
}

View File

@ -590,12 +590,22 @@ impl World {
_ => None,
})
.flatten()
.map(|wpos2d| lod::Object {
.filter_map(|wpos2d| {
ColumnGen::new(self.sim())
.get((wpos2d, index, self.sim().calendar.as_ref()))
.zip(Some(wpos2d))
})
.map(|(col, wpos2d)| lod::Object {
kind: lod::ObjectKind::House,
pos: (wpos2d - min_wpos)
.map(|e| e as i16)
.with_z(self.sim().get_alt_approx(wpos2d).unwrap_or(0.0) as i16),
flags: lod::Flags::empty(),
flags: lod::Flags::IS_BUILDING
| if col.snow_cover {
lod::Flags::SNOW_COVERED
} else {
lod::Flags::empty()
},
}),
);