Skip to content

Commit

Permalink
Add support for .frag.glsl files
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Sep 2, 2023
1 parent 5329aa2 commit 9bea6d8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
}
}
}
ext @ ("vert" | "frag" | "comp") => {
ext @ ("vert" | "frag" | "comp" | "glsl") => {
let input = String::from_utf8(input)?;
let mut parser = naga::front::glsl::Frontend::default();

Expand All @@ -314,6 +314,20 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
"vert" => naga::ShaderStage::Vertex,
"frag" => naga::ShaderStage::Fragment,
"comp" => naga::ShaderStage::Compute,
"glsl" => {
let internal_name = input_path.to_string_lossy();
match Path::new(&internal_name[..internal_name.len()-5])
.extension()
.ok_or(CliError("Input filename ending with .glsl has no internal extension"))?
.to_str()
.ok_or(CliError("Input filename not valid unicode"))?
{
"vert" => naga::ShaderStage::Vertex,
"frag" => naga::ShaderStage::Fragment,
"comp" => naga::ShaderStage::Compute,
_ => unreachable!(),
}
},
_ => unreachable!(),
},
defines: Default::default(),
Expand Down
27 changes: 27 additions & 0 deletions tests/in/glsl/210-bevy-2d-shader.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// AUTHOR: mrk-its
// ISSUE: #210
// FIX: #898
#version 450

layout(location = 0) in vec2 v_Uv;

layout(location = 0) out vec4 o_Target;

layout(set = 1, binding = 0) uniform ColorMaterial_color {
vec4 Color;
};

# ifdef COLORMATERIAL_TEXTURE
layout(set = 1, binding = 1) uniform texture2D ColorMaterial_texture;
layout(set = 1, binding = 2) uniform sampler ColorMaterial_texture_sampler;
# endif

void main() {
vec4 color = Color;
# ifdef COLORMATERIAL_TEXTURE
color *= texture(
sampler2D(ColorMaterial_texture, ColorMaterial_texture_sampler),
v_Uv);
# endif
o_Target = color;
}
27 changes: 27 additions & 0 deletions tests/in/glsl/210-bevy-2d-shader.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// AUTHOR: mrk-its
// ISSUE: #210
// FIX: #898
#version 450

layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv;

layout(location = 0) out vec2 v_Uv;

layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj;
};

layout(set = 2, binding = 0) uniform Transform {
mat4 Model;
};
layout(set = 2, binding = 1) uniform Sprite_size {
vec2 size;
};

void main() {
v_Uv = Vertex_Uv;
vec3 position = Vertex_Position * vec3(size, 1.0);
gl_Position = ViewProj * Model * vec4(position, 1.0);
}

0 comments on commit 9bea6d8

Please sign in to comment.