Ensure intensity is clamped
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
#include "render.h"
 | 
			
		||||
#include "aliases.h"
 | 
			
		||||
#include "constants.h"
 | 
			
		||||
#include "img.h"
 | 
			
		||||
#include "shader.h"
 | 
			
		||||
#include "typed_list.h"
 | 
			
		||||
#include "utils.h"
 | 
			
		||||
 
 | 
			
		||||
@@ -154,10 +154,14 @@ internal FragmentResult diffuse_shader_fragment(void *shader,
 | 
			
		||||
    output = *colour;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  f32 intensity = max(0.0f, dot_v3(normal, shdr->light_dir));
 | 
			
		||||
  output.r *= intensity + g_ambient_light.r;
 | 
			
		||||
  output.g *= intensity + g_ambient_light.g;
 | 
			
		||||
  output.b *= intensity + g_ambient_light.b;
 | 
			
		||||
  f32 intensity = max(0.001f, dot_v3(normal, shdr->light_dir));
 | 
			
		||||
  f32 r = clamp(intensity + g_ambient_light.r, 0.0f, 1.0f);
 | 
			
		||||
  f32 g = clamp(intensity + g_ambient_light.g, 0.0f, 1.0f);
 | 
			
		||||
  f32 b = clamp(intensity + g_ambient_light.b, 0.0f, 1.0f);
 | 
			
		||||
 | 
			
		||||
  output.r *= r;
 | 
			
		||||
  output.g *= g;
 | 
			
		||||
  output.b *= b;
 | 
			
		||||
 | 
			
		||||
  return (FragmentResult){.colour = output};
 | 
			
		||||
}
 | 
			
		||||
@@ -166,7 +170,25 @@ internal FragmentResult albedo_shader_fragment(void *shader,
 | 
			
		||||
                                               const V3f *barycentric,
 | 
			
		||||
                                               const Colour *colour,
 | 
			
		||||
                                               const Model *model) {
 | 
			
		||||
  return (FragmentResult){.colour = *colour};
 | 
			
		||||
  Shader *shdr = (Shader *)shader;
 | 
			
		||||
 | 
			
		||||
  // clang-format off
 | 
			
		||||
  M3x2f uvs = {shdr->vertices[0].uv, shdr->vertices[1].uv, shdr->vertices[2].uv};
 | 
			
		||||
  M2x3f uv_mat = mat3x2_transpose(uvs);
 | 
			
		||||
  // clang-format on
 | 
			
		||||
 | 
			
		||||
  V2f uv = mat2x3_mul_vec3(uv_mat, (*barycentric));
 | 
			
		||||
 | 
			
		||||
  Colour output;
 | 
			
		||||
  if (model->texture) {
 | 
			
		||||
    u64 tx_x = uv.u * model->texture->width;
 | 
			
		||||
    u64 tx_y = uv.v * model->texture->height;
 | 
			
		||||
    output = get_pixel(Colour, model->texture, tx_x, tx_y);
 | 
			
		||||
  } else {
 | 
			
		||||
    output = *colour;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (FragmentResult){.colour = output};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal M4x4f get_projection_matrix(ProjectionType projection_type) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user