31 lines
1.1 KiB
C
31 lines
1.1 KiB
C
#include "depth_shader.h"
|
|
#include "constants.h"
|
|
#include "img.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;
|
|
|
|
V4f vh = V3_to_V4(vert->position);
|
|
vh.y = 0.0 - vh.y;
|
|
vh = mat4x4_mul_vec4(shdr->final, vh);
|
|
shdr->vertices[index].position = project_vec4(vh);
|
|
|
|
return shdr->vertices[index];
|
|
}
|
|
|
|
FragmentResult depth_shader_fragment(void *shader, const V3f *barycentric, const Colour *colour,
|
|
const Model *model) {
|
|
DepthShader *shdr = (DepthShader *)shader;
|
|
|
|
M3x3f pos_mat = {.rows = {shdr->vertices[0].position, shdr->vertices[1].position, shdr->vertices[2].position}};
|
|
pos_mat = mat3x3_transpose(pos_mat);
|
|
|
|
V3f position = mat3x3_mul_vec3(pos_mat, (*barycentric));
|
|
f32 channel = clamp(position.z + DEPTH_MAX, 0.0f, DEPTH_MAX);
|
|
Colour output = {.r = (u8)(channel), .g = (u8)(channel), .b = (u8)(channel), .a = 255};
|
|
|
|
return (FragmentResult){.colour = output};
|
|
}
|