Debugging depth writes.

Broken: Depth writes.
fix-depth
itycodes 2 weeks ago
parent 0e92480ce8
commit e26cb6b13d

@ -7,16 +7,19 @@ layout(location = 0) out vec4 outColor;
layout(location = 0) in vec4 normal;
layout(location = 1) in vec4 pos_pre;
layout(location = 2) in vec4 view_orig;
layout(location = 3) in vec4 pos_post;
layout(push_constant, std430) uniform pc {
layout(offset=48) vec4 data;
};
void main() {
outColor = vec4(data.rgb*(1.0+dot(normal.xyz, normalize(vec3(-0.7, -0.5, -0.1))))/2.0, 1.0);
outColor = vec4(vec3(pos_post.z / pos_post.w), 1.0);
//if(pos_post.z <= 0.0) {
// outColor = vec4(1.0);
//}
//outColor = normal.xyz;
//outColor = vec4(vec3(1.0-gl_FragCoord.z), 1.0);
//gl_FragDepth = pos_post.z / pos_post.w;
}

@ -20,6 +20,8 @@ layout(push_constant, std430) uniform pc {
layout (location = 0) out vec4 normal;
layout (location = 1) out vec4 pos_pre;
layout (location = 2) out vec4 view_orig;
layout (location = 3) out vec4 pos_post;
const float PI = 3.14159;
// Forgive me for I have sinned
@ -32,7 +34,7 @@ void main() {
view_orig = cam_orig;
// define constants
const float zFar = 100.0;
const float zFar = 10.0;
const float zNear = 0.1;
// assign the transformee
@ -77,7 +79,7 @@ void main() {
mat4 project_div = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, tan((70.0/2.0)/360.0*TAU), 0.0
);
mat4 project_normal = mat4(
@ -127,4 +129,5 @@ void main() {
//gl_Position.z /= zFar;
gl_Position *= project_normal;
pos_post = gl_Position;
}

@ -9,6 +9,8 @@ layout(location = 0) out vec4 outColor;
layout(location = 0) in vec4 normal;
layout(location = 1) in vec4 pos_pre;
layout(location = 2) in vec4 view_orig;
layout(location = 3) in vec4 pos_post;
layout(push_constant, std430) uniform pc {
layout(offset=48) vec4 data;
@ -23,4 +25,5 @@ void main() {
//}
//outColor = normal.xyz;
//outColor = vec4(vec3(1.0-gl_FragCoord.z), 1.0);
//gl_FragDepth = pos_post.z / pos_post.w;
}

@ -20,6 +20,7 @@ layout(push_constant, std430) uniform pc {
layout (location = 0) out vec4 normal;
layout (location = 1) out vec4 pos_pre;
layout (location = 2) out vec4 view_orig;
layout (location = 3) out vec4 pos_post;
const float PI = 3.14159;
// Forgive me for I have sinned
@ -32,8 +33,8 @@ void main() {
view_orig = cam_orig;
// define constants
const float zFar = 100.0;
const float zNear = 0.1;
const float zFar = 10.0;
const float zNear = 0.01;
// assign the transformee
gl_Position = pos.posnrm[gl_VertexIndex].pos;
@ -77,7 +78,7 @@ void main() {
mat4 project_div = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, tan((70.0/2.0)/360.0*TAU), 0.0
);
mat4 project_normal = mat4(
@ -127,4 +128,5 @@ void main() {
//gl_Position.z /= zFar;
gl_Position *= project_normal;
pos_post = gl_Position;
}

@ -7,4 +7,7 @@ layout(location = 0) out vec4 outColor;
layout(location = 0) in vec4 pos_pre;
void main() { outColor = texture(combined_image, vec3(pos_pre)); }
void main() {
outColor = texture(combined_image, vec3(pos_pre));
gl_FragDepth = 0.99;
}

@ -4,52 +4,52 @@
const vec4 positions[36] = vec4[36](
// BOTTOM
vec4(-0.5, 0.5, -0.5, 1.0),
vec4(0.5, 0.5, 0.5, 1.0),
vec4(-0.5, 0.5, 0.5, 1.0),
vec4(0.5, 0.5, -0.5, 1.0),
vec4(0.5, 0.5, 0.5, 1.0),
vec4(-0.5, 0.5, -0.5, 1.0),
vec4(-50.0, 50.0, -50.0, 1.0),
vec4(50.0, 50.0, 50.0, 1.0),
vec4(-50.0, 50.0, 50.0, 1.0),
vec4(50.0, 50.0, -50.0, 1.0),
vec4(50.0, 50.0, 50.0, 1.0),
vec4(-50.0, 50.0, -50.0, 1.0),
// TOP
vec4(0.5, -0.5, 0.5, 1.0),
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(-0.5, -0.5, 0.5, 1.0),
vec4(0.5, -0.5, 0.5, 1.0),
vec4(0.5, -0.5, -0.5, 1.0),
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(50.0, -50.0, 50.0, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
vec4(-50.0, -50.0, 50.0, 1.0),
vec4(50.0, -50.0, 50.0, 1.0),
vec4(50.0, -50.0, -50.0, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
// FRONT
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(0.5, 0.5, -0.5, 1.0),
vec4(-0.5, 0.5, -0.5, 1.0),
vec4(0.5, -0.5, -0.5, 1.0),
vec4(0.5, 0.5, -0.5, 1.0),
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
vec4(50.0, 50.0, -50.0, 1.0),
vec4(-50.0, 50.0, -50.0, 1.0),
vec4(50.0, -50.0, -50.0, 1.0),
vec4(50.0, 50.0, -50.0, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
// BACK
vec4(0.5, 0.5, 0.5, 1.0),
vec4(-0.5, -0.5, 0.5, 1.0),
vec4(-0.5, 0.5, 0.5, 1.0),
vec4(0.5, 0.5, 0.5, 1.0),
vec4(0.5, -0.5, 0.5, 1.0),
vec4(-0.5, -0.5, 0.5, 1.0),
vec4(50.0, 50.0, 50.0, 1.0),
vec4(-50.0, -50.0, 50.0, 1.0),
vec4(-50.0, 50.0, 50.0, 1.0),
vec4(50.0, 50.0, 50.0, 1.0),
vec4(50.0, -50.0, 50.0, 1.0),
vec4(-50.0, -50.0, 50.0, 1.0),
// LEFT
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(-0.5, 0.5, 0.5, 1.0),
vec4(-0.5, -0.5, 0.5, 1.0),
vec4(-0.5, 0.5, -0.5, 1.0),
vec4(-0.5, 0.5, 0.5, 1.0),
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
vec4(-50.0, 50.0, 50.0, 1.0),
vec4(-50.0, -50.0, 50.0, 1.0),
vec4(-50.0, 50.0, -50.0, 1.0),
vec4(-50.0, 50.0, 50.0, 1.0),
vec4(-50.0, -50.0, -50.0, 1.0),
// RIGHT
vec4(0.5, 0.5, 0.5, 1.0),
vec4(0.5, -0.5, -0.5, 1.0),
vec4(0.5, -0.5, 0.5, 1.0),
vec4(0.5, 0.5, 0.5, 1.0),
vec4(0.5, 0.5, -0.5, 1.0),
vec4(0.5, -0.5, -0.5, 1.0)
vec4(50.0, 50.0, 50.0, 1.0),
vec4(50.0, -50.0, -50.0, 1.0),
vec4(50.0, -50.0, 50.0, 1.0),
vec4(50.0, 50.0, 50.0, 1.0),
vec4(50.0, 50.0, -50.0, 1.0),
vec4(50.0, -50.0, -50.0, 1.0)
);
layout(push_constant, std430) uniform pc {
@ -69,7 +69,7 @@ void main() {
pos_pre = positions[gl_VertexIndex];
// define constants
const float zFar = 100.0;
const float zFar = 50.0;
const float zNear = 0.1;
// assign the transformee

@ -7,8 +7,8 @@ use crate::{Game, InWorld};
use super::InputHandler;
const MOV_STEP: f32 = 0.05;
const ROT_MOUSE_SCALE: f32 = 0.001;
const MOV_STEP: f32 = 0.1;
const ROT_MOUSE_SCALE: f32 = 0.002;
impl InputHandler for Game<InWorld> {
fn handle_cont_key(&mut self, keycode: Keycode) {

@ -141,6 +141,18 @@ fn main() {
},
vec3!(1, 1, 1),
);
chunk.set_block(
Block {
typ: BlockType::Solid,
},
vec3!(1, 2, 1),
);
chunk.set_block(
Block {
typ: BlockType::Solid,
},
vec3!(2, 2, 1),
);
let chunk = game.create_chunk(&chunk);
game.add_component(chunk);

@ -213,7 +213,7 @@ fn setup_pipeline(
.topology(vk::PrimitiveTopology::TRIANGLE_LIST);
let rasterization = vk::PipelineRasterizationStateCreateInfo::default()
.polygon_mode(vk::PolygonMode::FILL)
.cull_mode(vk::CullModeFlags::NONE)
.cull_mode(vk::CullModeFlags::BACK)
.front_face(vk::FrontFace::CLOCKWISE)
.line_width(1.0);
let multisample = vk::PipelineMultisampleStateCreateInfo::default()
@ -222,7 +222,7 @@ fn setup_pipeline(
.depth_test_enable(true)
.depth_write_enable(true)
.depth_compare_op(vk::CompareOp::LESS)
.depth_bounds_test_enable(true)
.depth_bounds_test_enable(false)
.stencil_test_enable(false)
.min_depth_bounds(0.0)
.max_depth_bounds(1.0);

@ -345,7 +345,7 @@ fn setup_pipeline(
.depth_test_enable(true)
.depth_write_enable(true)
.depth_compare_op(vk::CompareOp::LESS)
.depth_bounds_test_enable(true)
.depth_bounds_test_enable(false)
.stencil_test_enable(false)
.min_depth_bounds(0.0)
.max_depth_bounds(1.0);

@ -198,7 +198,8 @@ impl Game<InWorld> {
*cmd_buf,
&[vk::Viewport::default()
.width(*width as f32)
.height(*height as f32)],
.height(*height as f32)
.max_depth(1.0)],
);
dev.cmd_set_scissor_with_count(
*cmd_buf,

@ -5,12 +5,12 @@ use crate::{game::chunk::Block, vec3, vector::Vector3};
use super::Mesh;
const TOP_POSITIONS: [Vector3<f32>; 6] = [
vec3!(0.0, 1.0, 0.0),
vec3!(1.0, 1.0, 0.0),
vec3!(0.0, 1.0, 1.0),
vec3!(1.0, 1.0, 1.0),
vec3!(1.0, 1.0, 0.0),
vec3!(0.0, 1.0, 1.0),
vec3!(0.0, 1.0, 0.0),
vec3!(1.0, 1.0, 1.0), // 3
vec3!(1.0, 1.0, 0.0), // 2
vec3!(0.0, 1.0, 1.0), // 1
];
const TOP_NORMAL: Vector3<f32> = vec3!(0.0, 1.0, 0.0);
@ -19,9 +19,9 @@ const BOTTOM_POSITIONS: [Vector3<f32>; 6] = [
vec3!(0.0, 0.0, 0.0),
vec3!(1.0, 0.0, 0.0),
vec3!(0.0, 0.0, 1.0),
vec3!(1.0, 0.0, 1.0),
vec3!(1.0, 0.0, 0.0),
vec3!(0.0, 0.0, 1.0),
vec3!(0.0, 0.0, 1.0), // 1
vec3!(1.0, 0.0, 0.0), // 2
vec3!(1.0, 0.0, 1.0), // 3
];
const BOTTOM_NORMAL: Vector3<f32> = vec3!(0.0, -1.0, 0.0);
@ -31,19 +31,19 @@ const NORTH_POSITIONS: [Vector3<f32>; 6] = [
vec3!(1.0, 1.0, 0.0),
vec3!(1.0, 0.0, 1.0),
vec3!(1.0, 1.0, 1.0),
vec3!(1.0, 1.0, 0.0),
vec3!(1.0, 0.0, 1.0),
vec3!(1.0, 1.0, 0.0),
];
const NORTH_NORMAL: Vector3<f32> = vec3!(1.0, 0.0, 0.0);
const SOUTH_POSITIONS: [Vector3<f32>; 6] = [
vec3!(0.0, 0.0, 0.0),
vec3!(0.0, 1.0, 0.0),
vec3!(0.0, 0.0, 1.0),
vec3!(0.0, 1.0, 1.0),
vec3!(0.0, 1.0, 0.0),
vec3!(0.0, 0.0, 1.0),
vec3!(0.0, 0.0, 0.0),
vec3!(0.0, 1.0, 1.0), // 3
vec3!(0.0, 1.0, 0.0), // 2
vec3!(0.0, 0.0, 1.0), // 1
];
const SOUTH_NORMAL: Vector3<f32> = vec3!(-1.0, 0.0, 0.0);
@ -52,17 +52,17 @@ const EAST_POSITIONS: [Vector3<f32>; 6] = [
vec3!(0.0, 0.0, 1.0),
vec3!(1.0, 0.0, 1.0),
vec3!(0.0, 1.0, 1.0),
vec3!(1.0, 1.0, 1.0),
vec3!(1.0, 0.0, 1.0),
vec3!(0.0, 1.0, 1.0),
vec3!(1.0, 0.0, 1.0),
vec3!(1.0, 1.0, 1.0),
];
const EAST_NORMAL: Vector3<f32> = vec3!(0.0, 0.0, 1.0);
const WEST_POSITIONS: [Vector3<f32>; 6] = [
vec3!(0.0, 0.0, 0.0),
vec3!(1.0, 0.0, 0.0),
vec3!(0.0, 1.0, 0.0),
vec3!(1.0, 0.0, 0.0),
vec3!(0.0, 0.0, 0.0),
vec3!(1.0, 1.0, 0.0),
vec3!(1.0, 0.0, 0.0),
vec3!(0.0, 1.0, 0.0),

@ -18,7 +18,7 @@ pub struct PosNorm {
impl PosNorm {
fn new(pos: Vector3<f32>, norm: Vector3<f32>) -> Self {
Self {
pos: [pos.x, pos.y, pos.z, 0.0],
pos: [pos.x, pos.y, pos.z, 1.0],
norm: [norm.x, norm.y, norm.z, 0.0],
}
}

Loading…
Cancel
Save