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