Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change the material submodule to support texture arrays; this is just…
… a proof of concept, not the best code; I stopped at the point where I tried resizing the sampler arrays in the frag shader to length=2, and the shader compiler gave me confusing errors about duplicate indices; I think we should try updating rendy/gfx before proceeding to make sure we get all of the upstream spirv-cross fixes
  • Loading branch information
bonsairobo committed Jul 28, 2020
1 parent 3182a2e commit fc85aef
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 301 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -9,7 +9,8 @@ name = "voxel_mapper"
path = "src/lib.rs"

[dependencies]
amethyst = "0.15"
# amethyst = "0.15"
amethyst = { git = "https://github.com/bonsairobo/amethyst", branch = "voxel-renderpass" }
bincode = "1.3.1"
derivative = "1.0.4"
failure = "0.1.8"
Expand Down
2 changes: 1 addition & 1 deletion src/rendering.rs
@@ -1,5 +1,5 @@
pub mod base_3d;
pub mod material_set;
pub mod material_array;
pub mod render_plugin;
pub mod slotted_buffer;
pub mod triplanar_pass;
23 changes: 14 additions & 9 deletions src/rendering/base_3d.rs
@@ -1,6 +1,6 @@
// Copied from amethyst_rendy. All skinning and transparent stuff removed.

use super::material_set::{MaterialId, MaterialSub};
use super::material_array::{MaterialArray, MaterialArrayId, MaterialSub};

use amethyst::assets::{AssetStorage, Handle};
use amethyst::core::{
Expand All @@ -9,7 +9,7 @@ use amethyst::core::{
};
use amethyst::renderer::{
batch::{GroupIterator, TwoLevelBatch},
mtl::{Material, StaticTextureSet},
mtl::StaticTextureSet,
pipeline::{PipelineDescBuilder, PipelinesBuilder},
pod::VertexArgs,
resources::Tint,
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<B: Backend, T: Base3DPassDef> RenderGroupDesc<B, World> for DrawBase3DDesc<
pub struct DrawBase3D<B: Backend, T: Base3DPassDef> {
pipeline_basic: B::GraphicsPipeline,
pipeline_layout: B::PipelineLayout,
static_batches: TwoLevelBatch<MaterialId, u32, SmallVec<[VertexArgs; 4]>>,
static_batches: TwoLevelBatch<MaterialArrayId, u32, SmallVec<[VertexArgs; 4]>>,
vertex_format_base: Vec<VertexFormat>,
env: EnvironmentSub<B>,
materials: MaterialSub<B, T::TextureSet>,
Expand All @@ -159,7 +159,7 @@ impl<B: Backend, T: Base3DPassDef> RenderGroup<B, World> for DrawBase3D<B, T> {
Read<'_, AssetStorage<Mesh>>,
ReadExpect<'_, Visibility>,
ReadStorage<'_, Handle<Mesh>>,
ReadStorage<'_, Handle<Material>>,
ReadStorage<'_, MaterialArray>,
ReadStorage<'_, Transform>,
ReadStorage<'_, JointTransforms>,
ReadStorage<'_, Tint>,
Expand All @@ -179,13 +179,18 @@ impl<B: Backend, T: Base3DPassDef> RenderGroup<B, World> for DrawBase3D<B, T> {
profile_scope_impl!("prepare");
(static_input(), &visibility.visible_unordered)
.join()
.map(|(((mat, mesh, tform, tint), _), _)| {
((mat, mesh.id()), VertexArgs::from_object_data(tform, tint))
.map(|(((mat_arr, mesh, tform, tint), _), _)| {
(
(mat_arr, mesh.id()),
VertexArgs::from_object_data(tform, tint),
)
})
.for_each_group(|(mat, mesh_id), data| {
.for_each_group(|(mat_arr, mesh_id), data| {
if mesh_storage.contains_id(mesh_id) {
if let Some((mat, _)) = materials_ref.insert(factory, resources, mat) {
statics_ref.insert(mat, mesh_id, data.drain(..));
if let Some((mat_arr_id, _)) =
materials_ref.insert(factory, resources, mat_arr)
{
statics_ref.insert(mat_arr_id, mesh_id, data.drain(..));
}
}
});
Expand Down

0 comments on commit fc85aef

Please sign in to comment.