rev: 21c5e6d2f665d0e8b4ff917a51b664c895dab2ed tukan/tukan/hash.sc -rw-r--r-- 1.5 KiB View raw Log this file
21c5e6d2f665 — Leonard Ritter * renamed project from Liminal to Tukan 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using import glm

# from https://www.shadertoy.com/view/4djSRW
let HASHSCALE = 0.1031
#better for smaller / uv values:
let NHASHSCALE = 443.8975

fn f32hashf (p3 scale)
    "f32 <- (vec3 f32)"
    let p3 = (fract (p3 * scale))
    let p3 = (p3 + (dot p3 (p3.yzx + 19.19)))
    fract ((p3.x + p3.y) * p3.z)

fn vec2hashf (p3 scale)
    "vec2 <- (vec3 f32)"
    let p3 = (fract (p3 * scale))
    let p3 = (p3 + (dot p3 (p3.yzx + 19.19)))
    fract
        vec2
            (p3.x + p3.y) * p3.z
            (p3.x + p3.z) * p3.y

fn vec3hashf (p scale)
    "vec3 <- (vec3 f32)"
    let p3 =
        fract
            * p
                vec3 scale
                    scale * 1.51
                    scale * 2.53
    let p3 = (p3 + (dot p3 (p3.yzx + 19.19)))
    fract
        vec3
            (p3.x + p3.y) * p3.z
            (p3.x + p3.z) * p3.y
            (p3.y + p3.z) * p3.x

fn... f32hash
    (p : f32)
        f32hashf (vec3 p) HASHSCALE
    (p : vec2)
        f32hashf p.xyx HASHSCALE
    (p3 : vec3)
        f32hashf p3 HASHSCALE

fn... f32hashuv
    (p : f32)
        f32hashf (vec3 p) NHASHSCALE
    (p : vec2)
        f32hashf p.xyx NHASHSCALE
    (p3 : vec3)
        f32hashf p3 NHASHSCALE

fn vec2hash (p3)
    "vec2 <- (vec3)"
    vec2hashf p3 HASHSCALE

fn vec2hashuv (p3)
    "vec2 <- (vec3)"
    vec2hashf p3 NHASHSCALE

fn vec3hash (p)
    "vec3 <- (f32)"
    vec3hashf (vec3 p) HASHSCALE

#if main-module?
    print
        hash3 (vec3 1 2 3)

do
    let f32hash f32hashuv vec2hash vec2hashuv vec3hash
    locals;