Try to fix some bugs:

- Z fighting with LOD terrain and water.
- Audio SFX not playing.
This commit is contained in:
Joshua Yanovski 2020-08-13 19:36:37 +02:00
parent 1fd104aa60
commit bc83360f2a
5 changed files with 17 additions and 6 deletions

View File

@ -60,7 +60,7 @@ void main() {
// // float surfaceAlt = min(floor(f_pos.z), floor(alt_at_real(cam_pos.xy))); // faces_fluid ? max(ceil(f_pos.z), floor(f_alt)) : floor(f_alt); // // float surfaceAlt = min(floor(f_pos.z), floor(alt_at_real(cam_pos.xy))); // faces_fluid ? max(ceil(f_pos.z), floor(f_alt)) : floor(f_alt);
// f_pos.z -= max(sign(view_distance.x - distance(focus_pos.xy, f_pos.xy)), 0.0) * (32.0 * view_distance.z / 255 + 32.0 * max(0.0, f_pos.z - cam_pos.z)); // f_pos.z -= max(sign(view_distance.x - distance(focus_pos.xy, f_pos.xy)), 0.0) * (32.0 * view_distance.z / 255 + 32.0 * max(0.0, f_pos.z - cam_pos.z));
f_pos.z -= max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(0.0, f_pos.z - focus_pos.z)); f_pos.z -= 0.1 + max(view_distance.x - distance(focus_pos.xy, f_pos.xy), 0.0) * (1.0 + max(0.0, f_pos.z - focus_pos.z));
// vec3 wRayinitial = f_pos; // cam_pos.z < f_pos.z ? f_pos : cam_pos.xyz; // vec3 wRayinitial = f_pos; // cam_pos.z < f_pos.z ? f_pos : cam_pos.xyz;
// vec3 wRayfinal = cam_pos.xyz; // cam_pos.z < f_pos.z ? cam_pos.xyz : f_pos; // vec3 wRayfinal = cam_pos.xyz; // cam_pos.z < f_pos.z ? cam_pos.xyz : f_pos;

View File

@ -53,7 +53,8 @@ impl EventMapper for CombatEventMapper {
let sfx_event_bus = ecs.read_resource::<EventBus<SfxEventItem>>(); let sfx_event_bus = ecs.read_resource::<EventBus<SfxEventItem>>();
let mut sfx_emitter = sfx_event_bus.emitter(); let mut sfx_emitter = sfx_event_bus.emitter();
let cam_pos = camera.dependents().cam_pos; let focus_off = camera.get_focus_pos().map(f32::trunc);
let cam_pos = camera.dependents().cam_pos + focus_off;
for (entity, pos, loadout, character) in ( for (entity, pos, loadout, character) in (
&ecs.entities(), &ecs.entities(),

View File

@ -50,7 +50,8 @@ impl EventMapper for MovementEventMapper {
let sfx_event_bus = ecs.read_resource::<EventBus<SfxEventItem>>(); let sfx_event_bus = ecs.read_resource::<EventBus<SfxEventItem>>();
let mut sfx_emitter = sfx_event_bus.emitter(); let mut sfx_emitter = sfx_event_bus.emitter();
let cam_pos = camera.dependents().cam_pos; let focus_off = camera.get_focus_pos().map(f32::trunc);
let cam_pos = camera.dependents().cam_pos + focus_off;
for (entity, pos, vel, body, physics, character) in ( for (entity, pos, vel, body, physics, character) in (
&ecs.entities(), &ecs.entities(),

View File

@ -234,8 +234,10 @@ impl SfxMgr {
} }
let ecs = state.ecs(); let ecs = state.ecs();
let focus_off = camera.get_focus_pos().map(f32::trunc);
let cam_pos = camera.dependents().cam_pos + focus_off;
audio.set_listener_pos(camera.dependents().cam_pos, camera.dependents().cam_dir); audio.set_listener_pos(cam_pos, camera.dependents().cam_dir);
// TODO: replace; deprecated in favor of outcomes // TODO: replace; deprecated in favor of outcomes
self.event_mapper self.event_mapper
@ -247,7 +249,7 @@ impl SfxMgr {
for event in events { for event in events {
let position = match event.pos { let position = match event.pos {
Some(pos) => pos, Some(pos) => pos,
_ => camera.dependents().cam_pos, _ => cam_pos,
}; };
if let Some(item) = self.triggers.get_trigger(&event.sfx) { if let Some(item) = self.triggers.get_trigger(&event.sfx) {

View File

@ -40,7 +40,10 @@ impl Lod {
pub fn get_data(&self) -> &LodData { &self.data } pub fn get_data(&self) -> &LodData { &self.data }
pub fn set_detail(&mut self, detail: u32) { self.data.tgt_detail = detail.max(100).min(2500); } pub fn set_detail(&mut self, detail: u32) {
// Make sure the recorded detail is even.
self.data.tgt_detail = detail.max(100).min(2500) - self.data.tgt_detail % 2;
}
pub fn maintain(&mut self, renderer: &mut Renderer, _time_of_day: f64) { pub fn maintain(&mut self, renderer: &mut Renderer, _time_of_day: f64) {
if self if self
@ -66,8 +69,12 @@ impl Lod {
} }
fn create_lod_terrain_mesh(detail: u32) -> Mesh<LodTerrainPipeline> { fn create_lod_terrain_mesh(detail: u32) -> Mesh<LodTerrainPipeline> {
// detail is even, so we choose odd detail (detail + 1) to create two even
// halves with an empty hole.
let detail = detail + 1;
Spiral2d::new() Spiral2d::new()
.take((detail * detail) as usize) .take((detail * detail) as usize)
.skip(1)
.map(|pos| { .map(|pos| {
let x = pos.x + detail as i32 / 2; let x = pos.x + detail as i32 / 2;
let y = pos.y + detail as i32 / 2; let y = pos.y + detail as i32 / 2;