-
Notifications
You must be signed in to change notification settings - Fork 1
/
lighter_test.cpp
575 lines (490 loc) · 16.2 KB
/
lighter_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "lighter.h"
#include "lighter_int.hpp"
#define LTR_VERIFY( x ) printf( "VERIFY: %s : %d\n", #x, x )
template< typename T > T safe_div( T a, T b ){ return b == T(0) ? T(0) : a / b; }
static double ltr_curtime()
{
#ifdef __linux
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC, &ts );
return (double) ts.tv_sec + 0.000000001 * (double) ts.tv_nsec;
#else
clock_t clk = clock();
return (double)( clk ) / (double)( CLOCKS_PER_SEC );
#endif
}
struct testmesh
{
Vec3Vector positions;
Vec3Vector normals;
Vec2Vector texcoords;
U32Vector indices;
u32 InsertVertex( const Vec3& P, const Vec3& N, const Vec2& T )
{
for( size_t i = 0; i < positions.size(); ++i )
{
if( positions[i] == P && normals[i] == N && texcoords[i] == T )
return i;
}
positions.push_back( P );
normals.push_back( N );
texcoords.push_back( T );
return positions.size() - 1;
}
bool Load( const char* file )
{
FILE* fh = fopen( file, "r" );
if( !fh )
return false;
Vec3Vector plist;
Vec3Vector nlist;
Vec2Vector tlist;
int i[9];
Vec3 tmp3;
Vec2 tmp2;
char bfr[5] = {0};
while( !feof( fh ) && fscanf( fh, "%4s", bfr ) )
{
if( !strcmp( bfr, "v" ) )
{
if( fscanf( fh, "%f %f %f\n", &tmp3.x, &tmp3.y, &tmp3.z ) )
plist.push_back( tmp3 );
}
else if( !strcmp( bfr, "vt" ) )
{
if( fscanf( fh, "%f %f\n", &tmp2.x, &tmp2.y ) )
{
tmp2.y = 1 - tmp2.y;
tlist.push_back( tmp2 );
}
}
else if( !strcmp( bfr, "vn" ) )
{
if( fscanf( fh, "%f %f %f\n", &tmp3.x, &tmp3.y, &tmp3.z ) )
nlist.push_back( tmp3 );
}
else if( !strcmp( bfr, "f" ) )
{
if( fscanf( fh, "%d/%d/%d %d/%d/%d %d/%d/%d\n", i+0, i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8 ) )
{
for( int j = 0; j < 9; ++j )
i[j]--;
Vec3 v1p = plist[i[0]], v2p = plist[i[3]], v3p = plist[i[6]];
Vec2 v1t = tlist[i[1]], v2t = tlist[i[4]], v3t = tlist[i[7]];
Vec3 v1n = nlist[i[2]], v2n = nlist[i[5]], v3n = nlist[i[8]];
indices.push_back( InsertVertex( v1p, v1n, v1t ) );
indices.push_back( InsertVertex( v2p, v2n, v2t ) );
indices.push_back( InsertVertex( v3p, v3n, v3t ) );
}
}
bfr[0] = 0;
}
printf( "loaded mesh '%s' - %d verts, %d tris (P %d N %d T %d)\n",
file, (int) positions.size(), (int) indices.size() / 3,
(int) plist.size(), (int) nlist.size(), (int) tlist.size() );
fclose( fh );
return true;
}
};
void dumpimg( const char* file, float* img_rgb, u32 width, u32 height, float top = 1.0f, bool alpha = false )
{
float mult = 255.0f / top;
FILE* fh = fopen( file, "wb" );
if( !fh )
{
printf( "FAILED TO WRITE TO FILE: %s\n", file );
return;
}
unsigned char header[18]={0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
header[12] = width & 0xFF;
header[13] = ( width >> 8) & 0xFF;
header[14] = (height) & 0xFF;
header[15] = (height >> 8) & 0xFF;
header[16] = alpha ? 32 : 24;
fwrite( header, 1, 18, fh );
for( u32 y = height; y > 0; )
{
--y;
if( alpha )
{
for( u32 x = 0; x < width; ++x )
{
u32 off = ( x + width * y ) * 4;
unsigned char btwr[4] =
{
(unsigned char) TMIN( img_rgb[ off+2 ] * mult, 255.0f ),
(unsigned char) TMIN( img_rgb[ off+1 ] * mult, 255.0f ),
(unsigned char) TMIN( img_rgb[ off+0 ] * mult, 255.0f ),
(unsigned char) TMIN( img_rgb[ off+3 ] * mult, 255.0f ),
};
fwrite( btwr, 1, 4, fh );
}
}
else
{
for( u32 x = 0; x < width; ++x )
{
u32 off = ( x + width * y ) * 3;
unsigned char btwr[3] =
{
(unsigned char) TMIN( img_rgb[ off+2 ] * mult, 255.0f ),
(unsigned char) TMIN( img_rgb[ off+1 ] * mult, 255.0f ),
(unsigned char) TMIN( img_rgb[ off+0 ] * mult, 255.0f ),
};
fwrite( btwr, 1, 3, fh );
}
}
}
fclose( fh );
}
void DOWORK( ltr_Scene* scene )
{
ltr_WorkStatus wstatus;
double ta = ltr_curtime();
ltr_Start( scene );
printf( "\n" );
while( ltr_GetStatus( scene, &wstatus ) )
{
printf( "\r%s ... %d%%", wstatus.stage, int(wstatus.completion * 100) );
ltr_Sleep( 50 );
}
double tb = ltr_curtime();
printf( "\n\ntime taken: %f\n", (tb-ta) );
}
void testfunc_basic()
{
puts( "LIGHTER test [basic]" );
ltr_Scene* scene = ltr_CreateScene();
// MESH 1
ltr_Mesh* mesh1 = ltr_CreateMesh( scene, "mesh1", strlen("mesh1") );
// MESH 1 PART 1
float m1_p1_positions[] = { -1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0 };
float m1_p1_normals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 };
float m1_p1_texcoords[] = { 0.1f, 0.1f, 0.9f, 0.1f, 0.9f, 0.9f, 0.1f, 0.9f };
u32 m1_p1_indices[] = { 0, 1, 2, 2, 3, 0 };
ltr_MeshPartInfo m1part1 =
{
m1_p1_positions, m1_p1_normals, m1_p1_texcoords, m1_p1_texcoords,
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
m1_p1_indices, 4, 6, 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh1, &m1part1 ) );
// MESH 1 INSTANCE 1
ltr_MeshInstanceInfo m1inst1;
memset( &m1inst1, 0, sizeof(m1inst1) );
m1inst1.importance = 1;
m1inst1.shadow = 1;
float matrix1[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m1inst1.matrix, matrix1, sizeof(matrix1) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst1 ) );
// MESH 1 INSTANCE 2
ltr_MeshInstanceInfo m1inst2;
memset( &m1inst2, 0, sizeof(m1inst2) );
m1inst2.importance = 1;
m1inst2.shadow = 1;
float c = cos( 0.5f ) * 0.2f, s = sin( 0.5f ) * 0.2f;
float matrix2[16] = { c, s, 0, 0, -s, c, 0, 0, 0, 0, 0.2f, 0, 0, 0, 0.5f, 1 };
memcpy( m1inst2.matrix, matrix2, sizeof(matrix2) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst2 ) );
// MESH 1 INSTANCE 3
ltr_MeshInstanceInfo m1inst3;
memset( &m1inst3, 0, sizeof(m1inst3) );
m1inst3.importance = 1;
m1inst3.shadow = 1;
float matrix3[16] = { 1.9f, 0, 0, 0, 0, 1.9f, 0, 0, 0, 0, 1.9f, 0, 0, 0, -0.5f, 1 };
memcpy( m1inst3.matrix, matrix3, sizeof(matrix3) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst3 ) );
// LIGHTS
ltr_LightInfo lights[] =
{
{ LTR_LT_POINT, { -0.4f, -0.4f, 1 }, {0,0,0}, {0,0,0}, { 0.9f, 0.1f, 0.05f }, 4.0f, 1.0f, 0.1f, 9 },
};
for( size_t lt = 0; lt < sizeof(lights)/sizeof(lights[0]); ++lt )
ltr_LightAdd( scene, &lights[ lt ] );
// --- DO WORK ---
DOWORK( scene );
// --- RETURN OUTPUT ---
ltr_WorkOutput wout;
ltr_WorkOutputInfo woutinfo;
ltr_GetWorkOutputInfo( scene, &woutinfo );
for( u32 lm = 0; lm < woutinfo.lightmap_count; ++lm )
{
LTR_VERIFY( ltr_GetWorkOutput( scene, lm, &wout ) );
char namebfr[ 64 ];
sprintf( namebfr, "%d.tga", (int) wout.uid );
dumpimg( namebfr, wout.lightmap_rgb, wout.width, wout.height );
}
ltr_DestroyScene( scene );
}
void testfunc_hugeoverlap()
{
puts( "LIGHTER test [hugeoverlap]" );
ltr_Scene* scene = ltr_CreateScene();
// MESH 1
ltr_Mesh* mesh1 = ltr_CreateMesh( scene, "mesh1", strlen("mesh1") );
// MESH 1 PART 1
float m1_p1_positions[] = { -1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0 };
float m1_p1_normals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 };
float m1_p1_texcoords[] = { 0.1f, 0.1f, 0.9f, 0.1f, 0.9f, 0.9f, 0.1f, 0.9f };
#define II 0, 1, 2, 2, 3, 0,
u32 m1_p1_indices[] = { II II II II II II II II II II II II II II II II };
ltr_MeshPartInfo m1part1 =
{
m1_p1_positions, m1_p1_normals, m1_p1_texcoords, m1_p1_texcoords,
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
m1_p1_indices, 4, sizeof(m1_p1_indices) / sizeof(m1_p1_indices[0]), 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh1, &m1part1 ) );
// MESH 1 INSTANCE 1
ltr_MeshInstanceInfo m1inst1;
memset( &m1inst1, 0, sizeof(m1inst1) );
m1inst1.importance = 1;
m1inst1.shadow = 1;
float matrix1[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m1inst1.matrix, matrix1, sizeof(matrix1) );
for( int i = 0; i < 10; ++i )
{
ltr_MeshAddInstance( mesh1, &m1inst1 );
}
// LIGHTS
ltr_LightInfo lights[] =
{
{ LTR_LT_POINT, { -0.4f, -0.4f, 1 }, {0,0,0}, {0,0,0}, { 0.9f, 0.1f, 0.05f }, 4.0f, 1.0f, 0.1f, 9 },
};
for( size_t lt = 0; lt < sizeof(lights)/sizeof(lights[0]); ++lt )
ltr_LightAdd( scene, &lights[ lt ] );
// --- DO WORK ---
DOWORK( scene );
ltr_DestroyScene( scene );
}
void testfunc_mesh1()
{
puts( "LIGHTER test [mesh1]" );
ltr_Scene* scene = ltr_CreateScene();
ltr_Config cfg;
ltr_GetConfig( &cfg, scene );
cfg.ao_distance = 2;
ltr_SetConfig( scene, &cfg );
// MESH 1
ltr_Mesh* mesh1 = ltr_CreateMesh( scene, "mesh1", strlen("mesh1") );
testmesh M;
LTR_VERIFY( (int) M.Load( "bin/test-mesh.data" ) );
// MESH 1 PART 1
ltr_MeshPartInfo m1part1 =
{
&M.positions[0], &M.normals[0], &M.texcoords[0], &M.texcoords[0],
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
&M.indices[0], (u32) M.positions.size(), (u32) M.indices.size(), 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh1, &m1part1 ) );
// MESH 1 INSTANCE 1
ltr_MeshInstanceInfo m1inst1;
memset( &m1inst1, 0, sizeof(m1inst1) );
m1inst1.importance = 1;
m1inst1.shadow = 1;
float matrix1[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m1inst1.matrix, matrix1, sizeof(matrix1) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst1 ) );
// LIGHTS
ltr_LightInfo lights[] =
{
{ LTR_LT_POINT, { -2.18f, -4.04f, 1.40f }, {0,0,0}, {0,0,0}, { 0.9f, 0.7f, 0.5f }, 16.0f, 1.0f, 0.1f, 5 },
{ LTR_LT_POINT, { 2.18f, 4.04f, 1.40f }, {0,0,0}, {0,0,0}, { 0.5f, 0.7f, 0.9f }, 16.0f, 1.0f, 0.1f, 5 },
{ LTR_LT_SPOT, { 0, 0, 1.60f }, {0,0,-1}, {1,0,0}, { 0.7f, 0.1f, 0.05f }, 16.0f, 1.0f, 0.1f, 5, 45.0f, 25.0f, 0.5f },
};
for( size_t lt = 0; lt < sizeof(lights)/sizeof(lights[0]); ++lt )
ltr_LightAdd( scene, &lights[ lt ] );
// --- DO WORK ---
DOWORK( scene );
// --- RETURN OUTPUT ---
ltr_WorkOutput wout;
ltr_WorkOutputInfo woutinfo;
ltr_GetWorkOutputInfo( scene, &woutinfo );
for( u32 lm = 0; lm < woutinfo.lightmap_count; ++lm )
{
LTR_VERIFY( ltr_GetWorkOutput( scene, lm, &wout ) );
char namebfr[ 64 ];
sprintf( namebfr, "%d.tga", (int) wout.uid );
dumpimg( namebfr, wout.lightmap_rgb, wout.width, wout.height );
}
ltr_DestroyScene( scene );
}
void testfunc_mesh2()
{
puts( "LIGHTER test [mesh2]" );
ltr_Scene* scene = ltr_CreateScene();
ltr_Config cfg;
ltr_GetConfig( &cfg, scene );
cfg.ao_distance = 2;
// cfg.ao_multiplier = 0.1f;
cfg.global_size_factor = 4;
cfg.blur_size = 0;
// cfg.ds2x = 1;
cfg.generate_normalmap_data = 1;
ltr_SetConfig( scene, &cfg );
// MESH 1
ltr_Mesh* mesh1 = ltr_CreateMesh( scene, "mesh1", strlen("mesh1") );
testmesh M;
LTR_VERIFY( (int) M.Load( "bin/test-set2-mesh1.data" ) );
// MESH 1 PART 1
ltr_MeshPartInfo m1part1 =
{
&M.positions[0], &M.normals[0], &M.texcoords[0], &M.texcoords[0],
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
&M.indices[0], (u32) M.positions.size(), (u32) M.indices.size(), 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh1, &m1part1 ) );
// MESH 1 INSTANCE 1
ltr_MeshInstanceInfo m1inst1;
memset( &m1inst1, 0, sizeof(m1inst1) );
m1inst1.importance = 1;
m1inst1.shadow = 1;
float matrix1[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m1inst1.matrix, matrix1, sizeof(matrix1) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst1 ) );
// MESH 2
ltr_Mesh* mesh2 = ltr_CreateMesh( scene, "mesh2", strlen("mesh2") );
testmesh M2;
LTR_VERIFY( (int) M2.Load( "bin/test-set2-mesh2.data" ) );
// MESH 2 PART 1
ltr_MeshPartInfo m2part1 =
{
&M2.positions[0], &M2.normals[0], &M2.texcoords[0], &M2.texcoords[0],
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
&M2.indices[0], (u32) M2.positions.size(), (u32) M2.indices.size(), 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh2, &m2part1 ) );
// MESH 2 INSTANCE 1
ltr_MeshInstanceInfo m2inst1;
memset( &m2inst1, 0, sizeof(m2inst1) );
m2inst1.importance = 0.3f;
m2inst1.shadow = 1;
float matrix2[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m2inst1.matrix, matrix2, sizeof(matrix2) );
LTR_VERIFY( ltr_MeshAddInstance( mesh2, &m2inst1 ) );
// LIGHTS
ltr_LightInfo lights[] =
{
{ LTR_LT_POINT, { -2.18f, -4.04f, 1.40f }, {0,0,0}, {0,0,0}, { 0.9f, 0.7f, 0.5f }, 16.0f, 1.0f, 0.2f, 5, 0, 0, 0 },
{ LTR_LT_POINT, { 2.18f, 4.04f, 1.40f }, {0,0,0}, {0,0,0}, { 0.5f, 0.7f, 0.9f }, 16.0f, 1.0f, 0.2f, 5, 0, 0, 0 },
{ LTR_LT_SPOT, { 0, 0, 1.60f }, {0,0,-1}, {1,0,0}, { 0.7f, 0.1f, 0.05f }, 16.0f, 1.0f, 0.2f, 5, 45.0f, 25.0f, 0.5f },
{ LTR_LT_DIRECT, {0,0,0}, { 1, 1, 1 }, {0,0,0}, { 0.6f, 0.55f, 0.5f }, 1000.0f, 1.0f, 0.2f, 1, 0, 0, 0 },
};
for( size_t lt = 0; lt < sizeof(lights)/sizeof(lights[0]); ++lt )
ltr_LightAdd( scene, &lights[ lt ] );
// --- DO WORK ---
DOWORK( scene );
// --- RETURN OUTPUT ---
ltr_WorkOutput wout;
ltr_WorkOutputInfo woutinfo;
ltr_GetWorkOutputInfo( scene, &woutinfo );
for( u32 lm = 0; lm < woutinfo.lightmap_count; ++lm )
{
LTR_VERIFY( ltr_GetWorkOutput( scene, lm, &wout ) );
char namebfr[ 64 ];
sprintf( namebfr, "%d.tga", (int) wout.uid );
dumpimg( namebfr, wout.lightmap_rgb, wout.width, wout.height );
sprintf( namebfr, "%dN.tga", (int) wout.uid );
for( u32 px = 0; px < wout.width * wout.height; ++px )
{
int off = px * 4;
wout.normals_xyzf[ off + 0 ] = wout.normals_xyzf[ off + 0 ] * 0.5f + 0.5f;
wout.normals_xyzf[ off + 1 ] = wout.normals_xyzf[ off + 1 ] * 0.5f + 0.5f;
wout.normals_xyzf[ off + 2 ] = wout.normals_xyzf[ off + 2 ] * 0.5f + 0.5f;
}
dumpimg( namebfr, wout.normals_xyzf, wout.width, wout.height, 1.0f, true );
}
ltr_DestroyScene( scene );
}
LTRBOOL rad1_samplefunc( ltr_Config* cfg, ltr_SampleRequest* req )
{
// printf( "T1[ %g %g ] T2[ %g %g ]\n", req->tex0u, req->tex0v, req->tex1u, req->tex1v );
if( req->position[0] <= -3 && Vec3Dot( Vec3::CreateFromPtr( req->normal ), Vec3::Create( 1, 0, 0 ) ) > 0.1f )
{
req->out_diffuse_color[0] = 0.5f;
req->out_diffuse_color[1] = 0.05f;
req->out_diffuse_color[2] = 0.02f;
}
return 1;
}
void testfunc_rad1()
{
puts( "LIGHTER test [rad1]" );
ltr_Scene* scene = ltr_CreateScene();
ltr_Config cfg;
ltr_GetConfig( &cfg, scene );
cfg.ao_distance = 2;
cfg.bounce_count = 2;
cfg.sample_fn = rad1_samplefunc;
ltr_SetConfig( scene, &cfg );
// MESH 1
ltr_Mesh* mesh1 = ltr_CreateMesh( scene, "mesh1", strlen("mesh1") );
testmesh M;
LTR_VERIFY( (int) M.Load( "bin/test-set2-mesh1.data" ) );
// MESH 1 PART 1
ltr_MeshPartInfo m1part1 =
{
&M.positions[0], &M.normals[0], &M.texcoords[0], &M.texcoords[0],
sizeof(float)*3, sizeof(float)*3, sizeof(float)*2, sizeof(float)*2,
&M.indices[0], (u32) M.positions.size(), (u32) M.indices.size(), 1
};
LTR_VERIFY( ltr_MeshAddPart( mesh1, &m1part1 ) );
// MESH 1 INSTANCE 1
ltr_MeshInstanceInfo m1inst1;
memset( &m1inst1, 0, sizeof(m1inst1) );
m1inst1.importance = 0.4f;
m1inst1.shadow = 1;
float matrix1[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
memcpy( m1inst1.matrix, matrix1, sizeof(matrix1) );
LTR_VERIFY( ltr_MeshAddInstance( mesh1, &m1inst1 ) );
// LIGHTS
ltr_LightInfo lights[] =
{
{ LTR_LT_POINT, { 10.18f, 0, 1.40f }, {0,0,0}, {0,0,0}, { 0.99f, 0.97f, 0.95f }, 24.0f, 1.0f, 0.1f, 5 },
// { LTR_LT_POINT, { 2.18f, 4.04f, 1.40f }, {0,0,0}, {0,0,0}, { 0.5f, 0.7f, 0.9f }, 16.0f, 1.0f, 0.1f, 5 },
// { LTR_LT_SPOT, { 0, 0, 1.60f }, {0,0,-1}, {1,0,0}, { 0.7f, 0.1f, 0.05f }, 16.0f, 1.0f, 0.1f, 5, 45.0f, 25.0f, 0.5f },
};
for( size_t lt = 0; lt < sizeof(lights)/sizeof(lights[0]); ++lt )
ltr_LightAdd( scene, &lights[ lt ] );
// --- DO WORK ---
DOWORK( scene );
// --- RETURN OUTPUT ---
ltr_WorkOutput wout;
ltr_WorkOutputInfo woutinfo;
ltr_GetWorkOutputInfo( scene, &woutinfo );
for( u32 lm = 0; lm < woutinfo.lightmap_count; ++lm )
{
LTR_VERIFY( ltr_GetWorkOutput( scene, lm, &wout ) );
char namebfr[ 64 ];
sprintf( namebfr, "%d.tga", (int) wout.uid );
dumpimg( namebfr, wout.lightmap_rgb, wout.width, wout.height );
}
ltr_DestroyScene( scene );
}
void test_systems()
{
testfunc_basic();
testfunc_hugeoverlap();
}
const char* testname = "test";
int main( int argc, char* argv[] )
{
if( argc > 1 )
testname = argv[1];
if( strcmp( testname, "basic" ) == 0 )
testfunc_basic();
else if( strcmp( testname, "mesh1" ) == 0 )
testfunc_mesh1();
else if( strcmp( testname, "mesh2" ) == 0 )
testfunc_mesh2();
else if( strcmp( testname, "rad1" ) == 0 )
testfunc_rad1();
else if( strcmp( testname, "test" ) == 0 )
test_systems();
else
printf( "TEST NOT FOUND: %s\n", testname );
return 0;
}