reduce register pressure
This commit is contained in:
@@ -18,6 +18,5 @@ void main() {
|
||||
}
|
||||
|
||||
pos = vec4((((position / 8.0) + internal_pos) * pc.dimensions) + pc.lowest_corner, 1.);
|
||||
vec4 worldview = camera_uniforms.view * pc.world * pos;
|
||||
gl_Position = camera_uniforms.proj * worldview;
|
||||
gl_Position = camera_uniforms.proj_view * pc.world * pos;
|
||||
}
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@
|
||||
|
||||
layout(push_constant) uniform PushConstantData {
|
||||
mat4 world;
|
||||
mat4 inv_world;
|
||||
vec3 dimensions;
|
||||
vec3 lowest_corner;
|
||||
uint enable[16];
|
||||
@@ -16,8 +17,8 @@ layout(set = 0, binding = 0) uniform Lights {
|
||||
} light_uniforms;
|
||||
|
||||
layout(set = 0, binding = 1) uniform Camera {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
mat4 proj_view;
|
||||
mat4 inv_proj_view;
|
||||
vec4 campos_and_time;
|
||||
} camera_uniforms;
|
||||
|
||||
|
||||
+11
-6
@@ -9,12 +9,17 @@ layout(input_attachment_index = 2, set = 1, binding = 2) uniform subpassInput u_
|
||||
layout(location = 0) in vec2 v_pos;
|
||||
layout(location = 0) out vec4 f_color;
|
||||
|
||||
vec3 WorldPosFromDepth(float depth) {
|
||||
vec4 clipSpacePosition = vec4(v_pos, depth, 1.0);
|
||||
vec3 calculate_view_position(float depth)
|
||||
{
|
||||
vec4 view_position = camera_uniforms.inv_proj_view * vec4(v_pos, depth, 1.0);
|
||||
//vec4 view_position = vec4(
|
||||
// fma(camera_uniforms.inv_proj_view[0][0], v_pos.x, camera_uniforms.inv_proj_view[3][0]),
|
||||
// fma(camera_uniforms.inv_proj_view[1][1], v_pos.y, camera_uniforms.inv_proj_view[3][1]),
|
||||
// fma(camera_uniforms.inv_proj_view[2][2], depth, camera_uniforms.inv_proj_view[3][2]),
|
||||
// fma(camera_uniforms.inv_proj_view[2][3], depth, camera_uniforms.inv_proj_view[3][3])
|
||||
// );
|
||||
|
||||
vec4 worldSpacePosition = inverse(camera_uniforms.proj * camera_uniforms.view) * clipSpacePosition;
|
||||
|
||||
return worldSpacePosition.xyz /= worldSpacePosition.w;
|
||||
return (view_position.xyz / view_position.w);
|
||||
}
|
||||
|
||||
vec3 shading(vec3 normal, vec3 position)
|
||||
@@ -37,6 +42,6 @@ void main() {
|
||||
if (depth == 1.0) {
|
||||
discard;
|
||||
}
|
||||
vec3 position = WorldPosFromDepth(depth);
|
||||
vec3 position = calculate_view_position(depth);
|
||||
f_color = vec4(col * shading(normal, position), 1.0);
|
||||
}
|
||||
|
||||
+20
-10
@@ -189,6 +189,7 @@ struct App {
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
uniform_buffer_allocator: SubbufferAllocator,
|
||||
pipeline_cache: Arc<PipelineCache>,
|
||||
draw_gui: bool,
|
||||
gstate: GState,
|
||||
csg_count: usize,
|
||||
previous_debug: PreviousDebug,
|
||||
@@ -305,9 +306,7 @@ impl App {
|
||||
_ => 5,
|
||||
}
|
||||
})
|
||||
.expect(
|
||||
"No suitable physical device found.",
|
||||
);
|
||||
.expect("No suitable physical device found.");
|
||||
|
||||
// Some little debug infos.
|
||||
info!(
|
||||
@@ -442,6 +441,7 @@ impl App {
|
||||
uniform_buffer_allocator,
|
||||
pipeline_cache,
|
||||
csg_count: gstate.csg.len(),
|
||||
draw_gui: true,
|
||||
gstate,
|
||||
previous_debug: PreviousDebug::default(),
|
||||
cstate,
|
||||
@@ -751,7 +751,11 @@ impl ApplicationHandler for App {
|
||||
let rcx_clone = self.rcx.clone();
|
||||
let mut rcx_lock = rcx_clone.lock().unwrap();
|
||||
let rcx = rcx_lock.as_mut().unwrap();
|
||||
if !rcx.gui.update(&event) {
|
||||
if self.draw_gui {
|
||||
if rcx.gui.update(&event) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
match &event {
|
||||
WindowEvent::CloseRequested => {
|
||||
event_loop.exit();
|
||||
@@ -812,6 +816,11 @@ impl ApplicationHandler for App {
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
PhysicalKey::Code(KeyCode::KeyG) => {
|
||||
if input.state == ElementState::Pressed {
|
||||
self.draw_gui = !self.draw_gui;
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
@@ -820,7 +829,6 @@ impl ApplicationHandler for App {
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
let rcx_clone = self.rcx.clone();
|
||||
@@ -885,8 +893,8 @@ impl App {
|
||||
* Mat4::from_translation(Vec3::ZERO - self.cstate.position);
|
||||
|
||||
let uniform_data = implicit_vs::Camera {
|
||||
view: view.to_cols_array_2d(),
|
||||
proj: proj.to_cols_array_2d(),
|
||||
proj_view: (proj * view).to_cols_array_2d(),
|
||||
inv_proj_view: (proj * view).inverse().to_cols_array_2d(),
|
||||
campos_and_time: [
|
||||
self.cstate.position.x,
|
||||
self.cstate.position.y,
|
||||
@@ -1096,9 +1104,7 @@ impl App {
|
||||
.push_constants(csg.deferred_pipeline.layout().clone(), 0, push_constants[i])
|
||||
.unwrap();
|
||||
|
||||
for i in 0..(8 * 8 * 8) {
|
||||
unsafe { builder.draw(VERTEX_COUNT as u32, 1, 0, i) }.unwrap();
|
||||
}
|
||||
unsafe { builder.draw(VERTEX_COUNT as u32, 8 * 8 * 8, 0, 0) }.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1196,6 +1202,7 @@ impl App {
|
||||
|
||||
rcx.render_start = Instant::now();
|
||||
|
||||
if self.draw_gui {
|
||||
let mut csg_needed = false;
|
||||
gui_up(&mut rcx.gui, &mut self.gstate, &mut csg_needed);
|
||||
if csg_needed {
|
||||
@@ -1212,6 +1219,7 @@ impl App {
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let mut push_constants = vec![PushConstantData::default(); self.gstate.csg.len()];
|
||||
let mut push_constants_left = self.gstate.csg.len();
|
||||
@@ -1352,7 +1360,9 @@ impl App {
|
||||
self.add_commands_primary_subpass(&mut builder);
|
||||
self.add_commands_lighting_pass(&mut builder, rcx, lighting_set1, lighting_set2);
|
||||
self.add_commands_secondary_subpass(&mut builder);
|
||||
if self.draw_gui {
|
||||
self.add_commands_gui(&mut builder, rcx, window_size);
|
||||
}
|
||||
|
||||
builder.end_render_pass(Default::default()).unwrap();
|
||||
let command_buffer = builder.build().unwrap();
|
||||
|
||||
+11
-6
@@ -16,12 +16,17 @@ float scene(vec4 p) {
|
||||
return length(p.xyz) - 1.0;
|
||||
}
|
||||
|
||||
vec3 WorldPosFromDepth(float depth) {
|
||||
vec4 clipSpacePosition = vec4(v_pos, depth, 1.0);
|
||||
vec3 calculate_view_position(float depth)
|
||||
{
|
||||
vec4 view_position = camera_uniforms.inv_proj_view * vec4(v_pos, depth, 1.0);
|
||||
//vec4 view_position = vec4(
|
||||
// fma(camera_uniforms.inv_proj_view[0][0], v_pos.x, camera_uniforms.inv_proj_view[3][0]),
|
||||
// fma(camera_uniforms.inv_proj_view[1][1], v_pos.y, camera_uniforms.inv_proj_view[3][1]),
|
||||
// fma(camera_uniforms.inv_proj_view[2][2], depth, camera_uniforms.inv_proj_view[3][2]),
|
||||
// fma(camera_uniforms.inv_proj_view[2][3], depth, camera_uniforms.inv_proj_view[3][3])
|
||||
// );
|
||||
|
||||
vec4 worldSpacePosition = inverse(camera_uniforms.proj * camera_uniforms.view) * clipSpacePosition;
|
||||
|
||||
return worldSpacePosition.xyz /= worldSpacePosition.w;
|
||||
return (view_position.xyz / view_position.w);
|
||||
}
|
||||
|
||||
const float EPSILON = .0001;
|
||||
@@ -44,7 +49,7 @@ void main() {
|
||||
if (depth == 1.0) {
|
||||
discard;
|
||||
}
|
||||
vec3 position = (inverse(pc.world) * vec4(WorldPosFromDepth(depth), 1.0)).xyz;
|
||||
vec3 position = (pc.inv_world * vec4(calculate_view_position(depth), 1.0)).xyz;
|
||||
|
||||
vec3 n = getNormal(position);
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::ahash::HashMapExt;
|
||||
use foldhash::HashMap;
|
||||
use rspirv::{dr::Module, spirv};
|
||||
|
||||
+7
-4
@@ -118,6 +118,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
WorkItem::GetPushConstants(csg, time, index) => {
|
||||
let mut push_constants = PushConstantData {
|
||||
world: Mat4::IDENTITY.to_cols_array_2d(),
|
||||
inv_world: Mat4::IDENTITY.to_cols_array_2d(),
|
||||
dimensions: Vec3::ONE.to_array().into(),
|
||||
lowest_corner: Vec3::ZERO.into(),
|
||||
enable: [0; 16],
|
||||
@@ -126,19 +127,21 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
|
||||
let csg = csg.read().unwrap();
|
||||
|
||||
push_constants.world = (Mat4::from_translation(csg.pos * 0.01)
|
||||
let world = Mat4::from_translation(csg.pos * 0.01)
|
||||
* Mat4::from_euler(
|
||||
EulerRot::XYZ,
|
||||
csg.rot.x.to_radians(),
|
||||
csg.rot.y.to_radians(),
|
||||
csg.rot.z.to_radians(),
|
||||
)
|
||||
* Mat4::from_scale(csg.scale * 2.0))
|
||||
.to_cols_array_2d();
|
||||
* Mat4::from_scale(csg.scale * 2.0);
|
||||
|
||||
push_constants.world = world.to_cols_array_2d();
|
||||
push_constants.inv_world = world.inverse().to_cols_array_2d();
|
||||
|
||||
interval_check(&csg, &mut push_constants, time);
|
||||
|
||||
push_constants.material = index as _;
|
||||
push_constants.material = index as u32 + 1;
|
||||
|
||||
send.send(WorkComplete::GetPushConstants(push_constants, index))
|
||||
.unwrap();
|
||||
|
||||
+2
-2
@@ -38,13 +38,13 @@ void main() {
|
||||
vec3 raypos = pos.xyz;
|
||||
|
||||
vec3 p;
|
||||
vec3 raydir = normalize(raypos - (inverse(pc.world) * vec4(camera_uniforms.campos_and_time.xyz, 1)).xyz);
|
||||
vec3 raydir = normalize(raypos - (pc.inv_world * vec4(camera_uniforms.campos_and_time.xyz, 1)).xyz);
|
||||
|
||||
vec2 td = spheretracing(raypos, raydir, p);
|
||||
|
||||
if (td.y < EPSILON)
|
||||
{
|
||||
vec4 tpoint = camera_uniforms.proj * camera_uniforms.view * pc.world * vec4(p, 1);
|
||||
vec4 tpoint = camera_uniforms.proj_view * pc.world * vec4(p, 1);
|
||||
gl_FragDepth = (tpoint.z / tpoint.w);
|
||||
material = pc.material;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user