Voxelise trees

This commit is contained in:
Joshua Barretto 2022-05-09 13:51:04 +01:00
parent 3881d2ea38
commit 2df01385d2
8 changed files with 38 additions and 5 deletions

2
.gitattributes vendored
View File

@ -7,6 +7,8 @@
*.ogg filter=lfs diff=lfs merge=lfs -text *.ogg filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text *.ico filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text *.tar filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
assets/world/map/*.bin filter=lfs diff=lfs merge=lfs -text assets/world/map/*.bin filter=lfs diff=lfs merge=lfs -text
*.ron gitlab-language=rust *.ron gitlab-language=rust

Binary file not shown.

View File

@ -1,4 +1,4 @@
# Blender v3.0.0 OBJ File: '' # Blender v3.0.0 OBJ File: 'pine.blend'
# www.blender.org # www.blender.org
o Cube.007 o Cube.007
v -2.819197 -0.013505 -2.712447 v -2.819197 -0.013505 -2.712447

View File

@ -69,6 +69,32 @@ void main() {
vec3 k_d = vec3(1.0); vec3 k_d = vec3(1.0);
vec3 k_s = vec3(R_s); vec3 k_s = vec3(R_s);
vec3 my_norm = vec3(f_norm.xy, abs(f_norm.z));
vec3 voxel_norm;
float my_alt = f_pos.z + focus_off.z;
float f_ao = 1.0;
const float VOXELIZE_DIST = 2000;
float voxelize_factor = clamp(1.0 - (distance(focus_pos.xy, f_pos.xy) - view_distance.x) / VOXELIZE_DIST, 0, 0.75);
vec3 cam_dir = normalize(cam_pos.xyz - f_pos.xyz);
vec3 side_norm = normalize(vec3(my_norm.xy, 0));
vec3 top_norm = vec3(0, 0, 1);
float side_factor = 1.0 - my_norm.z;
// min(dot(vec3(0, -sign(cam_dir.y), 0), -cam_dir), dot(vec3(-sign(cam_dir.x), 0, 0), -cam_dir))
if (max(abs(my_norm.x), abs(my_norm.y)) < 0.01 || fract(my_alt) * clamp(dot(normalize(vec3(cam_dir.xy, 0)), side_norm), 0, 1) < cam_dir.z / my_norm.z) {
f_ao *= mix(1.0, clamp(fract(my_alt) / length(my_norm.xy) + clamp(dot(side_norm, -cam_dir), 0, 1), 0, 1), voxelize_factor);
voxel_norm = top_norm;
} else {
f_ao *= mix(1.0, clamp(pow(fract(my_alt), 0.5), 0, 1), voxelize_factor);
if (fract(f_pos.x) * abs(my_norm.y / cam_dir.x) < fract(f_pos.y) * abs(my_norm.x / cam_dir.y)) {
voxel_norm = vec3(sign(cam_dir.x), 0, 0);
} else {
voxel_norm = vec3(0, sign(cam_dir.y), 0);
}
}
f_ao = min(f_ao, max(f_norm.z * 0.5 + 0.5, 0.0));
voxel_norm = mix(my_norm, voxel_norm == vec3(0.0) ? f_norm : voxel_norm, voxelize_factor);
vec3 emitted_light, reflected_light; vec3 emitted_light, reflected_light;
// This is a bit of a hack. Because we can't find the volumetric lighting of each particle (they don't talk to the // This is a bit of a hack. Because we can't find the volumetric lighting of each particle (they don't talk to the
@ -90,9 +116,12 @@ void main() {
// : compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz); // : compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
//#endif //#endif
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); max_light += get_sun_diffuse2(sun_info, moon_info, voxel_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, voxel_norm, 1.0, emitted_light, reflected_light);
//max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); emitted_light *= f_ao;
reflected_light *= f_ao;
//max_light += lights_at(f_pos, voxel_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, voxel_norm, 1.0, emitted_light, reflected_light);
surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light); surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light);

View File

@ -37,7 +37,7 @@ void main() {
f_pos.z -= pull_down; f_pos.z -= pull_down;
f_norm = v_norm; f_norm = v_norm;
f_col = vec4(vec3(0.01, 0.04, 0.0) * 1, 1.0);//vec4(v_col, 1.0); f_col = vec4(vec3(0.02, 0.1, 0.01) * (sin(inst_pos.xyy) * 0.33 + 0.66), 1.0);//vec4(v_col, 1.0);
if ((inst_flags & FLAG_SNOW_COVERED) > 0u) { if ((inst_flags & FLAG_SNOW_COVERED) > 0u) {
f_col.rgb = mix(f_col.rgb, vec3(1), pow(max(f_norm.z, 0.0), 0.5)); f_col.rgb = mix(f_col.rgb, vec3(1), pow(max(f_norm.z, 0.0), 0.5));

View File

@ -11,6 +11,7 @@ assets_manager = {version = "0.7", features = ["bincode", "ron", "json"]}
ron = { version = "0.7", default-features = false } ron = { version = "0.7", default-features = false }
dot_vox = "4.0" dot_vox = "4.0"
wavefront = "0.2" wavefront = "0.2"
#wavefront = { path = "../../../../wavefront" }
image = { version = "0.23.12", default-features = false, features = ["png"] } image = { version = "0.23.12", default-features = false, features = ["png"] }
tracing = "0.1" tracing = "0.1"

View File

@ -40,5 +40,5 @@ pub fn to_wpos(wpos: i32) -> i32 {
} }
pub fn from_wpos(zone_pos: i32) -> i32 { pub fn from_wpos(zone_pos: i32) -> i32 {
zone_pos / (TerrainChunkSize::RECT_SIZE.x * ZONE_SIZE) as i32 zone_pos.div_euclid((TerrainChunkSize::RECT_SIZE.x * ZONE_SIZE) as i32)
} }

View File

@ -166,6 +166,7 @@ fn make_lod_object(
v.position().into(), v.position().into(),
v.normal().unwrap_or([0.0, 0.0, 1.0]).into(), v.normal().unwrap_or([0.0, 0.0, 1.0]).into(),
Vec3::broadcast(1.0), Vec3::broadcast(1.0),
//v.color().unwrap_or([1.0; 3]).into(),
)); ));
Tri::new(a, b, c) Tri::new(a, b, c)
}) })