Skip to content

Commit

Permalink
Allow to have emissive textures
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAcPT committed Aug 7, 2024
1 parent e621000 commit e621000
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
9 changes: 8 additions & 1 deletion nmsr-3d-renderer/nmsr-player-parts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum PlayerPartTextureType {
Shadow,
Cape,
Skin,
Custom { key: &'static str, size: (u32, u32) },
Custom { key: &'static str, size: (u32, u32), is_emissive: bool },
}

impl std::fmt::Display for PlayerPartTextureType {
Expand All @@ -89,6 +89,13 @@ impl std::fmt::Display for PlayerPartTextureType {
}

impl PlayerPartTextureType {
pub fn is_emissive(&self) -> bool {
match self {
Self::Custom { is_emissive, .. } => *is_emissive,
_ => false,
}
}

pub fn get_texture_size(&self) -> (u32, u32) {
match self {
Self::Skin => (64, 64),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ where

let transform_bind_group = &self.scene_context.transform_bind_group;
let sun_bind_group = &self.scene_context.sun_information_bind_group;
let emissive_sun_bind_group = &self.scene_context.emissive_sun_information_bind_group;

let textures = self
.scene_context
Expand Down Expand Up @@ -369,7 +370,13 @@ where
rpass.set_pipeline(pipeline);
rpass.set_bind_group(0, transform_bind_group, &[]);
rpass.set_bind_group(1, &texture_sampler_bind_group, &[]);
rpass.set_bind_group(2, sun_bind_group, &[]);

if !texture.is_emissive() {
rpass.set_bind_group(2, sun_bind_group, &[]);
} else {
rpass.set_bind_group(2, emissive_sun_bind_group, &[]);
}

rpass.set_index_buffer(index_buf.slice(..), IndexFormat::Uint16);
rpass.set_vertex_buffer(0, vertex_buf.slice(..));
rpass.draw_indexed(0..(index_data.len() as u32), 0, 0..1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct SceneContext {
pub transform_bind_group: BindGroup,
pub sun_information_buffer: Buffer,
pub sun_information_bind_group: BindGroup,
pub emissive_sun_information_buffer: Buffer,
pub emissive_sun_information_bind_group: BindGroup,
pub(crate) textures: Option<SceneContextTextures>,
#[debug(skip)]
pub(crate) smaa_target: Option<SmaaTarget>,
Expand All @@ -55,11 +57,21 @@ impl SceneContext {
&[SunInformation::default()],
);

let (emissive_sun_information_buffer, emissive_sun_information_bind_group) =
create_buffer_and_bind_group(
device,
"Emissive Sun",
&context.layouts.sun_bind_group_layout,
&[SunInformation::new([0.0; 3].into(), 0.0, 1.0f32)],
);

Self {
transform_bind_group,
transform_matrix_buffer,
sun_information_buffer,
sun_information_bind_group,
emissive_sun_information_buffer,
emissive_sun_information_bind_group,
textures: None,
smaa_target: None,
}
Expand Down
2 changes: 2 additions & 0 deletions nmsr-aas/src/model/armor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ impl VanillaMinecraftArmorMaterialData {
pub const ARMOR_TEXTURE_ONE: PlayerPartTextureType = PlayerPartTextureType::Custom {
key: "armor_1",
size: (64, 64),
is_emissive: false
};

pub const ARMOR_TEXTURE_TWO: PlayerPartTextureType = PlayerPartTextureType::Custom {
key: "armor_2",
size: (64, 64),
is_emissive: false
};

#[must_use]
Expand Down
2 changes: 2 additions & 0 deletions nmsr-aas/src/model/request/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ impl CacheHandler<RenderRequestEntry, ResolvedRenderEntryTextures, ModelCacheCon
#[cfg(feature = "ears")]
ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::EmissiveProcessedSkin),
#[cfg(feature = "ears")]
ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::EmissiveProcessedWings),
#[cfg(feature = "ears")]
ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::EmissiveSkin),
#[cfg(feature = "ears")]
ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::EmissiveWings),
Expand Down
12 changes: 10 additions & 2 deletions nmsr-aas/src/model/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub enum ResolvedRenderEntryEarsTextureType {
Wings,
/// The non-emissive remaining part of the skin texture.
EmissiveProcessedSkin,
/// The non-emissive remaining part of the wings texture.
EmissiveProcessedWings,
/// The emissive skin texture type.
EmissiveSkin,
/// The emissive wings texture type.
Expand All @@ -77,6 +79,9 @@ impl From<ResolvedRenderEntryEarsTextureType> for PlayerPartEarsTextureType {
ResolvedRenderEntryEarsTextureType::EmissiveProcessedSkin => {
Self::EmissiveProcessedSkin
}
ResolvedRenderEntryEarsTextureType::EmissiveProcessedWings => {
Self::EmissiveProcessedWings
}
ResolvedRenderEntryEarsTextureType::EmissiveWings => Self::EmissiveWings,
}
}
Expand All @@ -88,7 +93,10 @@ impl ResolvedRenderEntryEarsTextureType {
match self {
Self::Cape => Some(AlfalfaDataKey::Cape),
Self::Wings => Some(AlfalfaDataKey::Wings),
Self::EmissiveSkin | Self::EmissiveProcessedSkin | Self::EmissiveWings => None,
Self::EmissiveSkin
| Self::EmissiveProcessedSkin
| Self::EmissiveProcessedWings
| Self::EmissiveWings => None,
}
}

Expand Down Expand Up @@ -440,7 +448,7 @@ impl RenderRequestResolver {
),
(
ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::Wings),
None,
Some(ResolvedRenderEntryTextureType::Ears(ResolvedRenderEntryEarsTextureType::EmissiveProcessedWings)),
ResolvedRenderEntryTextureType::Ears(
ResolvedRenderEntryEarsTextureType::EmissiveWings,
),
Expand Down

0 comments on commit e621000

Please sign in to comment.