Skip to content

Instantly share code, notes, and snippets.

@pferreir
Created August 1, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pferreir/35dff1b5ee2678f7e758b611e0ec4549 to your computer and use it in GitHub Desktop.
Save pferreir/35dff1b5ee2678f7e758b611e0ec4549 to your computer and use it in GitHub Desktop.
use amethyst::renderer::{
mtl::{TexAlbedo, TexEmission},
pass::Base3DPassDef,
plugins::RenderBase3D,
rendy::{
hal::pso::ShaderStageFlags,
mesh::{AsVertex, Normal, Position, TexCoord, VertexFormat},
shader::SpirvShader
},
skinning::JointCombined
};
lazy_static::lazy_static! {
// These uses the precompiled shaders.
// These can be obtained using glslc.exe in the vulkan sdk.
static ref VERTEX: SpirvShader = SpirvShader::from_bytes(
include_bytes!("../shaders/compiled/pos_norm_tex_skin.vert.spv"),
ShaderStageFlags::VERTEX,
"main",
).unwrap();
static ref VERTEX_SKINNED: SpirvShader = SpirvShader::from_bytes(
include_bytes!("../shaders/compiled/pos_norm_tex.vert.spv"),
ShaderStageFlags::VERTEX,
"main",
).unwrap();
static ref FRAGMENT: SpirvShader = SpirvShader::from_bytes(
include_bytes!("../shaders/compiled/shaded.frag.spv"),
ShaderStageFlags::FRAGMENT,
"main",
).unwrap();
}
#[derive(Debug)]
pub struct MyShaderPassDef;
impl Base3DPassDef for MyShaderPassDef {
const NAME: &'static str = "MyShader";
type TextureSet = (TexAlbedo, TexEmission);
fn vertex_shader() -> &'static SpirvShader {
&VERTEX
}
fn vertex_skinned_shader() -> &'static SpirvShader {
&VERTEX_SKINNED
}
fn fragment_shader() -> &'static SpirvShader {
&FRAGMENT
}
fn base_format() -> Vec<VertexFormat> {
vec![Position::vertex(), Normal::vertex(), TexCoord::vertex()]
}
fn skinned_format() -> Vec<VertexFormat> {
vec![
Position::vertex(),
Normal::vertex(),
TexCoord::vertex(),
JointCombined::vertex(),
]
}
}
pub type RenderMyShader = RenderBase3D<MyShaderPassDef>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment