There are few build-in uniform variables available in Synthclipse shaders. "Built-in" in a sense that their values are provided automatically without the need of Uniform Controls. However, it does not mean that you can use them without declaring them in your code.
A family of uniforms related to mouse state. They are analogous to Shadertoy's uniform iMouse.
// Mouse pixel coordinates: // xy: current (if mouse button is down) // zw: click point uniform vec4 synth_Mouse; // Left mouse button uniform vec4 synth_LMouse; // Left mouse button (same as "synth_Mouse") uniform vec4 synth_RMouse; // Right mouse button uniform vec4 synth_MMouse; // Middle mouse button
Camera uniforms are set by Synthclipse's built-in camera - the one which properties can be previewed in Camera View and which can be controlled by mouse and keyboard via Viewport view.
// Projection Matrix. Valid only for 3D cameras. uniform mat4 synth_ProjectionMatrix; // Camera's View Matrix. Valid only for 3D cameras. uniform mat4 synth_ViewMatrix; // Camera's Normal Matrix. Valid only for 3D cameras. uniform mat3 synth_NormalMatrix; // Camera's center position. Valid only for 2D camera. uniform vec2 synth_Center; // Camera's zoom factor. Valid for 2D and 3D cameras. uniform float synth_Zoom; // Viewport resolution. (Analogous to Shadertoy's "iResolution") uniform vec2 synth_Resolution;
Time uniform variable is probably the most important build-in variable. It is used for animating shaders. Its value is a current animation time, in seconds.
// Declaration of time uniform variable. uniform float time; // alternatively you could use Shadertoy's equivalent: uniform float iTime; // or Shadertoy's old one: uniform float iGlobalTime; // or Synthclipse's equivalent: uniform float synth_Time;
PixelSize is vec2 uniform variable whose components are given by:
pixelSize.x = 1.0 / width; pixelSize.y = 1.0 / height;
where width and height are Viewport's width and height, respectively. This variable is supported only for compatibility with the Fragmentarium.
// Declaration of pixelSize uniform variable. uniform vec2 pixelSize;
Subframe uniform indicates which "sub frame" is currently rendered. Sub frames are generated when Progressive Mode is enabled (which you can set in the Rendering View). If it is disabled, the uniform will always be set to 1.
// Declaration of subframe uniform variable. uniform int subframe;
SubframeCount uniform variable tells the total number of "sub frames". This is the same value as the "Subframes" parameter from the Rendering View.
// Declaration of subframeCount uniform variable. uniform int subframeCount;
Backbuffer uniform is an image generated in a previous "sub frame". Sub frames are generated when Progressive Mode is enabled (which you can set in the Rendering View). If it is disabled or when rendering the first sub frame, back buffer image is cleared with (0.0, 0.0, 0.0, 0.0) color value.
// Declaration of backbuffer uniform variable. uniform sampler2D backbuffer;
Frontbuffer uniform variable is available only in the post processing shaders. It is the result image generated during first pass of the rendering. (The second and final pass is the post processing).
// Declaration of frontbuffer uniform variable. uniform sampler2D frontbuffer;
Synthclipse supports every uniform known from Shadertoy. iChannelTime is treated a little bit different than in Shadertoy: its components are always equal to the iTime.
These uniforms are available not only in ".stoy" files but also in any other shader file type.
// Shadertoy uniforms uniform vec3 iResolution; // viewport resolution (in pixels) uniform float iTime; // shader playback time (in seconds) uniform float iTimeDelta; // render time (in seconds) uniform int iFrame; // shader playback frame uniform vec3 iChannelResolution[4]; // channel resolution (in pixels) uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click uniform vec4 iDate; // (year, month, day, time in seconds) uniform float iSampleRate; // sound sample rate (i.e., 44100)\n" uniform float iFrameRate; // frames per second (effectively "1.0 / iTimeDelta") // iChannelTime components are always equal to iTime. uniform float iChannelTime[4]; // channel playback time (in seconds)
Synthclipse also supports GLSL Sandbox uniforms needed for GLSL Sandbox Importer.
// GLSL Sandbox uniforms // Normalized mouse position. Components of this vector are always between 0.0 and 1.0. uniform vec2 mouse; // Screen (Viewport) resolution. uniform vec2 resolution; // surfaceSize is equal to: vec2(resolution.x / resolution.y, 1.0) uniform vec2 surfaceSize;
Sometimes it is useful to detect if current rendering is performed for the viewport or for recording an animation. With such information, for example, we could make shader quality a lot better for the recording (e.g. by adding brute-force anti-aliasing or more ray-marching iterations), and for the viewport we could keep the shader as much real-time as we can.
For such purpose we can use the SaveFormat uniform. It does more than just indicating recording/not recording state (see Recording movies) but for the goal of this section it is relevant only this.
// Uniform for detecting save format of an animation. If the recording is not turned on this variable is set to 0. // Possible values: // 0 - no recording is currently performed // 1 - when PNG is used as image format // 2 - when JPG is used as image format // 3 - when BMP is used as image format // 4 - when EXR is used as image format uniform int SaveFormat;
Sample usage:
#define NOT_RECORDING 0 #define SAVE_FORMAT_PNG 1 #define SAVE_FORMAT_JPG 2 #define SAVE_FORMAT_BMP 3 #define SAVE_FORMAT_EXR 4 // Automatically set by Synthclipse uniform int SaveFormat; void main() { vec3 col; switch (SaveFormat) { case NOT_RECORDING: col = vec3(0.0, 0.0, 0.0); break; case SAVE_FORMAT_PNG: col = vec3(1.0, 0.0, 0.0); break; case SAVE_FORMAT_JPG: col = vec3(0.0, 1.0, 0.0); break; case SAVE_FORMAT_BMP: col = vec3(0.0, 0.0, 1.0); break; case SAVE_FORMAT_EXR: col = vec3(1.0, 1.0, 1.0); break; default: col = vec3(0.0, 1.0, 1.0); } gl_FragColor = vec4(col, 1.0); }