// Filter is optional, it can be st to NULL to just render everything.
void csr_vmf_render( csr_target *rt, vmf_map *map, vdf_node *root, csr_filter *filter, m4x3f prev, m4x3f inst );
+
+void csr_rt_save_tga( csr_target *rt, const char *path, u32 offset, u32 nc );
+
// Obsolete
void csr_rt_save_buffers( csr_target *rt, const char *basename, const char *subname );
for( u32 px = start_x; px <= end_x; px ++ )
{
- u32 sample_index = (py * rt->y + px) * rt->num_samples;
+ u32 sample_index = ((rt->y-py-1)*rt->x+px) * rt->num_samples;
void *frag = rt->colour + sample_index*rt->shader->stride;
float *depth = &rt->depth[ sample_index ];
// Derive normal matrix
m4x3_to_3x3( transform, normal );
-
- // NOTE: This isn't strictly necessary since CS:GO only uses uniform scaling.
m3x3_inv_transpose( normal, normal );
for( u32 i = 0; i < triangle_count; i ++ )
m4x3_mulv( transform, triangle[0].co, new_tri[0].co );
m4x3_mulv( transform, triangle[1].co, new_tri[1].co );
m4x3_mulv( transform, triangle[2].co, new_tri[2].co );
+
m3x3_mulv( normal, triangle[0].nrm, new_tri[0].nrm );
m3x3_mulv( normal, triangle[1].nrm, new_tri[1].nrm );
m3x3_mulv( normal, triangle[2].nrm, new_tri[2].nrm );
+ v3_normalize( new_tri[0].nrm );
+ v3_normalize( new_tri[1].nrm );
+ v3_normalize( new_tri[2].nrm );
+
+ m4x3_mulv( transform, triangles[0].origin, new_tri[0].origin );
+
simple_raster( rt, new_tri );
}
}
{
v3_copy( &mdl->vertices[ mdl->indices[ i*3+j ] *8 ], tri[j].co );
v3_copy( &mdl->vertices[ mdl->indices[ i*3+j ] *8+3 ], tri[j].nrm );
- tri[j].xy[0] = 0.f;
- tri[j].xy[1] = 0.f;
+ v3_zero( tri[j].origin );
}
csr_draw( rt, tri, 1, model );
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 y = 0; y < rt->y; y ++ )
+ {
+ for( int x = 0; x < rt->x; x ++ )
+ {
+ u32 pixel_index = (y*rt->x + x);
+
+ void *src = rt->colour + offset + pixel_index * rt->num_samples * rt->shader->stride;
+ u8 *dst = image + pixel_index*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 ++ )
+ {
+ accum[ j ] += src_sample[ j ] * contrib;
+ }
+ }
+
+ // TODO: Clamp this value
+ dst[0] = accum[0];
+ dst[1] = accum[1];
+ dst[2] = accum[2];
+ dst[3] = accum[3];
+ }
+ }
+
+ csr_tga_write( path, rt->x, rt->y, nc, image );
+ free( image );
+}
+
#endif