All Projects → greggman → webgl-helpers

greggman / webgl-helpers

Licence: MIT License
some tiny webgl scripts that might come in handy

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to webgl-helpers

PintarJS
Micro JS lib for direct WebGL and canvas rendering.
Stars: ✭ 15 (-68.09%)
Mutual labels:  webgl2
gl-bench
⏱ WebGL performance monitor with CPU/GPU load.
Stars: ✭ 146 (+210.64%)
Mutual labels:  webgl2
webgl-dunes
WebGL dunes demo
Stars: ✭ 27 (-42.55%)
Mutual labels:  webgl2
KTX-Parse
KTX 2.0 (.ktx2) parser and serializer.
Stars: ✭ 23 (-51.06%)
Mutual labels:  webgl2
Shader-Playgrounds
A WebGL shaders editor for beginners and otherwise.
Stars: ✭ 28 (-40.43%)
Mutual labels:  webgl2
expo-gl
Expo module providing WebGL2 implementation
Stars: ✭ 18 (-61.7%)
Mutual labels:  webgl2
sdf-2d
A graphics library to enable the real-time rendering of 2D signed distance fields on the web.
Stars: ✭ 70 (+48.94%)
Mutual labels:  webgl2
nanogui-GLES-wasm
nanogui port for GLES and WASM
Stars: ✭ 37 (-21.28%)
Mutual labels:  webgl2
matcap-studio
An utility to tweak matcaps, with realtime visual feedback.
Stars: ✭ 51 (+8.51%)
Mutual labels:  webgl2
pathtracer-webgl2
Path tracing render engine for the web. Both ray tracing for conventional 3d models and ray marching for fractals implemented. Built with WebGL 2 and Angular 2.
Stars: ✭ 45 (-4.26%)
Mutual labels:  webgl2
revit-family-web-viewer
Revit Web Viewer is a Three.js-based project viewer. Revit projects / families must be exported using RvtVa3cExporter (https://github.com/va3c/RvtVa3c)
Stars: ✭ 48 (+2.13%)
Mutual labels:  webgl2
WebAssembly-WebGL-2
A simple port of the "Getting started with GLFW3" code to valid code for Emscripten compilation
Stars: ✭ 65 (+38.3%)
Mutual labels:  webgl2
W
A micro WebGL2 framework with a ton of features
Stars: ✭ 262 (+457.45%)
Mutual labels:  webgl2
three-noise
Simple gradient noise library for use with Three.js. Now with fBm!
Stars: ✭ 31 (-34.04%)
Mutual labels:  webgl2
webgl-memory
A library to track webgl-memory
Stars: ✭ 248 (+427.66%)
Mutual labels:  webgl2
InfiniCanvas
An infinite canvas to edit online with other users!
Stars: ✭ 26 (-44.68%)
Mutual labels:  webgl2
detect-gpu
Classifies GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications.
Stars: ✭ 749 (+1493.62%)
Mutual labels:  webgl2
js13k-2020
Island Not Found - a game for js13k 2020
Stars: ✭ 45 (-4.26%)
Mutual labels:  webgl2
v6.dooring.public
可视化大屏解决方案, 提供一套可视化编辑引擎, 助力个人或企业轻松定制自己的可视化大屏应用.
Stars: ✭ 323 (+587.23%)
Mutual labels:  webgl2
redcube
JS renderer based on GLTF to WebGPU or WebGL backends.
Stars: ✭ 86 (+82.98%)
Mutual labels:  webgl2

WebGL Helpers

Some scripts and debugger snippets that might come in handy.

Show Info

Shows how many vertices, instances, and draw calls are happening per frame as well as the amount of data being passed to WebGL via functions like bufferSubData and texSubImage2D.

See Live Example here.

Clicking the info box will show per function counts for the functions being tracked.

To use, add this script before your other scripts

<script src="https://greggman.github.io/webgl-helpers/webgl-show-info.js"></script>

It inserts a <div> in the <body> of the page and gives it a CSS class name of webgl-show-info so you can position with with .webgl-show-info { right: 0; bottom: 0; } etc...

Some things to note:

Certain things are marked in red.

  • updating ELEMENT_ARRAY_BUFFER buffers can cause perf issues because WebGL is required to make sure no indices are out of bounds. WebGL implementations usually cache this info but if you update the buffer they have to invalidate their cache for that buffer.

    Of course if you can't avoid updating indices then you'll have to live with whatever the perf hit is but if you can redesign so you don't need to update the indices you might find some perf gains.

  • Calling any getXXX function every frame can cause perf issues. Common things are calling gl.getUniformLocation or gl.getAttribLocation every frame instead of just looking them up at init time. The same for example for gl.checkFramebuffer. Do it once at init time. If you need different arrangements of framebuffer attachments then make multiple framebuffers at init time.

  • Setting up vertex attributes (calling gl.vertexAttribPointer, gl.enableVertexAttribArray, etc.... If you want perf you should really be using vertex arrays (ie, gl.createVertexArray, gl.bindVertexArray). To be honest, every WebGL app I've ever written breaks this rule because WebGL1 didn't support vertex arrays without an extension.

Also, remember that Premature Optimization is the root of all evil. The majority of WebGL out there just doesn't do enough work that these optimizations will matter. But, if you happen to be getting near the limits then these are places you might look for perf gains.

Remember though, find the biggest perf issues first. If you have lots of overdraw, or slow complex shaders, or a complex post processing pipeline doing a bunch of passes, or you're just drawing way to much stuff, the thing above are probably not your bottleneck.

Here's a script you can paste into the JavaScript console to use on a running page

(()=>{const s = document.createElement('script');s.src='https://greggman.github.io/webgl-helpers/webgl-show-info.js';document.firstElementChild.appendChild(s)})();

glEnumToString

A simple one, incomplete, but useful in a pinch.

function glEnumToString(value) {
  const keys = [];
  for (const key in WebGL2RenderingContext) {
    if (WebGL2RenderingContext[key] === value) {
      keys.push(key);
    }
  }
  return keys.length ? keys.join(' | ') : `0x${value.toString(16)}`;
}

The issue with it being incomplete it some enums are specified on extensions. One that covers all enums is a little too involved. Also, GL unfortunately chose 0 for 4 different values. NONE, POINTS, FALSE, NO_ERROR which is why the join above. Otherwise you'd need to know the function the value is going to be used with in order to return the correct string.

Show the available extensions

document.createElement("canvas").getContext("webgl").getSupportedExtensions().join('\n');
document.createElement("canvas").getContext("webgl2").getSupportedExtensions().join('\n');

Spy on draw calls

Copy and paste this into the JavaScript console

(()=>{const s = document.createElement('script');s.src='https://greggman.github.io/webgl-helpers/webgl-show-draw-calls.js';document.firstElementChild.appendChild(s)})();

or copy and pasted the entire file into the JavaScript console.

Example, select the correct context, then copy and paste

Or use

<script src="https://greggman.github.io/webgl-helpers/webgl-show-draw-calls.js"></script>

scripts to use when your including a 3rd party WebGL lib (Unity, three.js, etc...)

webgl-log-shaders.js

Want to dump shaders, add this script at the top of your HTML file

<script src="https://greggman.github.io/webgl-helpers/webgl-log-shaders.js"></script>

For example here's a Unity example with the script above added to the top of the HTML file.

And here's the same with three.js.

webgl-dump-shaders.js

Same as above except you can possibly copy and paste this contents into the JS console.

(()=>{const s = document.createElement('script');s.src='https://greggman.github.io/webgl-helpers/webgl-dump-shaders.js';document.firstElementChild.appendChild(s)})();

For example Google Maps

webgl-disable2.js

Disables WebGL2. Useful to force something to use WebGL1 assuming it can handle both

<script src="https://greggman.github.io/webgl-helpers/webgl2-disable.js"></script>

webgl-force-preservedrawingbuffer.js

Forces preserveDrawingBuffer: true.

Maybe you want to take a screenshot of some canvas that another script is controlling.

<script src="https://greggman.github.io/webgl-helpers/webgl-force-preservedrawingbuffer.js"></script>

Example:

webgl-force-alpha-true.js

webgl-force-alpha-false.js

Forces alpha: true or alpha: false

Could be useful if you can't figure out how to get a certain library to be one or the other. For example the myriad of poorly documented ways that emscripten creates a canvas.

<script src="https://greggman.github.io/webgl-helpers/webgl-force-alpha-true.js"></script>
<script src="https://greggman.github.io/webgl-helpers/webgl-force-alpha-false.js"></script>

webgl-force-premultipliedalpha-true.js

webgl-force-premultipliedalpha-false.js

Forces premultipliedAlpha: true or premultipliedAlpha: false

Could be useful if you can't figure out how to get a certain library to be one or the other. For example the myriad of poorly documented ways that emscripten creates a canvas.

<script src="https://greggman.github.io/webgl-helpers/webgl-force-premultipliedalpha-true.js"></script>
<script src="https://greggman.github.io/webgl-helpers/webgl-force-premultipliedalpha-false.js"></script>

webgl-force-powerpreference-low-power.js

webgl-force-powerpreference-high-performance.js

Forces the powerPreference setting.

Could be useful if the library you're using has no way to set this and you want it to be something other than the default.

<script src="https://greggman.github.io/webgl-helpers/webgl-powerpreference-low-power.js"></script>
<script src="https://greggman.github.io/webgl-helpers/webgl-powerpreference-high-performance.js"></script>

webgl-gl-error-check.js

This script has moved to https://github.com/greggman/webgl-lint

Other useful things

  • virtual-webgl: A library to virtualize WebGL to surpass the context limit
  • webgl-capture: A library to capture GL calls into a reproducible webpage
  • twgl: A library to simplify using WebGL
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].