Skip to content

Commit

Permalink
Add shader includes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyas-taouaou committed Oct 30, 2024
1 parent f4cc6bc commit 45c7d62
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
8 changes: 8 additions & 0 deletions engine/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ fn main() -> anyhow::Result<()> {
shaderc::EnvVersion::Vulkan1_3 as u32,
);
options.set_source_language(shaderc::SourceLanguage::GLSL);
options.set_include_callback(|name, _, _, _| {
let path = format!("devres/shaders/{}", name);
let source = std::fs::read_to_string(&path).unwrap();
Ok(shaderc::ResolvedInclude {
resolved_name: name.to_string(),
content: source,
})
});

let is_debug_build = std::env::var("OPT_LEVEL")? == "0";

Expand Down
4 changes: 3 additions & 1 deletion engine/devres/shaders/shader.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#version 450
#version 460

layout (location = 0) in vec3 fragColor;

layout (location = 0) out vec4 outColor;

#include "push_constants.glsl"

void main() {
outColor = vec4(fragColor, 1.0);
}
31 changes: 1 addition & 30 deletions engine/devres/shaders/shader.vert
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
#version 460
#extension GL_EXT_buffer_reference: require
#extension GL_EXT_scalar_block_layout: require

layout (location = 0) out vec3 fragColor;

struct Vertex {
vec3 position;
vec3 color;
};

struct Camera {
mat4 view_projection;
};

layout (buffer_reference, scalar) buffer VertexBuffer {
Vertex vertices[];
};

layout (buffer_reference, scalar) buffer CameraBuffer {
Camera cameras[];
};

layout (buffer_reference, scalar) buffer InstanceBuffer {
mat4 model[];
};

layout (scalar, push_constant) uniform Registers
{
VertexBuffer vertexBuffer;
InstanceBuffer instanceBuffer;
CameraBuffer cameraBuffer;
} pushConstants;
#include "push_constants.glsl"

void main() {
vec3 position = pushConstants.vertexBuffer.vertices[gl_VertexIndex].position;
Expand Down
4 changes: 2 additions & 2 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use crate::renderer::window_renderer::WindowRendererAttributes;
pub use anyhow;
pub use ash::vk;
use renderdoc::RenderDoc;
use tracing::{error, info};
use tracing::info;
pub use winit;
use winit::keyboard::{Key, NamedKey};

Expand All @@ -35,7 +35,7 @@ impl Engine {
primary_window_attributes: WindowAttributes,
primary_renderer_attributes: WindowRendererAttributes,
) -> Result<Self> {
let mut renderdoc = RenderDoc::new().ok();
let renderdoc = RenderDoc::new().ok();
if renderdoc.is_some() {
info!("RenderDoc is available");
}
Expand Down

0 comments on commit 45c7d62

Please sign in to comment.