Files
SimpleRayTracing/header/Rendering/Texture.h
Misaki 4c62b3ecde Add HDR sky lighting support and improve rendering
Added support for HDR sky lighting, including sampling environment maps with a hierarchical CDF.
Added new utility functions for handling HDR sky data, including memory management and sampling functions.
Added functions to improve texture handling, including pixel data retrieval and texture coordinate management.
Changed the path tracing algorithm to enhance light evaluation from HDR skies and adjust light contribution calculations.
Changed BSDF sampling functions to utilize constants from Common.h for better readability.
Changed the main application logic to load HDR textures and configure the scene with improved lighting settings.
Refactored ray intersection logic to enhance accuracy and performance in triangle intersections.
Adjusted the sample count in the rendering configuration to optimize performance.
Updated the README.md to document new features and example renders.
2025-05-04 01:33:00 +09:00

100 lines
2.1 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;
wrap_mode_t wrap_mode;
filter_mode_t filter_mode;
uint8_t channel_count;
stride_t stride;
char* 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, stride_t stride, texture_collection_t* textures);
vec4s texture_get_pixel(const texture_t* texture, uint32_t x, uint32_t y);
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].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