diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-28 13:43:27 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-28 14:46:39 -0700 |
| commit | 5b732ae3d8bf19d4fbade236f318df0f7221cdd2 (patch) | |
| tree | 523d17d144ac77e2c318629ff7be47e38b465382 /pbr.cginc | |
| parent | 06036b0452fdbc46d7372e79d09fc05da822ad4c (diff) | |
Begin work on Burley's per-pixel histogram preserving blending
Diffstat (limited to 'pbr.cginc')
| -rwxr-xr-x | pbr.cginc | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -181,6 +181,37 @@ void apply_letter_grid(v2f i, inout Pbr pbr) { #endif } +void apply_burley_tiling(v2f i, inout Pbr pbr) { +#if defined(_BURLEY_TILING) + float2 uv = i.uv01.xy - 0.5; + uv *= TWO_OVER_SQRT_3; + uv /= _Burley_Tiling_Output_Scale; + float3 hex_coord = cart_to_hex(uv); + float3 cell = round_hex(hex_coord); + float3 cube_id = float3(cell.y, cell.z, -cell.y - cell.z); + float3 local_hex = hex_coord - cell; + // Get UVs on [-1/2,1/2] for the current cell. + // This is the tightest square fit that preserves the hex aspect ratio. + float2 local_uv = hex_to_cart(local_hex) * SQRT_3_OVER_2; + float3 tile_rand3 = hash33_fast(cube_id); + // Apply input scaling. + float input_scale = saturate(_Burley_Tiling_Input_Scale); + local_uv *= input_scale; + // Rotate. + float theta = hash31_ff(tile_rand3) * TAU; + float2x2 rot = float2x2(cos(theta), -sin(theta), sin(theta), cos(theta)); + local_uv = mul(rot, local_uv); + // Apply randomized offset, staying within bounds. + // The scaled-and-rotated footprint is bounded by [-Input_Scale / 2, Input_Scale / 2], + // so we can offset by [(1 - Input_Scale) / 2]. + float2 random_offset = (tile_rand3.yz * 2.0 - 1.0) * (0.5 * (1.0 - input_scale)); + local_uv += random_offset; + // Finally, remap onto [0, 1]. + local_uv += 0.5; + pbr.albedo.xy = local_uv.xy; +#endif // _BURLEY_TILING +} + Pbr getPbr(v2f i) { Pbr pbr = (Pbr) 0; @@ -227,6 +258,7 @@ Pbr getPbr(v2f i) { apply_marble(i.worldPos, pbr.albedo.xyz); apply_kintsugi(i.worldPos, pbr.albedo.xyz, pbr.smoothness, pbr.metallic); apply_letter_grid(i, pbr); + apply_burley_tiling(i, pbr); applyDecals(i, pbr, normal_tangent); |
