rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/test_texture.sc -rw-r--r-- 2.4 KiB View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months 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
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env scopes

using import glm
using import glsl
using import ..tukan.gl
using import ..tukan.bitmap
using import .testfragment

import ..tukan.blur
let blur = tukan.blur

inline main ()
    #let image = (Bitmap4f (ivec2 256))
    #('fetch image 64 64) = 1

    let image =
        load-bitmap
            .. module-dir "/data/duangle_logo.png"
            components = 4
            float = true

    let test_texture = (GL.Texture2D)
    'setup test_texture
        bitmap = image

    uniform smp : sampler2D
        location = 2

    inline per-frame-setup ()
        GL.BindTextureUnit 0 (view test_texture)
        GL.Uniform smp 0

    inline shader (uv)
        let size =
            vec2 (textureSize smp 0)
        let texel = (1.0 / size)
        let pixel = (ivec2 (uv * size))
        #do
            # regular texel fetch
            texelFetch smp (pixel // 4) 2
        #do
            # texel fetch with offset
            texelFetchOffset smp pixel 0 (ivec2 64 64)
        do
            if (uv.x < 0.5)
                # basic interpolated sample
                pow
                    texture smp uv
                    vec4 0.4545
            else
                pow
                    blur.linear-moving-gauss-7x7 uv size
                        inline (uv offset)
                            texture smp ((uv + offset) * texel)
                    vec4 0.4545
                #pow
                    blur.bicubic uv size
                        inline (uv offset)
                            texture smp ((uv + offset) * texel)
                    vec4 0.4545

        #do
            # basic interpolated sample with lod bias
            texture smp uv (uv.y * 8.0)
        #do
            # texture with projection
            textureProj smp (vec3 uv (1.0 + uv.y))
        #do
            # texture with projection and lod bias
            textureProj smp (vec3 uv (1.0 + uv.y)) (uv.y * 8.0)
        #do
            # basic interpolated sample with explicit lod
            textureLod smp uv (uv.y * 8.0)
        #do
            # interpolated sample with offset
            textureOffset smp uv (ivec2 -64 64)
        #do
            # interpolated sample with offset and bias
            textureOffset smp uv (ivec2 -64 64) (uv.y * 8.0)

    # need to move test_texture to caller so resource survives
    _ per-frame-setup shader

render-fragment-shader main
    #debug = true
    size = (ivec2 256)