Added a new function `blinn_phong_specular_exponent_to_roughness` in `BSDF.h` to convert a specular exponent to roughness. Added a `textures` member to the `shading_context_t` structure in `Material.h` for passing texture information during shading. Added a new member `textures` in the `light_shading_context_t` structure in `Light.h` to hold texture information. Added inline functions in `Texture.h` for handling texture entities, including `invalid_texture_entity`, `is_texture_entity_valid`, and `get_texture`. Changed the texture-related members in `simple_lit_properties_t` in `SimpleLit.h` from pointers to `texture_entity_t` to better manage texture entities. Changed the `sample_material_bsdf` and `sample_material_bsdf_pdf` functions in `Material.h` to accept a `shading_context_t` instead of individual parameters. Changed the `mesh_load` function in `Mesh.c` to use the new roughness calculation and texture entity handling. Changed the `path_trace` function in `PathTracing.c` to use the new structure and functions for handling materials and textures. Refactored the `sample_material_bsdf` and `sample_material_bsdf_pdf` functions in `Material.c` to utilize the new `shading_context_t` structure. Updated the `material_collection_init` function in `Material.h` to reflect changes in the material sampling functions. Updated the `evaluate_bsdf_directional` and `evaluate_bsdf_const_sky` functions to use the new shading context structure. Adjusted the `simple_lit_data_default` function in `SimpleLit.c` to work with the new texture handling approach. Added texture entity handling in `Texture.c` for managing invalid texture entities.
74 lines
1.5 KiB
C
74 lines
1.5 KiB
C
#ifndef TEXTURE_H
|
|
#define TEXTURE_H
|
|
|
|
#include "cglm/struct/vec4.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define INVALID_TEXTURE_ID UINT16_MAX
|
|
|
|
typedef enum
|
|
{
|
|
REPEAT,
|
|
CLAMP,
|
|
} wrap_mode_t;
|
|
|
|
typedef enum
|
|
{
|
|
NEAREST,
|
|
LINEAR,
|
|
} filter_mode_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t width;
|
|
uint32_t height;
|
|
wrap_mode_t wrap_mode;
|
|
filter_mode_t filter_mode;
|
|
uint8_t channel_count;
|
|
uint8_t* data;
|
|
} texture_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t count;
|
|
uint16_t size;
|
|
texture_t* buffer;
|
|
} texture_collection_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t id;
|
|
} texture_entity_t;
|
|
|
|
bool texture_collection_init(uint16_t size, texture_collection_t* textures);
|
|
void texture_collection_resize(texture_collection_t* textures, uint16_t size);
|
|
void texture_collection_free(texture_collection_t* textures);
|
|
|
|
texture_entity_t texture_load(const char* filename, bool srgb, texture_collection_t* textures);
|
|
vec4s texture_sample(const texture_t* texture, float u, float v);
|
|
void texture_free(texture_t* texture);
|
|
|
|
inline texture_entity_t invalid_texture_entity()
|
|
{
|
|
return (texture_entity_t){.id = INVALID_TEXTURE_ID};
|
|
}
|
|
|
|
inline bool is_texture_entity_valid(texture_entity_t entity)
|
|
{
|
|
return entity.id != INVALID_TEXTURE_ID;
|
|
}
|
|
|
|
inline texture_t* get_texture(const texture_collection_t* textures, texture_entity_t entity)
|
|
{
|
|
if (entity.id >= textures->count || !is_texture_entity_valid(entity))
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
return &textures->buffer[entity.id];
|
|
}
|
|
|
|
#endif // TEXTURE_H
|