- float *dst = &image[ (l*1024+x)*3 ];
- void *src = rt->colour + ((1023-l)*1024+x) * rt->num_samples * rt->shader->stride;
-
- v3_muls( (float *)src, contrib, dst );
-
- for( int j = 1; j < rt->num_samples; j ++ )
+ v3_muladds( dst, (float *)(src + k*rt->shader->stride), contrib, dst );
+ }
+ }
+
+ if( !csr_32f_write( path, rt->x, rt->y, image ) )
+ csr_write_filerr( path );
+
+ free( image );
+}
+
+// Save floating point buffer to tga. Must be in range (0-1)
+// Offset and stride are in bytes
+void csr_rt_save_tga( csr_target *rt, const char *path, u32 offset, u32 nc )
+{
+ u8 *image = (u8 *)csr_malloc( rt->x*rt->y * 4 );
+
+ float contrib = 255.f/(float)rt->num_samples;
+
+ for( int i = 0; i < rt->x*rt->y; i ++ )
+ {
+ void *src = rt->colour + offset + i * rt->num_samples * rt->shader->stride;
+ u8 *dst = image + i*4;
+
+ v4f accum = { 0.f, 0.f, 0.f, 0.f };
+
+ for( int k = 0; k < rt->num_samples; k ++ )
+ {
+ float *src_sample = (float *)(src + k*rt->shader->stride);
+
+ for( int j = 0; j < nc; j ++ )