- v3_floor( q, rel );
- v3_sub( q, rel, q );
-
- int x=rel[0],
- y=rel[1],
- z=rel[2];
-
-#ifndef JUST_DO_EVERY_VERT
-#ifndef DYNAMIC_GRID
- x = VG_MIN(x,ax-2);
- y = VG_MIN(y,ay-2);
- z = VG_MIN(z,az-2);
- x = VG_MAX(x,0);
- y = VG_MAX(y,0);
- z = VG_MAX(z,0);
-
- float
- s0 = samplegrid[ x + y*ax + z*ax*ay],
- s1 = samplegrid[(x+1) + y*ax + z*ax*ay],
- s2 = samplegrid[ x + (y+1)*ax + z*ax*ay],
- s3 = samplegrid[(x+1) + (y+1)*ax + z*ax*ay],
- s4 = samplegrid[ x + y*ax + (z+1)*ax*ay],
- s5 = samplegrid[(x+1) + y*ax + (z+1)*ax*ay],
- s6 = samplegrid[ x + (y+1)*ax + (z+1)*ax*ay],
- s7 = samplegrid[(x+1) + (y+1)*ax + (z+1)*ax*ay],
-#else
- if( x!=cube_pos[0] || y!=cube_pos[1] || z!=cube_pos[2] )
- {
- cube_pos[0] = x;
- cube_pos[1] = y;
- cube_pos[2] = z;
-
- s0 = scene_ambient_sample( pscene, (v3f){ x,y,z }, sundir );
- s1 = scene_ambient_sample( pscene, (v3f){ x+1,y,z }, sundir );
- s2 = scene_ambient_sample( pscene, (v3f){ x,y+1,z }, sundir );
- s3 = scene_ambient_sample( pscene, (v3f){ x+1,y+1,z }, sundir );
- s4 = scene_ambient_sample( pscene, (v3f){ x,y,z+1 }, sundir );
- s5 = scene_ambient_sample( pscene, (v3f){ x+1,y,z+1 }, sundir );
- s6 = scene_ambient_sample( pscene, (v3f){ x,y+1,z+1 }, sundir );
- s7 = scene_ambient_sample( pscene, (v3f){ x+1,y+1,z+1 }, sundir );
-
- cube_resamples += 8;
- misses ++;
- }
- else
- hits ++;
-
- float
-#endif
-
- s0_s1 = vg_lerpf( s0, s1, q[0] ),
- s2_s3 = vg_lerpf( s2, s3, q[0] ),
- s4_s5 = vg_lerpf( s4, s5, q[0] ),
- s6_s7 = vg_lerpf( s6, s7, q[0] ),
-
- s0s1_s2s3 = vg_lerpf( s0_s1, s2_s3, q[1] ),
- s4s5_s6s7 = vg_lerpf( s4_s5, s6_s7, q[1] ),
- s0s1s2s3_s4s5s6s7 = vg_lerpf( s0s1_s2s3, s4s5_s6s7, q[2] );
-
- vert->colour[1] = s0s1s2s3_s4s5s6s7;
-#else
- vert->colour[1] = scene_ambient_sample( pscene, vert->co, sundir );
-#endif
- }
-
-#ifndef DYNAMIC_GRID
- int cube_resamples = -1, misses = 0, hits = 0;
-#endif
-
- int static_samples = ax*ay*az,
- vertex_samples = pscene->vertex_count;
-
- if( cube_resamples < static_samples )
- vg_success( "Walking cube beat static grid (%d<%d. %d)!\n",
- cube_resamples, static_samples, vertex_samples );
- else
- vg_warn( "Walking cube was worse than static grid (%d<%d. %d).\n",
- cube_resamples, static_samples, vertex_samples );
-
- vg_info( "Hits; %d, misses: %d\n", hits, misses );
-
-#ifndef DYNAMIC_GRID
- free( samplegrid );
-#endif
-
- return;
-
- for( int i=0; i<pscene->vertex_count; i++ )
- {
- model_vert *vert = &pscene->verts[i];
- float accum = 0.0f;
-
- for( int j=0; j<5; j++ )
- {
- v3f tracepos;
- v3_copy( vert->co, tracepos );
- v3_muladds( tracepos, sundir, 1.5f*(float)j, tracepos );
-
- float mindist = 99999.9f;
-
- for( int k=0; k<pscene->shadower_count; k++ )
- {
- struct shadower *shadower = &pscene->shadowers[k];
- float dist = vg_maxf( 0.0f, sd_cone( tracepos, &shadower->sdf ));
- mindist = vg_minf( mindist, dist );
- }
-
- accum += vg_clampf( 1.0f - mindist, 0.0f, 1.0f )*0.2f;
- }
-
- vert->colour[1] = vg_minf( accum, 1.0f );
- }
-}
-
-static void scene_upload( scene *pscene )
-{
- mesh_upload( &pscene->mesh,
- pscene->verts, pscene->vertex_count,
- pscene->indices, pscene->indice_count );
-
- vg_info( "Scene upload\n" );
- vg_info( " indices:%u\n", pscene->indice_count );
- vg_info( " verts:%u\n", pscene->vertex_count );
-}
-
-float scene_tree_sway = 0.1f;
-
-#if 0
-static void scene_foliage_shader_use(void)
-{
- SHADER_USE( shader_debug_vcol );
-
- glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol, "uPv" ),
- 1, GL_FALSE, (float *)vg_pv );
-
- glUniform1i( SHADER_UNIFORM( shader_debug_vcol, "uMode" ), debugview );
- glUniform1i( SHADER_UNIFORM( shader_debug_vcol, "uTexMain" ), 0 );