New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ogl

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ogl

WebGL Framework

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
decreased by-6.12%
Maintainers
1
Weekly downloads
 
Created
Source

O-GL

O-GL

version license

Minimal WebGL framework.


⚠️ Note: currently in alpha, so expect breaking changes.

Examples

O-GL is a small, effective WebGL framework aimed at developers who like minimal layers of abstraction, and are comfortable creating their own shaders.

With 0 dependencies, the API shares many similarities with ThreeJS, however it is tightly coupled with WebGL and comes with much fewer features.

In its design, the framework does the minimum abstraction necessary, so devs should still feel comfortable using it in conjunction with native WebGL commands.

Keeping the level of abstraction low helps to make the framework easier to understand and extend, and also makes it more practical as a WebGL learning resource.

Install

npm install ogl

or

Use directly in your project with es6 modules and load directly in the browser - no dev-stack required.

Examples

Show me what you got! - Explore a comprehensive list of examples, with comments in the source code.

Weight

Even though the source is completely modular, as a guide, below are the complete component download sizes.

ComponentSize (gzipped)
Core6kb
Math7kb
Extras2kb
Total15kb

Usage

Importing is done from a single point of access for simplicity. This may cause some issues with certain bundlers when tree-shaking.


import {Renderer, Camera, Transform, Cube, Program, Mesh} from './OGL.js';

Below renders a spinning black cube.


{
    const renderer = new Renderer({
        width: window.innerWidth,
        height: window.innerHeight,
    });
    const gl = renderer.gl;
    document.body.appendChild(gl.canvas);

    const camera = new Camera(gl, {
        fov: 35,
        aspect: gl.canvas.width / gl.canvas.height,
    });
    camera.position.z = 5;

    const scene = new Transform(gl);

    const geometry = new Cube(gl);

    const program = new Program(gl, {
        vertexShader: `
            attribute vec3 position;

            uniform mat4 modelViewMatrix;
            uniform mat4 projectionMatrix;

            void main() {
                gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
            }
            `,
        fragmentShader: `
            void main() {
                gl_FragColor = vec4(1.0);
            }
        `,
    });

    const mesh = new Mesh(gl, {geometry, program});
    mesh.setParent(scene);

    requestAnimationFrame(update);
    function update(t) {
        requestAnimationFrame(update);

        mesh.rotation.y -= 0.04;
        mesh.rotation.x += 0.03;
        renderer.render({scene, camera});
    }
}

Structure

In an attempt to leep things light and modular, the framework is split up into three components: Math, Core, and Extras.

The Math component is based on a fork of gl-matrix - featuring a practical API. 7kb when gzipped, it has no dependencies and can be used separately.

The Core is made up of the following:

  • Geometry.js
  • Program.js
  • Renderer.js
  • Camera.js
  • Transform.js
  • Mesh.js
  • Texture.js
  • RenderTarget.js

Any additional layers of abstraction will be included as Extras, and not part of the core as to reduce bloat.

Below is an Extras wish-list, and is still a work-in-progress as examples are developed.

  • Plane.js
  • Cube.js
  • Sphere.js
  • OrbitControls
  • Curve.js
  • Raycasting.js
  • Projection.js
  • Post.js
  • Rig.js
  • RigAnimation.js

Examples wishlist

Examples

In order to test the completeness of the framework, below is a wish-list that covers most commonly-used 3D techniques.

It is an opinionated, comprehensive list of examples for any fully-fledged WebGL framework.

Much inspired by ThreeJS' examples, they will serve as reference for how to achieve a wide range of techniques.

In order to make the framework as usable as possible, for more involved techniques, extra classes will be developed and contained within the 'Extras' folder of the framework.

Geometry

  • Triangle Screen Shader
  • Draw Modes
  • Indexed vs Non-Indexed
  • Load JSON (Javascript Object Notation)
  • Wireframe
  • Base Primitives - Plane, Cube, Sphere
  • Particles
  • Instancing
  • Billboard Depth Test (instances and points)
  • Frustum culling
  • LODs (Level Of Detail)
  • Thick Lines
  • Load GLTF (Graphics Language Transmission Format)

Scene

  • Scene Graph hierarchy
  • Render Hierarchy With Transparency

Interaction

  • Orbit controls
  • Raycasting
  • Projection (Mouse, clip space)

Shading

  • Fog
  • Textures
  • Skydome
  • Normal Maps
  • SDF Alpha test/clip (Signed Distance Fields)
  • MSDF Text Glyphs (Multichannel Signed Distance Fields)
  • Point lighting with specular highlights
  • PBR (Physically Based Rendering)

Frame Buffer

  • Render to texture
  • MRT (Multiple Render Targets)
  • Reflections
  • Shadow maps
  • Distortion (refraction)
  • Effects - DOF (Depth Of Field) + light rays + tone mapping

Animation

  • Skinning
  • Blendshapes

Stencil

  • Stencil Shadows and Mirror

Keywords

FAQs

Package last updated on 04 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc