8f9bdb3115e2bc05d0c05f1bf6459b1851773157
7 static int ray_world( v3f pos
, v3f dir
, ray_hit
*hit
);
9 typedef struct voxel_gi voxel_gi
;
16 v3i pt_dims
; /* Page table dimentions */
22 static void voxel_gi_setup( voxel_gi
*gi
, scene
*sc
,
23 i32 page_size
, float voxel_res
)
25 v3_copy( sc
->bbx
[0], gi
->origin
);
26 gi
->page_size
= page_size
;
29 v3_sub( sc
->bbx
[1], sc
->bbx
[0], extent
);
31 float fpage_size
= voxel_res
* (float)page_size
;
33 for( int i
=0; i
<3; i
++ )
35 i32 voxel_count
= extent
[i
] / voxel_res
;
36 gi
->pt_dims
[i
] = (voxel_count
+page_size
-1) / page_size
;
39 i32 pt_capacity
= gi
->pt_dims
[0]*gi
->pt_dims
[1]*gi
->pt_dims
[2];
40 vg_info( "Page table size: %dkb\n", (pt_capacity
*2*2)/1024 );
42 u16
*page_table
= malloc( pt_capacity
*sizeof(u16
)*3 );
47 for( int z
=0; z
<gi
->pt_dims
[2]; z
++ )
49 for( int y
=0; y
<gi
->pt_dims
[1]; y
++ )
51 for( int x
=0; x
<gi
->pt_dims
[0]; x
++ )
58 v3_muladds( sc
->bbx
[0], base
, ((float)page_size
)*voxel_res
, base
);
59 v3_muladds( sc
->bbx
[0], end
, ((float)page_size
)*voxel_res
, end
);
60 v3_copy( base
, page_region
[0] );
61 v3_copy( end
, page_region
[1] );
64 if( bh_select( &sc
->bhtris
, page_region
, nothing
, 2 ))
68 /* Calculate lighting */
74 /* Calculate physical storage size */
75 vg_info( "Hardware texture required size: %dmb\n",
76 ((active_count
*page_size
*page_size
*page_size
*1)/1024)/1024 );
77 vg_info( "Required physical blocks: %d\n", active_count
);
82 static void compute_lighting_vertex( scene
*sc
)
84 v3f light_dir
= { 0.2f
, 1.0f
, 1.0f
};
85 v3_normalize( light_dir
);
87 for( int i
=0; i
<sc
->vertex_count
; i
++ )
89 model_vert
*mv
= &sc
->verts
[i
];
94 ray_world( mv
->co
, light_dir
, &hit
);
95 float amt
= hit
.dist
/ 100.0f
;
100 mv
->colour
[3] = 1.0f
;
104 #endif /* LIGHTING_H */