X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=csrDraw.h;h=00346e444491d36e736ec116242787d3613b25c9;hp=f2b007fdd92bd13b0f1b65defa3602916e92fe54;hb=d7339f0f28ca5b35ad60a393ca270cbae1a154c6;hpb=3e1642e28847218d89d1bec2f8b035c10359ac91 diff --git a/csrDraw.h b/csrDraw.h index f2b007f..00346e4 100644 --- a/csrDraw.h +++ b/csrDraw.h @@ -1,6 +1,9 @@ typedef struct csr_frag csr_frag; typedef struct csr_target csr_target; typedef struct csr_filter csr_filter; +typedef enum EMSAA EMSAA; + +typedef void (* csr_frag_shader)( v4f, vmf_vert[3], float, float, float ); // MSAA patterns v2f csr_msaa_1[] = @@ -8,24 +11,51 @@ v2f csr_msaa_1[] = {0.f, 0.f} }; +// XX +// XX v2f csr_msaa_2x2[] = { - { 0.25f, 0.25f }, - { 0.25f, -0.25f }, - { -0.25f, -0.25f }, - { -0.25f, 0.25f } + { 0x0.4p0f, 0x0.4p0f }, + { 0x0.4p0f, -0x0.4p0f }, + { -0x0.4p0f, -0x0.4p0f }, + { -0x0.4p0f, 0x0.4p0f } }; +// X +// X +// X +// X v2f csr_msaa_2x2rgss[] = { + { 0x0.2p0f, 0x0.6p0f }, + { -0x0.6p0f, 0x0.2p0f }, + { -0x0.2p0f, -0x0.6p0f }, + { 0x0.6p0f, -0x0.2p0f } +}; +// X +// X +// X +// X +// X +// X +// X +// X +v2f csr_msaa_8rook[] = +{ + { 0x0.1p0f, 0x0.7p0f }, + { 0x0.5p0f, 0x0.1p0f }, + { 0x0.7p0f, -0x0.3p0f }, + { 0x0.3p0f, -0x0.5p0f }, + { -0x0.1p0f, -0x0.7p0f }, + { -0x0.5p0f, -0x0.1p0f }, + { -0x0.7p0f, 0x0.3p0f }, + { -0x0.3p0f, 0x0.5p0f } }; struct csr_frag { - v3f co; - v3f nrm; - + v4f colour; float depth; }; @@ -37,10 +67,18 @@ struct csr_target boxf bounds; float scale; - v2f subsamples[ 16 ]; + v2f subsamples[ 8 ]; int num_samples; + v2f *sample_src; + + csr_frag_shader shader; }; +void csr_use_program( csr_target *rt, csr_frag_shader shader ) +{ + rt->shader = shader; +} + struct csr_filter { const char *visgroup; // Limit to this visgroup only @@ -49,11 +87,42 @@ struct csr_filter int compute_bounds_only; }; -void csr_create_target( csr_target *rt, u32 x, u32 y ) +enum EMSAA +{ + k_EMSAA_none, + k_EMSAA_2x2, + k_EMSAA_RGSS, + k_EMSAA_8R +}; + +void csr_create_target( csr_target *rt, u32 x, u32 y, EMSAA aa ) { rt->x = x; rt->y = y; - rt->num_samples = 4; + + switch( aa ) + { + default: + case k_EMSAA_none: + rt->num_samples = 1; + rt->sample_src = csr_msaa_1; + break; + + case k_EMSAA_2x2: + rt->num_samples = 4; + rt->sample_src = csr_msaa_2x2; + break; + + case k_EMSAA_RGSS: + rt->num_samples = 4; + rt->sample_src = csr_msaa_2x2rgss; + break; + + case k_EMSAA_8R: + rt->num_samples = 8; + rt->sample_src = csr_msaa_8rook; + break; + } rt->fragments = (csr_frag *)csr_malloc( x*y*sizeof(csr_frag)*rt->num_samples ); @@ -68,14 +137,10 @@ void csr_update_subsamples( csr_target *rt ) v2f pixel_size = { range_x/(float)rt->x, range_y/(float)rt->y }; - rt->subsamples[0][0] = pixel_size[0] * -0.25f; - rt->subsamples[0][1] = 0.f; - rt->subsamples[1][0] = pixel_size[0] * 0.75f; - rt->subsamples[1][1] = pixel_size[1] * 0.25f; - rt->subsamples[2][0] = 0.f; - rt->subsamples[2][1] = pixel_size[1] * 0.5f; - rt->subsamples[3][0] = pixel_size[0] * 0.5f; - rt->subsamples[3][1] = pixel_size[1] * 0.75f; + for( int i = 0; i < rt->num_samples; i ++ ) + { + v2_mul( rt->sample_src[i], pixel_size, rt->subsamples[i] ); + } } void csr_rt_free( csr_target *rt ) @@ -87,8 +152,7 @@ void csr_rt_clear( csr_target *rt ) { for( u32 i = 0; i < rt->x*rt->y*rt->num_samples; i ++ ) { - v3_zero( rt->fragments[ i ].co ); - v3_zero( rt->fragments[ i ].nrm ); + v4_zero( rt->fragments[ i ].colour ); rt->fragments[i].depth = 0.f; } } @@ -96,7 +160,7 @@ void csr_rt_clear( csr_target *rt ) void csr_auto_fit( csr_target *rt, float padding ) { // Correct aspect ratio to be square - float dx, dy, d, l, cx, cy; + float dx, dy, l, cx, cy; dx = rt->bounds[1][0] - rt->bounds[0][0]; dy = rt->bounds[1][1] - rt->bounds[0][1]; @@ -131,6 +195,13 @@ void csr_write_txt( char const *path, const char *name, csr_target *rt ) fclose( write_ptr ); } +void frag_gbuffer( v4f frag_colour, vmf_vert tri[3], float bca, float bcb, float bcc ) +{ + v3_muls( tri[0].co, bca, frag_colour ); + v3_muladds( frag_colour, tri[1].co, bcb, frag_colour ); + v3_muladds( frag_colour, tri[2].co, bcc, frag_colour ); +} + void simple_raster( csr_target *rt, vmf_vert tri[3] ) { // Very very simplified rasterizing algorithm @@ -203,11 +274,7 @@ void simple_raster( csr_target *rt, vmf_vert tri[3] ) if( hit > frag[i].depth ) { frag[i].depth = hit; - v3_muls( tri[0].co, bca, frag[i].co ); - v3_muladds( frag[i].co, tri[1].co, bcb, frag[i].co ); - v3_muladds( frag[i].co, tri[2].co, bcc, frag[i].co ); - - // TODO: Same for normal map + rt->shader( frag[i].colour, tri, bca, bcb, bcc ); } } } @@ -314,11 +381,8 @@ void draw_vmf_group( csr_target *rt, vmf_map *map, vdf_node *root, csr_filter *f if( compute_bounds_only ) { - box_copy( mdl->bounds, trf_bounds ); - m4x3_transform_aabb( model, trf_bounds ); - - // Join - box_concat( rt->bounds, trf_bounds ); + map->models[ ent->user1 ].need_load = 1; + m4x3_expand_aabb_point( model, rt->bounds, (v3f){0.f,0.f,0.f} ); } else { @@ -384,6 +448,8 @@ void csr_rt_save_buffers( csr_target *rt, const char *basename, const char *subn float *image = (float *)csr_malloc( 1024*1024*sizeof(float)*3 ); + float contrib = 1.f/(float)rt->num_samples; + for( int l = 0; l < rt->x; l ++ ) { for( int x = 0; x < rt->y; x ++ ) @@ -392,10 +458,12 @@ void csr_rt_save_buffers( csr_target *rt, const char *basename, const char *subn csr_frag *src = &rt->fragments[ ((1023-l)*1024+x)*rt->num_samples ]; v3_zero( dst ); - v3_muls( src[0].co, 1.f/(float)rt->num_samples, dst ); - v3_muladds( dst, src[1].co, 1.f/(float)rt->num_samples, dst ); - v3_muladds( dst, src[2].co, 1.f/(float)rt->num_samples, dst ); - v3_muladds( dst, src[3].co, 1.f/(float)rt->num_samples, dst ); + v3_muls( src[0].colour, contrib, dst ); + + for( int j = 1; j < rt->num_samples; j ++ ) + { + v3_muladds( dst, src[j].colour, contrib, dst ); + } } }