exploring other rendering styles
This commit is contained in:
@@ -6,6 +6,10 @@ layout(set = 0, binding = 0) uniform Globals {
|
||||
mat4 u_ViewProj;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1) uniform Globals {
|
||||
mat4 u_ViewProj;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 0) uniform Entity {
|
||||
mat4 u_World;
|
||||
vec4 u_Color;
|
||||
@@ -30,6 +30,9 @@ layout(set = 1, binding = 0) uniform Entity {
|
||||
};
|
||||
|
||||
float fetch_shadow(int light_id, vec4 homogeneous_coords) {
|
||||
// homogeneous coords is the depth of the previously rendered
|
||||
// fragment, from the lights perspective. If it's less than 0
|
||||
// then it's behind the light, so it's obviously in shadow
|
||||
if (homogeneous_coords.w <= 0.0) {
|
||||
return 1.0;
|
||||
}
|
||||
@@ -37,6 +40,7 @@ float fetch_shadow(int light_id, vec4 homogeneous_coords) {
|
||||
const vec2 flip_correction = vec2(0.5, -0.5);
|
||||
// compute texture coordinates for shadow lookup
|
||||
vec4 light_local = vec4(
|
||||
// I don't know what kind of jank shit is going on on this line
|
||||
homogeneous_coords.xy * flip_correction/homogeneous_coords.w + 0.5,
|
||||
light_id,
|
||||
homogeneous_coords.z / homogeneous_coords.w
|
||||
@@ -18,7 +18,11 @@ use legion::world::SubWorld;
|
||||
use legion::*;
|
||||
use rapier3d::parry::motion::RigidMotionComposition;
|
||||
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::platform::unix::x11::ffi::Time;
|
||||
use winit_24::window::Window;
|
||||
@@ -26,11 +30,10 @@ use winit_24::window::Window;
|
||||
use crate::camera::{Camera, CameraController};
|
||||
use crate::components::{Mesh, Position, RangeCopy};
|
||||
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::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
|
||||
/// The uniform buf is just the ShadowUniforms or ForwardUniforms
|
||||
@@ -41,9 +44,7 @@ pub struct Pass {
|
||||
pub uniform_buf: wgpu::Buffer,
|
||||
}
|
||||
|
||||
|
||||
pub struct RenderState {
|
||||
|
||||
swapchain: SwapChain,
|
||||
swapchain_description: SwapChainDescriptor,
|
||||
instance: Arc<Instance>,
|
||||
@@ -109,10 +110,7 @@ impl RenderState {
|
||||
}
|
||||
|
||||
/// Create a buffer for a mesh
|
||||
fn create_buffer(
|
||||
device: &wgpu::Device,
|
||||
raw_mesh: &RawMesh,
|
||||
) -> (Arc<Buffer>, Arc<Buffer>) {
|
||||
fn create_buffer(device: &wgpu::Device, raw_mesh: &RawMesh) -> (Arc<Buffer>, Arc<Buffer>) {
|
||||
let vertex_buf = Arc::new(
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vertex-buffer"),
|
||||
@@ -133,8 +131,11 @@ impl RenderState {
|
||||
}
|
||||
|
||||
/// 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 (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
|
||||
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)?;
|
||||
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
|
||||
Need to open this up in renderdoc and see what it's actually doing
|
||||
The shadow pass renders from the perspective of each camera and applies that to the shadow
|
||||
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 = {
|
||||
@@ -330,25 +336,43 @@ impl RenderState {
|
||||
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
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer {
|
||||
buffer: &uniform_buf,
|
||||
offset: 0,
|
||||
size: wgpu::BufferSize::new(uniform_size),
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer {
|
||||
buffer: &uniform_buf,
|
||||
offset: 0,
|
||||
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"),
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
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 =
|
||||
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 {
|
||||
label: Some("shadow"),
|
||||
@@ -559,10 +583,10 @@ impl RenderState {
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
let vs_module =
|
||||
device.create_shader_module(&wgpu::include_spirv!("../../resources/forward.vert.spv"));
|
||||
let fs_module =
|
||||
device.create_shader_module(&wgpu::include_spirv!("../../resources/forward.frag.spv"));
|
||||
let vs_module = device
|
||||
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.vert.spv"));
|
||||
let fs_module = device
|
||||
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.frag.spv"));
|
||||
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("main"),
|
||||
@@ -685,9 +709,8 @@ impl RenderState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user