Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

shader-toy

> 开发工具
Open source

Shadertoy-like live preview for GLSL shaders in Visual Studio Code

698 stars0 likes2 views
WebsiteGitHub

About

Shadertoy-like live preview for GLSL shaders in Visual Studio Code

Visual Studio Code - Shader Toy

With this extension, view a live WebGL preview of GLSL shaders within VSCode, similar to shadertoy.com by providing a "Show GLSL Preview" command.

To run the command, either open the "Command Palette" and type "Shader Toy: Show GLSL Preview" or right-click inside a text editor and select "Shader Toy: Show GLSL Preview" from the context menu.

Running the command splits the view and displays a fullscreen quad with your shader applied. Your fragment shader's entry point is void main() or if that is unavailable void mainImage(out vec4, in vec2) where the first parameter is the output color and the second parameter is the fragments screen position.

An alternative command "Shader Toy: Show Static GLSL Preview" is available, which will open a preview that does not react to changing editors. An arbitrary amount of those views can be opened at one time, which enables a unique workflow to edit shaders that rely on multiple passes.

Features

Uniforms

At the moment, iResolution, iGlobalTime (also as iTime), iTimeDelta, iFrame, iMouse, iMouseButton, iDate, iSampleRate, iChannelN with N in [0, 9] and iChannelResolution[] are available uniforms.

Texture Input

The texture channels iChannelN may be defined by inserting code of the following form at the top of your shader

#iChannel0 "file://duck.png"
#iChannel1 "https://66.media.tumblr.com/tumblr_mcmeonhR1e1ridypxo1_500.jpg"
#iChannel2 "file://other/shader.glsl"
#iChannel2 "self"
#iChannel4 "file://music/epic.mp3"

This demonstrates using local and remote images as textures (Remember that power of 2 texture sizes is generally what you want to stick to.), using another shaders results as a texture, using the last frame of this shader by specifying self or using audio input. Note that to use relative paths for local input you will have to open a folder in Visual Code.

To influence the sampling behaviour of a texture, use the following syntax:

#iChannel0::MinFilter "NearestMipMapNearest"
#iChannel0::MagFilter "Nearest"
#iChannel0::WrapMode "Repeat"

Though keep in mind that, because of the WebGL standard, many options will only work with textures of width and height that are power of 2.

Cubemap Input

Cubemaps may be specified as any other texture, the fact that they are cubemaps is a combination of their path containing a wildcard and their type being explicitly stated.

#iChannel0 "file://cubemaps/yokohama_{}.jpg" // Note the wildcard '{}'
#iChannel0::Type "CubeMap"

The wildcard will be resolved by replacement with values from any of the following sets

  • [ 'e', 'w', 'u', 'd', 'n', 's' ],
  • [ 'east', 'west', 'up', 'down', 'north', 'south' ],
  • [ 'px', 'nx', 'py', 'ny', 'pz', 'nz' ] or
  • [ 'posx', 'negx', 'posy', 'negy', 'posz', 'negz' ].

If any of the six files can not be found, the next set is tried, starting from the first.

Audio Input (experimental)

Note: By default audio input is disabled, change the setting "Enable Audio Input" to use it.
Audio input is not supported from within Visual Studio Code, since ffmpeg is not shipped with Visual Studio Code, so you will have to generate a standalone version and host a local server to be able to load local files (or fiddle with your browsers security settings) if you want to use audio in your shaders. If your channel defines audio input, it will be inferred from the file extension. The channel will be a 2 pixels high and 512 pixels wide texture, where the width can be adjusted by the "Audio Domain Size" setting. The first row containing the audios frequency spectrum and the second row containing its waveform.

Keyboard Input

If you want to use keyboard input you can prepend #iKeyboard to your shader. This will expose to your shader the following functions:

bool isKeyPressed(int);
bool isKeyReleased(int);
bool isKeyDown(int);
bool isKeyToggled(int);

Additionally it will expose variables such as Key_A to Key_Z, Key_0 to Key_9, Key_UpArrow, Key_LeftArrow, Key_Shift, etc. Use these constants together with the functions mentioned above to query the state of a key.

Shader Includes

You may also include other files into your shader via a standard C-like syntax:

#include "some/shared/code.glsl"
#include "other/local/shader_code.glsl"
#include "d:/some/global/code.glsl"

These shaders may not define a void main() function and as such can be used only for utility functions, constant definitions etc.

Custom Uniforms (experimental and subject to change)

To use custom uniforms define those directly in your shader, giving an initial value as well as an optional range for the uniform.

…

Compatibility with Shadertoy.com

The following is an example of a shader ported from shadertoy.com:

…

Note that compared to shadertoy.com gl_FragCoord replaces fragCoord and gl_FragColor replaces fragColor in the original demo. There is however a rudimentary support for inserting a trivial void main() which will delegate to a void mainImage(out vec4, in vec2) function. The definition of void main() is found by matching the regex /void\s+main\s*\(\s*\)\s*\{/g, thus if you require to define void main() in addition to the extension generating a definition you may define it as void main(void). This might be necessary, for example, if your main definition would be processed away by the preprocessor and should thus not be picked up by the extension. Since compatibility is achieved with a simple regex match it is only semi-reliable. If you only use shaders from shadertoy.com that do things such as defining mainImage via macros you may want to enable the "Shader Toy Strict Compatibility" setting, which disables the ability to use shaders that define void main() and only allows shaders that define mainImage in some way. Alternatively you can use #StrictCompatibility in your shader to have this feature localized to just that shader.

Integration of glslify

You can enable support for glslify in the settings, but because glslify does not support line mappings pre and post its transform, line numbers on errors will unfortunately be disabled as long as you have the setting enabled. Using glslify allows using a node.js-style module system for your shaders:

glsl
#pragma glslify: snoise = require('glsl-noise/simplex/2d')

float noise(in vec2 pt) {
    return snoise(pt) * 0.5 + 0.5;
}

void main () {
    float r = noise(gl_FragCoord.xy * 0.01);
    float g = noise(gl_FragCoord.xy * 0.01 + 100.0);
    float b = noise(gl_FragCoord.xy * 0.01 + 300.0);
    gl_FragColor = vec4(r, g, b, 1);
}

WebGL-2 and GLSL ES 3.00

By default the webview will try to load a webgl2 and fallback to a webgl context if not available. However the option shader-toy.webglVersion can be used to explicitly request a webgl2 context with support for GLSL ES 3.00, if not available an error will be emitted.

Vertex Shader

If the above setting is set to WebGL2 then vertex shaders are supported by declaring them in a fragment shader via #iVertex. The shader declared as an input has to write to gl_Position and can additionaly declare output variables that can be used in the fragment shader, this can for example be used to generate uv-coordinates and output them like out vec2 uv;. See the demos for examples of vertex shader usage.

GLSL Preview Interaction

The extension provides a pause button inside the GLSL Preview to stop the progression of time. In conjunction with this you can use the screenshot button provided inside the GLSL Preview to capture and save a frame. The resolution of the saved screenshot will by default be the same resolution as the GLSL Preview, though a setting is available that allows the user to override the resolution with an arbitrary value. A recording button is also available, the quality as well as the size of the recording is determined by the webview. Lastly the extension provides a superficial view into the shaders performance and memory consumption.

Error Highlighting

The extension also supports highlighting of compilation errors in the text editor, for single shaders but also for multiple passes. It does so by showing errors as diagnostics directly in the text editor as well as presenting them in a digestible format inside the GLSL Preview and allowing the user to interact with the error messages to jump to the relevant lines, and open the relevant files if necessary:

Recording Capabilities

Two rendering modes are supported:

  • Realtime rendering: suitable for previews and scenarios where real-time interaction with the visuals are required. As with all real-time video capture, frame drops might occur, especially on lower spec hardware or when rendering very complex visuals.
  • Offline rendering: suitable for production-grade rendering. Each frame is rendered sequentially without any drops.

The default is real-time rendering to activate offline rendering set shader-toy.recordOfflineto true.

Shared parameters

  • shader-toy.recordTargetFramerate: Set recording target frame-rate. Default is 30fps.
  • shader-toy.recordMaxDuration: Maximum recording duration in seconds. 0 (the default) will keep recording until the record button is pressed again.

Real-time Rendering parameters

  • shader-toy.recordVideoContainer: Set the video file container. Currently only webm is supported, but mp4support is coming soon.
  • shader-toy.recordVideoCodec: Set video codec. vp8, vp9, h264 and avc1 are all supported. Default it vp8.
  • shader-toy.recordVideoBitRate: Set recording bit rate in bits/second. Default is 2500000.

Offline rendering parameters

  • shader-toy.recordOfflineFormat: Offline recording format. Possible value are webm, gif, png and jpg. PNG and JPEG images are individual images packaged in a .tar archive.
  • shader-toy.recordOfflineQuality: Offline recording quality. 0 is lowest and 100 highest. Applies when format is webm or jpg.

Requirements

  • A graphics card supporting WebGL.

Known Issues

  • Performance at the moment is not great for certain shaders, and the cause is under investigation
  • Shaders with audio from remote sources are currently not working properly, this is however an issue on VSCode side and will be fixed when releasing with Electron 6.
  • There seems to be a very rare bug that causes audio inputs to sound corrupted.

Contributing

Contributions of any kind are welcome and encouraged.

GitHub Project Page

Contributing Guidelines

Visual Studio Marketplace

Release Notes

0.11.4

  • Added float DDS (DX10) texture loading for iChannel inputs (including local files) and included LTC demo shaders.
  • Improved diagnostics when using glslify.
  • Added diagnostics when there is a js error happening in the webview, rather than the user ending up with a black screen.
  • Fixed error code lines diagnostics with multi-level includes support.
  • Added optoin shader-toy.webglVersion to explicitly request a webgl2 context with support for vertex shaders via #iVertex.

0.11.3

  • Added shader-toy.recordVideoContainer (set video file container).
  • Added shader-toy.recordVideoCodec (set video codec).
  • Added shader-toy.recordVideoBitRate (set recording bit rate).
  • Added shader-toy.recordMaxDuration (set maximum recording duration).
  • Fixed the shader-toy.recordTargetFramerate setting.
  • Moved the Stats widget to the bottom left, so it doesn't overlap with the GUI.
  • Added shader-toy.recordOffline to switch between real-time and offline rendering.
  • Added shader-toy.recordOfflineFormat. Used in conju

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptglsl-shadersshadersshadertoyvscode-extension

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具