def compute_shader(
    index: (pyshader.RES_INPUT, "GlobalInvocationId", "i32"),
    pos1: (pyshader.RES_BUFFER, (0, 0), Array(vec4)),
    pos2: (pyshader.RES_BUFFER, (0, 1), Array(vec4)),
    material: (pyshader.RES_UNIFORM, (0, 2), LineStripMaterial.uniform_type),
):
    p = pos1[index] * 1.0
    dz = material.thickness
    pos2[index * 2 + 0] = vec4(p.x, p.y + dz, p.z, 1.0)
    pos2[index * 2 + 1] = vec4(p.x, p.y - dz, p.z, 1.0)
Beispiel #2
0
def fragment_shader(
        in_tex: (RES_TEXTURE, 0, "2d f32"),
        in_uv: (RES_INPUT, 0, vec2),
        in_rot: (RES_UNIFORM, 1, vec4),
        out_color: (RES_OUTPUT, 0, vec4),
):
    # Distance squared to center of circle
    d2 = in_uv.x**2 + in_uv.y**2

    # Check if outside of map boundary
    if d2 > 1.0:
        # density = math.exp(50.0 * (1.0 - r))  # Display atmosphere
        out_color = vec4(0, 0, 0, 0)
    else:
        # Camera rotation
        in_uv_rot = vec2(
            in_uv.x * math.cos(in_rot.z) + in_uv.y * math.sin(in_rot.z),
            in_uv.y * math.cos(in_rot.z) - in_uv.x * math.sin(in_rot.z))

        # Map transformation
        c = math.sqrt(1.0 - d2)
        lam = in_rot.x + math.atan2(
            in_uv_rot.x,
            c * math.cos(in_rot.y) - in_uv_rot.y * math.sin(in_rot.y))
        phi = math.asin(c * math.sin(in_rot.y) +
                        in_uv_rot.y * math.cos(in_rot.y))

        # Get coordinates of color on texture
        uvCoord = vec2((lam / math.pi + 1.0) % 2.0 - 1.0, 2.0 * phi / math.pi)
        texCoords = ivec2((uvCoord + vec2(1, -1)) * vec2(800, -400))

        # Get normal in globe reference frame
        norm = math.normalize(
            vec3(
                math.cos(phi) * math.cos(lam),
                math.cos(phi) * math.sin(lam), math.sin(phi)))

        # Set light direction
        light = vec3(math.sin(in_rot.w), math.cos(in_rot.w), -.1 * in_rot.z)
        # Get light intensity
        intensity = norm @ math.normalize(light)
        # Set ambient lighting
        ambient = .1
        # Check if in shadow
        if intensity < 0.0:
            shading = vec4(ambient, ambient, ambient, 1)
        else:
            intensity += ambient
            shading = vec4(intensity, intensity, intensity, 1)

        # Get texture color and apply shading
        out_color = in_tex.read(texCoords).zyxw * shading  # noqa
Beispiel #3
0
    def compute_shader(
            index_xyz: ("input", "GlobalInvocationId", ivec3),
            data1: ("buffer", 0, Array(vec4)),
            data2: ("buffer", 1, Array(vec4)),
            data3: ("buffer", 2, Array(vec4)),
    ):
        index = index_xyz.x
        v = data1[index].x
        mi = data1[index].y
        ma = data1[index].z

        data2[index] = vec4(min(v, ma), max(v, mi), clamp(v, mi, ma), 0.0)
        data3[index] = vec4(nmin(v, ma), nmax(v, mi), nclamp(v, mi, ma), 0.0)
Beispiel #4
0
 def fragment_shader(
         tex: ("texture", 0, "2d i32"),
         sampler: ("sampler", 1, ""),
         tcoord: ("input", 0, vec2),
         out_color: ("output", 0, vec4),
 ):
     out_color = vec4(tex.sample(sampler, tcoord)) / 255.0  # noqa
def fragment_shader(
    out_color: (pyshader.RES_OUTPUT, 0, vec4),
    stdinfo: (pyshader.RES_UNIFORM, (0, 0), stdinfo_uniform_type),
    material: (pyshader.RES_UNIFORM, (0, 1), LineStripMaterial.uniform_type),
):
    out_color = vec4(material.color.rgb,
                     1.0)  # noqa - shader assign to input arg
Beispiel #6
0
def compute_shader_tex_add(
        index=("input", "GlobalInvocationId", ivec3),
        tex1=("texture", 0, "2d rg16i"),
        tex2=("texture", 1, "2d r32f"),
):
    val = vec2(tex1.read(index.xy).xy)  # ivec2 -> vec2
    tex2.write(index.xy, vec4(val.x + val.y, 0.0, 0.0, 0.0))
Beispiel #7
0
 def fragment_shader(
         texcoord: ("input", 0, f32),
         outcolor: ("output", 0, vec4),
         tex: ("texture", (0, 1), "1d i32"),
         sampler: ("sampler", (0, 2), ""),
 ):
     outcolor = vec4(tex.sample(sampler, texcoord))  # noqa
Beispiel #8
0
def fragment_shader(
        v_texcoord: ("input", 0, vec2),
        s_sam: ("sampler", SAMPLER_BINDING, ""),
        t_tex: ("texture", TEXTURE_BINDING, "2d i32"),
        out_color: ("output", 0, vec4),
):
    value = f32(t_tex.sample(s_sam, v_texcoord).r) / 255.0
    out_color = vec4(value, value, value, 1.0)  # noqa - shader output
Beispiel #9
0
 def fragment_shader(
         tex: ("texture", 0, "2d r32f"),
         sampler: ("sampler", 1, ""),
         tcoord: ("input", 0, vec2),
         out_color: ("output", 0, vec4),
 ):
     val = f32(tex.sample(sampler, tcoord).r)
     out_color = vec4(val / 255.0, val / 255.0, 0.0, 1.0)  # noqa
Beispiel #10
0
 def fragment_shader(
         texcoord: ("input", 0, vec3),
         outcolor: ("output", 0, vec4),
         tex: ("texture", (0, 1), "3d r16i"),
         sampler: ("sampler", (0, 2), ""),
 ):
     # outcolor = vec4(tex.sample(sampler, texcoord))  # noqa
     outcolor = vec4(stdlib.sample(tex, sampler, texcoord))  # noqa
Beispiel #11
0
 def compute_shader(
         index_xyz: ("input", "GlobalInvocationId", ivec3),
         data1: ("buffer", 0, Array(f32)),
         data2: ("buffer", 1, Array(vec4)),
 ):
     index = index_xyz.x
     a = data1[index]
     data2[index] = vec4(a**2, a**0.5, a**3.0, a**3.1)
Beispiel #12
0
 def compute_shader(
         index_xyz: ("input", "GlobalInvocationId", ivec3),
         data1: ("buffer", 0, Array(f32)),
         data2: ("buffer", 1, Array(vec4)),
 ):
     index = index_xyz.x
     a = data1[index]
     data2[index] = vec4(a**0.5, math.sqrt(a), stdlib.sqrt(a), 0.0)
Beispiel #13
0
def vertex_shader(
    index: (RES_INPUT, "VertexId", i32),
    pos: (RES_OUTPUT, "Position", vec4),
    color: (RES_OUTPUT, 0, vec3),
):
    positions = [vec2(+0.0, -0.5), vec2(+0.5, +0.5), vec2(-0.5, +0.7)]
    p = positions[index]
    pos = vec4(p, 0.0, 1.0)  # noqa
    color = vec3(p, 0.5)  # noqa
Beispiel #14
0
def vertex_shader(
        index=("input", "VertexId", i32),
        out_pos=("output", "Position", vec4),
        out_color=("output", 0, vec3),
):
    positions = [vec2(+0.0, -0.5), vec2(+0.5, +0.5), vec2(-0.5, +0.7)]

    p = positions[index]
    out_pos = vec4(p, 0.0, 1.0)  # noqa
    out_color = vec3(p, 0.5)  # noqa
Beispiel #15
0
def fragment_shader_textured_rgba(
        v_texcoord: (pyshader.RES_INPUT, 0, vec2),
        u_mesh: (pyshader.RES_UNIFORM, (1, 0), MeshBasicMaterial.uniform_type),
        s_sam: (pyshader.RES_SAMPLER, (1, 1), ""),
        t_tex: (pyshader.RES_TEXTURE, (1, 2), "2d i32"),
        out_color: (pyshader.RES_OUTPUT, 0, vec4),
):
    color = vec4(t_tex.sample(s_sam, v_texcoord))
    color = (color - u_mesh.clim[0]) / (u_mesh.clim[1] - u_mesh.clim[0])
    out_color = color  # noqa - shader output
Beispiel #16
0
 def compute_shader(
         index_xyz: ("input", "GlobalInvocationId", ivec3),
         data1: ("buffer", 0, Array(vec4)),
         data2: ("buffer", 1, Array(vec4)),
 ):
     index = index_xyz.x
     v = data1[index]
     v1 = mix(v.x, v.y, v.z)
     v2 = mix(vec2(v.x, v.x), vec2(v.y, v.y), v.z)
     data2[index] = vec4(v1, v2.x, v2.y, 0.0)
Beispiel #17
0
def vertex_shader(
        in_pos: ("input", 0, vec4),
        in_texcoord: ("input", 1, vec2),
        out_pos: ("output", "Position", vec4),
        v_texcoord: ("output", 0, vec2),
        u_locals: ("uniform", UNIFORM_BINDING, uniform_type),
):
    ndc = u_locals.transform * in_pos
    out_pos = vec4(ndc.xy, 0, 1)  # noqa - shader output
    v_texcoord = in_texcoord  # noqa - shader output
 def vertex_shader2(
     index: (RES_INPUT, "VertexId", i32),
     pos: (RES_OUTPUT, "Position", vec4),
 ):
     positions = [
         vec3(-0.5, -0.5, 0.0),
         vec3(-0.5, +0.5, 0.0),
         vec3(+0.5, -0.5, 0.2),
         vec3(+0.5, +0.5, 0.2),
     ]
     pos = vec4(positions[index], 1.0)  # noqa
def vertex_shader(
    # io
    in_pos: (pyshader.RES_INPUT, 0, vec4),
    out_pos: (pyshader.RES_OUTPUT, "Position", vec4),
    stdinfo: (pyshader.RES_UNIFORM, (0, 0), stdinfo_uniform_type),
    # resources
):
    world_pos = stdinfo.world_transform * vec4(in_pos.xyz, 1.0)
    ndc_pos = stdinfo.projection_transform * stdinfo.cam_transform * world_pos

    out_pos = ndc_pos  # noqa - shader assign to input arg
Beispiel #20
0
def fragment_shader_textured_gray(
        v_texcoord: (pyshader.RES_INPUT, 0, vec3),
        u_mesh: (pyshader.RES_UNIFORM, (1, 0),
                 MeshVolumeSliceMaterial.uniform_type),
        s_sam: (pyshader.RES_SAMPLER, (1, 1), ""),
        t_tex: (pyshader.RES_TEXTURE, (1, 2), "3d i32"),
        out_color: (pyshader.RES_OUTPUT, 0, vec4),
):
    val = f32(t_tex.sample(s_sam, v_texcoord).r)
    val = (val - u_mesh.clim[0]) / (u_mesh.clim[1] - u_mesh.clim[0])
    out_color = vec4(val, val, val, 1.0)  # noqa - shader output
Beispiel #21
0
def vertex_shader(
        in_pos: (pyshader.RES_INPUT, 0, vec4),
        in_texcoord: (pyshader.RES_INPUT, 1, vec2),
        out_pos: (pyshader.RES_OUTPUT, "Position", vec4),
        v_texcoord: (pyshader.RES_OUTPUT, 0, vec2),
        u_stdinfo: (pyshader.RES_UNIFORM, (0, 0), stdinfo_uniform_type),
):
    world_pos = u_stdinfo.world_transform * vec4(in_pos.xyz, 1.0)
    ndc_pos = u_stdinfo.projection_transform * u_stdinfo.cam_transform * world_pos

    out_pos = ndc_pos  # noqa - shader output
    v_texcoord = in_texcoord  # noqa - shader output
 def vertex_shader(
     index: (RES_INPUT, "VertexId", i32),
     pos: (RES_OUTPUT, "Position", vec4),
     pointsize: (RES_OUTPUT, "PointSize", f32),
 ):
     positions = [
         vec2(-0.5, -0.5),
         vec2(-0.5, +0.5),
         vec2(+0.5, -0.5),
         vec2(+0.5, +0.5),
     ]
     p = positions[index]
     pos = vec4(p, 0.0, 1.0)  # noqa
     pointsize = 16.0  # noqa
Beispiel #23
0
def vertex_shader(
        index: ("input", "VertexId", i32),
        pos: ("output", "Position", vec4),
        tcoord: ("output", 0, vec2),
):
    positions = [
        vec2(-0.5, -0.5),
        vec2(-0.5, +0.5),
        vec2(+0.5, -0.5),
        vec2(+0.5, +0.5),
    ]
    p = positions[index]
    pos = vec4(p, 0.0, 1.0)  # noqa
    tcoord = vec2(p + 0.5)  # noqa - map to 0..1
Beispiel #24
0
def vertex_shader(
    in_pos: ("input", 0, vec4),
    u_stdinfo: ("uniform", (0, 0), stdinfo_uniform_type),
    u_points: ("uniform", (1, 0), PointsMaterial.uniform_type),
    out_pos: ("output", "Position", vec4),
    out_point_size: ("output", "PointSize", f32),
    out_size: ("output", 0, f32),
):
    world_pos = u_stdinfo.world_transform * vec4(in_pos.xyz, 1.0)
    ndc_pos = u_stdinfo.projection_transform * u_stdinfo.cam_transform * world_pos

    scale_factor = u_stdinfo.physical_size.x / u_stdinfo.logical_size.x
    size = u_points.size * scale_factor + 1.5  # plus some for aa

    out_pos = ndc_pos  # noqa - shader output
    out_point_size = size  # noqa - shader output
    out_size = size  # noqa - shader output
Beispiel #25
0
def fragment_shader_gaussian(
    in_size: ("input", 0, f32),
    in_point_coord: ("input", "PointCoord", vec2),
    u_points: ("uniform", (1, 0), PointsMaterial.uniform_type),
    out_color: ("output", 0, vec4),
):
    color = u_points.color
    pcoord_pixels = in_point_coord * in_size
    hsize = 0.5 * (in_size - 1.5)
    sigma = hsize / 3.0
    d = distance(pcoord_pixels, vec2(hsize, hsize))
    if d <= hsize:
        t = d / sigma
        a = exp(-0.5 * t * t)
        out_color = vec4(color.rgb, color.a * a)  # noqa - shader output
    else:
        return  # discard
Beispiel #26
0
def vertex_shader(
        index: (RES_INPUT, "VertexId", i32),  # noqa
        pos: (RES_OUTPUT, "Position", vec4),  # noqa
        uv: (RES_OUTPUT, 0, vec2),
):
    # 6 vertices. TODO: Update with uniform to keep ratio
    positions = [
        vec2(1, 1),
        vec2(-1, 1),
        vec2(-1, -1),
        vec2(1, 1),
        vec2(1, -1),
        vec2(-1, -1)
    ]
    p = positions[index]
    pos = vec4(p, 0.0, 1.0)  # noqa
    uv = p  # noqa
Beispiel #27
0
def fragment_shader_points(
    in_size: ("input", 0, f32),
    in_point_coord: ("input", "PointCoord", vec2),
    u_points: ("uniform", (1, 0), PointsMaterial.uniform_type),
    out_color: ("output", 0, vec4),
):
    # See https://github.com/vispy/vispy/blob/master/vispy/visuals/markers.py
    color = u_points.color
    pcoord_pixels = in_point_coord * in_size
    hsize = 0.5 * (in_size - 1.5)
    aa_width = 1.0
    d = distance(pcoord_pixels, vec2(hsize, hsize))
    if d <= hsize - 0.5 * aa_width:
        out_color = u_points.color.rgba  # noqa - shader output
    elif d <= hsize + 0.5 * aa_width:
        alpha = 0.5 + (hsize - d) / aa_width
        alpha = alpha ** 2  # this works better
        out_color = vec4(color.rgb, color.a * alpha)  # noqa - shader output
    else:
        return  # discard
 def fragment_shader(
     out_color: (RES_OUTPUT, 0, vec4),
 ):
     out_color = vec4(1.0, 0.499, 0.0, 1.0)  # noqa
 def vertex_shader(
     pos_in: (RES_INPUT, 0, vec2),
     pos: (RES_OUTPUT, "Position", vec4),
 ):
     pos = vec4(pos_in, 0.0, 1.0)  # noqa
Beispiel #30
0
 def compute_shader(
         index: ("input", "GlobalInvocationId", ivec3),
         data2: ("buffer", 1, Array(vec4)),
 ):
     data2[index.x] = vec4(7.0, 3, ivec2(False, 2.7))