Fixed cdf and added Standard Lit

This commit is contained in:
2025-12-29 22:01:44 +09:00
parent e1693764f7
commit adee5acd10
24 changed files with 830 additions and 570 deletions

View File

@@ -96,6 +96,7 @@ static void average_pixels_box(const char* current_data, uint32_t current_width,
{
return;
}
float* sum_float = (float*)calloc(channel_count, sizeof(float));
if (sum_float == NULL)
{
@@ -252,7 +253,7 @@ static void generate_mipmap(char* raw_data, mipmap_t* texture_data, uint32_t wid
#endif
}
texture_entity_t texture_load(const char* filename, bool srgb, bool mipmap, stride_t stride, texture_collection_t* textures)
texture_handle_t texture_load(const char* filename, bool srgb, bool mipmap, stride_t stride, texture_collection_t* textures)
{
// TODO: This hurts performance, consider using a hash map or similar structure for faster lookups
@@ -283,7 +284,7 @@ texture_entity_t texture_load(const char* filename, bool srgb, bool mipmap, stri
if (raw_data == NULL)
{
return invalid_texture_entity();
return invalid_texture_handle();
}
uint8_t max_mip_level = mipmap ? (uint8_t)log2f(fmaxf((float)width, (float)height)) : 0;
@@ -291,7 +292,7 @@ texture_entity_t texture_load(const char* filename, bool srgb, bool mipmap, stri
if (temp_texture_data == NULL)
{
stbi_image_free(raw_data);
return invalid_texture_entity();
return invalid_texture_handle();
}
generate_mipmap(raw_data, temp_texture_data, (uint32_t)width, (uint32_t)height, (uint8_t)channels, max_mip_level, stride);
@@ -307,15 +308,15 @@ texture_entity_t texture_load(const char* filename, bool srgb, bool mipmap, stri
texture.stride = stride;
texture.data = temp_texture_data;
texture.wrap_mode = REPEAT;
texture.filter_mode = LINEAR;
texture.wrap_mode = WM_REPEAT;
texture.filter_mode = FM_LINEAR;
if (textures->count >= textures->size)
{
texture_collection_resize(textures, textures->size * 2);
}
texture_entity_t entity = {.id = textures->count};
texture_handle_t entity = {.id = textures->count};
textures->buffer[textures->count] = (texture_asset_t){.full_name = string_copy(filename), .texture = texture};
textures->count++;
@@ -327,11 +328,11 @@ static inline void warp_uv(wrap_mode_t mode, vec2s* uv)
{
switch (mode)
{
case REPEAT:
case WM_REPEAT:
uv->x = fmodf(fabsf(uv->x), 1.0f);
uv->y = fmodf(fabsf(uv->y), 1.0f);
break;
case CLAMP:
case WM_CLAMP:
*uv = glms_vec2_clamp(*uv, 0.0f, 1.0f);
break;
}
@@ -394,7 +395,7 @@ vec4s texture_get_pixel(const texture_t* texture, vec2s uv, uint8_t lod)
float texture_get_sample_lod(vec3s view_direction, vec3s normal, float distance)
{
// TODO: Implement a more accurate LOD calculation based on the distance to the surface and the view direction.
// TODO: Implement a more accurate LOD calculation.
const float factor = 1.0f;
float n_dot_v = glms_vec3_dot(normal, view_direction);
@@ -428,10 +429,10 @@ static vec4s linear_filter(const texture_t* texture, vec2s uv, uint8_t lod)
float sx = x - (float)x0;
float sy = y - (float)y0;
x0 = glm_clamp((float)x0, 0.0f, (float)mipmap->width - 1);
x1 = glm_clamp((float)x1, 0.0f, (float)mipmap->width - 1);
y0 = glm_clamp((float)y0, 0.0f, (float)mipmap->height - 1);
y1 = glm_clamp((float)y1, 0.0f, (float)mipmap->height - 1);
x0 = (uint32_t)glm_clamp((float)x0, 0.0f, (float)mipmap->width - 1.0f);
x1 = (uint32_t)glm_clamp((float)x1, 0.0f, (float)mipmap->width - 1.0f);
y0 = (uint32_t)glm_clamp((float)y0, 0.0f, (float)mipmap->height - 1.0f);
y1 = (uint32_t)glm_clamp((float)y1, 0.0f, (float)mipmap->height - 1.0f);
// Get the pixel values for the four corners of the 2x2 block
vec4s c00 = get_pixel_data_from_buffer(mipmap->data, x0, y0, mipmap->width, texture->channel_count, texture->stride);
@@ -450,9 +451,9 @@ static inline vec4s filter_texture(const texture_t* texture, vec2s uv, float lod
{
switch (texture->filter_mode)
{
case NEAREST:
case FM_NEAREST:
return nearest_filter(texture, uv, (uint8_t)lod);
case LINEAR:
case FM_LINEAR:
return linear_filter(texture, uv, (uint8_t)lod);
default:
return (vec4s){0.0f, 0.0f, 0.0f, 1.0f};