Reputation: 196
I'm trying to render a cube with a texture on all sides in bevy. The texture is 16x16
and the cube is 1
bevy coordinate large.
This is my code so far:
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
title: "Definitely Minecraft".to_string(),
..Default::default()
},
..Default::default()
}))
.add_startup_system(setup_system)
.add_startup_system_to_stage(StartupStage::PostStartup, generate_world_system)
.run();
}
#[derive(Resource)]
struct GameMaterials {
dirt: Handle<StandardMaterial>
}
fn setup_system (
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Light
commands.spawn(DirectionalLightBundle {
transform: Transform::from_xyz(4., 80., 4.),
..Default::default()
});
commands.insert_resource(GameMaterials {
dirt: materials.add(StandardMaterial {
base_color_texture: Some(asset_server.load("dirt.png")),
alpha_mode: AlphaMode::Blend,
unlit: false,
..Default::default()
})
});
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3., 5., 8.).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
fn generate_world_system(
mut commands: Commands,
game_materials: Res<GameMaterials>,
mut meshes: ResMut<Assets<Mesh>>,
) {
let block_handle = meshes.add(Mesh::from(shape::Cube::new(1.)));
commands.spawn(PbrBundle {
mesh: block_handle.clone(),
material: game_materials.dirt.clone(),
transform: Transform::from_xyz(0., 0., 1.5),
..Default::default()
});
}
When I compile I get a 1x1
cube with a blurry (the actual texture is sharp) texture on a single side. Why does this happen and how can I fix it?
Upvotes: 0
Views: 566
Reputation: 1
By default Bevy uses linear sampling which makes the low resolution textures blurry. You can change the sampler so that the textures look pixelated:
DefaultPlugins.set(ImagePlugin::default_nearest())
Upvotes: 0