Add testing depth shader
This commit is contained in:
parent
95895750e8
commit
ab71bbc438
33
src/shader/depth_shader.c
Normal file
33
src/shader/depth_shader.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#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;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
M3x3f pos_mat = {.rows = {shdr->vertices[0].position, shdr->vertices[1].position, shdr->vertices[2].position}};
|
||||||
|
pos_mat = mat3x3_transpose(pos_mat);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
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};
|
||||||
|
}
|
18
src/shader/depth_shader.h
Normal file
18
src/shader/depth_shader.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef DEPTH_SHADER_H
|
||||||
|
#define DEPTH_SHADER_H
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
#include "shader.h"
|
||||||
|
#include "vec.h"
|
||||||
|
|
||||||
|
typedef struct depth_shader DepthShader;
|
||||||
|
struct depth_shader {
|
||||||
|
#include "shader_base.inc"
|
||||||
|
};
|
||||||
|
|
||||||
|
VertexData depth_shader_vertex(void *shader, const VertexData *vert, u8 index,
|
||||||
|
const Model *model);
|
||||||
|
FragmentResult depth_shader_fragment(void *shader, const V3f *barycentric,
|
||||||
|
const Colour *colour, const Model *model);
|
||||||
|
|
||||||
|
#endif // !DEPTH_SHADER_H
|
Loading…
Reference in New Issue
Block a user