npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fragl

v1.0.11

Published

Small WebGL lib for shader compositions

Downloads

4

Readme

___________               ________.____     
\_   _____/___________   /  _____/|    |    
 |    __) \_  __ \__  \ /   \  ___|    |    
 |     \   |  | \// __ \\    \_\  \    |___ 
 \___  /   |__|  (____  /\______  /_______ \
     \/               \/        \/        \/

This is a small lib for WebGl shader effects.

  • It is not intended for moving vertices or 3d work.
  • It is good for creating animated and interactive graphics within fragment shaders and rendering to frame buffers for multiple shader passes and also stacking graphical layers for compositions.

Usage

    // import the fragl lib
    import FraGL from 'FraGL'

    // get canvas
    const canvas = document.querySelector('.canvas');

    // pass canvas to fragl constructor
    const fragl = new FraGL(args)

So thats the basic setup, contructor args are all optional, if no canvas is given then it will create a canvas element and it will be stored at fragl.domElement


    // defautls
    const args = {
        canvas: canvasDomEl, 
        clearColor: [0,0,0,0], 
        imageLoadColor = [255, 150, 150, 255], 
        size:{
            width: window.innerWidth, 
            height: window.innerHeight 
        },
        trasparent: false, 
        premultipliedAlpha: false,         
        antialias: false
        depth: false
    }
  • canvas
    • canvas dom el
  • clearColor
    • 4 part array (rgba) values between 0 and 1
  • imageLoadColor
    • 4 part array (rgba) values between 0 and 255;
  • size
    • object of width and height
  • trasparent
    • Boolean that indicates if the canvas contains an alpha buffer.
  • premultipliedAlpha
    • Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied
  • antialias
    • Boolean that indicates whether or not to perform anti-aliasing.
  • depth
    • Boolean that indicates that the drawing buffer has a depth buffer of at least 16 bits.

And to resize the FraGL renderer

    fragl.setSize(width,height)

Creating render layers


    //.createRenderLayer( 'name'= String, args = Object );

    const renderLayer = fragl.createRenderLayer('render-layer', {
        uniforms:{ 
            // dummy uniforms made up for the sake of demonstration
            u_res:{
                value: [ width, height ] // vec2
            },
            u_texture:{
                value: texture // texture
            },
            u_val:{
                value: 1. // float
            }
        },
        vertex:vertexShader, // string
        fragment:fragmentShader // string
    })

Updating uniforms

    renderLayer.uniforms['u_res'].value = [ width, height ]

Create a texture from an image

    const texture = fragl.textureFromImage('./path/to/image.jpg');

Creating render texture

    const renderTexture = fragl.createRenderTexture({
        width: window.innerWidth,
        height: window.innerHeight
    });

    renderLayer.uniforms['u_texture'].value = renderTexture.texture

and to resize

    renderTexture.setSize(w,h)

Rendering

    // render to canvas
    renderLayer.render()

    // render to renderTexture
    renderLayer.render(renderTexture)

an example

    render(){
        renderLayer1.render(renderTexture)

        renderLayer2.uniforms['u_texure'].value = renderTexture.texture

        renderLayer2.render()
    }

Vertex Shader

Something like this should be the base for your vertex shader

precision highp float;
attribute vec2 a_position;
attribute vec2 a_texcoord;

varying vec2 vUv;

void main() {
    vUv = a_texcoord;
    gl_Position = vec4(a_position, 0, 1);;
}