From 0ee9d77f45e007b119de2d44feef81516aaddaaf Mon Sep 17 00:00:00 2001 From: hgn Date: Sat, 17 Jul 2021 08:39:24 +0100 Subject: [PATCH 1/1] height filtering --- build.sh | 4 ++-- csRadar.c | 11 ++++++++++- csRadar.h | 3 +++ csrDraw.h | 7 ++++--- ext_csr_free.c => ext_csr_substance.c | 3 +++ 5 files changed, 22 insertions(+), 6 deletions(-) rename ext_csr_free.c => ext_csr_substance.c (97%) diff --git a/build.sh b/build.sh index a898a68..299bf3a 100755 --- a/build.sh +++ b/build.sh @@ -18,5 +18,5 @@ mkdir -p ext echo build: csRadar gcc $flags -rdynamic csRadar.c -o csRadar -lm -ldl -echo build: ext/csRadarFree.so -gcc $flags -fpic -shared -o ext/csRadarFree.so ext_csr_free.c -lm +echo build: ext/csr_substance.so +gcc $flags -fpic -shared -o ext/csr_substance.so ext_csr_substance.c -lm diff --git a/csRadar.c b/csRadar.c index 9f05c2b..f79fa3b 100644 --- a/csRadar.c +++ b/csRadar.c @@ -16,6 +16,8 @@ int main( int argc, char *argv[] ) { .padding = 128.f, .resolution = 1024, + .min_z = -INFINITY, + .max_z = INFINITY, .write_txt = 1, .api_version = csr_api_version, .sampling_mode = k_EMSAA_RGSS @@ -91,6 +93,11 @@ int main( int argc, char *argv[] ) { extension = arg; } + + if( (arg = csr_long_opt_arg( "min" )) ) + api.min_z = atof( arg ); + if( (arg = csr_long_opt_arg( "max" )) ) + api.max_z = atof( arg ); if( csr_opt( 'v' ) || csr_long_opt( "version" ) ) { @@ -121,6 +128,8 @@ int main( int argc, char *argv[] ) " --no-txt Don't create matching radar txt\n" " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n" " --extension=TAR Use an extension binary instead\n" + " --min=z Miniumum height to render\n" + " --max=z Maxiumum height to render\n" "\n" " -v --version Display program version\n" " -h --help Display this help text\n" @@ -169,7 +178,7 @@ int main( int argc, char *argv[] ) } if( !extension ) - extension = "csRadarFree"; + extension = "csr_substance"; csr_so ext = csr_libopen( extension ); diff --git a/csRadar.h b/csRadar.h index 4192e55..0415518 100644 --- a/csRadar.h +++ b/csRadar.h @@ -64,6 +64,9 @@ struct csr_api char vmf_name[ 128 ]; // Just the base name eg. my_map EMSAA sampling_mode; + float min_z; + float max_z; + // Main API interface vmf_map *map; csr_target target; diff --git a/csrDraw.h b/csrDraw.h index b744c04..fff1590 100644 --- a/csrDraw.h +++ b/csrDraw.h @@ -317,11 +317,12 @@ void simple_raster( csr_target *rt, vmf_vert tri[3] ) bcc = (v0[0]*vp[1] - vp[0]*v0[1]) * d; bca = 1.f - bcb - bcc; - float hit = (tri[0].co[2] * bca + tri[1].co[2] * bcb + tri[2].co[2] * bcc) +16385.f; + float hit = tri[0].co[2] * bca + tri[1].co[2] * bcb + tri[2].co[2] * bcc; + float hit_depth = hit + 16385.f; - if( hit > depth[i] ) + if( hit_depth > depth[i] && hit >= rt->bounds[0][2] && hit <= rt->bounds[1][2] ) { - depth[i] = hit; + depth[i] = hit_depth; rt->shader->frag( frag+i*rt->shader->stride, tri, bca, bcb, bcc ); } } diff --git a/ext_csr_free.c b/ext_csr_substance.c similarity index 97% rename from ext_csr_free.c rename to ext_csr_substance.c index ffec370..4dd2627 100644 --- a/ext_csr_free.c +++ b/ext_csr_substance.c @@ -43,6 +43,9 @@ void csr_ext_main( csr_api *api ) v2_copy( api->target.bounds[0], remapping_range ); v2_sub( api->target.bounds[1], api->target.bounds[0], &remapping_range[2] ); + api->target.bounds[0][2] = api->min_z; + api->target.bounds[1][2] = api->max_z; + // Draw everything draw_buffers( api, 0 ); } -- 2.25.1