From bca5dafabf0c649b196a3dcd2ef9c46ae392a508 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 14 Sep 2024 18:32:00 +0100 Subject: [PATCH] Fragment shader for depth returns valid u8 values --- src/shader/depth_shader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shader/depth_shader.c b/src/shader/depth_shader.c index 1facff6..907cef7 100644 --- a/src/shader/depth_shader.c +++ b/src/shader/depth_shader.c @@ -1,5 +1,7 @@ #include "depth_shader.h" +#include "constants.h" #include "shader.h" +#include "utils.h" VertexData depth_shader_vertex(void *shader, const VertexData *vert, u8 index, const Model *model) { DepthShader *shdr = (DepthShader *)shader; @@ -20,7 +22,8 @@ FragmentResult depth_shader_fragment(void *shader, const V3f *barycentric, const pos_mat = mat3x3_transpose(pos_mat); V3f position = mat3x3_mul_vec3(pos_mat, (*barycentric)); - V4f output = {.r = position.z, .g = position.z, .b = position.z, .a = 255}; + f32 channel = clamp(position.z + DEPTH_MAX, 0.0f, DEPTH_MAX); + V4f output = {.r = channel, .g = channel, .b = channel, .a = 255}; return (FragmentResult){.colour = output}; }