14static inline std::vector<float> log_space(std::size_t start, std::size_t end, std::size_t count)
16 std::vector<float> result;
17 result.reserve(count);
18 for(std::size_t i = 0;
i <=
count; ++
i)
20 float f =
start * glm::pow(
float(end) /
float(start),
float(i) /
float(count));
146 return (u.i & 0x80000000) != 0;
163 const glm::mat4& proj,
164 const glm::vec3& axis,
166 std::int32_t& in_out_min_x,
167 std::int32_t& in_out_max_x)
169 auto view_x = float(in_out_min_x);
170 auto view_size_x = float(in_out_max_x - in_out_min_x);
174 if(discriminant >= 0)
176 float sqrt_discriminant = glm::sqrt(discriminant);
177 float inv_light_square = 1.0f / (
square(light_x) +
square(light_z));
179 float Nxa = (radius * light_x - sqrt_discriminant) * inv_light_square;
180 float Nxb = (radius * light_x + sqrt_discriminant) * inv_light_square;
181 float Nza = (radius - Nxa * light_x) / light_z;
182 float Nzb = (radius - Nxb * light_x) / light_z;
183 float Pza = light_z - radius * Nza;
184 float Pzb = light_z - radius * Nzb;
189 float Pxa = -Pza * Nza / Nxa;
190 glm::vec4 P = proj * glm::vec4(axis.x * Pxa, axis.y * Pxa, Pza, 1);
191 float X = (glm::dot(glm::vec3(P), axis) / P.w + 1.0f * axis_sign) / 2.0f * axis_sign;
194 in_out_max_x = std::min<std::int32_t>(std::int32_t(glm::ceil(view_size_x * X + view_x)), in_out_max_x);
198 in_out_min_x = std::max<std::int32_t>(std::int32_t(glm::floor(view_size_x * X + view_x)), in_out_min_x);
205 float Pxb = -Pzb * Nzb / Nxb;
206 glm::vec4 P = proj * glm::vec4(axis.x * Pxb, axis.y * Pxb, Pzb, 1);
207 float X = (glm::dot(glm::vec3(P), axis) / P.w + 1.0f * axis_sign) / 2.0f * axis_sign;
210 in_out_max_x = std::min<std::int32_t>(std::int32_t(glm::ceil(view_size_x * X + view_x)), in_out_max_x);
214 in_out_min_x = std::max<std::int32_t>(std::int32_t(glm::floor(view_size_x * X + view_x)), in_out_min_x);
219 return in_out_min_x <= in_out_max_x;
226 std::int32_t& bottom,
227 const glm::vec3& sphere_center,
229 const glm::vec3& view_origin,
230 const glm::mat4& view,
231 const glm::mat4& proj)
234 if(glm::length2(sphere_center - view_origin) >
square(radius))
236 glm::vec3 lv = glm::vec3(view * glm::vec4(sphere_center, 1.0f));
256inline float halton(std::uint32_t Index, std::uint32_t Base)
259 float InvBase = 1.0f / Base;
260 float Fraction = InvBase;
263 Result += (Index % Base) * Fraction;
272 std::uint32_t currentVal = n;
273 std::uint32_t iter = 1;
274 while(currentVal < val)
289 static color c(1.0f, 1.0f, 1.0f, 1.0f);
294 static color c(0.0f, 0.0f, 0.0f, 1.0f);
299 static color c(0.0f, 0.0f, 0.0f, 0.0f);
304 static color c(1.0f, 0.0f, 0.0f, 1.0f);
309 static color c(1.0f, 0.0f, 1.0f, 1.0f);
320 return random(std::string(seed));
331 std::hash<std::string> hasher;
332 std::size_t hash_value = hasher(seed);
335 auto lcg = [](std::size_t& state) ->
float {
336 state = (state * 1103515245u + 12345u) & 0x7fffffffu;
337 return static_cast<float>(state) /
static_cast<float>(0x7fffffffu);
340 std::size_t state = hash_value;
343 float hue = lcg(state);
346 float saturation = 0.4f + 0.6f * lcg(state);
349 float value = 0.6f + 0.4f * lcg(state);
351 return hsv(hue, saturation,
value, 1.0f);
362 float sc = 1.0f / 255.0f;
363 value.x = (float)r * sc;
364 value.y = (float)g * sc;
370 float sc = 1.0f / 255.0f;
371 value.x = (float)(rgba & 0xFF) * sc;
372 value.y = (float)((rgba >> 8) & 0xFF) * sc;
373 value.z = (float)((rgba >> 16) & 0xFF) * sc;
374 value.w = (float)(rgba >> 24) * sc;
376 color(
float r,
float g,
float b,
float a = 1.0f)
387 inline operator std::uint32_t()
const
391 inline operator vec4()
const
396 inline void set_hsv(
float h,
float s,
float v,
float a = 1.0f)
402 static color hsv(
float h,
float s,
float v,
float a = 1.0f)
411 float s = 1.0f / 255.0f;
412 return vec4((in & 0xFF) * s, ((in >> 8) & 0xFF) * s, ((in >> 16) & 0xFF) * s, (in >> 24) * s);
418 out = ((std::uint32_t)(saturate(in.x) * 255.0f));
419 out |= ((std::uint32_t)(saturate(in.y) * 255.0f)) << 8;
420 out |= ((std::uint32_t)(saturate(in.z) * 255.0f)) << 16;
421 out |= ((std::uint32_t)(saturate(in.w) * 255.0f)) << 24;
428 static void rgb_to_hsv(
float r,
float g,
float b,
float& out_h,
float& out_s,
float& out_v)
446 const float chroma = r - (g <
b ? g :
b);
447 out_h = glm::abs(K + (g -
b) / (6.f * chroma + 1e-20f));
448 out_s = chroma / (r + 1e-20f);
455 static void hsv_to_rgb(
float h,
float s,
float v,
float& out_r,
float& out_g,
float& out_b)
460 out_r = out_g = out_b = v;
464 h = glm::mod(h, 1.0f) / (60.0f / 360.0f);
466 float f = h - float(i);
467 float p = v * (1.0f - s);
468 float q = v * (1.0f - s * f);
469 float t = v * (1.0f - s * (1.0f - f));
int count(const generator_t &generator) noexcept
Counts the number of steps left in the generator.
std::uint32_t compute_projected_sphere_rect(std::int32_t &left, std::int32_t &right, std::int32_t &top, std::int32_t &bottom, const glm::vec3 &sphere_center, float radius, const glm::vec3 &view_origin, const glm::mat4 &view, const glm::mat4 &proj)
std::uint32_t power_of_n_round_down(std::uint32_t val, std::uint32_t n)
float halton(std::uint32_t Index, std::uint32_t Base)
bool compute_projected_sphere_shaft(float light_x, float light_z, float radius, const glm::mat4 &proj, const glm::vec3 &axis, float axis_sign, std::int32_t &in_out_min_x, std::int32_t &in_out_max_x)
bool is_negative_float(const float &A)
auto start(seq_action action, const seq_scope_policy &scope_policy, hpp::source_location location) -> seq_id_t
Starts a new action.
static vec4 u32_to_float4(std::uint32_t in)
void set_hsv(float h, float s, float v, float a=1.0f)
static color random(const std::string &seed)
Generates a consistent random color based on a string seed.
color(std::uint32_t rgba)
static void rgb_to_hsv(float r, float g, float b, float &out_h, float &out_s, float &out_v)
static std::uint32_t float4_to_u32(const vec4 &in)
static color random(const char *seed)
Generates a consistent random color based on a string seed.
static color transparent()
static void hsv_to_rgb(float h, float s, float v, float &out_r, float &out_g, float &out_b)
static color hsv(float h, float s, float v, float a=1.0f)
color(int r, int g, int b, int a=255)
color(float r, float g, float b, float a=1.0f)