⬆️ ⬇️

Editing WebGL shaders on the fly using Firefox Developer Tools

Firefox 27 has a new tool - shader editor - which greatly simplifies their development. The editor shows all programs launched in the context of WebGL, makes it possible to edit them and immediately see the changes without any breaks in animations or loss of state.









If you've seen the HTML5 version of the Epic Stronghold from Epic Games, you're probably impressed with its incredible performance and detail. Most of the code that is responsible for what you see on the screen is written in the form of shaders, assembled into special shader programs that run directly on the video card and provide high performance visual effects.

')

Writing vertex and fragment shaders is an important part of developing 3D for the web, even if you use a special library. Epic citadel, for example, includes more than 200 shader programs. This is due to the fact that the rendering is sharpened and optimized for specific tasks in the application. Shader development is now inconvenient for several reasons:





The following screencast demonstrates changing the shader code using the example of a relatively simple demo:







Firefox 27 has a new tool - shader editor - which greatly simplifies their development. The editor shows all programs launched in the context of WebGL, makes it possible to edit them and immediately see the changes without breaking animations or losing state. Repeated shader editing does not affect WebGL performance.



How to enable shader editor?



The shader editor is not enabled by default, since not all pages use WebGL. However, it is easy to turn it on.



  1. By opening the toolbar with F12 or Ctrl / Cmd + Shift + I,
  2. Clicking a “gear” there to get into the options,
  3. And, finally, putting the birdie on the left opposite the shader editor. The editor tab will immediately appear in the toolbar.


How to use the shader editor?



To try the shader editor in business, go to any WebGL demo and open the editor tab. You may need to reload the page to give the editor access to the WebGL context, after which you will see this picture (clickable):







How to edit shader programs?



Shader programs are written in GLSL and not in JavaScript. To learn how to work with the shader code, you can read various lessons (or in Russian somewhere here ). There is a hard compilation of lessons on the Learning WebGL blog. The shader editor gives you direct access to the code, so you can just experiment and see what this leads to:









More information about the shader editor can be found on the Mozilla website .



In conclusion, the second screencast demonstrating editing shaders on the fly in the epic citadel:



Source: https://habr.com/ru/post/202046/



All Articles