|
|
@ -18,7 +18,11 @@ use legion::world::SubWorld;
|
|
|
|
use legion::*;
|
|
|
|
use legion::*;
|
|
|
|
use rapier3d::parry::motion::RigidMotionComposition;
|
|
|
|
use rapier3d::parry::motion::RigidMotionComposition;
|
|
|
|
use wgpu::util::DeviceExt;
|
|
|
|
use wgpu::util::DeviceExt;
|
|
|
|
use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder};
|
|
|
|
use wgpu::{
|
|
|
|
|
|
|
|
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, CommandEncoder, Device,
|
|
|
|
|
|
|
|
Features, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor,
|
|
|
|
|
|
|
|
SwapChainFrame, TextureView, VertexState,
|
|
|
|
|
|
|
|
};
|
|
|
|
use winit_24::dpi::PhysicalSize;
|
|
|
|
use winit_24::dpi::PhysicalSize;
|
|
|
|
use winit_24::platform::unix::x11::ffi::Time;
|
|
|
|
use winit_24::platform::unix::x11::ffi::Time;
|
|
|
|
use winit_24::window::Window;
|
|
|
|
use winit_24::window::Window;
|
|
|
@ -26,11 +30,10 @@ use winit_24::window::Window;
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::components::{Mesh, Position, RangeCopy};
|
|
|
|
use crate::components::{Mesh, Position, RangeCopy};
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::geometry::{load_obj, Vertex, RawMesh};
|
|
|
|
use crate::geometry::{load_obj, RawMesh, Vertex};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::render::{EntityUniforms, ShadowUniforms, ForwardUniforms};
|
|
|
|
use crate::render::{EntityUniforms, ForwardUniforms, ShadowUniforms};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// A render pass consists of a pipeline, bindgroup, and uniform buf
|
|
|
|
/// A render pass consists of a pipeline, bindgroup, and uniform buf
|
|
|
|
/// The uniform buf is just the ShadowUniforms or ForwardUniforms
|
|
|
|
/// The uniform buf is just the ShadowUniforms or ForwardUniforms
|
|
|
@ -41,9 +44,7 @@ pub struct Pass {
|
|
|
|
pub uniform_buf: wgpu::Buffer,
|
|
|
|
pub uniform_buf: wgpu::Buffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct RenderState {
|
|
|
|
pub struct RenderState {
|
|
|
|
|
|
|
|
|
|
|
|
swapchain: SwapChain,
|
|
|
|
swapchain: SwapChain,
|
|
|
|
swapchain_description: SwapChainDescriptor,
|
|
|
|
swapchain_description: SwapChainDescriptor,
|
|
|
|
instance: Arc<Instance>,
|
|
|
|
instance: Arc<Instance>,
|
|
|
@ -109,10 +110,7 @@ impl RenderState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a buffer for a mesh
|
|
|
|
/// Create a buffer for a mesh
|
|
|
|
fn create_buffer(
|
|
|
|
fn create_buffer(device: &wgpu::Device, raw_mesh: &RawMesh) -> (Arc<Buffer>, Arc<Buffer>) {
|
|
|
|
device: &wgpu::Device,
|
|
|
|
|
|
|
|
raw_mesh: &RawMesh,
|
|
|
|
|
|
|
|
) -> (Arc<Buffer>, Arc<Buffer>) {
|
|
|
|
|
|
|
|
let vertex_buf = Arc::new(
|
|
|
|
let vertex_buf = Arc::new(
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
label: Some("vertex-buffer"),
|
|
|
|
label: Some("vertex-buffer"),
|
|
|
@ -133,8 +131,11 @@ impl RenderState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Take a meshes raw representation and upload it to a GPU buffer
|
|
|
|
/// Take a meshes raw representation and upload it to a GPU buffer
|
|
|
|
pub fn upload_mesh_to_buffer(&mut self, mesh: &RawMesh, color: Option<wgpu::Color>) -> Result<Mesh, String> {
|
|
|
|
pub fn upload_mesh_to_buffer(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
mesh: &RawMesh,
|
|
|
|
|
|
|
|
color: Option<wgpu::Color>,
|
|
|
|
|
|
|
|
) -> Result<Mesh, String> {
|
|
|
|
let index_count = mesh.indices.len() * 3; // TODO bad bad bad bad!
|
|
|
|
let index_count = mesh.indices.len() * 3; // TODO bad bad bad bad!
|
|
|
|
|
|
|
|
|
|
|
|
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, mesh);
|
|
|
|
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, mesh);
|
|
|
@ -174,7 +175,11 @@ impl RenderState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// explicitly load from file, and upload to gpu the mesh
|
|
|
|
/// explicitly load from file, and upload to gpu the mesh
|
|
|
|
pub fn load_mesh_to_buffer(&mut self, filepath: &str, color: Option<wgpu::Color>) -> Result<Mesh, String> {
|
|
|
|
pub fn load_mesh_to_buffer(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
filepath: &str,
|
|
|
|
|
|
|
|
color: Option<wgpu::Color>,
|
|
|
|
|
|
|
|
) -> Result<Mesh, String> {
|
|
|
|
let raw_mesh = load_obj(filepath)?;
|
|
|
|
let raw_mesh = load_obj(filepath)?;
|
|
|
|
self.upload_mesh_to_buffer(&raw_mesh, color)
|
|
|
|
self.upload_mesh_to_buffer(&raw_mesh, color)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -292,8 +297,9 @@ impl RenderState {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
There appear to be two passes required for shadows, the shadow pass, and the forward pass
|
|
|
|
The shadow pass renders from the perspective of each camera and applies that to the shadow
|
|
|
|
Need to open this up in renderdoc and see what it's actually doing
|
|
|
|
texture. Due to light FOV and the shadow texture itself, it's rather difficult to have
|
|
|
|
|
|
|
|
hands-off global lighting / point lights
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
let shadow_pass = {
|
|
|
|
let shadow_pass = {
|
|
|
@ -330,25 +336,43 @@ impl RenderState {
|
|
|
|
mapped_at_creation: false,
|
|
|
|
mapped_at_creation: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Holds the shadow uniforms, which is just a 4 vec of quaternians
|
|
|
|
|
|
|
|
let g_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
|
|
|
|
|
|
|
label: Some("shadow_pass_g_buffer"),
|
|
|
|
|
|
|
|
size: uniform_size,
|
|
|
|
|
|
|
|
usage: wgpu::BufferUsage::STORAGE | wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
|
|
|
mapped_at_creation: false,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Create bind group
|
|
|
|
// Create bind group
|
|
|
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
|
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
|
|
layout: &bind_group_layout,
|
|
|
|
layout: &bind_group_layout,
|
|
|
|
entries: &[wgpu::BindGroupEntry {
|
|
|
|
entries: &[
|
|
|
|
|
|
|
|
wgpu::BindGroupEntry {
|
|
|
|
binding: 0,
|
|
|
|
binding: 0,
|
|
|
|
resource: wgpu::BindingResource::Buffer {
|
|
|
|
resource: wgpu::BindingResource::Buffer {
|
|
|
|
buffer: &uniform_buf,
|
|
|
|
buffer: &uniform_buf,
|
|
|
|
offset: 0,
|
|
|
|
offset: 0,
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
|
|
|
|
wgpu::BindGroupEntry {
|
|
|
|
|
|
|
|
binding: 1,
|
|
|
|
|
|
|
|
resource: wgpu::BindingResource::Buffer {
|
|
|
|
|
|
|
|
buffer: &g_buffer,
|
|
|
|
|
|
|
|
offset: 0,
|
|
|
|
|
|
|
|
size: wgpu::BufferSize::new(uniform_size),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
label: Some("Shadow uniform bind group"),
|
|
|
|
label: Some("Shadow uniform bind group"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Create the render pipeline
|
|
|
|
// Create the render pipeline
|
|
|
|
let vs_module =
|
|
|
|
let vs_module =
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/bake.vert.spv"));
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.vert.spv"));
|
|
|
|
let fs_module =
|
|
|
|
let fs_module =
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/bake.frag.spv"));
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.frag.spv"));
|
|
|
|
|
|
|
|
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
label: Some("shadow"),
|
|
|
|
label: Some("shadow"),
|
|
|
@ -559,10 +583,10 @@ impl RenderState {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Create the render pipeline
|
|
|
|
// Create the render pipeline
|
|
|
|
let vs_module =
|
|
|
|
let vs_module = device
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/forward.vert.spv"));
|
|
|
|
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.vert.spv"));
|
|
|
|
let fs_module =
|
|
|
|
let fs_module = device
|
|
|
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/forward.frag.spv"));
|
|
|
|
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.frag.spv"));
|
|
|
|
|
|
|
|
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
|
|
label: Some("main"),
|
|
|
|
label: Some("main"),
|
|
|
@ -685,7 +709,6 @@ impl RenderState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|