Mewa User's Guide/Extending Mewa with custom shaders

< Mewa User's Guide

This chapter explains how to extend Mewa with nodes running custom GLSL shaders. To create Mewa shader nodes you might need some knowledge on GLSL programming. For those who don't know, GLSL is a programming language used to create programs that run on graphics hardware.

At the core of Mewa is a script engine that executes Mewa script files. Nodes are created through the execution of a script.

Script files are accessible through nodes toolbar.

The best way to start creating Mewa nodes is to look at examples. All mewa script files are located in the scripts directory which location depends on the platform running Mewa. On Mewa's main window click on File:InfoButton.png to open the general information window. The scripts folder path is shown in it. You can open any .mw file in the scripts folder with a text editor and modify it, save the changes and restart Mewa for the changes to take effect. All scripts are listed in the nodes list.

Node library button

An exampleEdit

Let's create a node called MyNode. Below is the content of

// this is a mewa script that creates a node with a custom shader
shaderSource = "
void mainImage( out vec4 fragColor, in vec2 fragCoord )
    vec3 col = 0.5 + 0.5*cos( iTime + fragCoord.xyx + vec3(0,2,4) );
    fragColor = vec4(col,1.0);

node = newShaderNode("MyNode", shaderSource);

The Mewa script file above encapsulates the GLSL source code and Mewa API call to create the node. This node has no inputs or GUI controls.

Mewa provides the following shader Inputs:

Type Name Description
vec3 iResolution Viewport resolution in pixels
float iTime Playback time in seconds
int iFrame Playback frame number
vec3 iChannelResolution[4] Input texture resolution for each channel
sampler2D iChannel0..3 Input channel

GUI ControlsEdit

Now that we have a node running a shader lets add a uniform to the shader and change the value of the uniform using a GUI control.

GUI controls are used to update shader's uniform variables. The GUI controls are visible in Mewa through the node parameters.