Compare commits
9 Commits
deferred
...
b98c7312cc
| Author | SHA1 | Date | |
|---|---|---|---|
| b98c7312cc | |||
|
|
c06d884050 | ||
| 00a4a4275a | |||
| 73df55b689 | |||
|
|
339351c207 | ||
| b37fd66164 | |||
| 4955909aa8 | |||
| b989146249 | |||
| b67a180341 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
.idea/*
|
||||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
@@ -33,7 +33,7 @@ toml = "0.5.8"
|
|||||||
cgmath = "0.18.0"
|
cgmath = "0.18.0"
|
||||||
rapier3d = { version = "0.5.0", features = ["simd-nightly", "parallel"] }
|
rapier3d = { version = "0.5.0", features = ["simd-nightly", "parallel"] }
|
||||||
nalgebra = "0.24.1"
|
nalgebra = "0.24.1"
|
||||||
legion = "0.4.0"
|
legion = "0.3.1"
|
||||||
wgpu = "0.7.0"
|
wgpu = "0.7.0"
|
||||||
imgui = "0.7.0"
|
imgui = "0.7.0"
|
||||||
imgui-wgpu = "0.14.0"
|
imgui-wgpu = "0.14.0"
|
||||||
|
|||||||
@@ -1,30 +1,21 @@
|
|||||||
[[entities]]
|
[[entities]]
|
||||||
name = "terrain.1"
|
name = "terrain.1"
|
||||||
type = "Terrain"
|
type = "StaticMesh"
|
||||||
mesh = "test-textured.obj"
|
mesh = "test-textured.obj"
|
||||||
|
|
||||||
[[entities]]
|
[[entities]]
|
||||||
name = "ball.1"
|
name = "tile.1"
|
||||||
type = "PhysicsEntity"
|
type = "Sprite"
|
||||||
mesh = "ball.obj"
|
texture = "test.jpg"
|
||||||
|
|
||||||
[entities.position]
|
[entities.position]
|
||||||
x = 15.0
|
x = 15.0
|
||||||
y = 15.0
|
y = 15.0
|
||||||
z = 15.0
|
z = 0.0
|
||||||
|
|
||||||
[entities.position.rotation]
|
[entities.position.rotation]
|
||||||
x = 0.0
|
x = 0.0
|
||||||
y = 0.0
|
y = 0.0
|
||||||
z = 0.0
|
|
||||||
|
|
||||||
[entities.physics]
|
|
||||||
body_status = "static"
|
|
||||||
|
|
||||||
[entities.physics.cuboid]
|
|
||||||
x = 1.0
|
|
||||||
y = 1.0
|
|
||||||
z = 1.0
|
|
||||||
|
|
||||||
[[entities]]
|
[[entities]]
|
||||||
name = "camera.1"
|
name = "camera.1"
|
||||||
|
|||||||
26
note.md
26
note.md
@@ -1,26 +0,0 @@
|
|||||||
# Texture Samplers
|
|
||||||
|GLSL sampler|OpenGL texture enum|Texture type|
|
|
||||||
|---|---|---|
|
|
||||||
gsampler1D | GL_TEXTURE_1D | 1D texture
|
|
||||||
gsampler2D | GL_TEXTURE_2D | 2D texture
|
|
||||||
gsampler3D | GL_TEXTURE_3D | 3D texture
|
|
||||||
gsamplerCube | GL_TEXTURE_CUBE_MAP | Cubemap Texture
|
|
||||||
gsampler2DRect | GL_TEXTURE_RECTANGLE | Rectangle Texture
|
|
||||||
gsampler1DArray | GL_TEXTURE_1D_ARRAY | 1D Array Texture
|
|
||||||
gsampler2DArray | GL_TEXTURE_2D_ARRAY | 2D Array Texture
|
|
||||||
gsamplerCubeArray | GL_TEXTURE_CUBE_MAP_ARRAY | Cubemap Array Texture
|
|
||||||
gsamplerBuffer | GL_TEXTURE_BUFFER | Buffer Texture
|
|
||||||
gsampler2DMS | GL_TEXTURE_2D_MULTISAMPLE | Multisample Texture
|
|
||||||
gsampler2DMSArray | GL_TEXTURE_2D_MULTISAMPLE_ARRAY | Multisample Array Texture
|
|
||||||
|
|
||||||
|
|
||||||
# Shadow Samplers
|
|
||||||
|GLSL sampler|OpenGL texture enum|
|
|
||||||
|---|---|
|
|
||||||
sampler1DShadow | GL_TEXTURE_1D
|
|
||||||
sampler2DShadow | GL_TEXTURE_2D
|
|
||||||
samplerCubeShadow | GL_TEXTURE_CUBE_MAP
|
|
||||||
sampler2DRectShadow | GL_TEXTURE_RECTANGLE
|
|
||||||
sampler1DArrayShadow | GL_TEXTURE_1D_ARRAY
|
|
||||||
sampler2DArrayShadow | GL_TEXTURE_2D_ARRAY
|
|
||||||
samplerCubeArrayShadow | GL_TEXTURE_CUBE_MAP_ARRAY
|
|
||||||
@@ -6,10 +6,6 @@ layout(set = 0, binding = 0) uniform Globals {
|
|||||||
mat4 u_ViewProj;
|
mat4 u_ViewProj;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(set = 0, binding = 1) uniform Globals {
|
|
||||||
mat4 u_ViewProj;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform Entity {
|
layout(set = 1, binding = 0) uniform Entity {
|
||||||
mat4 u_World;
|
mat4 u_World;
|
||||||
vec4 u_Color;
|
vec4 u_Color;
|
||||||
@@ -30,23 +30,18 @@ layout(set = 1, binding = 0) uniform Entity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
float fetch_shadow(int light_id, vec4 homogeneous_coords) {
|
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) {
|
if (homogeneous_coords.w <= 0.0) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
// compensate for the Y-flip difference between the normalized device
|
// compensate for the Y-flip difference between the NDC and texture coordinates
|
||||||
// coordinates (NDC) and texture coordinates
|
|
||||||
const vec2 flip_correction = vec2(0.5, -0.5);
|
const vec2 flip_correction = vec2(0.5, -0.5);
|
||||||
// compute texture coordinates for shadow lookup
|
// compute texture coordinates for shadow lookup
|
||||||
vec4 light_local = vec4(
|
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,
|
homogeneous_coords.xy * flip_correction/homogeneous_coords.w + 0.5,
|
||||||
light_id, // array layer
|
light_id,
|
||||||
homogeneous_coords.z / homogeneous_coords.w // D-Ref
|
homogeneous_coords.z / homogeneous_coords.w
|
||||||
);
|
);
|
||||||
// do the lookup, using HW percentage closer filtering(PCF) and comparison
|
// do the lookup, using HW PCF and comparison
|
||||||
return texture(sampler2DArrayShadow(t_Shadow, s_Shadow), light_local);
|
return texture(sampler2DArrayShadow(t_Shadow, s_Shadow), light_local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 3.0 MiB After Width: | Height: | Size: 3.0 MiB |
13
resources/texture-test-1.mtl
Normal file
13
resources/texture-test-1.mtl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material.002
|
||||||
|
Ns 225.000000
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.800000 0.800000 0.800000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.450000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd /Users/mitchellhansen/source/minimum-viable-game-engine/resources/test.jpg
|
||||||
18
resources/texture-test-1.obj
Normal file
18
resources/texture-test-1.obj
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Blender v2.93.1 OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib texture-test-1.mtl
|
||||||
|
o Plane_Plane.001
|
||||||
|
v -1.000000 0.000000 1.000000
|
||||||
|
v 1.000000 0.000000 1.000000
|
||||||
|
v -1.000000 0.000000 -1.000000
|
||||||
|
v 1.000000 0.000000 -1.000000
|
||||||
|
vt 1.000000 0.000000
|
||||||
|
vt 0.000000 1.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 1.000000 1.000000
|
||||||
|
vn 0.0000 1.0000 0.0000
|
||||||
|
g Plane_Plane.001_Material.002
|
||||||
|
usemtl Material.002
|
||||||
|
s off
|
||||||
|
f 2/1/1 3/2/1 1/3/1
|
||||||
|
f 2/1/1 4/4/1 3/2/1
|
||||||
12
resources/textured-plane.mtl
Normal file
12
resources/textured-plane.mtl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material.001
|
||||||
|
Ns 323.999994
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.800000 0.800000 0.800000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
17
resources/textured-plane.obj
Normal file
17
resources/textured-plane.obj
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Blender v2.93.1 OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib textured-plane.mtl
|
||||||
|
o Plane
|
||||||
|
v -1.000000 0.000000 1.000000
|
||||||
|
v 1.000000 0.000000 1.000000
|
||||||
|
v -1.000000 0.000000 -1.000000
|
||||||
|
v 1.000000 0.000000 -1.000000
|
||||||
|
vt 1.000000 0.000000
|
||||||
|
vt 0.000000 1.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 1.000000 1.000000
|
||||||
|
vn 0.0000 1.0000 0.0000
|
||||||
|
usemtl Material.001
|
||||||
|
s off
|
||||||
|
f 2/1/1 3/2/1 1/3/1
|
||||||
|
f 2/1/1 4/4/1 3/2/1
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#version 450
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 v_Normal;
|
|
||||||
layout(location = 1) in vec4 v_Position;
|
|
||||||
layout(location = 2) in vec2 v_Uv;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_Normal;
|
|
||||||
layout(location = 1) out vec4 o_Position;
|
|
||||||
layout(location = 2) out vec4 o_Uv;
|
|
||||||
|
|
||||||
// so I need to have my 3 color attachments and 1? sampler.
|
|
||||||
|
|
||||||
layout(set = 0, binding = 1) uniform texture2DArray t_Uv;
|
|
||||||
layout(set = 0, binding = 2) uniform gsampler2D s_Uv;
|
|
||||||
|
|
||||||
// I also need my 1 depth texture and its sampler
|
|
||||||
layout(set = 0, binding = 3) uniform texture2DArray t_Shadow;
|
|
||||||
layout(set = 0, binding = 4) uniform samplerShadow s_Shadow;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#version 450
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 a_Pos;
|
|
||||||
|
|
||||||
|
|
||||||
layout(location = 0) out vec3 v_Normal;
|
|
||||||
layout(location = 1) out vec4 v_Position;
|
|
||||||
layout(location = 2) out vec2 v_Uv;
|
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform Globals {
|
|
||||||
mat4 u_ViewProj;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform Entity {
|
|
||||||
mat4 u_World;
|
|
||||||
vec4 u_Color;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = u_ViewProj * u_World * vec4(a_Pos);
|
|
||||||
}
|
|
||||||
@@ -58,6 +58,11 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
|
|||||||
for model in models {
|
for model in models {
|
||||||
let mesh = &model.mesh;
|
let mesh = &model.mesh;
|
||||||
|
|
||||||
|
if let Some(mat_id) = mesh.material_id {
|
||||||
|
let mat : &Material = materials.get(mat_id).unwrap();
|
||||||
|
println!("{:?}", mat);
|
||||||
|
}
|
||||||
|
|
||||||
// Cycle through the faces and chunk out the indices
|
// Cycle through the faces and chunk out the indices
|
||||||
let mut next_face = 0;
|
let mut next_face = 0;
|
||||||
for f in 0..mesh.num_face_indices.len() {
|
for f in 0..mesh.num_face_indices.len() {
|
||||||
@@ -112,3 +117,28 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
|
|||||||
indices: index_data.to_vec(),
|
indices: index_data.to_vec(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub fn create_quad_mesh() -> RawMesh {
|
||||||
|
//
|
||||||
|
// let mut index_data: Vec<[u32; 3]> = Vec::new();
|
||||||
|
// let mut vertex_data = Vec::new();
|
||||||
|
//
|
||||||
|
// vertex_data.push(Vertex::from(
|
||||||
|
// [
|
||||||
|
// mesh.positions[3 * v],
|
||||||
|
// mesh.positions[3 * v + 1],
|
||||||
|
// mesh.positions[3 * v + 2],
|
||||||
|
// ],
|
||||||
|
// [
|
||||||
|
// mesh.normals[3 * v],
|
||||||
|
// mesh.normals[3 * v + 1],
|
||||||
|
// mesh.normals[3 * v + 2],
|
||||||
|
// ],
|
||||||
|
// [mesh.texcoords[2 * v], mesh.texcoords[2 * v + 1]],
|
||||||
|
// ));
|
||||||
|
//
|
||||||
|
// RawMesh {
|
||||||
|
// vertices: vertex_data.to_vec(),
|
||||||
|
// indices: index_data.to_vec(),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ use wgpu_subscriber;
|
|||||||
use winit_24::event::DeviceEvent::MouseMotion;
|
use winit_24::event::DeviceEvent::MouseMotion;
|
||||||
use winit_24::event::{ElementState, VirtualKeyCode};
|
use winit_24::event::{ElementState, VirtualKeyCode};
|
||||||
use winit_24::event_loop::EventLoopProxy;
|
use winit_24::event_loop::EventLoopProxy;
|
||||||
use winit_24::platform::unix::x11::ffi::Time;
|
|
||||||
use winit_24::window::Window;
|
use winit_24::window::Window;
|
||||||
use winit_24::{
|
use winit_24::{
|
||||||
event::{self, WindowEvent},
|
event::{self, WindowEvent},
|
||||||
@@ -108,6 +107,10 @@ Todo:
|
|||||||
Figure out eventing, GameInput, passing all events, etc.
|
Figure out eventing, GameInput, passing all events, etc.
|
||||||
+ texturing
|
+ texturing
|
||||||
|
|
||||||
|
I need to figure out the way that I want to do 2d graphics in a 3d engine...
|
||||||
|
I suppose I will need sprites. And those are just 2 polygons which are textured
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -66,12 +66,3 @@ pub struct ShadowUniforms {
|
|||||||
|
|
||||||
unsafe impl Pod for ShadowUniforms {}
|
unsafe impl Pod for ShadowUniforms {}
|
||||||
unsafe impl Zeroable for ShadowUniforms {}
|
unsafe impl Zeroable for ShadowUniforms {}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct CameraProjectionView {
|
|
||||||
proj: [[f32; 4]; 4],
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Pod for CameraProjectionView {}
|
|
||||||
unsafe impl Zeroable for CameraProjectionView {}
|
|
||||||
@@ -18,35 +18,31 @@ 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::{
|
use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder};
|
||||||
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::window::Window;
|
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, RawMesh, Vertex};
|
use crate::geometry::{load_obj, Vertex, RawMesh};
|
||||||
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::{CameraProjectionView, EntityUniforms, ForwardUniforms, ShadowUniforms};
|
use crate::render::{EntityUniforms, ShadowUniforms, ForwardUniforms};
|
||||||
|
|
||||||
|
|
||||||
/// 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
|
||||||
/// They are uniform across all cu's.
|
|
||||||
/// And the bindgroup is just the localbindgroup (the EntityUniforms) and the rest
|
/// And the bindgroup is just the localbindgroup (the EntityUniforms) and the rest
|
||||||
///
|
|
||||||
pub struct Pass {
|
pub struct Pass {
|
||||||
pub pipeline: wgpu::RenderPipeline,
|
pub pipeline: wgpu::RenderPipeline,
|
||||||
pub bind_group: wgpu::BindGroup,
|
pub bind_group: wgpu::BindGroup,
|
||||||
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>,
|
||||||
@@ -64,15 +60,6 @@ pub struct RenderState {
|
|||||||
pub(in crate::render) forward_pass: Pass,
|
pub(in crate::render) forward_pass: Pass,
|
||||||
pub(in crate::render) forward_depth: wgpu::TextureView,
|
pub(in crate::render) forward_depth: wgpu::TextureView,
|
||||||
|
|
||||||
// Gbuffer bs
|
|
||||||
pub(in crate::render) gbuffer_pass: Pass,
|
|
||||||
pub(in crate::render) gbuffer_cam_projection_buffer: wgpu::Buffer,
|
|
||||||
pub(in crate::render) gbuffer_depth_texture: wgpu::TextureView,
|
|
||||||
pub(in crate::render) gbuffer_depth_views: Vec<Arc<TextureView>>,
|
|
||||||
pub(in crate::render) gbuffer_target_texture: wgpu::TextureView,
|
|
||||||
pub(in crate::render) gbuffer_target_views: Vec<Arc<TextureView>>,
|
|
||||||
|
|
||||||
// this is for the set=1 entity uniforms
|
|
||||||
entity_bind_group_layout: BindGroupLayout,
|
entity_bind_group_layout: BindGroupLayout,
|
||||||
|
|
||||||
pub(in crate::render) light_uniform_buf: wgpu::Buffer,
|
pub(in crate::render) light_uniform_buf: wgpu::Buffer,
|
||||||
@@ -85,14 +72,12 @@ pub struct RenderState {
|
|||||||
impl RenderState {
|
impl RenderState {
|
||||||
const MAX_LIGHTS: usize = 10;
|
const MAX_LIGHTS: usize = 10;
|
||||||
const SHADOW_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
const SHADOW_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
||||||
const G_BUFFER_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba32Float;
|
|
||||||
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
|
||||||
|
|
||||||
const SHADOW_SIZE: wgpu::Extent3d = wgpu::Extent3d {
|
const SHADOW_SIZE: wgpu::Extent3d = wgpu::Extent3d {
|
||||||
width: 1024,
|
width: 1024,
|
||||||
height: 1024,
|
height: 1024,
|
||||||
depth: Self::MAX_LIGHTS as u32,
|
depth: Self::MAX_LIGHTS as u32,
|
||||||
};
|
};
|
||||||
|
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
||||||
|
|
||||||
/// Generate a projection matrix with no look-at yet
|
/// Generate a projection matrix with no look-at yet
|
||||||
pub fn generate_matrix(&self) -> cgmath::Matrix4<f32> {
|
pub fn generate_matrix(&self) -> cgmath::Matrix4<f32> {
|
||||||
@@ -123,7 +108,10 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a buffer for a mesh
|
/// 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(
|
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"),
|
||||||
@@ -144,11 +132,8 @@ 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(
|
pub fn upload_mesh_to_buffer(&mut self, mesh: &RawMesh, color: Option<wgpu::Color>) -> Result<Mesh, String> {
|
||||||
&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);
|
||||||
@@ -188,11 +173,7 @@ 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(
|
pub fn load_mesh_to_buffer(&mut self, filepath: &str, color: Option<wgpu::Color>) -> Result<Mesh, String> {
|
||||||
&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)
|
||||||
}
|
}
|
||||||
@@ -223,105 +204,6 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a render pass with the ability to add external bindings
|
|
||||||
pub fn create_render_pass(
|
|
||||||
device: &Device,
|
|
||||||
external_binding_layout: &BindGroupLayout,
|
|
||||||
vertex_description: &wgpu::VertexBufferLayout,
|
|
||||||
uniform_size: u64,
|
|
||||||
label: Option<&str>,
|
|
||||||
) -> Option<Pass> {
|
|
||||||
// The g-buffers camera projection matrix that we stream data to
|
|
||||||
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
||||||
label: Some(format!("{} uniform-buffer", label.unwrap_or("unnamed")).as_str()),
|
|
||||||
size: uniform_size,
|
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
||||||
mapped_at_creation: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Uniform bind group for the view matrix
|
|
||||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
||||||
label: Some(format!("{} bind group layout", label.unwrap_or("unnamed")).as_str()),
|
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 0, // global
|
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
|
||||||
ty: wgpu::BindingType::Buffer {
|
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
|
||||||
min_binding_size: wgpu::BufferSize::new(uniform_size),
|
|
||||||
has_dynamic_offset: false,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
|
|
||||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
||||||
label: Some(format!("{} uniform bind group", label.unwrap_or("unnamed")).as_str()),
|
|
||||||
layout: &bind_group_layout,
|
|
||||||
entries: &[wgpu::BindGroupEntry {
|
|
||||||
binding: 0,
|
|
||||||
resource: wgpu::BindingResource::Buffer {
|
|
||||||
buffer: &uniform_buf,
|
|
||||||
offset: 0,
|
|
||||||
size: wgpu::BufferSize::new(uniform_size),
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
|
|
||||||
let vs_module =
|
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.vert.spv"));
|
|
||||||
let fs_module =
|
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.frag.spv"));
|
|
||||||
|
|
||||||
// The bind group layouts are accessed by layout(set = X, binding = x)
|
|
||||||
// in the shader.
|
|
||||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
|
||||||
label: Some(format!("{} pipeline layout", label.unwrap_or("unnamed")).as_str()),
|
|
||||||
bind_group_layouts: &[&bind_group_layout, external_binding_layout],
|
|
||||||
push_constant_ranges: &[],
|
|
||||||
});
|
|
||||||
|
|
||||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
||||||
label: Some(format!("{} render pipeline", label.unwrap_or("unnamed")).as_str()),
|
|
||||||
layout: Some(&pipeline_layout),
|
|
||||||
|
|
||||||
vertex: VertexState {
|
|
||||||
module: &vs_module,
|
|
||||||
entry_point: "main",
|
|
||||||
buffers: &[vertex_description.clone()],
|
|
||||||
},
|
|
||||||
fragment: Some(FragmentState {
|
|
||||||
module: &fs_module,
|
|
||||||
entry_point: "main",
|
|
||||||
targets: &[],
|
|
||||||
}),
|
|
||||||
primitive: wgpu::PrimitiveState {
|
|
||||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
|
||||||
cull_mode: wgpu::CullMode::Back,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
depth_stencil: Some(wgpu::DepthStencilState {
|
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
|
||||||
depth_write_enabled: true,
|
|
||||||
depth_compare: wgpu::CompareFunction::LessEqual,
|
|
||||||
stencil: wgpu::StencilState::default(),
|
|
||||||
bias: wgpu::DepthBiasState {
|
|
||||||
constant: 2, // corresponds to bilinear filtering
|
|
||||||
slope_scale: 2.0,
|
|
||||||
clamp: 0.0,
|
|
||||||
},
|
|
||||||
clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING),
|
|
||||||
}),
|
|
||||||
multisample: wgpu::MultisampleState::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
Some(Pass {
|
|
||||||
pipeline,
|
|
||||||
bind_group,
|
|
||||||
uniform_buf,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init(window: &Window, imgui_context: &mut ImguiContext) -> RenderState {
|
pub fn init(window: &Window, imgui_context: &mut ImguiContext) -> RenderState {
|
||||||
// Grab the GPU instance, and query its features
|
// Grab the GPU instance, and query its features
|
||||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
||||||
@@ -408,150 +290,6 @@ impl RenderState {
|
|||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This pass is just going to forward the vertex info to the fragments
|
|
||||||
// And they are going to render to the gbuffer
|
|
||||||
let g_buffer_pass = Self::create_render_pass(
|
|
||||||
&device,
|
|
||||||
&entity_bind_group_layout,
|
|
||||||
&vb_desc,
|
|
||||||
mem::size_of::<CameraProjectionView>() as wgpu::BufferAddress,
|
|
||||||
Some("g-buffer"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let shadow_pass = Self::create_render_pass(
|
|
||||||
&device,
|
|
||||||
&entity_bind_group_layout,
|
|
||||||
&vb_desc,
|
|
||||||
mem::size_of::<ShadowUniforms>() as wgpu::BufferAddress,
|
|
||||||
Some("shadow-pass"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let g_buffer_pass = {
|
|
||||||
let uniform_size = mem::size_of::<CameraProjectionView>() as wgpu::BufferAddress;
|
|
||||||
|
|
||||||
// The g-buffers camera projection matrix that we stream data to
|
|
||||||
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
||||||
label: Some("g-buffers CameraProjectionView uniform buffer"),
|
|
||||||
size: uniform_size,
|
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
||||||
mapped_at_creation: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Uniform bind group for the view matrix
|
|
||||||
let bind_group_layout =
|
|
||||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
||||||
label: Some("g-buffer input pass bindgroup layout (cam)"),
|
|
||||||
entries: &[
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 0, // global
|
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
|
||||||
ty: wgpu::BindingType::Buffer {
|
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
|
||||||
min_binding_size: wgpu::BufferSize::new(uniform_size),
|
|
||||||
has_dynamic_offset: false,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 1, // texture2DArray
|
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Texture {
|
|
||||||
multisampled: false,
|
|
||||||
sample_type: wgpu::TextureSampleType::Depth,
|
|
||||||
view_dimension: wgpu::TextureViewDimension::D2Array,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 2, // samplerShadow
|
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Sampler {
|
|
||||||
filtering: false,
|
|
||||||
comparison: true,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
//sudo rm /usr/bin/ld
|
|
||||||
//sudo ln -s /usr/bin/lld /usr/bin/ld
|
|
||||||
//sudo ln -s /usr/bin/x86_64-linux-gnu-ld /usr/bin/ld
|
|
||||||
|
|
||||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
||||||
label: Some("g-buffers uniform bind group"),
|
|
||||||
layout: &bind_group_layout,
|
|
||||||
entries: &[wgpu::BindGroupEntry {
|
|
||||||
binding: 0, // globals
|
|
||||||
resource: wgpu::BindingResource::Buffer {
|
|
||||||
buffer: &uniform_buf,
|
|
||||||
offset: 0,
|
|
||||||
size: wgpu::BufferSize::new(uniform_size),
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
|
|
||||||
let vs_module =
|
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.vert.spv"));
|
|
||||||
let fs_module =
|
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.frag.spv"));
|
|
||||||
|
|
||||||
// The bind group layouts are accessed by layout(set = X, binding = x)
|
|
||||||
// in the shader.
|
|
||||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
|
||||||
label: Some("g-buffer input pipeline layout"),
|
|
||||||
bind_group_layouts: &[&bind_group_layout, &entity_bind_group_layout],
|
|
||||||
push_constant_ranges: &[],
|
|
||||||
});
|
|
||||||
|
|
||||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
||||||
label: Some("g-buffer"),
|
|
||||||
layout: Some(&pipeline_layout),
|
|
||||||
|
|
||||||
vertex: VertexState {
|
|
||||||
module: &vs_module,
|
|
||||||
entry_point: "main",
|
|
||||||
buffers: &[vb_desc.clone()],
|
|
||||||
},
|
|
||||||
fragment: Some(FragmentState {
|
|
||||||
module: &fs_module,
|
|
||||||
entry_point: "main",
|
|
||||||
targets: &[],
|
|
||||||
}),
|
|
||||||
primitive: wgpu::PrimitiveState {
|
|
||||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
|
||||||
cull_mode: wgpu::CullMode::Back,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
depth_stencil: Some(wgpu::DepthStencilState {
|
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
|
||||||
depth_write_enabled: true,
|
|
||||||
depth_compare: wgpu::CompareFunction::LessEqual,
|
|
||||||
stencil: wgpu::StencilState::default(),
|
|
||||||
bias: wgpu::DepthBiasState {
|
|
||||||
constant: 2, // corresponds to bilinear filtering
|
|
||||||
slope_scale: 2.0,
|
|
||||||
clamp: 0.0,
|
|
||||||
},
|
|
||||||
clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING),
|
|
||||||
}),
|
|
||||||
multisample: wgpu::MultisampleState::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
Pass {
|
|
||||||
pipeline,
|
|
||||||
bind_group,
|
|
||||||
uniform_buf,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let shadow_pass = {
|
let shadow_pass = {
|
||||||
let uniform_size = mem::size_of::<ShadowUniforms>() as wgpu::BufferAddress;
|
let uniform_size = mem::size_of::<ShadowUniforms>() as wgpu::BufferAddress;
|
||||||
|
|
||||||
@@ -602,9 +340,9 @@ impl RenderState {
|
|||||||
|
|
||||||
// Create the render pipeline
|
// Create the render pipeline
|
||||||
let vs_module =
|
let vs_module =
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.vert.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/bake.vert.spv"));
|
||||||
let fs_module =
|
let fs_module =
|
||||||
device.create_shader_module(&wgpu::include_spirv!("../../shaders/bake.frag.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/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"),
|
||||||
@@ -648,19 +386,6 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pre init the gbuffers camera projection uniform
|
|
||||||
let gbuffer_cam_uniform_size =
|
|
||||||
mem::size_of::<CameraProjectionView>() as wgpu::BufferAddress;
|
|
||||||
|
|
||||||
let gbuffer_cam_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
|
||||||
label: Some("g-buffer camera projection uniform buffer"),
|
|
||||||
size: gbuffer_cam_uniform_size,
|
|
||||||
usage: wgpu::BufferUsage::UNIFORM
|
|
||||||
| wgpu::BufferUsage::COPY_SRC
|
|
||||||
| wgpu::BufferUsage::COPY_DST,
|
|
||||||
mapped_at_creation: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pre init the light uniform, with slots enough for MAX_LIGHTS
|
// Pre init the light uniform, with slots enough for MAX_LIGHTS
|
||||||
let light_uniform_size =
|
let light_uniform_size =
|
||||||
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
|
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
|
||||||
@@ -706,22 +431,8 @@ impl RenderState {
|
|||||||
50.0,
|
50.0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let g_buffer_camera_projection_matrix = CameraProjectionView {
|
|
||||||
proj: *mx_projection.as_ref(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let g_buffer_camera_projection_uniform =
|
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some("g-buffer camera projection uniform buffer"),
|
|
||||||
contents: bytemuck::bytes_of(&g_buffer_camera_projection_matrix),
|
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
||||||
});
|
|
||||||
|
|
||||||
let forward_pass = {
|
let forward_pass = {
|
||||||
// Create pipeline layout
|
// Create pipeline layout
|
||||||
let forward_uniform_size =
|
|
||||||
mem::size_of::<ForwardUniforms>() as wgpu::BufferAddress;
|
|
||||||
|
|
||||||
let bind_group_layout =
|
let bind_group_layout =
|
||||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
entries: &[
|
entries: &[
|
||||||
@@ -730,7 +441,11 @@ impl RenderState {
|
|||||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Buffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
min_binding_size: wgpu::BufferSize::new(forward_uniform_size),
|
min_binding_size: wgpu::BufferSize::new(mem::size_of::<
|
||||||
|
ForwardUniforms,
|
||||||
|
>(
|
||||||
|
)
|
||||||
|
as _),
|
||||||
has_dynamic_offset: false,
|
has_dynamic_offset: false,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
@@ -746,7 +461,7 @@ impl RenderState {
|
|||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 2, // texture2DArray
|
binding: 2,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Texture {
|
ty: wgpu::BindingType::Texture {
|
||||||
multisampled: false,
|
multisampled: false,
|
||||||
@@ -756,7 +471,7 @@ impl RenderState {
|
|||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 3, // samplerShadow
|
binding: 3,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler {
|
ty: wgpu::BindingType::Sampler {
|
||||||
filtering: false,
|
filtering: false,
|
||||||
@@ -838,10 +553,10 @@ impl RenderState {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create the render pipeline
|
// Create the render pipeline
|
||||||
let vs_module = device
|
let vs_module =
|
||||||
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.vert.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/forward.vert.spv"));
|
||||||
let fs_module = device
|
let fs_module =
|
||||||
.create_shader_module(&wgpu::include_spirv!("../../shaders/forward.frag.spv"));
|
device.create_shader_module(&wgpu::include_spirv!("../../resources/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"),
|
||||||
@@ -879,7 +594,7 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let forward_depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
size: wgpu::Extent3d {
|
size: wgpu::Extent3d {
|
||||||
width: sc_desc.width,
|
width: sc_desc.width,
|
||||||
height: sc_desc.height,
|
height: sc_desc.height,
|
||||||
@@ -890,73 +605,9 @@ impl RenderState {
|
|||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: Self::DEPTH_FORMAT,
|
format: Self::DEPTH_FORMAT,
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
label: Some("Forward Depth Texture"),
|
label: Some("Depth Texture"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let g_buffer_depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
|
||||||
size: wgpu::Extent3d {
|
|
||||||
width: sc_desc.width,
|
|
||||||
height: sc_desc.height,
|
|
||||||
depth: 5,
|
|
||||||
},
|
|
||||||
mip_level_count: 1,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: wgpu::TextureDimension::D2,
|
|
||||||
format: Self::DEPTH_FORMAT,
|
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED,
|
|
||||||
label: Some("g-buffer depth texture"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// I need one of these for each of the g-buffer elements I'm calculating
|
|
||||||
let mut g_buffer_depth_texture_views = (0..4)
|
|
||||||
.map(|i| {
|
|
||||||
Arc::new(
|
|
||||||
g_buffer_depth_texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some("g-buffer depth texture"),
|
|
||||||
format: None,
|
|
||||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
|
||||||
aspect: wgpu::TextureAspect::All,
|
|
||||||
base_mip_level: 0,
|
|
||||||
level_count: None,
|
|
||||||
base_array_layer: i as u32,
|
|
||||||
array_layer_count: NonZeroU32::new(1),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let g_buffer_data_texture = device.create_texture(&wgpu::TextureDescriptor {
|
|
||||||
size: wgpu::Extent3d {
|
|
||||||
width: sc_desc.width,
|
|
||||||
height: sc_desc.height,
|
|
||||||
depth: 5,
|
|
||||||
},
|
|
||||||
mip_level_count: 1,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: wgpu::TextureDimension::D2,
|
|
||||||
format: Self::DEPTH_FORMAT,
|
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED,
|
|
||||||
label: Some("g-buffer depth texture"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// I need one of these for each of the g-buffer elements I'm calculating
|
|
||||||
let mut g_buffer_data_texture_views = (0..4)
|
|
||||||
.map(|i| {
|
|
||||||
Arc::new(
|
|
||||||
g_buffer_depth_texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some("g-buffer depth texture"),
|
|
||||||
format: None,
|
|
||||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
|
||||||
aspect: wgpu::TextureAspect::All,
|
|
||||||
base_mip_level: 0,
|
|
||||||
level_count: None,
|
|
||||||
base_array_layer: i as u32,
|
|
||||||
array_layer_count: NonZeroU32::new(1),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
// Imgui renderer
|
// Imgui renderer
|
||||||
let renderer_config = ImguiRendererConfig {
|
let renderer_config = ImguiRendererConfig {
|
||||||
texture_format: sc_desc.format,
|
texture_format: sc_desc.format,
|
||||||
@@ -966,15 +617,6 @@ impl RenderState {
|
|||||||
ImguiRenderer::new(&mut imgui_context.context, &device, &queue, renderer_config);
|
ImguiRenderer::new(&mut imgui_context.context, &device, &queue, renderer_config);
|
||||||
|
|
||||||
RenderState {
|
RenderState {
|
||||||
gbuffer_pass: g_buffer_pass,
|
|
||||||
gbuffer_cam_projection_buffer: g_buffer_camera_projection_uniform,
|
|
||||||
gbuffer_depth_texture: g_buffer_depth_texture
|
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
||||||
gbuffer_depth_views: g_buffer_depth_texture_views,
|
|
||||||
gbuffer_target_texture: g_buffer_data_texture
|
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
||||||
gbuffer_target_views: g_buffer_data_texture_views,
|
|
||||||
|
|
||||||
swapchain: swap_chain,
|
swapchain: swap_chain,
|
||||||
queue: queue,
|
queue: queue,
|
||||||
size,
|
size,
|
||||||
@@ -982,8 +624,7 @@ impl RenderState {
|
|||||||
lights_are_dirty: true,
|
lights_are_dirty: true,
|
||||||
shadow_pass,
|
shadow_pass,
|
||||||
forward_pass,
|
forward_pass,
|
||||||
forward_depth: forward_depth_texture
|
forward_depth: depth_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
||||||
.create_view(&wgpu::TextureViewDescriptor::default()),
|
|
||||||
entity_bind_group_layout: entity_bind_group_layout,
|
entity_bind_group_layout: entity_bind_group_layout,
|
||||||
shadow_target_views: shadow_target_views,
|
shadow_target_views: shadow_target_views,
|
||||||
light_uniform_buf,
|
light_uniform_buf,
|
||||||
@@ -1038,8 +679,9 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@@ -1,32 +1,31 @@
|
|||||||
use std::{iter, num::NonZeroU32, ops::Range, rc::Rc};
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::iter::Chain;
|
use std::iter::Chain;
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread::current;
|
use std::thread::current;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::{iter, num::NonZeroU32, ops::Range, rc::Rc};
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
|
||||||
use bytemuck::__core::mem;
|
use bytemuck::__core::mem;
|
||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
use cgmath::{
|
use cgmath::{
|
||||||
Decomposed, Deg, Euler, InnerSpace, Matrix4, Point3, Quaternion, Rad, Rotation3, Transform,
|
vec3, Decomposed, Deg, Euler, InnerSpace, Matrix4, Point3, Quaternion, Rad, Rotation3,
|
||||||
vec3, Vector3,
|
Transform, Vector3,
|
||||||
};
|
};
|
||||||
use futures::executor::LocalPool;
|
use futures::executor::LocalPool;
|
||||||
use imgui::*;
|
|
||||||
use imgui::sys::ImGuiContext;
|
use imgui::sys::ImGuiContext;
|
||||||
|
use imgui::*;
|
||||||
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
|
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
|
||||||
use legion::*;
|
|
||||||
use legion::world::SubWorld;
|
use legion::world::SubWorld;
|
||||||
|
use legion::*;
|
||||||
use rapier3d::parry::motion::RigidMotionComposition;
|
use rapier3d::parry::motion::RigidMotionComposition;
|
||||||
|
use wgpu::util::DeviceExt;
|
||||||
use wgpu::{
|
use wgpu::{
|
||||||
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, CommandEncoder, Device,
|
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, CommandEncoder, Device,
|
||||||
FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame,
|
FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame,
|
||||||
TextureView, VertexState,
|
TextureView, VertexState,
|
||||||
};
|
};
|
||||||
use wgpu::util::DeviceExt;
|
|
||||||
use winit_24::dpi::PhysicalSize;
|
use winit_24::dpi::PhysicalSize;
|
||||||
use winit_24::platform::unix::x11::ffi::Time;
|
|
||||||
use winit_24::window::Window;
|
use winit_24::window::Window;
|
||||||
|
|
||||||
use crate::camera::{Camera, CameraController};
|
use crate::camera::{Camera, CameraController};
|
||||||
@@ -35,8 +34,10 @@ use crate::current_ui;
|
|||||||
use crate::geometry::{load_obj, Vertex};
|
use crate::geometry::{load_obj, 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, ForwardUniforms, insert_debug_marker_checked, pop_debug_group_checked, push_debug_group_checked};
|
|
||||||
use crate::render::state::RenderState;
|
use crate::render::state::RenderState;
|
||||||
|
use crate::render::{
|
||||||
|
insert_debug_marker_checked, pop_debug_group_checked, push_debug_group_checked, EntityUniforms,
|
||||||
|
};
|
||||||
|
|
||||||
#[system]
|
#[system]
|
||||||
#[write_component(Camera)]
|
#[write_component(Camera)]
|
||||||
@@ -79,12 +80,11 @@ fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld,
|
|||||||
.build(&ui, || (window_func.unwrap())(ui, v));
|
.build(&ui, || (window_func.unwrap())(ui, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Go through each "global" window-data component and render it's data
|
/// Go through each "global" window-data component and render it's data
|
||||||
#[system]
|
#[system]
|
||||||
#[write_component(ImguiWindow < ImguiPerformanceProfilerLine >)]
|
#[write_component(ImguiWindow<ImguiPerformanceProfilerLine>)]
|
||||||
#[write_component(ImguiPerformanceProfilerLine)]
|
#[write_component(ImguiPerformanceProfilerLine)]
|
||||||
#[write_component(ImguiWindow < ImguiGenericOutputLine >)]
|
#[write_component(ImguiWindow<ImguiGenericOutputLine>)]
|
||||||
#[write_component(ImguiGenericOutputLine)]
|
#[write_component(ImguiGenericOutputLine)]
|
||||||
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
||||||
let ui = unsafe { crate::current_ui().unwrap() };
|
let ui = unsafe { crate::current_ui().unwrap() };
|
||||||
@@ -175,7 +175,7 @@ pub fn render_performance_flag(world: &mut SubWorld, #[resource] loop_state: &mu
|
|||||||
#[write_component(Camera)]
|
#[write_component(Camera)]
|
||||||
#[write_component(Position)]
|
#[write_component(Position)]
|
||||||
#[write_component(ImguiPerformanceProfilerLine)]
|
#[write_component(ImguiPerformanceProfilerLine)]
|
||||||
#[write_component(Point3 < f32 >)]
|
#[write_component(Point3<f32>)]
|
||||||
#[write_component(Mesh)]
|
#[write_component(Mesh)]
|
||||||
#[write_component(DirectionalLight)]
|
#[write_component(DirectionalLight)]
|
||||||
pub fn render_test(
|
pub fn render_test(
|
||||||
@@ -234,7 +234,6 @@ pub fn render_test(
|
|||||||
mesh_stack.push(mesh.clone());
|
mesh_stack.push(mesh.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the light uniforms only if flagged
|
|
||||||
if renderer.lights_are_dirty {
|
if renderer.lights_are_dirty {
|
||||||
renderer.lights_are_dirty = false;
|
renderer.lights_are_dirty = false;
|
||||||
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
||||||
@@ -247,58 +246,10 @@ pub fn render_test(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the g buffer
|
|
||||||
push_debug_group_checked("g-buffer stuff", &mut encoder);
|
|
||||||
{
|
|
||||||
// insert_debug_marker_checked("render entities", &mut encoder);
|
|
||||||
|
|
||||||
// The render pass for the g buffer.. Does it need any attachments
|
|
||||||
// the shadow pass uses a target view as the input, which are just views on
|
|
||||||
// top of the shadow texture. So the attachment is a RW buffer which clears on load
|
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
|
||||||
label: Some("render pass"),
|
|
||||||
color_attachments: &[
|
|
||||||
wgpu::RenderPassColorAttachmentDescriptor {
|
|
||||||
attachment: &renderer.gbuffer_target_views.get(0).unwrap(),
|
|
||||||
resolve_target: None,
|
|
||||||
ops: Default::default(),
|
|
||||||
},
|
|
||||||
wgpu::RenderPassColorAttachmentDescriptor {
|
|
||||||
attachment: &renderer.gbuffer_target_views.get(1).unwrap(),
|
|
||||||
resolve_target: None,
|
|
||||||
ops: Default::default(),
|
|
||||||
},
|
|
||||||
wgpu::RenderPassColorAttachmentDescriptor {
|
|
||||||
attachment: &renderer.gbuffer_target_views.get(2).unwrap(),
|
|
||||||
resolve_target: None,
|
|
||||||
ops: Default::default(),
|
|
||||||
}],
|
|
||||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
|
||||||
attachment: &renderer.gbuffer_target_views.get(3).unwrap(),
|
|
||||||
depth_ops: Some(wgpu::Operations {
|
|
||||||
load: wgpu::LoadOp::Clear(1.0),
|
|
||||||
store: true,
|
|
||||||
}),
|
|
||||||
stencil_ops: None,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
pass.set_pipeline(&renderer.gbuffer_pass.pipeline);
|
|
||||||
pass.set_bind_group(0, &renderer.gbuffer_pass.bind_group, &[]);
|
|
||||||
|
|
||||||
// for mesh in &mesh_stack {
|
|
||||||
// pass.set_bind_group(1, &mesh.bind_group, &[]);
|
|
||||||
// // TODO, pipe through this index format through the mesh
|
|
||||||
// pass.set_index_buffer(mesh.index_buffer.slice(..), mesh.index_format);
|
|
||||||
// pass.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
|
||||||
// pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
pop_debug_group_checked(&mut encoder);
|
|
||||||
|
|
||||||
// Render the shadow textures
|
|
||||||
push_debug_group_checked("shadow passes", &mut encoder);
|
push_debug_group_checked("shadow passes", &mut encoder);
|
||||||
|
|
||||||
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
||||||
|
|
||||||
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
|
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
|
||||||
insert_debug_marker_checked(
|
insert_debug_marker_checked(
|
||||||
&format!("shadow pass {} (light at position {:?})", i, pos),
|
&format!("shadow pass {} (light at position {:?})", i, pos),
|
||||||
@@ -317,7 +268,6 @@ pub fn render_test(
|
|||||||
|
|
||||||
insert_debug_marker_checked("render entities", &mut encoder);
|
insert_debug_marker_checked("render entities", &mut encoder);
|
||||||
|
|
||||||
//
|
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: Some("render pass"),
|
label: Some("render pass"),
|
||||||
color_attachments: &[],
|
color_attachments: &[],
|
||||||
@@ -341,10 +291,11 @@ pub fn render_test(
|
|||||||
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pop_debug_group_checked(&mut encoder);
|
|
||||||
|
|
||||||
// And then render the viewport
|
pop_debug_group_checked(&mut encoder);
|
||||||
|
// forward pass
|
||||||
push_debug_group_checked("forward rendering pass", &mut encoder);
|
push_debug_group_checked("forward rendering pass", &mut encoder);
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: Some("forward render pass"),
|
label: Some("forward render pass"),
|
||||||
@@ -375,7 +326,6 @@ pub fn render_test(
|
|||||||
|
|
||||||
let mut query = <(&mut Position, &mut Mesh)>::query();
|
let mut query = <(&mut Position, &mut Mesh)>::query();
|
||||||
|
|
||||||
// I could use that mesh stack here lol
|
|
||||||
for (pos, mesh) in query.iter_mut(world) {
|
for (pos, mesh) in query.iter_mut(world) {
|
||||||
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
pass.set_bind_group(1, &mesh.bind_group, &[]);
|
||||||
// TODO: Pipe this in through the mesh
|
// TODO: Pipe this in through the mesh
|
||||||
@@ -384,12 +334,9 @@ pub fn render_test(
|
|||||||
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pop_debug_group_checked(&mut encoder);
|
||||||
pop_debug_group_checked(&mut encoder);
|
pop_debug_group_checked(&mut encoder);
|
||||||
|
|
||||||
|
|
||||||
// Run the Imgui render
|
|
||||||
push_debug_group_checked("imgui rendering pass", &mut encoder);
|
|
||||||
{
|
{
|
||||||
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
|
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
|
||||||
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
|
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
|
||||||
@@ -424,10 +371,6 @@ pub fn render_test(
|
|||||||
.render(draw_data, &renderer.queue, &renderer.device, &mut rpass)
|
.render(draw_data, &renderer.queue, &renderer.device, &mut rpass)
|
||||||
.expect("Rendering failed");
|
.expect("Rendering failed");
|
||||||
}
|
}
|
||||||
pop_debug_group_checked(&mut encoder);
|
|
||||||
|
|
||||||
// the startfunction debug group
|
|
||||||
pop_debug_group_checked(&mut encoder);
|
|
||||||
|
|
||||||
renderer.queue.submit(iter::once(encoder.finish()));
|
renderer.queue.submit(iter::once(encoder.finish()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,5 +111,7 @@ impl RuntimeState {
|
|||||||
self.mesh_cache.insert(filename, mesh);
|
self.mesh_cache.insert(filename, mesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panic!("nah");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,12 @@ use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
|||||||
|
|
||||||
use crate::camera::{Camera, CameraController};
|
use crate::camera::{Camera, CameraController};
|
||||||
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
||||||
use crate::geometry::RawMesh;
|
use crate::geometry;
|
||||||
use crate::physics::state::PhysicsState;
|
use crate::physics::state::PhysicsState;
|
||||||
use crate::render::state::RenderState;
|
use crate::render::state::RenderState;
|
||||||
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
||||||
use crate::runtime::state::RuntimeState;
|
use crate::runtime::state::RuntimeState;
|
||||||
|
use crate::geometry::RawMesh;
|
||||||
|
|
||||||
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
||||||
[color, color, color, color]
|
[color, color, color, color]
|
||||||
@@ -126,6 +127,59 @@ pub fn runtime_spawn(
|
|||||||
) {
|
) {
|
||||||
for entity in &runtime_state.get_entities() {
|
for entity in &runtime_state.get_entities() {
|
||||||
match entity.type_name.as_ref() {
|
match entity.type_name.as_ref() {
|
||||||
|
// "Sprite" => {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// let mesh_name = entity.mesh.clone().unwrap();
|
||||||
|
// let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||||
|
// None => {
|
||||||
|
// log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// Some(mesh) => mesh,
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// let position = Position::from(entity.position.clone());
|
||||||
|
//
|
||||||
|
// let mut static_body = RigidBodyBuilder::new_static()
|
||||||
|
// .position(Isometry3::new(
|
||||||
|
// Vector3::new(position.x, position.y, position.z),
|
||||||
|
// Vector::y(),
|
||||||
|
// ))
|
||||||
|
// .build();
|
||||||
|
//
|
||||||
|
// let mesh_collider = ColliderBuilder::trimesh(
|
||||||
|
// raw_mesh.vertices.iter().map(|v| v.position()).collect(),
|
||||||
|
// raw_mesh.indices.clone(),
|
||||||
|
// )
|
||||||
|
// .build();
|
||||||
|
//
|
||||||
|
// let gpu_mesh_buffer = renderer
|
||||||
|
// .upload_mesh_to_buffer(
|
||||||
|
// raw_mesh,
|
||||||
|
// Some(wgpu::Color {
|
||||||
|
// r: 1.0,
|
||||||
|
// g: 0.7,
|
||||||
|
// b: 0.3,
|
||||||
|
// a: 1.0,
|
||||||
|
// }),
|
||||||
|
// )
|
||||||
|
// .unwrap();
|
||||||
|
//
|
||||||
|
// let entity: Entity = cmd.push((
|
||||||
|
// position,
|
||||||
|
// gpu_mesh_buffer,
|
||||||
|
// Physics {
|
||||||
|
// rigid_body: static_body,
|
||||||
|
// rigid_body_handle: None,
|
||||||
|
// },
|
||||||
|
// Collider {
|
||||||
|
// collider: mesh_collider,
|
||||||
|
// collider_handle: None,
|
||||||
|
// },
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
"PhysicsEntity" => {
|
"PhysicsEntity" => {
|
||||||
let mesh_name = entity.mesh.as_ref().unwrap();
|
let mesh_name = entity.mesh.as_ref().unwrap();
|
||||||
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||||
@@ -144,6 +198,10 @@ pub fn runtime_spawn(
|
|||||||
|
|
||||||
let collider = ColliderBuilder::capsule_y(2.0, 1.0).build();
|
let collider = ColliderBuilder::capsule_y(2.0, 1.0).build();
|
||||||
|
|
||||||
|
|
||||||
|
//let mut vec = Vec::new();
|
||||||
|
//vec.push()
|
||||||
|
|
||||||
let gpu_mesh_buffer = renderer
|
let gpu_mesh_buffer = renderer
|
||||||
.upload_mesh_to_buffer(
|
.upload_mesh_to_buffer(
|
||||||
raw_mesh,
|
raw_mesh,
|
||||||
@@ -178,7 +236,7 @@ pub fn runtime_spawn(
|
|||||||
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
"Terrain" => {
|
"StaticMesh" => {
|
||||||
let mesh_name = entity.mesh.clone().unwrap();
|
let mesh_name = entity.mesh.clone().unwrap();
|
||||||
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
Reference in New Issue
Block a user