-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bevy 0.10 #18
Bevy 0.10 #18
Conversation
@Game4all I need your help here. There is something I missed or did wrong when configuring the stages. It seems that when it reaches the render stage, something is missing from the app, a resource of something. I presume it might have to do with where ChunkLoadingStage is located |
I'll check out your branch later, but the errors you're running into are kind of weird for sure |
Thanks |
started investigating late night, pipelined rendering doesn 't seem to play nice with extract<> resources. Managed to get stuff running without crashing (no chunks were rendered though) with the following patch: diff --git a/src/voxel/render/terrain_uniforms.rs b/src/voxel/render/terrain_uniforms.rs
index dd0cb1f..2131718 100644
--- a/src/voxel/render/terrain_uniforms.rs
+++ b/src/voxel/render/terrain_uniforms.rs
@@ -217,11 +217,13 @@ impl Plugin for VoxelTerrainUniformsPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.sub_app_mut(RenderApp)
.init_resource::<TerrainUniforms>()
- .add_system(extract_voxel_materials.in_set(RenderSet::ExtractCommands))
+ .init_resource::<GpuTerrainMaterials>()
+ .init_resource::<GpuTerrainRenderSettings>()
+ //.add_system(extract_voxel_materials.in_set(RenderSet::ExtractCommands))
.add_system(prepare_terrain_uniforms.in_set(RenderSet::Queue))
.add_system(upload_voxel_materials.in_set(RenderSet::Prepare))
- .add_system(upload_render_distance_uniform.in_set(RenderSet::Prepare))
- .add_system(extract_terrain_render_settings_uniform.in_set(RenderSet::ExtractCommands));
+ .add_system(upload_render_distance_uniform.in_set(RenderSet::Prepare));
+ // .add_system(extract_terrain_render_settings_uniform.in_set(RenderSet::ExtractCommands));
info!("type size: {}", GpuVoxelMaterial::min_size().get() * 256);
}
|
Thanks, will take a look as well |
@naomijub wow, that's very cool to hear! But since this is quite a colossal task, I would like to assist you in doing so. Before you start migrating anything, could you please add me on discord (Game4all#0727) or reach me through the mail displayed on my github profile so we can discuss the way to go with this before potentially wasting any effort? Thanks. |
@Game4all I fixed the crash but Now I'm getting another error, shader error. But I'm not that good with
Commenting this line ( impl Plugin for VoxelTerrainUniformsPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.sub_app_mut(RenderApp)
.init_resource::<TerrainUniforms>()
.init_resource::<GpuTerrainMaterials>()
// .init_resource::<GpuTerrainRenderSettings>()
.add_system(extract_voxel_materials.in_set(RenderSet::ExtractCommands).in_schedule(ExtractSchedule))
.add_system(prepare_terrain_uniforms.in_set(RenderSet::Queue))
.add_system(upload_voxel_materials.in_set(RenderSet::Prepare))
.add_system(extract_terrain_render_settings_uniform.in_set(RenderSet::ExtractCommands).in_schedule(ExtractSchedule))
.add_system(upload_render_distance_uniform.in_set(RenderSet::Prepare));
info!("type size: {}", GpuVoxelMaterial::min_size().get() * 256);
}
} |
looking into this |
You need to add some shader_defs and some additional imports
|
Did some more digging, you probably want to specialize the mesh pipeline which will add all these shader defs for you as well as populating known vertex data
This issue is relevant: bevyengine/bevy#7285 |
Thanks a lot @hans-pistor I will try that |
@hans-pistor by doing this change I get:
|
Did you read the error message? It tells you what it's expecting vs what it got |
I'm far from specialist in shaders, but it doesnt seem to make much sense: let VOXEL_MAT_FLAG_LIQUID: u32 = 2u; // 1 << 1
let TERRAIN_CHUNK_LENGTH: u32 = 32u;
struct VoxelMat {
base_color: vec4<f32>,
flags: u32,
emissive: vec4<f32>,
perceptual_roughness: f32,
metallic: f32,
reflectance: f32,
};
// A GPU-suited representation of voxel materials.
struct VoxelMaterials {
materials: array<VoxelMat>
};
struct TerrainRenderSettings {
render_distance: u32,
};
@group(2) @binding(0)
var<storage> VOXEL_MATERIALS: VoxelMaterials;
@group(2) @binding(1)
var<storage> terrain_settings: TerrainRenderSettings;
// Returns computed fragment color from the current ambient light + diffuse per face lighting
fn calc_voxel_lighting(col: vec3<f32>, n: vec3<f32>) -> vec3<f32> {
let per_face_light = vec3<f32>(0.8, 1.0, 0.6);
let normal = abs(dot(n, vec3<f32>(1., 0., 0.)) * per_face_light.x)
+ abs(dot(n, vec3<f32>(0., 1., 0.)) * per_face_light.y)
+ abs(dot(n, vec3<f32>(0., 0., 1.)) * per_face_light.z);
return normal * col + lights.ambient_color.xyz * 0.21;
} |
Replace the global lets with const |
Weird it is not working well on my windows 🤔 |
Seems there's definitely a problem somewhere as 0 meshes get extracted to the render world hence why nothing gets rendered, as exposed by this patch: diff --git a/src/voxel/render/pipeline.rs b/src/voxel/render/pipeline.rs
index 7d73908..0ac8746 100644
--- a/src/voxel/render/pipeline.rs
+++ b/src/voxel/render/pipeline.rs
@@ -95,6 +95,7 @@ fn queue_voxel_meshes(
) {
let draw_custom = oq_draw_funcs.read().get_id::<DrawVoxel>().unwrap();
let key = MeshPipelineKey::from_msaa_samples(msaa.samples());
+ println!("{} queueable voxel meshes", material_meshes.iter().len());
for (view, mut transparent_phase) in views.iter_mut() {
let view_matrix = view.transform.compute_matrix();
let view_row_2 = view_matrix.row(2); This looks like some system ordering problem??? Will dig deeper and hopefully find the root cause of this. |
Oh you know what. This is likely related to Frustrum culling. Let me pull your latest commit & confirm that |
@Game4all Can you try removing the Aabb on the VoxelTerrainMeshBundle? The Mesh will calculate it's own (from it's vertices) if there isn't an Aabb component present on the entity. The camera uses the Aabb to determine if points are within the frustrum |
Diff
Output:
|
Consistent rendering naomijub/vx_bevy@bevy-0.10...hans-pistor:vx_bevy:fix-schedule-ambiguties (frustrum culling wasn't the root issue) I left in all the debug code, @Game4all @naomijub can one of you productionalize this & I think that should be the final "big" blocker for 0.10? For one, I am manually scheduling via systems but we should probably have better scheduling via the Sets |
@Game4all This branch is working perfectly from my side with @hans-pistor changes |
@@ -12,8 +12,8 @@ mod debug; | |||
mod voxel; | |||
|
|||
fn main() { | |||
App::default() | |||
.add_plugins(DefaultPlugins) | |||
let mut app = App::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hans-pistor : "I left this in to demonstrate how to find scheduling ambiguties."
// app.edit_schedule(CoreSchedule::Main, |schedule| {
// schedule.set_build_settings(ScheduleBuildSettings {
// ambiguity_detection: bevy::ecs::schedule::LogLevel::Error,
// ..Default::default()
// });
// });
src/voxel/world/meshing.rs
Outdated
@@ -39,7 +39,7 @@ static SHARED_MESH_BUFFERS: Lazy<ThreadLocal<RefCell<MeshBuffers<Voxel, ChunkSha | |||
Lazy::new(ThreadLocal::default); | |||
|
|||
/// Queues meshing tasks for the chunks in need of a remesh. | |||
fn queue_mesh_tasks( | |||
pub fn queue_mesh_tasks( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hans-pistor: "Probably not right to keep these as pub. Instead we should have more strict ordering within the different Sets"
Will look at this later in the week |
I also noticed a significant fps drop, maybe LODs could improve this |
Can't believe I didn't see this PR before embarking upon my own epic quest... ugh. Well, feel free to take anything you want from the other one. Only major difference is that I simplified the pipeline by using a custom material for voxels, so we can get actual shadows using the default prepasses. |
@meyerzinn do you want to merge your changes in this one? Maybe create a pr in my fork? |
I can try rebasing on this PR. |
Linked PR got some improvements I would love to get merged in after finishing migrating this. Also system scheduling looks a bit better over there so I may cherry pick on top of the existing branch. |
This reverts commit 2c73e2e.
I've reverted the changes to worldgen for now. Let's get things rolling |
Remaining stuff