All Projects → tsherif → Picogl.js

tsherif / Picogl.js

Licence: mit
A minimal WebGL 2 rendering library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Picogl.js

Helixjs
A Javascript 3D game engine.
Stars: ✭ 84 (-87.48%)
Mutual labels:  3d, webgl, webgl2
Spritejs
A cross platform high-performance graphics system.
Stars: ✭ 4,712 (+602.24%)
Mutual labels:  3d, webgl, webgl2
Three.js
JavaScript 3D Library.
Stars: ✭ 78,237 (+11559.76%)
Mutual labels:  3d, webgl, webgl2
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+54.84%)
Mutual labels:  3d, webgl, webgl2
Babylon.js
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
Stars: ✭ 15,479 (+2206.86%)
Mutual labels:  3d, webgl, webgl2
Webgl2examples
Rendering algorithms implemented in raw WebGL 2.
Stars: ✭ 353 (-47.39%)
Mutual labels:  3d, webgl, webgl2
Spector.js
Explore and Troubleshoot your WebGL scenes with ease.
Stars: ✭ 599 (-10.73%)
Mutual labels:  3d, webgl, webgl2
React Force Graph
React component for 2D, 3D, VR and AR force directed graphs
Stars: ✭ 589 (-12.22%)
Mutual labels:  3d, webgl
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (-35.32%)
Mutual labels:  3d, webgl
Ray Tracing Renderer
[UNMAINTAINED] Real-time path tracing on the web with three.js
Stars: ✭ 444 (-33.83%)
Mutual labels:  webgl, webgl2
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (-33.68%)
Mutual labels:  3d, webgl
Detect Gpu
Classifies GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications.
Stars: ✭ 460 (-31.45%)
Mutual labels:  webgl, webgl2
Webglstudio.js
A full open source 3D graphics editor in the browser, with scene editor, coding pad, graph editor, virtual file system, and many features more.
Stars: ✭ 4,508 (+571.83%)
Mutual labels:  3d, webgl
Butterchurn
Butterchurn is a WebGL implementation of the Milkdrop Visualizer
Stars: ✭ 592 (-11.77%)
Mutual labels:  webgl, webgl2
Webworldwind
The NASA WorldWind Javascript SDK (WebWW) includes the library and examples for creating geo-browser web applications and for embedding a 3D globe in HTML5 web pages.
Stars: ✭ 628 (-6.41%)
Mutual labels:  3d, webgl
Glchaos.p
3D GPUs Strange Attractors and Hypercomplex Fractals explorer - up to 256 Million particles in RealTime
Stars: ✭ 590 (-12.07%)
Mutual labels:  webgl, webgl2
Beam
✨ Expressive WebGL
Stars: ✭ 383 (-42.92%)
Mutual labels:  3d, webgl
Xbsjearthui
XbsjEarthUI是基于Cesium和EarthSDK的三维GIS/BIM的UI模板,可以基于此定制自己的三维App
Stars: ✭ 373 (-44.41%)
Mutual labels:  3d, webgl
Itowns
A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
Stars: ✭ 517 (-22.95%)
Mutual labels:  3d, webgl
Graph Visualization
3D graph visualization with WebGL / Three.js
Stars: ✭ 507 (-24.44%)
Mutual labels:  3d, webgl

PicoGL.js

Build Status Coverage Status GZIP size Gitter License NPM

API Docs | Tutorial | Chat

PicoGL.js is a minimal WebGL 2 rendering library. It's meant for developers who understand the WebGL 2 rendering pipeline and want to use it, but with a more convenient API. Typical usage of PicoGL.js will involve creating programs, vertex buffers, vertex arrays, uniform buffers, framebuffers, textures, transform feedbacks, and combining them into draw calls.


    // Create App which manages all GL state
    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);
    
    // Create Program
    // Shaders are compiled in parallel if supported by the platform.
    app.createPrograms([vertexShaderSource, fragmentShaderSource]).then(([program]) => {
        // Create a buffer of vertex attributes
        let positions = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
            -0.5, -0.5,
             0.5, -0.5,
             0.0,  0.5
        ]));

        // VertexArray manages attribute buffer state
        let vertexArray = app.createVertexArray()
        .vertexAttributeBuffer(0, positions);

        // UniformBuffer allows multiple uniforms to be bound
        // as a single block of memory.
        // First part defines layout of the UniformBuffer.
        // Second part updates values.
        let uniformBuffer = app.createUniformBuffer([
            PicoGL.FLOAT_VEC4,
            PicoGL.FLOAT_VEC4
        ])
        .set(0, new Float32Array([1.0, 0.0, 0.0, 0.3]))
        .set(1, new Float32Array([0.0, 0.0, 1.0, 0.7]))
        .update();

        // Create DrawCall from Program and VertexArray (both required),
        // and a UniformBuffer.
        let drawCall = app.createDrawCall(program, vertexArray)
        .uniformBlock("ColorUniforms", uniformBuffer);

        // Draw
        app.clear();
        drawCall.draw();
    });

Note that PicoGL.js is not a scene graph library. There are no objects, hierarchies, transforms, materials, etc. It has been designed only to make management of GPU state more convenient. Its conceptual model maps fairly directly to the constructs one deals with when writing directly with the WebGL 2 API. The only higher-level construct is the draw call, which manages sets of related lower-level constructs.

Usage

PicoGL.js can be used directly by downloading the built source and loading it via a script tag:

    <script src="js/picogl.min.js"></script>

or it can be installed via npm:

    npm install picogl

and loaded via ES6-style import:

    import PicoGL from "picogl";

Features

PicoGL.js simplifies usage of some more complex WebGL 2 features, such as multiple render targets, uniform buffers, transform feedback and instanced drawing.

Multiple Render Targets

    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);


    // Texture render targets
    let colorTarget0 = app.createTexture2D(app.width, app.height);
    let colorTarget1 = app.createTexture2D(app.width, app.height);
    let depthTarget = app.createTexture2D(app.width, app.height, {
        internalFormat: PicoGL.DEPTH_COMPONENT16
    });


    // Create framebuffer with color targets at attachments 
    // 0 and 1, and a depth target.
    let framebuffer = app.createFramebuffer()
    .colorTarget(0, colorTarget0)
    .colorTarget(1, colorTarget1)
    .depthTarget(depthTarget);
    
    // ... set up programs and vertex arrays for offscreen and
    // main draw passes...
    
    let offscreenDrawCall = app.createDrawCall(offscreenProgram, offscreenVAO);

    // Bind main program texture samplers to framebuffer targets
    let mainDrawCall = app.createDrawCall(mainProgram, mainVAO)
    .texture("texture1", framebuffer.colorAttachments[0])
    .texture("texture2", framebuffer.colorAttachments[1])
    .texture("depthTexture", framebuffer.depthAttachment);

    // Offscreen pass
    app.drawFramebuffer(framebuffer).clear();
    offscreenDrawCall.draw();
    
    // Main draw pass
    app.defaultDrawFramebuffer().clear()
    mainDrawCall.draw();

Uniform Buffers

    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);
    
    // ... set up program and vertex array...

    // Layout is std140
    let uniformBuffer = app.createUniformBuffer([
        PicoGL.FLOAT_MAT4,
        PicoGL.FLOAT_VEC4,
        PicoGL.INT_VEC4,
        PicoGL.FLOAT
    ])
    .set(0, matrix)
    .set(1, float32Vector)
    .set(2, int32Vector)
    .set(3, scalar)
    .update();      // Data only sent to GPU when update() is called

    let drawCall = app.createDrawCall(program, vertexArray)
    .uniformBlock("UniformBlock", uniformBuffer);

Transform Feedback

    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);

    // Last argument is transform feedback varyings
    app.createPrograms([vertexShaderSource, fragmentShaderSource, ["vPosition"]]).then(([program]) => {
        let positions1 = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
            -0.5, -0.5,
             0.5, -0.5,
             0.0,  0.5
        ]));
        let vertexArray = app.createVertexArray()
        .vertexAttributeBuffer(0, positions1);

        // Empty destination buffer of 6 floats
        let positions2 = app.createVertexBuffer(PicoGL.FLOAT, 2, 6);  

        // Capture transform results into positions2 buffer
        let transformFeedback = app.createTransformFeedback()
        .feedbackBuffer(0, positions2);

        let drawCall = app.createDrawCall(program, vertexArray)
        .transformFeedback(transformFeedback);

        app.clear();
        drawCall.draw();
    });

Instanced Drawing

    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);

    // The starting positions of the triangle. Each pair of coordinates
    // will be passed per-vertex
    let positions = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
        -0.3, -0.3,
         0.3, -0.3,
         0.0,  0.3
    ]));

    // This is an instance buffer meaning each pair of numbers will be passed
    // per-instance, rather than per-vertex
    let offsets = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
        -0.5, 0.0,
         0.0, 0.2,
         0.5, 0.0
    ]));

    // This vertex array is set up to draw 3 instanced triangles 
    // with the offsets given above
    let vertexArray = app.createVertexArray()
    .vertexAttributeBuffer(0, positions); // Pass positions per-vertex
    .instanceAttributeBuffer(1, offset); // Pass offsets per-instance
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].