Load the shader in runtime

This commit is contained in:
numzero 2024-12-24 02:07:34 +03:00
parent 001d7051ad
commit 61d3a90c7c

View File

@ -1,4 +1,7 @@
use std::mem::{offset_of, size_of};
use std::{
fs,
mem::{offset_of, size_of},
};
use bytemuck::{bytes_of, Pod, Zeroable};
use glam::{Vec2, Vec3};
@ -25,8 +28,6 @@ pub struct Pipeline {
pipeline: wgpu::RenderPipeline,
}
static SHADER: &str = include_str!("perlin.wgsl");
impl Pipeline {
pub fn new(device: &wgpu::Device) -> Self {
let view_buf = device.create_buffer(&wgpu::BufferDescriptor {
@ -41,9 +42,11 @@ impl Pipeline {
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let shader = fs::read_to_string("src/bin/envmap/perlin.wgsl").unwrap();
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(SHADER.into()),
source: wgpu::ShaderSource::Wgsl(shader.into()),
});
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,