Correct depth handling
This commit is contained in:
+104
@@ -0,0 +1,104 @@
|
|||||||
|
// global fragment shader
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
#include "include.glsl"
|
||||||
|
|
||||||
|
layout(constant_id=0)const uint RES_X=1920;
|
||||||
|
layout(constant_id=1)const uint RES_Y=1080;
|
||||||
|
|
||||||
|
#ifdef implicit
|
||||||
|
|
||||||
|
layout(location=0)in VertexInput
|
||||||
|
{
|
||||||
|
vec4 position;
|
||||||
|
}vertexInput;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
layout(location=0)in vec3 tri_normal;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
layout(location=0)out vec4 f_color;
|
||||||
|
|
||||||
|
const float EPSILON=.0001;
|
||||||
|
const uint MAX_STEPS=50;
|
||||||
|
|
||||||
|
/// SHARED CODE ///
|
||||||
|
vec3 shading(vec3 normal)
|
||||||
|
{
|
||||||
|
vec3 accum=vec3(0.,0.,0.);
|
||||||
|
|
||||||
|
for(int i=0;i<light_uniforms.light_count;i++)
|
||||||
|
{
|
||||||
|
accum+=light_uniforms.col[i].xyz*((dot(normalize(normal),light_uniforms.pos[i].xyz)*.5)+.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return accum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// IMPLICIT CODE ///
|
||||||
|
#ifdef implicit
|
||||||
|
|
||||||
|
#define NEARPLANE 0.
|
||||||
|
#define FARPLANE length(vec3(10))
|
||||||
|
|
||||||
|
float scene(vec3 p)
|
||||||
|
{
|
||||||
|
return length(p-vec3(5.))-5.;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 getNormal(vec3 p,float dens){
|
||||||
|
vec3 n;
|
||||||
|
n.x=scene(vec3(p.x+EPSILON,p.y,p.z));
|
||||||
|
n.y=scene(vec3(p.x,p.y+EPSILON,p.z));
|
||||||
|
n.z=scene(vec3(p.x,p.y,p.z+EPSILON));
|
||||||
|
return normalize(n-scene(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){
|
||||||
|
vec2 td=vec2(NEARPLANE,1.);
|
||||||
|
p=ori;
|
||||||
|
for(int i=0;i<MAX_STEPS&&td.y>EPSILON&&td.x<FARPLANE;i++){
|
||||||
|
td.y=scene(p);
|
||||||
|
td.x+=(td.y)*.9;
|
||||||
|
p=ori+dir*td.x;
|
||||||
|
}
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Implicit Surface Entrypoint
|
||||||
|
void main(){
|
||||||
|
|
||||||
|
vec3 raypos=vertexInput.position.xyz;
|
||||||
|
vec2 iResolution=vec2(RES_X,RES_Y);
|
||||||
|
vec2 iuv=(gl_FragCoord.xy+gl_SamplePosition)/iResolution.xy*2.-1.;
|
||||||
|
vec2 uv=iuv;
|
||||||
|
uv.x*=iResolution.x/iResolution.y;
|
||||||
|
vec3 p;
|
||||||
|
vec3 raydir=normalize(raypos-camera_uniforms.campos);
|
||||||
|
vec2 td=spheretracing(raypos,raydir,p);
|
||||||
|
vec3 n=getNormal(p,td.y);
|
||||||
|
if(td.y<EPSILON)
|
||||||
|
{
|
||||||
|
f_color=vec4(shading(n),1.);
|
||||||
|
|
||||||
|
vec4 tpoint=camera_uniforms.proj*camera_uniforms.view*vec4(p,1);
|
||||||
|
gl_FragDepth=(tpoint.z/tpoint.w);
|
||||||
|
//gl_FragDepth=gl_DepthRange.diff*(((tpoint.z/tpoint.w)+1.)*.5)+gl_DepthRange.near;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/// TRIANGLE CODE ///
|
||||||
|
|
||||||
|
//Mesh Surface Entrypoint
|
||||||
|
void main(){
|
||||||
|
f_color=vec4(shading(tri_normal),1.);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Implicit Fragment shader
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
layout(push_constant)uniform PushConstantData{
|
|
||||||
mat4 world;
|
|
||||||
}pc;
|
|
||||||
|
|
||||||
layout(set=0,binding=0)uniform Lights{
|
|
||||||
vec4[32]pos;
|
|
||||||
vec4[32]col;
|
|
||||||
uint light_count;
|
|
||||||
}light_uniforms;
|
|
||||||
|
|
||||||
layout(set=0,binding=1)uniform Camera{
|
|
||||||
mat4 view;
|
|
||||||
mat4 proj;
|
|
||||||
vec3 campos;
|
|
||||||
}camera_uniforms;
|
|
||||||
|
|
||||||
layout(constant_id=0)const uint RES_X=1920;
|
|
||||||
layout(constant_id=1)const uint RES_Y=1080;
|
|
||||||
|
|
||||||
layout(location=0)in VertexInput
|
|
||||||
{
|
|
||||||
vec4 position;
|
|
||||||
}vertexInput;
|
|
||||||
|
|
||||||
layout(location=0)out vec4 f_color;
|
|
||||||
|
|
||||||
const float EPSILON=.0001;
|
|
||||||
const uint MAX_STEPS=50;
|
|
||||||
|
|
||||||
float scene(vec3 p)
|
|
||||||
{
|
|
||||||
return length(p-vec3(5.))-5.;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 getNormal(vec3 p,float dens){
|
|
||||||
vec3 n;
|
|
||||||
n.x=scene(vec3(p.x+EPSILON,p.y,p.z));
|
|
||||||
n.y=scene(vec3(p.x,p.y+EPSILON,p.z));
|
|
||||||
n.z=scene(vec3(p.x,p.y,p.z+EPSILON));
|
|
||||||
return normalize(n-scene(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){
|
|
||||||
vec2 td=vec2(0.);
|
|
||||||
for(int i=0;i<MAX_STEPS;i++){
|
|
||||||
p=ori+dir*td.x;
|
|
||||||
td.y=scene(p);
|
|
||||||
if(td.y<EPSILON)break;
|
|
||||||
td.x+=(td.y)*.9;
|
|
||||||
}
|
|
||||||
return td;
|
|
||||||
}
|
|
||||||
#define frac_pi_2 1.57079632679489661923132169163975144
|
|
||||||
void main(){
|
|
||||||
|
|
||||||
vec3 raypos=vertexInput.position.xyz;
|
|
||||||
vec2 iResolution=vec2(RES_X,RES_Y);
|
|
||||||
vec2 iuv=gl_FragCoord.xy/iResolution.xy*2.-1.;
|
|
||||||
vec2 uv=iuv;
|
|
||||||
uv.x*=iResolution.x/iResolution.y;
|
|
||||||
vec3 p;
|
|
||||||
vec3 raydir=normalize(raypos-camera_uniforms.campos);
|
|
||||||
//raydir=(camera_uniforms.view*vec4(raydir,1.)).xyz;
|
|
||||||
vec2 td=spheretracing(raypos,raydir,p);
|
|
||||||
vec3 n=getNormal(p,td.y);
|
|
||||||
if(td.y<EPSILON)
|
|
||||||
{
|
|
||||||
vec3 accum=vec3(0.,0.,0.);
|
|
||||||
|
|
||||||
for(int i=0;i<light_uniforms.light_count;i++)
|
|
||||||
{
|
|
||||||
accum+=light_uniforms.col[i].xyz*((dot(normalize(n),light_uniforms.pos[i].xyz)*.5)+.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
f_color=vec4(accum,1.);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//f_color=vec4(raydir,0.);
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+10
-35
@@ -3,28 +3,14 @@
|
|||||||
#version 450
|
#version 450
|
||||||
#extension GL_EXT_mesh_shader:require
|
#extension GL_EXT_mesh_shader:require
|
||||||
|
|
||||||
layout(push_constant)uniform PushConstantData{
|
#include "include.glsl"
|
||||||
mat4 world;
|
|
||||||
}pc;
|
|
||||||
|
|
||||||
layout(set=0,binding=0)uniform Lights{
|
|
||||||
vec4[32]pos;
|
|
||||||
vec4[32]col;
|
|
||||||
uint light_count;
|
|
||||||
}light_uniforms;
|
|
||||||
|
|
||||||
layout(set=0,binding=1)uniform Camera{
|
|
||||||
mat4 view;
|
|
||||||
mat4 proj;
|
|
||||||
vec3 campos;
|
|
||||||
}camera_uniforms;
|
|
||||||
|
|
||||||
layout(local_size_x=1,local_size_y=1,local_size_z=1)in;
|
layout(local_size_x=1,local_size_y=1,local_size_z=1)in;
|
||||||
layout(triangles,max_vertices=64,max_primitives=162)out;
|
layout(triangles,max_vertices=64,max_primitives=162)out;
|
||||||
|
|
||||||
layout(location=0)out VertexOutput
|
layout(location=0)out VertexOutput
|
||||||
{
|
{
|
||||||
vec4 color;
|
vec4 position;
|
||||||
}vertexOutput[];
|
}vertexOutput[];
|
||||||
|
|
||||||
const vec4[8]positions={
|
const vec4[8]positions={
|
||||||
@@ -60,14 +46,14 @@ void main()
|
|||||||
gl_MeshVerticesEXT[5].gl_Position=mvp*(positions[5]+offset);
|
gl_MeshVerticesEXT[5].gl_Position=mvp*(positions[5]+offset);
|
||||||
gl_MeshVerticesEXT[6].gl_Position=mvp*(positions[6]+offset);
|
gl_MeshVerticesEXT[6].gl_Position=mvp*(positions[6]+offset);
|
||||||
gl_MeshVerticesEXT[7].gl_Position=mvp*(positions[7]+offset);
|
gl_MeshVerticesEXT[7].gl_Position=mvp*(positions[7]+offset);
|
||||||
vertexOutput[0].color=scale*positions[0];
|
vertexOutput[0].position=scale*positions[0];
|
||||||
vertexOutput[1].color=scale*positions[1];
|
vertexOutput[1].position=scale*positions[1];
|
||||||
vertexOutput[2].color=scale*positions[2];
|
vertexOutput[2].position=scale*positions[2];
|
||||||
vertexOutput[3].color=scale*positions[3];
|
vertexOutput[3].position=scale*positions[3];
|
||||||
vertexOutput[4].color=scale*positions[4];
|
vertexOutput[4].position=scale*positions[4];
|
||||||
vertexOutput[5].color=scale*positions[5];
|
vertexOutput[5].position=scale*positions[5];
|
||||||
vertexOutput[6].color=scale*positions[6];
|
vertexOutput[6].position=scale*positions[6];
|
||||||
vertexOutput[7].color=scale*positions[7];
|
vertexOutput[7].position=scale*positions[7];
|
||||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+0]=uvec3(0,1,2);
|
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+0]=uvec3(0,1,2);
|
||||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+1]=uvec3(1,2,3);
|
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+1]=uvec3(1,2,3);
|
||||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+2]=uvec3(4,5,6);
|
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+2]=uvec3(4,5,6);
|
||||||
@@ -81,14 +67,3 @@ void main()
|
|||||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+10]=uvec3(0,1,4);
|
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+10]=uvec3(0,1,4);
|
||||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+11]=uvec3(1,4,5);
|
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex+11]=uvec3(1,4,5);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
0 1 2 3 0
|
|
||||||
4 5 6 7 4
|
|
||||||
0 1 2
|
|
||||||
1 2 3
|
|
||||||
4 5 6
|
|
||||||
5 6 7
|
|
||||||
0 1 4
|
|
||||||
1 4 5
|
|
||||||
1 2
|
|
||||||
*/
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
layout(push_constant)uniform PushConstantData{
|
||||||
|
mat4 world;
|
||||||
|
}pc;
|
||||||
|
|
||||||
|
layout(set=0,binding=0)uniform Lights{
|
||||||
|
vec4[32]pos;
|
||||||
|
vec4[32]col;
|
||||||
|
uint light_count;
|
||||||
|
}light_uniforms;
|
||||||
|
|
||||||
|
layout(set=0,binding=1)uniform Camera{
|
||||||
|
mat4 view;
|
||||||
|
mat4 proj;
|
||||||
|
vec3 campos;
|
||||||
|
}camera_uniforms;
|
||||||
+82
-21
@@ -7,16 +7,18 @@ use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator;
|
|||||||
use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet};
|
use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet};
|
||||||
use vulkano::device::{DeviceOwned, Features, QueueFlags};
|
use vulkano::device::{DeviceOwned, Features, QueueFlags};
|
||||||
use vulkano::format::Format;
|
use vulkano::format::Format;
|
||||||
use vulkano::image::AttachmentImage;
|
use vulkano::image::view::ImageViewCreateInfo;
|
||||||
|
use vulkano::image::{AttachmentImage, SampleCount};
|
||||||
use vulkano::memory::allocator::StandardMemoryAllocator;
|
use vulkano::memory::allocator::StandardMemoryAllocator;
|
||||||
use vulkano::pipeline::graphics::depth_stencil::DepthStencilState;
|
use vulkano::pipeline::graphics::depth_stencil::DepthStencilState;
|
||||||
|
use vulkano::pipeline::graphics::multisample::MultisampleState;
|
||||||
use vulkano::pipeline::graphics::rasterization::CullMode;
|
use vulkano::pipeline::graphics::rasterization::CullMode;
|
||||||
use vulkano::pipeline::graphics::rasterization::FrontFace::Clockwise;
|
use vulkano::pipeline::graphics::rasterization::FrontFace::Clockwise;
|
||||||
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
||||||
use vulkano::pipeline::PipelineBindPoint;
|
use vulkano::pipeline::PipelineBindPoint;
|
||||||
use vulkano::shader::{ShaderModule, SpecializationConstants};
|
use vulkano::shader::{ShaderModule, SpecializationConstants};
|
||||||
use vulkano::swapchain::{PresentMode, SwapchainPresentInfo};
|
use vulkano::swapchain::{PresentMode, SwapchainPresentInfo};
|
||||||
use vulkano::VulkanLibrary;
|
use vulkano::{Version, VulkanLibrary};
|
||||||
use winit::event::{DeviceEvent, ElementState, MouseButton, VirtualKeyCode};
|
use winit::event::{DeviceEvent, ElementState, MouseButton, VirtualKeyCode};
|
||||||
|
|
||||||
use egui_winit_vulkano::Gui;
|
use egui_winit_vulkano::Gui;
|
||||||
@@ -133,6 +135,7 @@ fn main() {
|
|||||||
enabled_features: Features {
|
enabled_features: Features {
|
||||||
mesh_shader: true,
|
mesh_shader: true,
|
||||||
task_shader: true,
|
task_shader: true,
|
||||||
|
sample_rate_shading: true,
|
||||||
..Features::empty()
|
..Features::empty()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -201,14 +204,15 @@ fn main() {
|
|||||||
mod mesh_fs {
|
mod mesh_fs {
|
||||||
vulkano_shaders::shader! {
|
vulkano_shaders::shader! {
|
||||||
ty: "fragment",
|
ty: "fragment",
|
||||||
path: "src/triangle.frag.glsl",
|
path: "src/frag.glsl",
|
||||||
types_meta: {
|
types_meta: {
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Zeroable, Pod, Debug)]
|
#[derive(Clone, Copy, Zeroable, Pod, Debug)]
|
||||||
},
|
},
|
||||||
vulkan_version: "1.2",
|
vulkan_version: "1.2",
|
||||||
spirv_version: "1.6"
|
spirv_version: "1.6",
|
||||||
|
define: [("triangle","1")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,14 +236,15 @@ fn main() {
|
|||||||
mod implicit_fs {
|
mod implicit_fs {
|
||||||
vulkano_shaders::shader! {
|
vulkano_shaders::shader! {
|
||||||
ty: "fragment",
|
ty: "fragment",
|
||||||
path: "src/implicit.frag.glsl",
|
path: "src/frag.glsl",
|
||||||
types_meta: {
|
types_meta: {
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Zeroable, Pod, Debug)]
|
#[derive(Clone, Copy, Zeroable, Pod, Debug)]
|
||||||
},
|
},
|
||||||
vulkan_version: "1.2",
|
vulkan_version: "1.2",
|
||||||
spirv_version: "1.6"
|
spirv_version: "1.6",
|
||||||
|
define: [("implicit","1")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,26 +256,33 @@ fn main() {
|
|||||||
let render_pass = vulkano::ordered_passes_renderpass!(
|
let render_pass = vulkano::ordered_passes_renderpass!(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
attachments: {
|
attachments: {
|
||||||
color: {
|
intermediary: {
|
||||||
load: Clear,
|
load: Clear,
|
||||||
|
store: DontCare,
|
||||||
|
format: swapchain.image_format(),
|
||||||
|
samples: 4,
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
load: DontCare,
|
||||||
store: Store,
|
store: Store,
|
||||||
format: swapchain.image_format(),
|
format: swapchain.image_format(),
|
||||||
samples: 1,
|
samples: 1,
|
||||||
},
|
},
|
||||||
depth: {
|
multi_depth: {
|
||||||
load: Clear,
|
load: Clear,
|
||||||
store: DontCare,
|
store: DontCare,
|
||||||
format: Format::D16_UNORM,
|
format: Format::D16_UNORM,
|
||||||
samples: 1,
|
samples: 4,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
passes: [{
|
passes: [{
|
||||||
color: [color],
|
color: [intermediary],
|
||||||
depth_stencil: {depth},
|
depth_stencil: {multi_depth},
|
||||||
input: []
|
input: [],
|
||||||
|
resolve: [color]
|
||||||
},{
|
},{
|
||||||
color: [color],
|
color: [color],
|
||||||
depth_stencil: {depth},
|
depth_stencil: {},
|
||||||
input: []
|
input: []
|
||||||
}]
|
}]
|
||||||
)
|
)
|
||||||
@@ -512,13 +524,16 @@ fn main() {
|
|||||||
keys.d = false;
|
keys.d = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let near = 0.01;
|
||||||
|
let far = 100.0;
|
||||||
|
|
||||||
let aspect_ratio =
|
let aspect_ratio =
|
||||||
swapchain.image_extent()[0] as f32 / swapchain.image_extent()[1] as f32;
|
swapchain.image_extent()[0] as f32 / swapchain.image_extent()[1] as f32;
|
||||||
let proj = cgmath::perspective(
|
let proj = cgmath::perspective(
|
||||||
Rad(std::f32::consts::FRAC_PI_2),
|
Rad(std::f32::consts::FRAC_PI_2),
|
||||||
aspect_ratio,
|
aspect_ratio,
|
||||||
0.01,
|
near,
|
||||||
100.0,
|
far,
|
||||||
);
|
);
|
||||||
let scale = 0.01;
|
let scale = 0.01;
|
||||||
let view = Matrix4::from(camforward)
|
let view = Matrix4::from(camforward)
|
||||||
@@ -533,7 +548,7 @@ fn main() {
|
|||||||
let uniform_data = mesh_fs::ty::Camera {
|
let uniform_data = mesh_fs::ty::Camera {
|
||||||
view: view.into(),
|
view: view.into(),
|
||||||
proj: proj.into(),
|
proj: proj.into(),
|
||||||
campos: (campos * 100.0).into(),
|
campos: (campos * (far - near)).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let sub = uniform_buffer.allocate_sized().unwrap();
|
let sub = uniform_buffer.allocate_sized().unwrap();
|
||||||
@@ -622,6 +637,7 @@ fn main() {
|
|||||||
RenderPassBeginInfo {
|
RenderPassBeginInfo {
|
||||||
clear_values: vec![
|
clear_values: vec![
|
||||||
Some([0.12, 0.1, 0.1, 1.0].into()),
|
Some([0.12, 0.1, 0.1, 1.0].into()),
|
||||||
|
None,
|
||||||
Some(1.0.into()),
|
Some(1.0.into()),
|
||||||
],
|
],
|
||||||
..RenderPassBeginInfo::framebuffer(
|
..RenderPassBeginInfo::framebuffer(
|
||||||
@@ -722,24 +738,54 @@ fn window_size_dependent_setup<Mms>(
|
|||||||
specs: Mms,
|
specs: Mms,
|
||||||
) -> ([Arc<GraphicsPipeline>; 2], Vec<Arc<Framebuffer>>)
|
) -> ([Arc<GraphicsPipeline>; 2], Vec<Arc<Framebuffer>>)
|
||||||
where
|
where
|
||||||
Mms: SpecializationConstants,
|
Mms: SpecializationConstants + Clone,
|
||||||
{
|
{
|
||||||
let dimensions = images[0].dimensions().width_height();
|
let dimensions = images[0].dimensions().width_height();
|
||||||
viewport.dimensions = [dimensions[0] as f32, dimensions[1] as f32];
|
viewport.dimensions = [dimensions[0] as f32, dimensions[1] as f32];
|
||||||
|
|
||||||
let depth_buffer = ImageView::new_default(
|
let depth_buffer = ImageView::new_default(
|
||||||
AttachmentImage::transient(allocator, dimensions, Format::D16_UNORM).unwrap(),
|
AttachmentImage::transient_multisampled(
|
||||||
|
allocator,
|
||||||
|
dimensions,
|
||||||
|
SampleCount::Sample4,
|
||||||
|
Format::D16_UNORM,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let intermediary_image = AttachmentImage::transient_multisampled(
|
||||||
|
allocator,
|
||||||
|
dimensions,
|
||||||
|
SampleCount::Sample4,
|
||||||
|
images[0].format(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let intermediary = ImageView::new(
|
||||||
|
intermediary_image.clone(),
|
||||||
|
ImageViewCreateInfo {
|
||||||
|
usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
|
||||||
|
..ImageViewCreateInfo::from_image(&intermediary_image)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let framebuffers = images
|
let framebuffers = images
|
||||||
.iter()
|
.iter()
|
||||||
.map(|image| {
|
.map(|image| {
|
||||||
let view = ImageView::new_default(image.clone()).unwrap();
|
let view = ImageView::new(
|
||||||
|
image.clone(),
|
||||||
|
ImageViewCreateInfo {
|
||||||
|
usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSFER_DST,
|
||||||
|
..ImageViewCreateInfo::from_image(&intermediary_image)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
Framebuffer::new(
|
Framebuffer::new(
|
||||||
render_pass.clone(),
|
render_pass.clone(),
|
||||||
FramebufferCreateInfo {
|
FramebufferCreateInfo {
|
||||||
attachments: vec![view, depth_buffer.clone()],
|
attachments: vec![intermediary.clone(), view, depth_buffer.clone()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -759,13 +805,20 @@ where
|
|||||||
depth_range: 0.0..1.0,
|
depth_range: 0.0..1.0,
|
||||||
},
|
},
|
||||||
]))
|
]))
|
||||||
.fragment_shader(mesh_fs.entry_point("main").unwrap(), ())
|
.fragment_shader(mesh_fs.entry_point("main").unwrap(), specs.clone())
|
||||||
.depth_stencil_state(DepthStencilState::simple_depth_test())
|
.depth_stencil_state(DepthStencilState::simple_depth_test())
|
||||||
.rasterization_state(RasterizationState {
|
.rasterization_state(RasterizationState {
|
||||||
front_face: Fixed(Clockwise),
|
front_face: Fixed(Clockwise),
|
||||||
cull_mode: Fixed(CullMode::Back),
|
cull_mode: Fixed(CullMode::Back),
|
||||||
..RasterizationState::default()
|
..RasterizationState::default()
|
||||||
})
|
})
|
||||||
|
.multisample_state(MultisampleState {
|
||||||
|
rasterization_samples: Subpass::from(render_pass.clone(), 0)
|
||||||
|
.unwrap()
|
||||||
|
.num_samples()
|
||||||
|
.unwrap(),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
.build(allocator.device().clone())
|
.build(allocator.device().clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -786,6 +839,14 @@ where
|
|||||||
.rasterization_state(RasterizationState {
|
.rasterization_state(RasterizationState {
|
||||||
..RasterizationState::default()
|
..RasterizationState::default()
|
||||||
})
|
})
|
||||||
|
.multisample_state(MultisampleState {
|
||||||
|
rasterization_samples: Subpass::from(render_pass.clone(), 0)
|
||||||
|
.unwrap()
|
||||||
|
.num_samples()
|
||||||
|
.unwrap(),
|
||||||
|
sample_shading: Some(0.5),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
.build(allocator.device().clone())
|
.build(allocator.device().clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
#version 450
|
|
||||||
|
|
||||||
layout(push_constant)uniform PushConstantData{
|
|
||||||
mat4 world;
|
|
||||||
}pc;
|
|
||||||
|
|
||||||
layout(set=0,binding=0)uniform Lights{
|
|
||||||
vec4[32]pos;
|
|
||||||
vec4[32]col;
|
|
||||||
uint light_count;
|
|
||||||
}light_uniforms;
|
|
||||||
|
|
||||||
layout(set=0,binding=1)uniform Camera{
|
|
||||||
mat4 view;
|
|
||||||
mat4 proj;
|
|
||||||
vec3 campos;
|
|
||||||
}camera_uniforms;
|
|
||||||
|
|
||||||
layout(location=0)in vec3 normal;
|
|
||||||
|
|
||||||
layout(location=0)out vec4 f_color;
|
|
||||||
|
|
||||||
void main(){
|
|
||||||
vec3 accum=vec3(0.,0.,0.);
|
|
||||||
|
|
||||||
for(int i=0;i<light_uniforms.light_count;i++)
|
|
||||||
{
|
|
||||||
accum+=light_uniforms.col[i].xyz*((dot(normalize(normal),light_uniforms.pos[i].xyz)*.5)+.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
f_color=vec4(accum,1.);
|
|
||||||
}
|
|
||||||
+1
-16
@@ -1,20 +1,5 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
#include "include.glsl"
|
||||||
layout(push_constant)uniform PushConstantData{
|
|
||||||
mat4 world;
|
|
||||||
}pc;
|
|
||||||
|
|
||||||
layout(set=0,binding=0)uniform Lights{
|
|
||||||
vec4[32]pos;
|
|
||||||
vec4[32]col;
|
|
||||||
uint light_count;
|
|
||||||
}light_uniforms;
|
|
||||||
|
|
||||||
layout(set=0,binding=1)uniform Camera{
|
|
||||||
mat4 view;
|
|
||||||
mat4 proj;
|
|
||||||
vec3 campos;
|
|
||||||
}camera_uniforms;
|
|
||||||
|
|
||||||
layout(location=0)in vec3 position;
|
layout(location=0)in vec3 position;
|
||||||
layout(location=1)in vec3 normal;
|
layout(location=1)in vec3 normal;
|
||||||
|
|||||||
Reference in New Issue
Block a user