+static void audio_spacialize( sfx_system *sys,
+ v3f pos, v3f camera, v3f ears, float vol )
+{
+ float attn = (v3_dist( pos, camera ) / vol) +1.0f;
+
+ v3f delta;
+ v3_sub( pos, camera, delta );
+ v3_normalize( delta );
+
+ float pan = v3_dot( ears, delta );
+
+ sys->vol = 1.0f/(attn*attn);
+ sys->pan = pan;
+}
+
+static void audio_sample_occlusion( v3f origin )
+{
+ float d = 0.0f,
+ sample_dist = 880.0f;
+
+ int sample_count = 8;
+
+ for( int i=0; i<sample_count; i++ )
+ {
+ v3f dir;
+ vg_rand_dir( dir );
+
+ ray_hit contact;
+ contact.dist = 15.0f;
+
+ if( ray_world( origin, dir, &contact ) )
+ {
+ d += contact.dist;
+
+ vg_line( origin, contact.pos, 0xff0000ff );
+ vg_line_pt3( contact.pos, 0.1f, 0xff0000ff );
+ }
+ else
+ {
+ v3f p1;
+ v3_muladds( origin, dir, sample_dist, p1 );
+ vg_line( origin, p1, 0xffcccccc );
+
+ d += sample_dist;
+ }
+ }
+
+ float occlusion = 1.0f - (d * (1.0f/(sample_dist*(float)sample_count))),
+ rate = ktimestep * k_audio_occlusion_rate,
+ target = powf( occlusion, 6.0f );
+ audio_occlusion_current = vg_lerpf( audio_occlusion_current, target, rate );
+}
+
+static void audio_debug_soundscapes(void)
+{
+ if( !k_audio_debug_soundscape ) return;
+
+ char buf[64];
+ snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current );
+
+ ui_global_ctx.cursor[0] = 250;
+ ui_global_ctx.cursor[1] = 10;
+ ui_global_ctx.cursor[2] = audio_occlusion_current * 200.0f;
+ ui_global_ctx.cursor[3] = 20;
+
+ gui_fill_rect( ui_global_ctx.cursor, 0x55cccccc );
+ gui_text( ui_global_ctx.cursor, buf, 1, 0 );
+}
+