1 // Copyright (C) 2021 Harry Godden (hgn)
3 // Basic buffers-only version of csRadar
4 //=======================================================================================================================
8 float min_height
= 0.f
;
12 void frag_gbuffer( void *dest
, vmf_vert tri
[3], float bca
, float bcb
, float bcc
);
13 void frag_gbuffer_clear( void *dest
);
15 csr_shader shader_gbuffer
=
17 .stride
= sizeof(float)*8, // (origin) x,y, (actual height) z
19 .clear
= frag_gbuffer_clear
22 // Main drawing function
23 void draw_buffers( csr_api
*api
, int bounds_only
);
25 // Extension implementation
26 // =========================================================================================================
29 void csr_ext_main( csr_api
*api
)
31 if( !csr_init( api
) )
34 csr_create_target( &api
->target
, api
->resolution
, api
->resolution
, api
->sampling_mode
, &shader_gbuffer
);
35 csr_rt_clear( &api
->target
);
37 // Compute bounds, collect models
38 draw_buffers( api
, 1 );
39 csr_auto_fit( &api
->target
, api
->padding
);
40 vmf_load_models( api
->map
);
42 min_height
= api
->target
.bounds
[0][2];
43 v2_copy( api
->target
.bounds
[0], remapping_range
);
44 v2_sub( api
->target
.bounds
[1], api
->target
.bounds
[0], &remapping_range
[2] );
47 draw_buffers( api
, 0 );
50 void csr_ext_exit( csr_api
*api
)
52 csr_rt_free( &api
->target
);
55 void draw_buffers( csr_api
*api
, int bounds_only
)
57 csr_filter filter
= { .compute_bounds_only
= bounds_only
};
58 vmf_map
*map
= api
->map
;
60 if( api
->num_strings
== 1 )
63 csr_vmf_render( &api
->target
, map
, map
->root
, &filter
, NULL
, NULL
);
67 csr_rt_save_buffers( &api
->target
, api
->output_path
, "all" );
68 csr_rt_save_tga( &api
->target
, "test_test_test.tga", 3*sizeof(float), 4 );
74 for( int i
= 1; i
< api
->num_strings
; i
++ )
76 csr_filter_update_from_strings( &filter
, &api
->strings
[i
] );
78 csr_vmf_render( &api
->target
, map
, map
->root
, &filter
, NULL
, NULL
);
82 csr_rt_save_buffers( &api
->target
, api
->output_path
, api
->strings
[i
].str
);
83 //csr_rt_save_c32f( ... );
84 //csr_rt_save_tga( ... );
86 // tar_write_dds( ... );
87 csr_rt_save_tga( &api
->target
, "test_test_test.tga", 3*sizeof(float), 4 );
89 csr_rt_clear( &api
->target
);
95 void frag_gbuffer( void *dest
, vmf_vert tri
[3], float bca
, float bcb
, float bcc
)
97 float *dest_colour
= (float *)dest
;
100 v2_sub( tri
[0].origin
, remapping_range
, dest_colour
);
101 v2_div( dest_colour
, &remapping_range
[2], dest_colour
);
103 dest_colour
[2] = tri
[0].co
[2]*bca
+ tri
[1].co
[2]*bcb
+ tri
[2].co
[2]*bcc
;
106 v3_muls( tri
[0].nrm
, bca
, dest_colour
+3 );
107 v3_muladds( dest_colour
+3, tri
[1].nrm
, bcb
, dest_colour
+3 );
108 v3_muladds( dest_colour
+3, tri
[2].nrm
, bcc
, dest_colour
+3 );
110 v3_muls( dest_colour
+3, 0.5f
, dest_colour
+3 );
111 v3_add( (v3f
){0.5f
,0.5f
,0.5f
}, dest_colour
+3, dest_colour
+3 );
114 dest_colour
[6] = 1.f
;
117 void frag_gbuffer_clear( void *dest
)
119 float *dest_colour
= (float *)dest
;
120 dest_colour
[0] = 0.f
;
121 dest_colour
[1] = 0.f
;
122 dest_colour
[2] = min_height
;
124 dest_colour
[3] = 0.5f
;
125 dest_colour
[4] = 0.5f
;
126 dest_colour
[5] = 1.0f
;
128 dest_colour
[6] = 0.f
;