All Projects → allotrop3 → Four

allotrop3 / Four

Licence: mit
Four: WebGL made easier -

Projects that are alternatives of or similar to Four

3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+4616.94%)
Mutual labels:  3d, webgl, shaders, 3d-graphics
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (+75%)
Mutual labels:  3d, webgl, 3d-graphics
Tinykaboom
A brief computer graphics / rendering course
Stars: ✭ 2,077 (+737.5%)
Mutual labels:  3d, shaders, 3d-graphics
Renderhelp
⚡️ 可编程渲染管线实现,帮助初学者学习渲染
Stars: ✭ 494 (+99.19%)
Mutual labels:  3d, shaders, 3d-graphics
React Regl
React Fiber Reconciler Renderer for Regl WebGL
Stars: ✭ 171 (-31.05%)
Mutual labels:  webgl, shaders, 3d-graphics
Tinyraytracer
A brief computer graphics / rendering course
Stars: ✭ 3,971 (+1501.21%)
Mutual labels:  3d, shaders, 3d-graphics
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 (+1717.74%)
Mutual labels:  3d, webgl, shaders
Glas
WebGL in WebAssembly with AssemblyScript
Stars: ✭ 278 (+12.1%)
Mutual labels:  3d, webgl, 3d-graphics
Renderer
A shader-based software renderer written from scratch in C89
Stars: ✭ 1,366 (+450.81%)
Mutual labels:  3d, shaders, 3d-graphics
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+318.95%)
Mutual labels:  3d, webgl, shaders
Webgl Fundamentals
WebGL lessons that start with the basics
Stars: ✭ 3,315 (+1236.69%)
Mutual labels:  3d, webgl, shaders
Yave
Yet Another Vulkan Engine
Stars: ✭ 211 (-14.92%)
Mutual labels:  3d, shaders, 3d-graphics
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (+79.44%)
Mutual labels:  3d, webgl, 3d-graphics
Awesome Creative Coding
Creative Coding: Generative Art, Data visualization, Interaction Design, Resources.
Stars: ✭ 8,696 (+3406.45%)
Mutual labels:  webgl, shaders, 3d-graphics
Tinyrenderer
A brief computer graphics / rendering course
Stars: ✭ 11,776 (+4648.39%)
Mutual labels:  3d, shaders, 3d-graphics
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (-34.27%)
Mutual labels:  3d, webgl, shaders
Unity Dithered Transparency Shader
Unity material and shader for applying clipped, dithered transparency
Stars: ✭ 174 (-29.84%)
Mutual labels:  3d, shaders
Aframe Effects
A VR Ready Post processing framework for Three.js and/or A-Frame
Stars: ✭ 176 (-29.03%)
Mutual labels:  webgl, shaders
Awesome Webgpu
😎 Curated list of awesome things around WebGPU ecosystem.
Stars: ✭ 182 (-26.61%)
Mutual labels:  3d, webgl
Satin
A 3D Graphics Framework built on Apple's Metal
Stars: ✭ 182 (-26.61%)
Mutual labels:  3d, shaders

Four is a slightly higher level graphics API based on WebGL 1.0. It abstracts only what is necessary to simplify getting started whilst still exposing the flexibility you would have using the WebGL API directly. Notably the classes defined map directly to the concepts familiar to an OpenGL application, including Attributes, Uniforms, Structures, Shaders, Programs and more; all of which implement the basic functions associated to them, but with fewer function calls to the user. This allows you, as the developer, to focus on what is important: getting something on the screen.

It uses the gl-matrix library, which is also included in the framework. The documentation for the gl-matrix librabry can be found here.

In case you want to learn more about Four and why I've built it, I suggest you to read the article I've published on SitePoint.

Demo

See a live demo.

Getting started

Simply download Four and include the script in your project.

<script src="path/to/four.min.js"></script>

Also be sure to include an HTML canvas element in your project. If no default width or height attributes are set, the framework assumes their respective window dimension.

<canvas width="500" height="500"></canvas>

Example

The following example assumes an OBJ mesh file loader to import a mesh into the scene. It further constructs a point light source and a three dimensional perspective projection to illuminate and visualise the scene, respectively. The scenes pre-render execution routine simply rotates the scene around the mesh.

JavaScript

<script>
   var context = new Four.Context({ selector: '#canvas' });
   var mesh_loader_1 = new Four.OBJMeshLoader({ path: 'path/to/mesh-1.obj', indexed: true });
   var mesh_loader_2 = new Four.OBJMeshLoader({ path: 'path/to/mesh-2.obj', indexed: true });
   var bundle = new Four.Bundle({ items: [mesh_1, mesh_2] });

   bundle.ready(function() {
      var program = new Four.Program({ selector: '.renderer' });
      var light = new Four.PointLight({ diffuse: 0xFFD1B2, location: [10, 15, 0] });
      var mesh_1 = new Four.Mesh({ loader: mesh_loader_1 });
      var mesh_2 = new Four.Mesh({ loader: mesh_loader_2 });
      var view = new Four.Framebuffer();
      var camera = new Four.PerspectiveCamera({ location: [10, 5, 5], width: context.canvas.width, height: context.canvas.height });
      var scene = new Four.Scene();
      
      scene.use(program);

      scene.put(light);
      
      scene.put(mesh_1);
      scene.put(mesh_2);
      
      scene.animate(view, camera, function() {
         scene.rotation += 0.25;
      });
   });
</script>

Shaders

Vertex shader
<script class="renderer" type="x-shader/x-vertex">
   #version 100
   
   precision mediump int;
   precision mediump float;

   @use Camera;

   attribute vec3 a_position;
   attribute vec3 a_normal;

   uniform Camera u_camera;

   varying vec4 v_position;
   varying vec3 v_normal;

   void main()
   {
      vec4 position = vec4(a_position, 1);

      gl_Position = u_camera.projectionMatrix * u_camera.modelViewMatrix * position;

      v_position = position;
      v_normal = u_camera.normalMatrix * a_normal;
   }
</script>
Fragment shader
<script class="renderer" type="x-shader/x-fragment">
   #version 100
   
   precision mediump int;
   precision mediump float;

   @use Material;
   @use PointLight;

   uniform Material u_material;
   uniform PointLight u_light;

   varying vec4 v_position;
   varying vec3 v_normal;

   void main()
   {
      vec3 lighting = PointLight_main(u_light, u_material, v_position, v_normal);

      gl_FragColor = vec4(lighting, 1);
   }
</script>

Documentation

See full documentation.

Author

Jason Petersen @allotrop3.

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].