use texture index
This commit is contained in:
@@ -5,30 +5,33 @@ use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
||||
mod phos;
|
||||
mod prelude;
|
||||
mod shaders;
|
||||
|
||||
use phos::PhosGamePlugin;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Phos".into(),
|
||||
name: Some("phos".into()),
|
||||
resolution: (1920.0, 1080.0).into(),
|
||||
resizable: true,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
DefaultPlugins
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Phos".into(),
|
||||
name: Some("phos".into()),
|
||||
resolution: (1920.0, 1080.0).into(),
|
||||
resizable: true,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
.set(ImagePlugin {
|
||||
default_sampler: ImageSamplerDescriptor {
|
||||
address_mode_u: ImageAddressMode::Repeat,
|
||||
address_mode_v: ImageAddressMode::Repeat,
|
||||
mag_filter: ImageFilterMode::Nearest,
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
}).set(ImagePlugin {
|
||||
default_sampler: ImageSamplerDescriptor {
|
||||
address_mode_u: ImageAddressMode::Repeat,
|
||||
address_mode_v: ImageAddressMode::Repeat,
|
||||
mag_filter: ImageFilterMode::Nearest,
|
||||
..default()
|
||||
}
|
||||
}),
|
||||
WorldInspectorPlugin::new(),
|
||||
PhosGamePlugin,
|
||||
))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use crate::shaders::chunk::ChunkMaterial;
|
||||
use bevy::asset::LoadState;
|
||||
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin;
|
||||
use bevy::pbr::ExtendedMaterial;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
use bevy::asset::{Asset, Handle};
|
||||
use bevy::pbr::{MaterialExtension, MaterialExtensionKey, MaterialExtensionPipeline, MaterialPipeline, MaterialPipelineKey};
|
||||
use bevy::prelude::{Component, Image, Mesh, Resource, TypePath};
|
||||
use bevy::render::mesh::{Indices, MeshVertexBufferLayout};
|
||||
use bevy::render::render_resource::{AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError};
|
||||
use world_generation::prelude::ATTRIBUTE_TEXTURE_INDEX;
|
||||
use bevy::asset::Handle;
|
||||
use bevy::prelude::{Component, Image, Resource};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct ChunkAtlas {
|
||||
@@ -19,33 +15,3 @@ pub struct PhosMap {
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct PhosChunk;
|
||||
|
||||
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct ChunkMaterial {
|
||||
#[texture(100, dimension = "2d_array")]
|
||||
#[sampler(101)]
|
||||
pub array_texture: Handle<Image>,
|
||||
}
|
||||
|
||||
impl MaterialExtension for ChunkMaterial {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/world/chunk.wgsl".into()
|
||||
}
|
||||
|
||||
// fn specialize(
|
||||
// _pipeline: &MaterialExtensionPipeline,
|
||||
// descriptor: &mut RenderPipelineDescriptor,
|
||||
// layout: &MeshVertexBufferLayout,
|
||||
// _key: MaterialExtensionKey<Self>,
|
||||
// ) -> Result<(), SpecializedMeshPipelineError> {
|
||||
// let vertex_layout = layout.get_layout(&[
|
||||
// Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||
// Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
||||
// Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
||||
// ATTRIBUTE_TEXTURE_INDEX.at_shader_location(3),
|
||||
// ])?;
|
||||
// descriptor.vertex.buffers = vec![vertex_layout];
|
||||
// Ok(())
|
||||
// }
|
||||
}
|
||||
|
||||
43
game/main/src/shaders/chunk.rs
Normal file
43
game/main/src/shaders/chunk.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use bevy::{
|
||||
asset::{Asset, Handle},
|
||||
pbr::{MaterialExtension, MaterialExtensionKey, MaterialExtensionPipeline},
|
||||
prelude::*,
|
||||
reflect::TypePath,
|
||||
render::{
|
||||
mesh::MeshVertexBufferLayout,
|
||||
render_resource::{
|
||||
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
|
||||
},
|
||||
texture::Image,
|
||||
},
|
||||
};
|
||||
use world_generation::prelude::ATTRIBUTE_TEXTURE_INDEX;
|
||||
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct ChunkMaterial {
|
||||
#[texture(100, dimension = "2d_array")]
|
||||
#[sampler(101)]
|
||||
pub array_texture: Handle<Image>,
|
||||
}
|
||||
|
||||
impl MaterialExtension for ChunkMaterial {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/world/chunk.wgsl".into()
|
||||
}
|
||||
|
||||
fn specialize(
|
||||
_pipeline: &MaterialExtensionPipeline,
|
||||
descriptor: &mut RenderPipelineDescriptor,
|
||||
layout: &MeshVertexBufferLayout,
|
||||
_key: MaterialExtensionKey<Self>,
|
||||
) -> Result<(), SpecializedMeshPipelineError> {
|
||||
let vertex_layout = layout.get_layout(&[
|
||||
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||
Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
||||
Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
||||
ATTRIBUTE_TEXTURE_INDEX.at_shader_location(7),
|
||||
])?;
|
||||
descriptor.vertex.buffers = vec![vertex_layout];
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
1
game/main/src/shaders/mod.rs
Normal file
1
game/main/src/shaders/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod chunk;
|
||||
Reference in New Issue
Block a user