Move viewport matrix multiplication out of vertex shader
This commit is contained in:
@@ -28,10 +28,8 @@ ShaderID register_shader(void *shader, VertexShader *vertex,
|
||||
return (ShaderID){g_repository.count};
|
||||
}
|
||||
|
||||
V3f run_vertex_shader(ShaderID shader, const V3f *vertex,
|
||||
const Buffer *out_buf) {
|
||||
if (IS_INVALID_SHADER(shader) || shader.id > g_repository.count || !vertex ||
|
||||
!out_buf) {
|
||||
V3f run_vertex_shader(ShaderID shader, const V3f *vertex) {
|
||||
if (IS_INVALID_SHADER(shader) || shader.id > g_repository.count || !vertex) {
|
||||
return (V3f){0};
|
||||
}
|
||||
|
||||
@@ -42,7 +40,7 @@ V3f run_vertex_shader(ShaderID shader, const V3f *vertex,
|
||||
return (V3f){0};
|
||||
}
|
||||
|
||||
return vertex_func(shader_obj, vertex, out_buf);
|
||||
return vertex_func(shader_obj, vertex);
|
||||
}
|
||||
|
||||
FragmentResult run_fragment_shader(ShaderID shader, const FragmentData *data,
|
||||
|
||||
@@ -29,16 +29,14 @@ struct fragment_data {
|
||||
#define DISCARDED_FRAGMENT ((FragmentResult){.discard = true})
|
||||
#define DISCARD_FRAGMENT(RESULT) (RESULT.discard)
|
||||
|
||||
typedef V3f(VertexShader)(void *shader, const V3f *vertex,
|
||||
const Buffer *out_buf);
|
||||
typedef V3f(VertexShader)(void *shader, const V3f *vertex);
|
||||
typedef FragmentResult(FragmentShader)(void *shader, const FragmentData *data,
|
||||
const Colour *colour,
|
||||
const Model *model);
|
||||
|
||||
ShaderID register_shader(void *shader, VertexShader *vertex,
|
||||
FragmentShader *fragment);
|
||||
V3f run_vertex_shader(ShaderID shader, const V3f *vertex,
|
||||
const Buffer *out_buf);
|
||||
V3f run_vertex_shader(ShaderID shader, const V3f *vertex);
|
||||
FragmentResult run_fragment_shader(ShaderID shader, const FragmentData *data,
|
||||
const Colour *colour, const Model *model);
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ internal V3f g_target = {0};
|
||||
internal V3f g_up = {0.0f, 1.0f, 0.0f};
|
||||
internal M4x4f g_cam_matrix = mat4x4_identity;
|
||||
|
||||
internal V3f general_shader_vertex(void *shader, const V3f *vertex,
|
||||
const Buffer *out_buf);
|
||||
internal V3f general_shader_vertex(void *shader, const V3f *vertex);
|
||||
internal FragmentResult phong_shader_fragment(void *shader,
|
||||
const FragmentData *data,
|
||||
const Colour *colour,
|
||||
@@ -66,22 +65,14 @@ void load_shaders(void) {
|
||||
albedo_shader_fragment);
|
||||
}
|
||||
|
||||
internal V3f general_shader_vertex(void *shader, const V3f *vertex,
|
||||
const Buffer *out_buf) {
|
||||
internal V3f general_shader_vertex(void *shader, const V3f *vertex) {
|
||||
Shader *shader_ptr = (Shader *)shader;
|
||||
|
||||
V4f vh = {.x = vertex->x, .y = vertex->y, .z = vertex->z, .w = 1.0f};
|
||||
vh = mat4x4_mul_vec4(shader_ptr->projection,
|
||||
mat4x4_mul_vec4(shader_ptr->model_view, vh));
|
||||
vh.y = 0.0 - vh.y;
|
||||
vh = mat4x4_mul_vec4(viewport(vh.x, vh.y, out_buf->width, out_buf->height),
|
||||
vh);
|
||||
|
||||
V3f output = project_vec4(vh);
|
||||
output.x = clamp(output.x, 0.0f, out_buf->width);
|
||||
output.y = clamp(output.y, 0.0f, out_buf->height);
|
||||
|
||||
return output;
|
||||
return project_vec4(vh);
|
||||
}
|
||||
|
||||
internal FragmentResult phong_shader_fragment(void *shader,
|
||||
|
||||
Reference in New Issue
Block a user