Note: Currently version still have lots of fireflies after applying normal map. And those fireflies are mostly coming from the nee sky. Need to double check the sky cdf and ray intersection. Changed the `hit_result_t` structure to rename a parameter in `RayIntersection.h`. Removed the `normal` field from the `path_output` structure in `Common.h`. Added new fields `screen_size`, `camera_position`, and `camera_direction` in `Material.h`. Changed the `mipmap_t` structure in `Texture.h` to include a `max_mip` field and modify the `data` field. Changed the `texture_load` function in `Texture.c` to include a `mipmap` parameter and improve texture data handling. Changed the `path_trace` function in `PathTracing.c` to update the `shading_context_t` structure and ray creation. Changed the `evaluate_bsdf_directional` function in `LightEvaluation.c` to modify angular radius calculation. Changed the `sky_create_hdr_sky` and `evaluate_bsdf_hdr_sky` functions in `SkyLight.c` to enhance texture sampling. Changed the `get_surface_data` function in `SimpleLit.c` to incorporate camera distance and view direction in calculations. Changed the `texture_get_pixel` function in `Texture.c` to improve pixel data retrieval. Changed the `warp_uv` function to use a `vec2s` structure for UV coordinates. Changed the `texture_sample` function to include additional parameters for improved sampling accuracy. Changed the `scene_setup` function in `main.c` to adjust sun light intensity and HDRI texture loading.
113 lines
2.4 KiB
C
113 lines
2.4 KiB
C
#ifndef TEXTURE_H
|
|
#define TEXTURE_H
|
|
|
|
#include "Common.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 enum
|
|
{
|
|
UINT_8 = 1,
|
|
UINT_16 = 2,
|
|
FLOAT_32 = 4,
|
|
} stride_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t width;
|
|
uint32_t height;
|
|
char* data;
|
|
} mipmap_t;
|
|
|
|
typedef struct
|
|
{
|
|
vec2s texel_size;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
|
|
wrap_mode_t wrap_mode;
|
|
filter_mode_t filter_mode;
|
|
stride_t stride;
|
|
|
|
uint8_t channel_count;
|
|
uint8_t max_mip;
|
|
mipmap_t* data;
|
|
} texture_t;
|
|
|
|
typedef struct
|
|
{
|
|
char* full_name;
|
|
texture_t texture;
|
|
} texture_asset_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t count;
|
|
uint16_t size;
|
|
texture_asset_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, bool mipmap, stride_t stride, texture_collection_t* textures);
|
|
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);
|
|
vec4s texture_sample(const texture_t* texture, vec2s uv, vec3s view_direction, vec3s normal, float distance);
|
|
vec4s texture_sample_lod(const texture_t* texture, vec2s uv, float lod);
|
|
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].texture;
|
|
}
|
|
|
|
inline size_t texture_get_pixel_index(texture_t* texture, uint32_t x, uint32_t y)
|
|
{
|
|
return (size_t)(y * texture->width + x) * texture->channel_count * texture->stride;
|
|
}
|
|
|
|
inline void texture_uv_to_index(texture_t* texture, vec2s uv, uint32_t* x, uint32_t* y)
|
|
{
|
|
uv_to_index(uv, texture->width, texture->height, x, y);
|
|
}
|
|
|
|
#endif // TEXTURE_H
|