Guide to Customizing Textures and Using the Shader in VSCode (via Shader Toy extension) OR Shadertoy.com
This shader code uses three texture “channels” (iChannel0, iChannel1, iChannel2), each referenced by a file path or name in the code’s header comments. Below is a step-by-step guide on how to change or customize these textures, both in Visual Studio Code with the Shader Toy extension and in the online Shadertoy environment.
- Open Visual Studio Code.
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar (on the left) or press Ctrl+Shift+X.
- In the search bar, type:
stevensona.shader-toy
- Click Install next to the “Shader Toy” extension by Stevensona.
- Once installed, you can open
.glsl
or.frag
files, and a Shader Toy preview window can be displayed (using the “Shader Toy: Show Preview” command from the Command Palette).
Inside your project folder (where your .glsl
file lives), you’ll see lines like these at the top:
#iChannel0 "file://../textures/gray_noise_small.png" // noise displacement map
#iChannel1 "file://../textures/rocks.jpg" // background texture
#iChannel2 "file://../textures/pebbles.png" // caustics displacement map
-
Add or Replace Texture Files
- In VSCode, create a folder (e.g.,
textures
) within your project. - Copy or place any images you want to use (e.g.,
.png
,.jpg
) into thistextures
folder. - Make sure to confirm the path is correct relative to your shader file.
- In VSCode, create a folder (e.g.,
-
Update the Channel Paths
- Adjust the lines above to point to your new textures. For example, if you want to use a file called
water_noise.png
, stored in the sametextures
folder, you could change#iChannel0
to:#iChannel0 "file://../textures/water_noise.png"
- Repeat for channels 1 and 2 as needed.
- Adjust the lines above to point to your new textures. For example, if you want to use a file called
-
Texture Dimensions
- This shader currently expects single-channel grayscale images for displacement maps (stored in the red channel), though it will also work fine with color images (and it just samples the
.r
channel). - Background textures (iChannel1 in the example) are typically full-color.
- There is no absolute resolution requirement. However, typical sizes like
256x256
,512x512
, or1024x1024
are common for displacement maps and backgrounds.
- This shader currently expects single-channel grayscale images for displacement maps (stored in the red channel), though it will also work fine with color images (and it just samples the
-
Preview
- After updating and saving your
.glsl
file, open the Shader Toy preview (via Command Palette → “Shader Toy: Show Preview”) to see your changes in real time.
- After updating and saving your
That’s it—using “file://” references, you have full control over which textures are used in each channel.
Shadertoy.com provides a simple interface to experiment with GLSL shaders right in the browser. By default, each channel can be set to some internal Shadertoy texture or none at all.
- Go to https://www.shadertoy.com.
- Sign in (or create an account) if you want to save or edit shaders.
- Create a new shader or open an existing one you own. In the code editor on Shadertoy, you’ll see code referencing channels as
iChannel0
,iChannel1
,iChannel2
, etc.
- Look at the Shader Inputs panel (usually on the left side or in a tab below the main editor). Each channel (0, 1, 2, 3) has a dropdown for texture type.
- Select a preset Shadertoy texture, or choose “None” if you do not want to use that channel.
- For displacement maps, you can choose from Shadertoy’s default library. For example, there might be a noise or a cloudy texture you can select.
- If you have a Pro (paid) Shadertoy account, you can upload your own custom textures. Otherwise, you’ll rely on the default library.
- Single-Channel vs. Full Color
Shadertoy typically provides color textures in RGBA. In this shader, the red channel (.r
) is used to read displacement intensity. If you choose a color texture, it will work, but just the.r
component is what’s effectively used as the displacement “height.” - Default Texture Dimensions
Shadertoy’s default textures vary in size but are typically large enough (e.g., 512×512 or 1024×1024). The shader only depends on reading normalizeduv
coordinates, so the physical resolution is not strictly an issue.
-
Texture Channels
- iChannel0: Grayscale noise displacement map(s) stored in red channel.
- iChannel1: Background image (full color).
- iChannel2: Grayscale caustics displacement map(s) stored in red channel.
-
Current Dimensions (as defined in the example)
#define VIRTUAL_DS_RES_X 256.0 #define VIRTUAL_DS_RES_Y 192.0
- These define a virtual (pixelated) resolution. It’s used by the
pixelate_uv
function (ifPIXELATE_UV
is enabled) to produce a retro “pixel” effect. You can adjust these numbers to get different pixelation.
- These define a virtual (pixelated) resolution. It’s used by the
-
Dimming Factors
#define NOISE_DISP_MAP_DIMMING_FACTOR 0.33 #define CAUSTICS_DISP_MAP_DIMMING_FACTOR 0.22
- These scale down the brightness from the red channel. If your textures are too bright or too dark, adjust these to refine how strong the displacement effect appears.
-
Opacity Thresholds
#define NOISE_DISP_INDUCED_INTENSITY_THRESHOLD 0.30 #define ALL_DISP_MAP_INDUCED_INTENSITY_THRESHOLD 0.75
- These thresholds drive the final alpha/opacity in the water effect. Feel free to experiment: lower them for more pronounced “peaks,” or raise them for a subtler effect.
- If you want an easy, immediate environment: Shadertoy.com is the fastest way to experiment—just paste the shader code, set your channels (noise, background, etc.), and tweak away.
- If you want custom textures locally: Install the VSCode Shader Toy extension, place your images in the project folder, and update the
#iChannelN "file://"
paths accordingly. This gives full control over which textures are used in each channel.