Enhance graphics library functionality and structure
Added new function signatures in `assimp-vc143-mt.lib` for improved logging, parsing, and vector operations. Added new metadata and configuration information in `assimp-vc143-mt.dll` for versioning and licensing compliance. Added Sobol sequence generation in `Sobol.c` for quasi-random sampling. Added window message handling in `Window.c` for rendering graphics. Added ray-triangle intersection tests in `RayIntersection.c` for collision detection. Added functions for loading mesh data in `Mesh.c` to support 3D model import. Added functions for managing triangle collections in `Triangle.c` to enhance geometric data handling. Added light evaluation functions in `LightEvaluation.c` and `SkyLight.c` for realistic rendering. Added sampling and evaluation functions for simple lit materials in `SimpleLit.c`. Changed various header files to include copyright and licensing information. Changed existing functions in multiple files to improve performance and clarity. Removed unused code in several files to streamline the library.
This commit is contained in:
@@ -1,17 +1,68 @@
|
||||
#ifndef BSDF_H
|
||||
#define BSDF_H
|
||||
|
||||
#include "Material.h"
|
||||
#include "cglm/types-struct.h"
|
||||
#include "cglm/struct/vec3.h"
|
||||
|
||||
typedef struct
|
||||
inline float power_heuristic(float pdf_a, float pdf_b)
|
||||
{
|
||||
vec3s albedo;
|
||||
float roughness;
|
||||
float metallic;
|
||||
}simple_lit_data_t;
|
||||
float a2 = pdf_a * pdf_a;
|
||||
float b2 = pdf_b * pdf_b;
|
||||
return a2 / (a2 + b2);
|
||||
}
|
||||
|
||||
vec3s sample_bsdf_simple_lit(const void* data, const vec3s normal, const vec3s wo, float* pdf_out);
|
||||
vec3s evaluate_bsdf_simple_lit(const shading_context_t* context, const void* data);
|
||||
inline float roughness_to_blinn_phong_specular_exponent(float roughness)
|
||||
{
|
||||
return glm_clamp(2.0f * 1.0f / (fmaxf(roughness * roughness, FLT_EPSILON)) - 2.0f, FLT_EPSILON, 1.0f / FLT_EPSILON);
|
||||
}
|
||||
|
||||
inline vec3s fresnel_schlick_vec3(vec3s f0, float cos_theta)
|
||||
{
|
||||
float x = 1.0f - cos_theta;
|
||||
float x5 = x * x * x * x * x;
|
||||
return glms_vec3_adds(glms_vec3_scale(f0, (1.0f - x5)), x5);
|
||||
}
|
||||
|
||||
inline float pdf_cosine_weighted_hemisphere(const vec3s normal, const vec3s wi)
|
||||
{
|
||||
return fmaxf(glms_vec3_dot(wi, normal), 0.0f) / (float)M_PI;
|
||||
}
|
||||
|
||||
inline float pdf_blinn_phong_lobe(const vec3s normal, const vec3s wi, const vec3s wo, const float roughness)
|
||||
{
|
||||
// Check if wo and wi are on the same side of the surface normal geometry
|
||||
if (glms_vec3_dot(wo, normal) <= 0.0f || glms_vec3_dot(wi, normal) <= 0.0f)
|
||||
{
|
||||
return 0.0f; // Cannot scatter from below horizon to above, or vice versa
|
||||
}
|
||||
|
||||
// Calculate the half-vector h based on input wo and wi
|
||||
vec3s wo_n = glms_vec3_normalize(wo); // Ensure normalized inputs if not guaranteed
|
||||
vec3s wi_n = glms_vec3_normalize(wi);
|
||||
vec3s h = glms_vec3_add(wo_n, wi_n);
|
||||
float h_len_sq = glms_vec3_norm2(h);
|
||||
if (h_len_sq < FLT_EPSILON)
|
||||
{
|
||||
return 0.0f; // wo and wi are opposite, highly unlikely for reflection
|
||||
}
|
||||
h = glms_vec3_scale(h, 1.0f / sqrtf(h_len_sq)); // Normalize h
|
||||
|
||||
// Calculate Blinn-Phong specular exponent
|
||||
float specular_exponent = roughness_to_blinn_phong_specular_exponent(roughness);
|
||||
|
||||
// PDF of sampling h (Blinn-Phong distribution)
|
||||
// D(h) = (specular_exponent + 1) / (2 * PI) * pow(max(0, dot(n, h)), specular_exponent)
|
||||
float n_dot_h = fmaxf(0.0f, glms_vec3_dot(normal, h));
|
||||
float pdf_h = (specular_exponent + 1.0f) / (2.0f * (float)M_PI) * powf(n_dot_h, specular_exponent);
|
||||
|
||||
// Jacobian of the transformation from h to wi
|
||||
// jacobian = 1 / (4 * dot(wo, h))
|
||||
float wo_dot_h = fmaxf(FLT_EPSILON, glms_vec3_dot(wo_n, h)); // Use normalized wo, ensure > 0
|
||||
float jacobian = 1.0f / (4.0f * wo_dot_h);
|
||||
|
||||
// PDF of sampling wi is pdf(h) * jacobian
|
||||
float pdf_spec = pdf_h * jacobian;
|
||||
|
||||
return pdf_spec;
|
||||
}
|
||||
|
||||
#endif // BSDF_H
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef PATH_TRACING_H
|
||||
#define PATH_TRACING_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Material.h"
|
||||
#include "Triangle.h"
|
||||
#include "Algorithm/RayIntersection.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Geometry/Triangle.h"
|
||||
#include "Rendering/Scene.h"
|
||||
|
||||
static hit_result_t ray_intersect(const triangle_t triangle, const ray_t ray);
|
||||
vec3s path_trace(const triangle_collection_t* triangles, const material_collection_t* materials, ray_t ray, int depth);
|
||||
vec3s path_trace(const scene_t* scene, const ray_t ray, const uint32_t sample_index, const int depth);
|
||||
|
||||
#endif // PATH_TRACING_H
|
||||
|
||||
26
header/Algorithm/RayIntersection.h
Normal file
26
header/Algorithm/RayIntersection.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef RAY_INTERSECTION_H
|
||||
#define RAY_INTERSECTION_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Geometry/Triangle.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3s origin;
|
||||
vec3s direction;
|
||||
} ray_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3s point;
|
||||
vec3s normal;
|
||||
uint64_t triangle_id;
|
||||
float distance;
|
||||
bool hit;
|
||||
} hit_result_t;
|
||||
|
||||
hit_result_t ray_intersect(const triangle_t triangle, const ray_t ray);
|
||||
hit_result_t ray_intersect_closest(const triangle_collection_t* triangles, const ray_t ray);
|
||||
hit_result_t ray_intersect_any(const triangle_collection_t* triangles, const ray_t ray);
|
||||
|
||||
#endif // RAY_INTERSECTION_H
|
||||
39
header/Algorithm/Sobol.h
Normal file
39
header/Algorithm/Sobol.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef SOBOL_H
|
||||
#define SOBOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SOBOL_BITS 32
|
||||
// NOTE: May need more dimensions for later
|
||||
#define SOBOL_DIMENSIONS 8
|
||||
|
||||
// #define COS_WEIGHTED_HEMISPHERE_R1_INDEX 0
|
||||
// #define COS_WEIGHTED_HEMISPHERE_R2_INDEX 1
|
||||
|
||||
static uint32_t sobol_direction_vectors[SOBOL_DIMENSIONS][SOBOL_BITS];
|
||||
|
||||
// Precomputed table: s, a, and m_i's
|
||||
// https://web.maths.unsw.edu.au/~fkuo/sobol/
|
||||
static const int s_vals[SOBOL_DIMENSIONS - 1] = {1, 2, 3, 3, 4, 4, 5};
|
||||
static const int a_vals[SOBOL_DIMENSIONS - 1] = {0, 1, 1, 2, 1, 4, 2};
|
||||
static const int m_vals[SOBOL_DIMENSIONS - 1][5] = {
|
||||
{1}, // dim 2
|
||||
{1, 3}, // dim 3
|
||||
{1, 3, 1}, // dim 4
|
||||
{1, 1, 1}, // dim 5
|
||||
{1, 1, 3, 3}, // dim 6
|
||||
{1 ,1, 5, 13}, // dim 7
|
||||
{1, 1, 5, 5, 17} // dim 8
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t index;
|
||||
uint32_t dimension;
|
||||
} sobol_state_t;
|
||||
|
||||
void sobol_init();
|
||||
float sobol_sample(uint32_t index, uint32_t dimension);
|
||||
float sobol_next(sobol_state_t* state);
|
||||
|
||||
#endif // SOBOL_H
|
||||
Reference in New Issue
Block a user