ttypt/chaff_glsl.h(3)chaff

NAME

ttypt/chaff_glsl.h - Canonical GLSL ES 3.0 / WebGL 2 shader source contract, UBO packing helpers, and bit-exact CPU reference evaluators for libchaff.

SYNOPSIS

#include <stdint.h>
#include <math.h>
#include <ttypt/chaff_surf.h>

Data Structures

struct chaff_gl_uniforms_t
struct chaff_glsl_ref_vec4_t

4-component float vector returned by CPU reference 3D/4D gradient noise evaluators.

struct chaff_glsl_ref_vec5_t

5-component float vector (value + 4D gradient) returned by 4D reference evaluators.

struct chaff_surf_ubo_t

std140-aligned GPU Uniform Buffer Object representation of chaff_surf_t.

Macros

#define CHAFF_GLSL_VERSION

GLSL ES 3.0 header directive with highp float/int precision.

#define CHAFF_GLSL_HASH_FN
#define CHAFF_GLSL_GRAD2D_NORM 0.70710678f

Normalization factor for 2D GLSL gradient noise.

#define CHAFF_GLSL_GRAD4D_NORM 0.72f

Normalization factor for 4D GLSL gradient noise.

#define CHAFF_GLSL_DEFAULT_RIDGE_OCTAVE_STEP 0.25f

Default per-octave ridge step increment for GLSL multi-warp evaluation.

#define CHAFF_GLSL_GRAD_NOISE_FN
#define CHAFF_GLSL_BAND_FN
#define CHAFF_GLSL_EVAL_FN
#define CHAFF_GLSL_EVAL_MULTI_FN

GLSL ES 3.0 multi-layer warped noise evaluation shader snippet.

#define CHAFF_GLSL_FULLSCREEN_FRAG

Complete fullscreen GLSL ES 3.0 fragment shader source for noise evaluation.

#define CHAFF_MULTI_WARP_PARAMS_DEFAULT

Default initializer macro for chaff_multi_warp_params_t.

#define CHAFF_GLSL_SURF_FN

GLSL ES 3.0 continuous multi-scale surface evaluator matching chaff_surf.h.

Functions

static const char * chaff_glsl_fragment_shader_source (void)

Return the complete GLSL ES 3.0 fullscreen fragment shader source string.

static uint32_t chaff_glsl_ref_rotl32 (uint32_t x, int r)
static uint32_t chaff_glsl_ref_hash2 (int16_t y, int16_t x, uint32_t seed)

CPU reference implementation of GLSL chaff_hash2().

static float chaff_glsl_ref_sample_octave (float wx, float wy, unsigned shift, unsigned vshift, uint32_t seed)

CPU reference implementation of single-octave 2D GLSL noise sampling.

static uint32_t chaff_glsl_ref_hash3 (int16_t x, int16_t y, int16_t z, uint32_t seed)

CPU reference implementation of GLSL chaff_hash3().

static float chaff_glsl_ref_sample_3d_ex (float wx, float wy, float wz, unsigned shift, unsigned vshift, uint32_t seed)

CPU reference implementation of extended 3D GLSL noise sampling.

static float chaff_glsl_ref_sample_3d (float wx, float wy, float wz, unsigned shift, uint32_t seed)

CPU reference implementation of 3D GLSL noise sampling.

static chaff_glsl_ref_vec4_t chaff_glsl_ref_sample_grad_3d_ex (float wx, float wy, float wz, unsigned shift, unsigned vshift, uint32_t seed)

CPU reference implementation of extended 3D value-noise with analytical gradient.

static chaff_glsl_ref_vec4_t chaff_glsl_ref_sample_grad_3d (float wx, float wy, float wz, unsigned shift, uint32_t seed)

CPU reference implementation of 3D value-noise with analytical gradient.

static uint32_t chaff_glsl_ref_hash4 (int16_t x, int16_t y, int16_t z, int16_t w, uint32_t seed)

CPU reference implementation of GLSL chaff_hash4().

static float chaff_glsl_ref_sample_4d_ex (float wx, float wy, float wz, float ww, unsigned shift, unsigned vshift, uint32_t seed)

CPU reference implementation of extended 4D GLSL noise sampling.

static float chaff_glsl_ref_sample_4d (float wx, float wy, float wz, float ww, unsigned shift, uint32_t seed)

CPU reference implementation of 4D GLSL noise sampling.

static chaff_glsl_ref_vec5_t chaff_glsl_ref_sample_grad_4d_ex (float wx, float wy, float wz, float ww, unsigned shift, unsigned vshift, uint32_t seed)

CPU reference implementation of extended 4D value-noise with analytical gradient.

static chaff_glsl_ref_vec5_t chaff_glsl_ref_sample_grad_4d (float wx, float wy, float wz, float ww, unsigned shift, uint32_t seed)

CPU reference implementation of 4D value-noise with analytical gradient.

static void chaff_glsl_ref_grad_dir (int32_t cx, int32_t cy, uint32_t seed, float *out_gx, float *out_gy)
static void chaff_glsl_ref_grad_noise2d_ex (float px, float py, uint32_t seed, float grad_norm, float *out_val, float *out_gx, float *out_gy)

CPU reference implementation of extended 2D gradient noise with custom norm.

static void chaff_glsl_ref_grad_noise2d (float px, float py, uint32_t seed, float *out_val, float *out_gx, float *out_gy)

CPU reference implementation of 2D GLSL gradient noise.

static void chaff_glsl_ref_value_grad_noise2d (float px, float py, uint32_t seed, float *out_val, float *out_gx, float *out_gy)

CPU reference implementation of 2D value-gradient noise.

static float chaff_glsl_ref_lowpass_weight (float wavelength, float step_wu)

CPU reference implementation of GLSL Nyquist low-pass weight.

static float chaff_glsl_ref_band_weight (float wavelength, float fine_step_wu, float coarse_step_wu)

CPU reference implementation of GLSL Nyquist band-pass weight.

static void chaff_glsl_ref_grad4 (int32_t cx, int32_t cy, int32_t cz, int32_t cw, uint32_t seed, float out_g[4])

CPU reference 4D gradient vector lookup.

static chaff_glsl_ref_vec4_t chaff_glsl_ref_grad_noise4d_ex (float px, float py, float pz, float pw, uint32_t seed, float grad_norm)

CPU reference implementation of extended 4D gradient noise with custom norm.

static chaff_glsl_ref_vec4_t chaff_glsl_ref_grad_noise4d (float px, float py, float pz, float pw, uint32_t seed)

CPU reference implementation of 4D GLSL gradient noise.

static float chaff_glsl_ref_eval_uniforms (const chaff_gl_uniforms_t *u, float frag_x, float frag_y)

CPU reference evaluator matching the GLSL uniform-driven noise cascade.

static float chaff_glsl_ref_smoothstep (float e0, float e1, float x)

CPU reference implementation matching GLSL smoothstep(e0, e1, x).

static void chaff_glsl_ref_curl_2d (float px, float py, uint32_t seed, float *out_vx, float *out_vy)

CPU reference implementation of 2D GLSL curl noise.

static void chaff_glsl_ref_eval_multi_warped_ex (const chaff_multi_warp_params_t *params, float wx, float wy, float base_shift, uint32_t seed, float texel_span, float *out_val, float *out_gx, float *out_gy)

CPU reference implementation of extended multi-layer warped GLSL noise.

static void chaff_surf_pack_ubo (const chaff_surf_t *c, chaff_surf_ubo_t *out)

Pack a host chaff_surf_t descriptor into a std140-aligned chaff_surf_ubo_t.

Detailed Description

Canonical GLSL ES 3.0 / WebGL 2 shader source contract, UBO packing helpers, and bit-exact CPU reference evaluators for libchaff.

ttypt/chaff_glsl.h โ€” Canonical GPU Shader Contract for libchaff.

Exposes GLSL ES 3.0 / WebGL 2 shader source strings and uniform layouts for hardware-accelerated procedural noise on clients.

INVARIANT: Bit-exact corner hashing matching XXH32(p, 4, seed) on CPU. Zero OpenGL/EGL runtime library links or compile-time dependencies on server.

Macro Definition Documentation

#define CHAFF_GLSL_BAND_FN

Value:

    "float chaff_lowpass_weight(float wavelength, float step_wu) {\n" \
    "    if (step_wu <= 0.0) return 1.0;\n" \
    "    float t = clamp((wavelength - 2.0 * step_wu) / (2.0 * step_wu), 0.0, 1.0);\n" \
    "    return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n" \
    "}\n" \
    "float chaff_band_weight(float wavelength, float fine_step_wu, float coarse_step_wu) {\n" \
    "    float w_fine = chaff_lowpass_weight(wavelength, fine_step_wu);\n" \
    "    if (w_fine <= 0.0) return 0.0;\n" \
    "    float w_coarse = chaff_lowpass_weight(wavelength, coarse_step_wu);\n" \
    "    return w_fine * (1.0 - w_coarse);\n" \
    "}\n"

Continuous scale-space C2 Nyquist low-pass and complementary band-pass weights

#define CHAFF_GLSL_EVAL_FN

Continuous cubic Hermite interpolation matching noise_wcorners and noise_wstep. Evaluates corner vertices at cell = floor(world_pos / 2^shift) * 2^shift.

#define CHAFF_GLSL_GRAD_NOISE_FN

Continuous C2-quintic 2D and 4D gradient noise with analytical spatial derivatives. Loop-free explicit corner evaluations for consumer GPU shader compiler friendliness.

#define CHAFF_GLSL_HASH_FN

Bit-exact XXH32 hash for 2D, 3D, and 4D lattice coordinates in GLSL ES 3.0. Memory layout matches int16_t va[2] = { y, x }, va[3] = { y, x, z }, and va[4] = { y, x, z, w } in little-endian.

Function Documentation

void chaff_glsl_ref_grad_dir (int32_t cx, int32_t cy, uint32_t seed, float * out_gx, float * out_gy) [inline], [static]

Reference C mirrors for CHAFF_GLSL_GRAD_NOISE_FN

uint32_t chaff_glsl_ref_rotl32 (uint32_t x, int r) [inline], [static]

Reference C implementation of the exact GLSL shader logic for CPU-GPU parity verification

Author

Generated automatically by Doxygen for chaff from the source code.