Giter Site home page Giter Site logo

babylonjs / spector.js Goto Github PK

View Code? Open in Web Editor NEW
1.2K 28.0 164.0 32.2 MB

Explore and Troubleshoot your WebGL scenes with ease.

Home Page: http://spector.babylonjs.com

License: MIT License

JavaScript 8.40% HTML 0.71% TypeScript 86.87% SCSS 4.02%
webgl webgl2 debugger debug inspector 3d webvr

spector.js's Introduction

Summary

Explore and Troubleshoot your WebGL scenes (All engines and Vanilla script support) with ease.

Spector is a tool aimed at WebGL developers wanting to know what happens in their context. It enables capturing of all the available information from a frame. You will be able to look at your entire commands list with their associated visual states and context information.

Build Status devDependencies Status

This can be used either as a browser extension or directly from your page with a Standalone Version.

Table of Content

Why

As a core member of the BabylonJS team I often found the need to debug what was happening to my webgl context. I was a huge fan of webgl inspector until we introduced WebGl2 in Babylon. As the WebGL community as a whole is our focus, I thought it would be great to share an extension compatible with all the Webgl/Webgl2 engines available.

You can use the library inside of your own application easily as it is transpiled as a UMD module. It will either work as a script reference or with your favorite bundling tools like webpack.

Browser extension

If you are willing to use the browser extension, you can direclty install it from the store:

You can find on Real Time Rendering a complete tutorial about the Spector extension. Else, you can refer to the extension documentation to learn how to use it.

Or you can take a look at the following documentation to load it from the source: Browser Extension.

Use as a Module

In order to install the library in your application directory, please type the following command on a command line prompt open on the application directory:

npm install spectorjs

From this point you are all set to use it in your app.

Webpack sample

As a quick demo, here is a simple way to use the spector module with webpack.

Please follow the instructions below to create a new directory and install the required tools:

mkdir sample
cd sample
npm init
npm install webpack --save-dev
npm install spectorjs --save-dev

Following the HelloWorld example from Webpack, you can now create it in the sample folder:

A js file named entry.js containing the following code:

var SPECTOR = require("spectorjs");

var spector = new SPECTOR.Spector();
spector.displayUI();

And an html file named index.js containing the following code:

<html>
    <head>
    </head>
    <body>
        <script type="text/javascript" src="bundle.js" charset="utf-8"></script>
    </body>
</html>

Now your application is ready. Go back to your command line and bundle the javascript file:

webpack entry.js bundle.js

You are all set. You can open your index.html file and see the inspector running. It obviously won't be that usefull on an empty page but at least you get the integration idea.

Use as a Script Reference

CDN

Feel free to leverage the jsDeliver CDN to use the library from your own projets: https://cdn.jsdelivr.net/npm/[email protected]/dist/spector.bundle.js

Repo

If you prefer to host your own version, the library is available in the dist folder of the repo.

node_modules

If you used npm to install the library you can find the spector.bundle.js file in the node_module/spectorjs/dist folder.

How To Reference

Simply add the following tag in your html page header:

<script type="text/javascript" src="https://spectorcdn.babylonjs.com/spector.bundle.js"></script>

Basic Usage

Once available in your app, you can instantiate an inspector by inserting the following command in your script:

var spector = new SPECTOR.Spector();

You can then display the embedded UI directly in your page:

spector.displayUI();

Or launch a capture and reuse its JSON result at your will:

spector.onCapture.add((capture) => {
    // Do something with capture.
    var myEvent = new CustomEvent("SpectorOnCaptureEvent", { detail: { captureString: JSON.stringify(capture) } });
    document.dispatchEvent(myEvent);
});

var canvas = document.getElementById("renderCanvas");
spector.captureCanvas(canvas);

Another api you can rely upon is:

spector.spyCanvases();

This will enable a complete tracking of the gl calls even before capturing which enables for instance access to the texture inputs or memory consumption information.

Custom Data

You can simply add custom data to the capture by adding a special field named __SPECTOR_Metadata to your WebGLObjects.

var cubeVerticesColorBuffer = gl.createBuffer();
cubeVerticesColorBuffer.__SPECTOR_Metadata = { name: "cubeVerticesColorBuffer" };

This will enable the visibility of your custom name in your capture. This can be an invaluable asset during troubleshoot session. This can also help with referencing your materials' friendly names from your captures.

Learn About WebGL

I would advise you to check out and start with the Awesome BabylonJS the community there will be more than happy to welcome anybody willing to learn Web 3d.

spector.js's People

Contributors

06wj avatar ameobea avatar b4u7 avatar de-panther avatar deltakosh avatar dependabot[bot] avatar dmliao avatar duckwhale avatar frguthmann avatar ivanpopelyshev avatar jannikgm avatar juj avatar kenrussell avatar kuranes avatar luruke avatar mehmetoguzderin avatar monfera avatar prestomation avatar raananw avatar rhmoller avatar sebavan avatar stefanschmutz avatar temechon avatar upisfree avatar xsbchen avatar yunhsiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spector.js's Issues

disableVertexAttribArray input interpreted incorrectly

It looks like the index parameter in calls to GL.disableVertexAttribArray(index) is incorrectly interpreted as an enum for GL.drawArrays primitive type. See the following screenshot:

10kcubes

which reads

disableVertexAttribArray: TRIANGLES
disableVertexAttribArray: TRIANGLE_STRIP

whereas it should read

disableVertexAttribArray: 4
disableVertexAttribArray: 5

Feature request: programmatic control of Spector captures

I am often dealing with complex problems where a particular condition sets off a particular graphics bug or warning. I would love it if I could turn Spector's capture on and off as needed. That is, I might have

if ( cursor location over particular part ) { Spector.beginRecording(); }

possibly with optional arguments if you want to get fancy, and maybe

if ( Spector.isRecording() ) { Spector.endRecording(); }

If other words, some way to see if we're currently recording so that we could turn it off (or just allow Spector.endRecording() to be called and do nothing if not recording). You'd want to think this through, of course, e.g., what happens if two begins are hit, or no end method is encountered (I'm not quite sure what triggers "end of frame" currently).

OSX: TypeError: Converting circular structure to JSON

I'm getting the following error when trying to inspect my deferred rendering demo http://marcinignac.com/experiments/deferred-rendering/demo/

Uncaught TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Array.spector.onCapture.add (<anonymous>:21:104)
    at e.trigger (<anonymous>:1:16800)
    at t.triggerCapture (<anonymous>:1:208884)
    at t.onFrameEnd (<anonymous>:1:208721)
    at e.trigger (<anonymous>:1:16800)
    at <anonymous>:1:88005

Show function argument names on the right hand side?

When looking at a function call, like in

10kcubes_2

the right hand side reads

command Arguments

    0: 0
    1: 3
    2: 5126
    3: 0
    4: 24
    5: 12

It would be great if that read

command Arguments

    index: 0
    size: 3
    type: 5126
    normalized: 0
    stride: 24
    offset: 12

since it's easy to forget which parameter means what, so the second form would show that clearly (btw, the links to the spec in the API call is a great idea!)

An unnecessary trace log is output in the latest version of Spector.js

I discovered that unnecessary trace logs will appear in the latest version of Spector.js.
Relate: #35

OS / Browser : Windows 10 + Chrome 58 + Spector.js v0.2.1

How to reproduce the problem:

  1. Install Spector.js from the Chrome Web Store.
    https://chrome.google.com/webstore/detail/spectorjs/denbgaamihkadbghdceggmchnflmhpmk
  2. Please access the WebGL sample page with Chrome.
  3. Start the Spector.js extension from the toolbar.
    image
    Unnecessary trace log (glp -> [object Object]) seems to be outputted.
    image

Feature request: tagging specific code locations with strings

In some debug and performance tools for the GPU you can tag code with a label. That is, you might be entering, say, a blur pass and you want to know that's where you are when you see the dump of command in Spector.js. You make a debug call at that point, and Spector.js would display the label you've put as a string, e.g.

spector.label('GaussianBlur');

This code does nothing, but Spector.js would print out the label in the command stream shown in debug.

Anyway, there are obviously issues with the format above, since Spector instruments the code, but some way to add dummy code that Spector would use as labeling would be nice. Currently I'm finding I have to do things like count the number of clear commands encountered - ugh. I know about how you can label buffers, but that's different than labeling code locations. Buffers might get reused, a code location gives a specific execution location.

There might also be some WebGL command that I could use instead, some essentially no-operation API command that lets me pass in a string. That would be a kludge, but I'd be happy to use one, if anyone thinks of a way to do this.

Please allow capturing of transient WebGL contexts starting upon page reload

There are unfortunately some feature detection libraries that are starting to query properties from the WebGL context, even though they don't intend to perform any rendering with it. Some functionality was recently added to SpectorJS to capture the command stream upon page reload, but this doesn't work unless SpectorJS notices that a canvas is actively being rendered to.

Here's a simple test case which it would be greatly appreciated if SpectorJS would work with:

<head>
<script>
function run() {
  var c = document.createElement('canvas');
  var gl = c.getContext('webgl');
  var ext = gl.getExtension('WEBGL_debug_renderer_info');
  var renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
  document.getElementById('console').innerHTML = renderer;
  window._c = c;
}
</script>
</head>
<body onload="run()">
<div id="console">
</div>
</body>

In this case, the extension doesn't activate, even though it does see that a WebGL context is created; this can be seen by setting an Event Listener Breakpoint on the "Create canvas context" event and noticing that it stops inside SpectorJS's code.

It would be great if SpectorJS would activate at that point and allow capturing of the first context's commands upon page reload, so that we can see what these (usually heavily obfuscated) feature detection libraries are doing.

Thanks.

Allow seeing several captures side by side

Captures are always open in the same tab. As a workaround I open the browser as a different user, capture whatever, and then open the .json captured previously.

Also, at least in linux with chromium-browser, I can't drag a file to the spector pop up (that's why I have to go to some webgl example to capture).

Capture frame like WebGL Inspector does on loading

I have scene where I am not animating, I would like spector to work in similar manner like WebGL inspector works i.e. on refreshing or loading of page, it captures frames and all webgl calls that were made as well as any color attachments that were used/generated. Is that possible? This tool looks great but it doesn't seems to work with my custom framework. My custom framework only draws static scenes (we don't animate), WebGL inspector (https://benvanik.github.io/WebGL-Inspector/) works as long as our code is webgl 1.0 , something similar to webgl inspector but with all features of spector will be great.

TypeError: Array.prototype.slice called on null or undefined

Forgive me if Spector.js is not intended to work in any WebGL application including those which may not use WebGL correctly.

The Issue

While working on a WebGL2 project I kept getting a null/undefined reference exception here when hitting the record button in the Spector.js Chrome extension.

It seems the call to gl.getVertexAttrib is returning undefined.

image

A little background on the project

The goal of this project is to use the GPU to simulate the interaction between a collection of particles. Since the particles can interact with any other particle I have to use a combination of textures and VBOs to fetch the vertex attributes. For this reason the vertex positions are being stored in a texture and the rest are stored in the VBO since the position of the particles are the only relevant attributes to neighboring vertices. That means I have to setup a FBO as well as a transform feedback object to write the output of the simulation to both the VBO and the texture.

Here are the source files:
main.js
particlesim.vs
particlesim.fs

Despite calling gl.uniform1i(positionTexLoc, theirTex);
I get RENDER WARNING: there is no texture bound to the unit 0. Which I assume means the sampler in the vertex shader is not being set.

I predict this may be what is causing the error in Spector.js.

Error in r.getWebGlConstant, on frame capture

Chrome Extension version 0.0.10
When capturing a frame, I get the following error:

TypeError: Cannot read property 'name' of undefined
    at r.getWebGlConstant (<anonymous>:1:152159)
    at r.readTextureFromContext (<anonymous>:1:147254)
    at r.readUniformFromContext (<anonymous>:1:146917)
    at r.readFromContext (<anonymous>:1:140688)
    at r.e.readFromContextNoSideEffects (<anonymous>:1:111560)
    at r.e.onConsumeCommand (<anonymous>:1:109506)
    at t.captureState (<anonymous>:1:105345)
    at t.onCommand (<anonymous>:1:91481)
    at WebGLRenderingContext.drawElements (<anonymous>:1:94953)

better stacktraces support?

more like feature request, I guess - in firefox there are no stack traces, in chrome stack traces are present but not clickable.

Keyboard keys to navigate API call and canvas framebuffer lists?

When having clicked the keyboard focus to be on a API call, as follows:

10kcubes

It would be nice to be able to use keyboard Up and Down keys to navigate between adjacent API calls, and for example Ctrl-Up and Ctrl-Down to navigate to next/previous draw call.

Similarly, when clicking on the left hand side on a "Canvas frame buffer" icon, it would be nice to be able to use Up and Down keys to navigate between frame buffer states.

Currently Up and Down keys seem to always scroll the API call list view without moving the keyboard focus.

The display of arguments of drawElements is incorrect

I traced triangle drawing by Babylon.js with Spector.js.
However, I noticed that the arguments of drawElements function are not displayed properly.
image

void gl.drawElements(mode, count, type, offset);

I think that count and offset arguments should not be displayed as constants.

glReadPixels: format and type incompatible with the current read framebuffer

I try to use Spector with WebGL2 MRT render. I have two framebuffers with 3 R8G8B8A8 attachements
When I started capture I will get errors
[.Offscreen-For-WebGL-0A503658]GL ERROR :GL_INVALID_OPERATION : glReadPixels: format and type incompatible with the current read framebuffer.
Is WebGL2 MRT supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.