Three pass gbuffer
This commit is contained in:
+282
-67
@@ -192,7 +192,8 @@ struct App {
|
||||
previous_debug: PreviousDebug,
|
||||
cstate: CState,
|
||||
vertex_buffer: Subbuffer<[IVertex; VERTEX_COUNT]>,
|
||||
base_module: Module,
|
||||
trace_module: Module,
|
||||
normals_module: Module,
|
||||
rcx: Option<RenderContext>,
|
||||
}
|
||||
|
||||
@@ -201,6 +202,7 @@ struct ShaderModules {
|
||||
implicit_fs: Arc<ShaderModule>,
|
||||
lighting_vs: Arc<ShaderModule>,
|
||||
lighting_fs: Arc<ShaderModule>,
|
||||
normals_fs: Arc<ShaderModule>,
|
||||
}
|
||||
|
||||
struct RenderContext {
|
||||
@@ -213,6 +215,7 @@ struct RenderContext {
|
||||
depth_buffer: Arc<ImageView>,
|
||||
shader_modules: ShaderModules,
|
||||
implicit_pipeline: Arc<GraphicsPipeline>,
|
||||
normals_pipeline: Arc<GraphicsPipeline>,
|
||||
lighting_pipeline: Arc<GraphicsPipeline>,
|
||||
viewport: Viewport,
|
||||
recreate_swapchain: bool,
|
||||
@@ -547,14 +550,23 @@ impl App {
|
||||
|
||||
*vertex_buffer.write().unwrap() = CUBE_VERTEX;
|
||||
|
||||
let spv_code = include_bytes!("recompiled.spv");
|
||||
let spv_code_u32 = spv_code
|
||||
let trace_spv_code = include_bytes!("trace.recompiled.spv");
|
||||
let trace_spv_code_u32 = trace_spv_code
|
||||
.array_chunks::<4>()
|
||||
.map(|u| u32::from_le_bytes(*u))
|
||||
.collect::<Vec<_>>();
|
||||
let mut loader = rspirv::dr::Loader::new();
|
||||
rspirv::binary::parse_words(spv_code_u32, &mut loader).unwrap();
|
||||
let base_module = loader.module();
|
||||
rspirv::binary::parse_words(trace_spv_code_u32, &mut loader).unwrap();
|
||||
let trace_module = loader.module();
|
||||
|
||||
let normals_spv_code = include_bytes!("normals.recompiled.spv");
|
||||
let normals_spv_code_u32 = normals_spv_code
|
||||
.array_chunks::<4>()
|
||||
.map(|u| u32::from_le_bytes(*u))
|
||||
.collect::<Vec<_>>();
|
||||
let mut loader = rspirv::dr::Loader::new();
|
||||
rspirv::binary::parse_words(normals_spv_code_u32, &mut loader).unwrap();
|
||||
let normals_module = loader.module();
|
||||
|
||||
App {
|
||||
instance,
|
||||
@@ -570,7 +582,8 @@ impl App {
|
||||
previous_debug: PreviousDebug::default(),
|
||||
cstate,
|
||||
vertex_buffer,
|
||||
base_module,
|
||||
trace_module,
|
||||
normals_module,
|
||||
rcx: None,
|
||||
}
|
||||
}
|
||||
@@ -720,38 +733,70 @@ impl ApplicationHandler for App {
|
||||
.map(|load| load(self.device.clone()).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.base_module.clone()));
|
||||
let trace_module = {
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.trace_module.clone()));
|
||||
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("out.spv")
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("trace.out.spv")
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let smodule = unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
let normals_module = {
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.normals_module.clone()));
|
||||
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("normals.out.spv")
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
let shader_modules = ShaderModules {
|
||||
implicit_vs: pariter[0].clone(),
|
||||
implicit_fs: smodule,
|
||||
implicit_fs: trace_module,
|
||||
lighting_vs: pariter[1].clone(),
|
||||
lighting_fs: pariter[2].clone(),
|
||||
normals_fs: normals_module,
|
||||
};
|
||||
|
||||
drop(pariter);
|
||||
@@ -785,10 +830,15 @@ impl ApplicationHandler for App {
|
||||
},
|
||||
},
|
||||
passes: [{
|
||||
color: [color, normals],
|
||||
color: [],
|
||||
depth_stencil: {depth},
|
||||
input: [],
|
||||
},
|
||||
{
|
||||
color: [color, normals],
|
||||
depth_stencil: {},
|
||||
input: [depth],
|
||||
},
|
||||
{
|
||||
color: [final_color],
|
||||
depth_stencil: {},
|
||||
@@ -811,7 +861,7 @@ impl ApplicationHandler for App {
|
||||
let (framebuffers, color_buffer, normal_buffer, depth_buffer) =
|
||||
framebuffer_generation(&images, &render_pass, &self.memory_allocator);
|
||||
|
||||
let (implicit_pipeline, lighting_pipeline) = deferred_pipeline_recompile(
|
||||
let (implicit_pipeline, normals_pipeline, lighting_pipeline) = deferred_pipeline_recompile(
|
||||
&render_pass,
|
||||
&self.pipeline_cache,
|
||||
&shader_modules,
|
||||
@@ -826,7 +876,7 @@ impl ApplicationHandler for App {
|
||||
event_loop,
|
||||
surface.clone(),
|
||||
self.graphics_queue.clone(),
|
||||
Subpass::from(render_pass.clone(), 2).unwrap(),
|
||||
Subpass::from(render_pass.clone(), 3).unwrap(),
|
||||
images[0].format(),
|
||||
GuiConfig {
|
||||
allow_srgb_render_target: true,
|
||||
@@ -845,6 +895,7 @@ impl ApplicationHandler for App {
|
||||
depth_buffer,
|
||||
shader_modules,
|
||||
implicit_pipeline,
|
||||
normals_pipeline,
|
||||
lighting_pipeline,
|
||||
viewport,
|
||||
recreate_swapchain: false,
|
||||
@@ -1010,41 +1061,78 @@ impl App {
|
||||
|
||||
if rcx.recreate_shaders {
|
||||
rcx.new_object_start = Some(Instant::now());
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.base_module.clone()));
|
||||
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
let trace_module = {
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.trace_module.clone()));
|
||||
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("out.spv")
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("trace.out.spv")
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let smodule = unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
rcx.shader_modules.implicit_fs = smodule;
|
||||
let normals_module = {
|
||||
let new_module = self.gstate.csg[0]
|
||||
.parts
|
||||
.compile_to_spirv(Some(self.normals_module.clone()));
|
||||
|
||||
let assembled_module = new_module.assemble();
|
||||
let module_as_bytes = assembled_module
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(u32::to_le_bytes)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if DUMP_SPV_TO_FILE {
|
||||
File::create("normals.out.spv")
|
||||
.unwrap()
|
||||
.write(&module_as_bytes)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
::vulkano::shader::ShaderModule::new(
|
||||
self.device.clone(),
|
||||
ShaderModuleCreateInfo::new(&assembled_module),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
rcx.shader_modules.implicit_fs = trace_module;
|
||||
rcx.shader_modules.normals_fs = normals_module;
|
||||
|
||||
rcx.recreate_shaders = false;
|
||||
rcx.recreate_pipelines = true;
|
||||
}
|
||||
|
||||
if rcx.recreate_pipelines {
|
||||
(rcx.implicit_pipeline, rcx.lighting_pipeline) = deferred_pipeline_recompile(
|
||||
(
|
||||
rcx.implicit_pipeline,
|
||||
rcx.normals_pipeline,
|
||||
rcx.lighting_pipeline,
|
||||
) = deferred_pipeline_recompile(
|
||||
&rcx.render_pass,
|
||||
&self.pipeline_cache,
|
||||
&rcx.shader_modules,
|
||||
@@ -1184,14 +1272,41 @@ impl App {
|
||||
|
||||
//assert!(rcx.lighting_pipeline.layout().set_layouts().len() == 2);
|
||||
|
||||
let normals_layout1 = &rcx.normals_pipeline.layout().set_layouts()[0];
|
||||
let normals_set1 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
normals_layout1.clone(),
|
||||
[
|
||||
//WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer.clone()),
|
||||
WriteDescriptorSet::buffer(1, cam_set.clone()),
|
||||
],
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let normals_layout2 = &rcx.normals_pipeline.layout().set_layouts()[1];
|
||||
let normals_set2 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
normals_layout2.clone(),
|
||||
[WriteDescriptorSet::image_view(0, rcx.depth_buffer.clone())],
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let lighting_layout2 = &rcx.lighting_pipeline.layout().set_layouts()[1];
|
||||
let lighting_set2 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
lighting_layout2.clone(),
|
||||
[
|
||||
WriteDescriptorSet::image_view(0, rcx.color_buffer.clone()),
|
||||
WriteDescriptorSet::image_view(1, rcx.normal_buffer.clone()),
|
||||
WriteDescriptorSet::image_view(2, rcx.depth_buffer.clone()),
|
||||
],
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let lighting_layout1 = &rcx.lighting_pipeline.layout().set_layouts()[0];
|
||||
//println!(
|
||||
// "Descriptor counts: {:?}",
|
||||
// lighting_layout1
|
||||
// .descriptor_counts()
|
||||
// .iter()
|
||||
// .collect::<Vec<_>>()
|
||||
//);
|
||||
let lighting_set1 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
lighting_layout1.clone(),
|
||||
@@ -1308,6 +1423,45 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
builder
|
||||
.next_subpass(
|
||||
Default::default(),
|
||||
SubpassBeginInfo {
|
||||
contents: SubpassContents::Inline,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
builder
|
||||
.bind_pipeline_graphics(rcx.normals_pipeline.clone())
|
||||
.unwrap()
|
||||
.bind_descriptor_sets(
|
||||
PipelineBindPoint::Graphics,
|
||||
rcx.normals_pipeline.layout().clone(),
|
||||
0,
|
||||
vec![normals_set1, normals_set2],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for csg in &self.gstate.csg {
|
||||
push_constants.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();
|
||||
|
||||
builder
|
||||
.push_constants(rcx.normals_pipeline.layout().clone(), 0, push_constants)
|
||||
.unwrap();
|
||||
|
||||
unsafe { builder.draw(3, 1, 0, 0) }.unwrap();
|
||||
}
|
||||
|
||||
builder
|
||||
.next_subpass(
|
||||
Default::default(),
|
||||
@@ -1474,7 +1628,11 @@ fn deferred_pipeline_recompile(
|
||||
shader_modules: &ShaderModules,
|
||||
debug: &PreviousDebug,
|
||||
viewport: Option<&Viewport>,
|
||||
) -> (Arc<GraphicsPipeline>, Arc<GraphicsPipeline>) {
|
||||
) -> (
|
||||
Arc<GraphicsPipeline>,
|
||||
Arc<GraphicsPipeline>,
|
||||
Arc<GraphicsPipeline>,
|
||||
) {
|
||||
let device = cache.device();
|
||||
|
||||
const SPEC_BOUNDING_BOXES: u32 = 0;
|
||||
@@ -1592,11 +1750,68 @@ fn deferred_pipeline_recompile(
|
||||
..Default::default()
|
||||
}),
|
||||
multisample_state: Some(MultisampleState::default()),
|
||||
color_blend_state: None,
|
||||
subpass: Some(deferred_subpass.into()),
|
||||
..GraphicsPipelineCreateInfo::layout(layout.clone())
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let lighting_vs_entry = shader_modules
|
||||
.lighting_vs
|
||||
.specialize(specs.clone())
|
||||
.unwrap()
|
||||
.single_entry_point()
|
||||
.unwrap();
|
||||
|
||||
let vertex_input_state = VertexInputState::new();
|
||||
|
||||
let lighting_vs_info = PipelineShaderStageCreateInfo::new(lighting_vs_entry);
|
||||
let normals_fs_info = PipelineShaderStageCreateInfo::new(
|
||||
shader_modules
|
||||
.normals_fs
|
||||
.specialize(specs.clone())
|
||||
.unwrap()
|
||||
.single_entry_point()
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let layout = PipelineLayout::new(
|
||||
device.clone(),
|
||||
PipelineDescriptorSetLayoutCreateInfo::from_stages([&lighting_vs_info, &normals_fs_info])
|
||||
.into_pipeline_layout_create_info(device.clone())
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let stages = [lighting_vs_info, normals_fs_info].into_iter().collect();
|
||||
let normals_subpass = Subpass::from(render_pass.clone(), 1).unwrap();
|
||||
|
||||
let normals_pipeline = {
|
||||
GraphicsPipeline::new(
|
||||
device.clone(),
|
||||
Some(cache.clone()),
|
||||
GraphicsPipelineCreateInfo {
|
||||
flags: PipelineCreateFlags::DISABLE_OPTIMIZATION,
|
||||
stages,
|
||||
vertex_input_state: Some(vertex_input_state),
|
||||
input_assembly_state: Some(InputAssemblyState::default()),
|
||||
dynamic_state: dynamic_state.clone(),
|
||||
viewport_state: Some(viewport_state.clone()),
|
||||
rasterization_state: Some(RasterizationState {
|
||||
front_face: FrontFace::Clockwise,
|
||||
cull_mode: CullMode::Back,
|
||||
polygon_mode: PolygonMode::Fill,
|
||||
..RasterizationState::default()
|
||||
}),
|
||||
depth_stencil_state: None,
|
||||
multisample_state: Some(MultisampleState::default()),
|
||||
color_blend_state: Some(ColorBlendState::with_attachment_states(
|
||||
deferred_subpass.num_color_attachments(),
|
||||
normals_subpass.num_color_attachments(),
|
||||
ColorBlendAttachmentState::default(),
|
||||
)),
|
||||
subpass: Some(deferred_subpass.into()),
|
||||
subpass: Some(normals_subpass.into()),
|
||||
..GraphicsPipelineCreateInfo::layout(layout.clone())
|
||||
},
|
||||
)
|
||||
@@ -1631,7 +1846,7 @@ fn deferred_pipeline_recompile(
|
||||
.unwrap();
|
||||
|
||||
let stages = [lighting_vs_info, lighting_fs_info].into_iter().collect();
|
||||
let lighting_subpass = Subpass::from(render_pass.clone(), 1).unwrap();
|
||||
let lighting_subpass = Subpass::from(render_pass.clone(), 2).unwrap();
|
||||
|
||||
let lighting_pipeline = {
|
||||
GraphicsPipeline::new(
|
||||
@@ -1673,7 +1888,7 @@ fn deferred_pipeline_recompile(
|
||||
|
||||
dump_pipeline_cache(cache.clone());
|
||||
|
||||
(implicit_pipeline, lighting_pipeline)
|
||||
(implicit_pipeline, normals_pipeline, lighting_pipeline)
|
||||
}
|
||||
|
||||
fn gpu_buffer<T>(
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// global fragment shader
|
||||
|
||||
#version 460
|
||||
#extension GL_GOOGLE_include_directive:require
|
||||
#include "include.glsl"
|
||||
|
||||
layout(location = 0) in vec2 v_pos;
|
||||
|
||||
layout(input_attachment_index = 0, set = 1, binding = 0) uniform subpassInput u_depth;
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
layout(location = 1) out vec4 f_normal;
|
||||
|
||||
float scene(vec3 p) {
|
||||
return length(p) - 1.0;
|
||||
}
|
||||
|
||||
vec3 WorldPosFromDepth(float depth) {
|
||||
vec4 clipSpacePosition = vec4(v_pos, depth, 1.0);
|
||||
|
||||
vec4 worldSpacePosition = inverse(camera_uniforms.proj * camera_uniforms.view) * clipSpacePosition;
|
||||
|
||||
return worldSpacePosition.xyz /= worldSpacePosition.w;
|
||||
}
|
||||
|
||||
const float EPSILON = .0001;
|
||||
|
||||
vec3 getNormal(vec3 p) {
|
||||
vec3 n;
|
||||
n.x = scene(vec3(p.x + EPSILON, p.y, p.z)).x;
|
||||
n.y = scene(vec3(p.x, p.y + EPSILON, p.z)).x;
|
||||
n.z = scene(vec3(p.x, p.y, p.z + EPSILON)).x;
|
||||
return normalize(n - (scene(p)));
|
||||
}
|
||||
|
||||
//Implicit Surface Entrypoint
|
||||
void main() {
|
||||
float depth = subpassLoad(u_depth).x;
|
||||
if (depth == 1.0) {
|
||||
discard;
|
||||
}
|
||||
vec3 position = (inverse(pc.world) * vec4(WorldPosFromDepth(depth), 1.0)).xyz;
|
||||
|
||||
vec3 n = getNormal(position);
|
||||
|
||||
f_color = vec4(0.5, 0.5, 0.5, 1.0);
|
||||
mat3 rotation = mat3(pc.world[0].xyz, pc.world[1].xyz, pc.world[2].xyz);
|
||||
|
||||
f_normal = vec4(normalize(rotation * n), 1.0);
|
||||
|
||||
return;
|
||||
}
|
||||
Binary file not shown.
+1
-20
@@ -8,26 +8,14 @@ layout(location = 0) in vec4 pos;
|
||||
|
||||
layout(depth_greater) out float gl_FragDepth;
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
layout(location = 1) out vec4 f_normal;
|
||||
|
||||
float scene(vec3 p) {
|
||||
return length(p) - 1.0;
|
||||
}
|
||||
|
||||
const float EPSILON = .0001;
|
||||
const uint MAX_STEPS = 50;
|
||||
#define NEARPLANE 0.
|
||||
const float NEARPLANE = 0.;
|
||||
float FARPLANE = length(pc.dimensions / 8.);
|
||||
#define gl_GlobalInvocationID uvec3(1)
|
||||
|
||||
vec3 getNormal(vec3 p, float dens) {
|
||||
vec3 n;
|
||||
n.x = scene(vec3(p.x + EPSILON, p.y, p.z)).x;
|
||||
n.y = scene(vec3(p.x, p.y + EPSILON, p.z)).x;
|
||||
n.z = scene(vec3(p.x, p.y, p.z + EPSILON)).x;
|
||||
return normalize(n - (scene(p)));
|
||||
}
|
||||
|
||||
vec2 spheretracing(vec3 ori, vec3 dir, out vec3 p) {
|
||||
vec2 td = vec2(NEARPLANE, 1.);
|
||||
@@ -54,13 +42,6 @@ void main() {
|
||||
|
||||
if (td.y < EPSILON)
|
||||
{
|
||||
vec3 n = getNormal(p, td.y);
|
||||
|
||||
f_color = vec4(0.5, 0.5, 0.5, 1.0);
|
||||
mat3 rotation = mat3(pc.world[0].xyz, pc.world[1].xyz, pc.world[2].xyz);
|
||||
|
||||
f_normal = vec4(normalize(rotation * n), 1.0);
|
||||
|
||||
vec4 tpoint = camera_uniforms.proj * camera_uniforms.view * pc.world * vec4(p, 1);
|
||||
gl_FragDepth = (tpoint.z / tpoint.w);
|
||||
}
|
||||
|
||||
@@ -1,371 +0,0 @@
|
||||
; SPIR-V
|
||||
; Version: 1.6
|
||||
; Generator: Khronos Glslang Reference Front End; 11
|
||||
; Bound: 289
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %4 "main" %27 %35 %171 %182 %217 %246 %gl_FragDepth %288
|
||||
OpExecutionMode %4 OriginUpperLeft
|
||||
OpExecutionMode %4 DepthReplacing
|
||||
OpExecutionMode %4 DepthGreater
|
||||
OpDecorate %_arr_uint_uint_16 ArrayStride 4
|
||||
OpDecorate %_struct_33 Block
|
||||
OpMemberDecorate %_struct_33 0 ColMajor
|
||||
OpMemberDecorate %_struct_33 0 MatrixStride 16
|
||||
OpMemberDecorate %_struct_33 0 Offset 0
|
||||
OpMemberDecorate %_struct_33 1 Offset 64
|
||||
OpMemberDecorate %_struct_33 2 Offset 80
|
||||
OpMemberDecorate %_struct_33 3 Offset 92
|
||||
OpDecorate %171 Location 0
|
||||
OpDecorate %_struct_180 Block
|
||||
OpMemberDecorate %_struct_180 0 ColMajor
|
||||
OpMemberDecorate %_struct_180 0 MatrixStride 16
|
||||
OpMemberDecorate %_struct_180 0 Offset 0
|
||||
OpMemberDecorate %_struct_180 1 ColMajor
|
||||
OpMemberDecorate %_struct_180 1 MatrixStride 16
|
||||
OpMemberDecorate %_struct_180 1 Offset 64
|
||||
OpMemberDecorate %_struct_180 2 Offset 128
|
||||
OpDecorate %182 Binding 1
|
||||
OpDecorate %182 DescriptorSet 0
|
||||
OpDecorate %217 Location 0
|
||||
OpDecorate %246 Location 1
|
||||
OpDecorate %gl_FragDepth BuiltIn FragDepth
|
||||
OpDecorate %_arr_v4float_uint_32 ArrayStride 16
|
||||
OpDecorate %_arr_v4float_uint_32_0 ArrayStride 16
|
||||
OpDecorate %_struct_286 Block
|
||||
OpMemberDecorate %_struct_286 0 Offset 0
|
||||
OpMemberDecorate %_struct_286 1 Offset 512
|
||||
OpMemberDecorate %_struct_286 2 Offset 1024
|
||||
OpDecorate %288 Binding 0
|
||||
OpDecorate %288 DescriptorSet 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%v3float = OpTypeVector %float 3
|
||||
%_ptr_Function_v3float = OpTypePointer Function %v3float
|
||||
%9 = OpTypeFunction %float %_ptr_Function_v3float
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%14 = OpTypeFunction %v3float %_ptr_Function_v3float %_ptr_Function_float
|
||||
%v2float = OpTypeVector %float 2
|
||||
%20 = OpTypeFunction %v2float %_ptr_Function_v3float %_ptr_Function_v3float %_ptr_Function_v3float
|
||||
%_ptr_Private_float = OpTypePointer Private %float
|
||||
%27 = OpVariable %_ptr_Private_float Private
|
||||
%v4float = OpTypeVector %float 4
|
||||
%mat4v4float = OpTypeMatrix %v4float 4
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_16 = OpConstant %uint 16
|
||||
%_arr_uint_uint_16 = OpTypeArray %uint %uint_16
|
||||
%_struct_33 = OpTypeStruct %mat4v4float %v3float %v3float %_arr_uint_uint_16
|
||||
%_ptr_PushConstant__struct_33 = OpTypePointer PushConstant %_struct_33
|
||||
%35 = OpVariable %_ptr_PushConstant__struct_33 PushConstant
|
||||
%int = OpTypeInt 32 1
|
||||
%int_1 = OpConstant %int 1
|
||||
%_ptr_PushConstant_v3float = OpTypePointer PushConstant %v3float
|
||||
%float_8 = OpConstant %float 8
|
||||
%float_1 = OpConstant %float 1
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%float_9_99999975en05 = OpConstant %float 9.99999975e-05
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%uint_2 = OpConstant %uint 2
|
||||
%_ptr_Function_v2float = OpTypePointer Function %v2float
|
||||
%float_0 = OpConstant %float 0
|
||||
%101 = OpConstantComposite %v2float %float_0 %float_1
|
||||
%float_0_899999976 = OpConstant %float 0.899999976
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%int_0 = OpConstant %int 0
|
||||
%bool = OpTypeBool
|
||||
%uint_50 = OpConstant %uint 50
|
||||
%_ptr_Input_v4float = OpTypePointer Input %v4float
|
||||
%171 = OpVariable %_ptr_Input_v4float Input
|
||||
%_ptr_PushConstant_mat4v4float = OpTypePointer PushConstant %mat4v4float
|
||||
%_struct_180 = OpTypeStruct %mat4v4float %mat4v4float %v3float
|
||||
%_ptr_Uniform__struct_180 = OpTypePointer Uniform %_struct_180
|
||||
%182 = OpVariable %_ptr_Uniform__struct_180 Uniform
|
||||
%int_2 = OpConstant %int 2
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%217 = OpVariable %_ptr_Output_v4float Output
|
||||
%float_0_5 = OpConstant %float 0.5
|
||||
%219 = OpConstantComposite %v4float %float_0_5 %float_0_5 %float_0_5 %float_1
|
||||
%mat3v3float = OpTypeMatrix %v3float 3
|
||||
%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
|
||||
%_ptr_PushConstant_v4float = OpTypePointer PushConstant %v4float
|
||||
%246 = OpVariable %_ptr_Output_v4float Output
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%gl_FragDepth = OpVariable %_ptr_Output_float Output
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%uint_32 = OpConstant %uint 32
|
||||
%_arr_v4float_uint_32 = OpTypeArray %v4float %uint_32
|
||||
%_arr_v4float_uint_32_0 = OpTypeArray %v4float %uint_32
|
||||
%_struct_286 = OpTypeStruct %_arr_v4float_uint_32 %_arr_v4float_uint_32_0 %uint
|
||||
%_ptr_Uniform__struct_286 = OpTypePointer Uniform %_struct_286
|
||||
%288 = OpVariable %_ptr_Uniform__struct_286 Uniform
|
||||
%4 = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%169 = OpVariable %_ptr_Function_v3float Function
|
||||
%174 = OpVariable %_ptr_Function_v3float Function
|
||||
%195 = OpVariable %_ptr_Function_v2float Function
|
||||
%196 = OpVariable %_ptr_Function_v3float Function
|
||||
%197 = OpVariable %_ptr_Function_v3float Function
|
||||
%199 = OpVariable %_ptr_Function_v3float Function
|
||||
%201 = OpVariable %_ptr_Function_v3float Function
|
||||
%209 = OpVariable %_ptr_Function_v3float Function
|
||||
%210 = OpVariable %_ptr_Function_v3float Function
|
||||
%212 = OpVariable %_ptr_Function_float Function
|
||||
%222 = OpVariable %_ptr_Function_mat3v3float Function
|
||||
%256 = OpVariable %_ptr_Function_v4float Function
|
||||
%39 = OpAccessChain %_ptr_PushConstant_v3float %35 %int_1
|
||||
%40 = OpLoad %v3float %39
|
||||
%42 = OpCompositeConstruct %v3float %float_8 %float_8 %float_8
|
||||
%43 = OpFDiv %v3float %40 %42
|
||||
%44 = OpExtInst %float %1 Length %43
|
||||
OpStore %27 %44
|
||||
%172 = OpLoad %v4float %171
|
||||
%173 = OpVectorShuffle %v3float %172 %172 0 1 2
|
||||
OpStore %169 %173
|
||||
%175 = OpLoad %v3float %169
|
||||
%177 = OpAccessChain %_ptr_PushConstant_mat4v4float %35 %int_0
|
||||
%178 = OpLoad %mat4v4float %177
|
||||
%179 = OpExtInst %mat4v4float %1 MatrixInverse %178
|
||||
%185 = OpAccessChain %_ptr_Uniform_v3float %182 %int_2
|
||||
%186 = OpLoad %v3float %185
|
||||
%187 = OpCompositeExtract %float %186 0
|
||||
%188 = OpCompositeExtract %float %186 1
|
||||
%189 = OpCompositeExtract %float %186 2
|
||||
%190 = OpCompositeConstruct %v4float %187 %188 %189 %float_1
|
||||
%191 = OpMatrixTimesVector %v4float %179 %190
|
||||
%192 = OpVectorShuffle %v3float %191 %191 0 1 2
|
||||
%193 = OpFSub %v3float %175 %192
|
||||
%194 = OpExtInst %v3float %1 Normalize %193
|
||||
OpStore %174 %194
|
||||
%198 = OpLoad %v3float %169
|
||||
OpStore %197 %198
|
||||
%200 = OpLoad %v3float %174
|
||||
OpStore %199 %200
|
||||
%202 = OpFunctionCall %v2float %24 %197 %199 %201
|
||||
%203 = OpLoad %v3float %201
|
||||
OpStore %196 %203
|
||||
OpStore %195 %202
|
||||
%204 = OpAccessChain %_ptr_Function_float %195 %uint_1
|
||||
%205 = OpLoad %float %204
|
||||
%206 = OpFOrdLessThan %bool %205 %float_9_99999975en05
|
||||
OpSelectionMerge %208 None
|
||||
OpBranchConditional %206 %207 %280
|
||||
%207 = OpLabel
|
||||
%211 = OpLoad %v3float %196
|
||||
OpStore %210 %211
|
||||
%213 = OpAccessChain %_ptr_Function_float %195 %uint_1
|
||||
%214 = OpLoad %float %213
|
||||
OpStore %212 %214
|
||||
%215 = OpFunctionCall %v3float %17 %210 %212
|
||||
OpStore %209 %215
|
||||
OpStore %217 %219
|
||||
%224 = OpAccessChain %_ptr_PushConstant_v4float %35 %int_0 %int_0
|
||||
%225 = OpLoad %v4float %224
|
||||
%226 = OpVectorShuffle %v3float %225 %225 0 1 2
|
||||
%227 = OpAccessChain %_ptr_PushConstant_v4float %35 %int_0 %int_1
|
||||
%228 = OpLoad %v4float %227
|
||||
%229 = OpVectorShuffle %v3float %228 %228 0 1 2
|
||||
%230 = OpAccessChain %_ptr_PushConstant_v4float %35 %int_0 %int_2
|
||||
%231 = OpLoad %v4float %230
|
||||
%232 = OpVectorShuffle %v3float %231 %231 0 1 2
|
||||
%233 = OpCompositeExtract %float %226 0
|
||||
%234 = OpCompositeExtract %float %226 1
|
||||
%235 = OpCompositeExtract %float %226 2
|
||||
%236 = OpCompositeExtract %float %229 0
|
||||
%237 = OpCompositeExtract %float %229 1
|
||||
%238 = OpCompositeExtract %float %229 2
|
||||
%239 = OpCompositeExtract %float %232 0
|
||||
%240 = OpCompositeExtract %float %232 1
|
||||
%241 = OpCompositeExtract %float %232 2
|
||||
%242 = OpCompositeConstruct %v3float %233 %234 %235
|
||||
%243 = OpCompositeConstruct %v3float %236 %237 %238
|
||||
%244 = OpCompositeConstruct %v3float %239 %240 %241
|
||||
%245 = OpCompositeConstruct %mat3v3float %242 %243 %244
|
||||
OpStore %222 %245
|
||||
%247 = OpLoad %mat3v3float %222
|
||||
%248 = OpLoad %v3float %209
|
||||
%249 = OpMatrixTimesVector %v3float %247 %248
|
||||
%250 = OpExtInst %v3float %1 Normalize %249
|
||||
%251 = OpCompositeExtract %float %250 0
|
||||
%252 = OpCompositeExtract %float %250 1
|
||||
%253 = OpCompositeExtract %float %250 2
|
||||
%254 = OpCompositeConstruct %v4float %251 %252 %253 %float_1
|
||||
OpStore %246 %254
|
||||
%258 = OpAccessChain %_ptr_Uniform_mat4v4float %182 %int_1
|
||||
%259 = OpLoad %mat4v4float %258
|
||||
%260 = OpAccessChain %_ptr_Uniform_mat4v4float %182 %int_0
|
||||
%261 = OpLoad %mat4v4float %260
|
||||
%262 = OpMatrixTimesMatrix %mat4v4float %259 %261
|
||||
%263 = OpAccessChain %_ptr_PushConstant_mat4v4float %35 %int_0
|
||||
%264 = OpLoad %mat4v4float %263
|
||||
%265 = OpMatrixTimesMatrix %mat4v4float %262 %264
|
||||
%266 = OpLoad %v3float %196
|
||||
%267 = OpCompositeExtract %float %266 0
|
||||
%268 = OpCompositeExtract %float %266 1
|
||||
%269 = OpCompositeExtract %float %266 2
|
||||
%270 = OpCompositeConstruct %v4float %267 %268 %269 %float_1
|
||||
%271 = OpMatrixTimesVector %v4float %265 %270
|
||||
OpStore %256 %271
|
||||
%274 = OpAccessChain %_ptr_Function_float %256 %uint_2
|
||||
%275 = OpLoad %float %274
|
||||
%277 = OpAccessChain %_ptr_Function_float %256 %uint_3
|
||||
%278 = OpLoad %float %277
|
||||
%279 = OpFDiv %float %275 %278
|
||||
OpStore %gl_FragDepth %279
|
||||
OpBranch %208
|
||||
%280 = OpLabel
|
||||
OpTerminateInvocation
|
||||
%208 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%17 = OpFunction %v3float None %14
|
||||
%15 = OpFunctionParameter %_ptr_Function_v3float
|
||||
%16 = OpFunctionParameter %_ptr_Function_float
|
||||
%18 = OpLabel
|
||||
%51 = OpVariable %_ptr_Function_v3float Function
|
||||
%64 = OpVariable %_ptr_Function_v3float Function
|
||||
%75 = OpVariable %_ptr_Function_v3float Function
|
||||
%86 = OpVariable %_ptr_Function_v3float Function
|
||||
%90 = OpVariable %_ptr_Function_v3float Function
|
||||
%53 = OpAccessChain %_ptr_Function_float %15 %uint_0
|
||||
%54 = OpLoad %float %53
|
||||
%56 = OpFAdd %float %54 %float_9_99999975en05
|
||||
%58 = OpAccessChain %_ptr_Function_float %15 %uint_1
|
||||
%59 = OpLoad %float %58
|
||||
%61 = OpAccessChain %_ptr_Function_float %15 %uint_2
|
||||
%62 = OpLoad %float %61
|
||||
%63 = OpCompositeConstruct %v3float %56 %59 %62
|
||||
OpStore %64 %63
|
||||
%65 = OpFunctionCall %float %1000 %64
|
||||
%66 = OpAccessChain %_ptr_Function_float %51 %uint_0
|
||||
OpStore %66 %65
|
||||
%67 = OpAccessChain %_ptr_Function_float %15 %uint_0
|
||||
%68 = OpLoad %float %67
|
||||
%69 = OpAccessChain %_ptr_Function_float %15 %uint_1
|
||||
%70 = OpLoad %float %69
|
||||
%71 = OpFAdd %float %70 %float_9_99999975en05
|
||||
%72 = OpAccessChain %_ptr_Function_float %15 %uint_2
|
||||
%73 = OpLoad %float %72
|
||||
%74 = OpCompositeConstruct %v3float %68 %71 %73
|
||||
OpStore %75 %74
|
||||
%76 = OpFunctionCall %float %1000 %75
|
||||
%77 = OpAccessChain %_ptr_Function_float %51 %uint_1
|
||||
OpStore %77 %76
|
||||
%78 = OpAccessChain %_ptr_Function_float %15 %uint_0
|
||||
%79 = OpLoad %float %78
|
||||
%80 = OpAccessChain %_ptr_Function_float %15 %uint_1
|
||||
%81 = OpLoad %float %80
|
||||
%82 = OpAccessChain %_ptr_Function_float %15 %uint_2
|
||||
%83 = OpLoad %float %82
|
||||
%84 = OpFAdd %float %83 %float_9_99999975en05
|
||||
%85 = OpCompositeConstruct %v3float %79 %81 %84
|
||||
OpStore %86 %85
|
||||
%87 = OpFunctionCall %float %1000 %86
|
||||
%88 = OpAccessChain %_ptr_Function_float %51 %uint_2
|
||||
OpStore %88 %87
|
||||
%89 = OpLoad %v3float %51
|
||||
%91 = OpLoad %v3float %15
|
||||
OpStore %90 %91
|
||||
%92 = OpFunctionCall %float %1000 %90
|
||||
%93 = OpCompositeConstruct %v3float %92 %92 %92
|
||||
%94 = OpFSub %v3float %89 %93
|
||||
%95 = OpExtInst %v3float %1 Normalize %94
|
||||
OpReturnValue %95
|
||||
OpFunctionEnd
|
||||
%24 = OpFunction %v2float None %20
|
||||
%21 = OpFunctionParameter %_ptr_Function_v3float
|
||||
%22 = OpFunctionParameter %_ptr_Function_v3float
|
||||
%23 = OpFunctionParameter %_ptr_Function_v3float
|
||||
%25 = OpLabel
|
||||
%99 = OpVariable %_ptr_Function_v2float Function
|
||||
%103 = OpVariable %_ptr_Function_v3float Function
|
||||
%122 = OpVariable %_ptr_Function_int Function
|
||||
%147 = OpVariable %_ptr_Function_v3float Function
|
||||
OpStore %99 %101
|
||||
%102 = OpLoad %v3float %21
|
||||
OpStore %23 %102
|
||||
%104 = OpLoad %v3float %23
|
||||
OpStore %103 %104
|
||||
%105 = OpFunctionCall %float %1000 %103
|
||||
%107 = OpFMul %float %105 %float_0_899999976
|
||||
%108 = OpAccessChain %_ptr_Function_float %99 %uint_1
|
||||
OpStore %108 %107
|
||||
%109 = OpAccessChain %_ptr_Function_float %99 %uint_1
|
||||
%110 = OpLoad %float %109
|
||||
%111 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
%112 = OpLoad %float %111
|
||||
%113 = OpFAdd %float %112 %110
|
||||
%114 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
OpStore %114 %113
|
||||
%115 = OpLoad %v3float %21
|
||||
%116 = OpLoad %v3float %22
|
||||
%117 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
%118 = OpLoad %float %117
|
||||
%119 = OpVectorTimesScalar %v3float %116 %118
|
||||
%120 = OpFAdd %v3float %115 %119
|
||||
OpStore %23 %120
|
||||
OpStore %122 %int_0
|
||||
OpBranch %124
|
||||
%124 = OpLabel
|
||||
OpLoopMerge %126 %127 None
|
||||
OpBranch %128
|
||||
%128 = OpLabel
|
||||
%130 = OpLoad %int %122
|
||||
%131 = OpBitcast %uint %130
|
||||
%133 = OpULessThan %bool %131 %uint_50
|
||||
OpSelectionMerge %135 None
|
||||
OpBranchConditional %133 %134 %135
|
||||
%134 = OpLabel
|
||||
%136 = OpAccessChain %_ptr_Function_float %99 %uint_1
|
||||
%137 = OpLoad %float %136
|
||||
%138 = OpFOrdGreaterThan %bool %137 %float_9_99999975en05
|
||||
OpBranch %135
|
||||
%135 = OpLabel
|
||||
%139 = OpPhi %bool %133 %128 %138 %134
|
||||
OpSelectionMerge %141 None
|
||||
OpBranchConditional %139 %140 %141
|
||||
%140 = OpLabel
|
||||
%142 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
%143 = OpLoad %float %142
|
||||
%144 = OpLoad %float %27
|
||||
%145 = OpFOrdLessThan %bool %143 %144
|
||||
OpBranch %141
|
||||
%141 = OpLabel
|
||||
%146 = OpPhi %bool %139 %135 %145 %140
|
||||
OpBranchConditional %146 %125 %126
|
||||
%125 = OpLabel
|
||||
%148 = OpLoad %v3float %23
|
||||
OpStore %147 %148
|
||||
%149 = OpFunctionCall %float %1000 %147
|
||||
%150 = OpFMul %float %149 %float_0_899999976
|
||||
%151 = OpAccessChain %_ptr_Function_float %99 %uint_1
|
||||
OpStore %151 %150
|
||||
%152 = OpAccessChain %_ptr_Function_float %99 %uint_1
|
||||
%153 = OpLoad %float %152
|
||||
%154 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
%155 = OpLoad %float %154
|
||||
%156 = OpFAdd %float %155 %153
|
||||
%157 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
OpStore %157 %156
|
||||
%158 = OpLoad %v3float %21
|
||||
%159 = OpLoad %v3float %22
|
||||
%160 = OpAccessChain %_ptr_Function_float %99 %uint_0
|
||||
%161 = OpLoad %float %160
|
||||
%162 = OpVectorTimesScalar %v3float %159 %161
|
||||
%163 = OpFAdd %v3float %158 %162
|
||||
OpStore %23 %163
|
||||
OpBranch %127
|
||||
%127 = OpLabel
|
||||
%164 = OpLoad %int %122
|
||||
%165 = OpIAdd %int %164 %int_1
|
||||
OpStore %122 %165
|
||||
OpBranch %124
|
||||
%126 = OpLabel
|
||||
%166 = OpLoad %v2float %99
|
||||
OpReturnValue %166
|
||||
OpFunctionEnd
|
||||
Reference in New Issue
Block a user