Files
SimpleRayTracing/source/Algorithm/Sobol.c
Misaki 6800810369 Update project structure and improve performance
Added new files for BVH, AABB, and Debug functionalities.
Added new utility functions in Common.h.
Added gamma correction function in PostProcessing.h.
Changed the return type of path_trace to vec4s for alpha blending.
Changed BSDF function signatures to include sample index and bounce.
Changed the BSDF.h to replace inline functions with declarations.
Changed the Light and SkyLight evaluation functions to include throughput and sample index.
Changed the sphere creation function in GeometryUtilities.h for better quality.
Changed the scene structure to include a BVH tree for improved ray intersection.
Changed the scene initialization parameters for better performance.
Created new Debug functions for ray intersection counting.
Created new functions for triangle collection management in Triangle.c.
Improved pixel updating logic in Window.c.
Improved ray intersection performance with new BVH implementation.
Removed unused includes from Common.h.
Removed old library linking methods in CMakeLists.txt.
2025-04-21 15:56:19 +09:00

74 lines
1.7 KiB
C

#include "Algorithm/Sobol.h"
static inline int sobol_get_bit(uint32_t index, uint32_t bit)
{
return (index >> bit) & 1;
}
//NOTE: Maybe precompute the vector table?
void sobol_init()
{
// First, set dimension 0 manually (Van der Corput)
for (int i = 0; i < SOBOL_BITS; i++)
{
sobol_direction_vectors[0][i] = 1U << (31 - i);
}
for (int d = 1; d < SOBOL_DIMENSIONS; d++)
{
int s = s_vals[d - 1];
int a = a_vals[d - 1];
// Set initial direction numbers
for (int i = 0; i < s; i++)
{
sobol_direction_vectors[d][i] = m_vals[d - 1][i] << (31 - i);
}
// Compute remaining direction numbers
for (int i = s; i < SOBOL_BITS; i++)
{
uint32_t v = sobol_direction_vectors[d][i - s];
v ^= v >> s;
for (int k = 1; k < s; k++)
{
if ((a >> (s - 1 - k)) & 1)
v ^= sobol_direction_vectors[d][i - k];
}
sobol_direction_vectors[d][i] = v;
}
}
}
uint16_t sobol_get_dimension(uint16_t bounce, sampling_dimension_t operation_type)
{
return PRNG_BASE_NUM + bounce * PRNG_BOUNCE_NUM + operation_type;
}
static inline float sobol_uint_to_float(uint32_t x)
{
return x * 2.3283064365386963e-10f; // 1/2^32
}
float sobol_sample(uint32_t index, uint32_t dimension)
{
// return random_float();
if (dimension >= SOBOL_DIMENSIONS)
{
return 0.0f; // Invalid dimension
}
uint32_t result = 0;
for (int i = 0; i < SOBOL_BITS; i++)
{
if (sobol_get_bit(index, i))
{
result ^= sobol_direction_vectors[dimension][i];
}
}
return sobol_uint_to_float(result);
}