- v3f sundir = { 0.2f, 0.9f, 0.2f };
- v3_normalize( sundir );
-
- /* TODO: Make this sample grid be dynamically required.
- *
- * 1. Only resample the light grid (1x1x1), when a vertex is outside the
- * current cube
- *
- * 2. Reorder all vertices so that each group of vertices that fit in a
- * cube are next to eachother in the buffer. This will save cache
- * misses.
- *
- * for the sorting algorithm, i think we can already assume that *most
- * vertices will be quite close to eachother. so instead of doing an
- * exhaustive search we can reorder 1k chunks at a time.
- */
-
- v3f sample_area;
- v3_sub( pscene->bbx[1], pscene->bbx[0], sample_area );
- v3_ceil( sample_area, sample_area );
- int ax = sample_area[0],
- ay = sample_area[1],
- az = sample_area[2];
-
-#ifndef DYNAMIC_GRID
- float *samplegrid = malloc( ax*ay*az* sizeof(float) );
-
- for( int x=0; x<ax; x++ ){
- for( int y=0; y<ay; y++ ){
- for( int z=0; z<az; z++ )
- {
- v3f sample_pos = { x,y,z };
- v3_add( pscene->bbx[0], sample_pos, sample_pos );
- float accum = scene_ambient_sample( pscene, sample_pos, sundir );
-
- samplegrid[x + y*ax + z*ax*ay] = accum;
- }}}
-#else
- v3i cube_pos = { -999999, -999999, -999999 };
- int cube_resamples = 0, hits = 0, misses = 0;
-
- float s0=0.0f,s1=0.0f,s2=0.0f,s3=0.0f,s4=0.0f,s5=0.0f,s6=0.0f,s7=0.0f;
-#endif
-
- for( int i=0; i<pscene->vertex_count; i++ )
- {
- model_vert *vert = &pscene->verts[i];
- v3f rel, q;
-
-#ifndef DYNAMIC_GRID
- v3_sub( vert->co, pscene->bbx[0], q );
-#else
- v3_copy( vert->co, q );
-#endif