Shaders (GLSL) and starters
A shader is a small program that decides how a surface is drawn. In TinyGameEngine a shader is a file (Files → New → Shader) with two pieces of GLSL, a vertex part (where the points of the shape go) and a fragment part (the colour of each pixel). You use it through a material: a shared material set to Style → ShaderMaterial (Custom GLSL) with that shader picked.
Make one
- Files → New → Shader. A list opens: Blank, then the starters.
- Pick one and name it. The shader editor opens, with the code to change.
- Make a material (Files → New → Material), set its Style to ShaderMaterial (Custom GLSL) and pick your shader. You can also do this on an object's own material.
- Give the material to an object. The settings of the shader (see below) are fields on the material.
Starters
| Starter | Look | Settings (starting value) |
|---|---|---|
| Hologram | See-through blue glow with scrolling lines, a bright edge and a flicker. Uses the material Color. | Speed (1), Lines (40), Rim (2), Flicker (0.3) |
| Dissolve | The object burns away through noise with a glowing edge. | Amount (0.4), Speed (0.25), Scale (6), Edge (0.06), Edge colour (#ff7a18) |
| Toon outline | Flat bands of light and a dark line round the shape. | Bands (3), Width (0.25), Outline colour (#101018) |
| Fresnel glow | The object is lit normally and glows at its edges. | Glow colour (#4cc3ff), Power (3), Strength (1.2), Pulse (1) |
| Water | A wavy, slightly see-through surface with sparkles. Best on a plane. | Wave height (0.08), Wave speed (1), Scale (4), Deep colour (#0b4f7a), Shine (0.5) |
| Wind sway | The top of the object sways, the base stays still. For grass, trees and flags. The base of the object has to be at its origin (y = 0 is the bottom). | Strength (0.15), Speed (1.5), Height (1) |
| Particle dissolve | For a Particle System's Renderer → Shader: each particle burns away with a glowing edge as its Custom Data rises. See Custom Data and particle shaders. | Edge colour (#ffb347), Scale (6), Edge (0.08) |
Notes:
- Dissolve: with Speed above 0 it burns away over and over by itself. Set Speed to 0 to hold it at the Amount you choose (0 shows everything, 1 shows nothing).
- Wind sway: set Height to the height of your object so the whole length bends smoothly.
- The lit starters (Dissolve, Toon, Fresnel, Wind) use the material Color and its picture, if it has one.
- Every starter is ordinary GLSL. Change it as you like.
Write your own
A shader may use these without declaring them in your material:
| Name | Is |
|---|---|
uTime | Seconds since the scene started. |
uColor | The material colour. |
uOpacity | The material opacity. |
uMap, uHasMap | The material picture, and 1 when it has one. |
uResolution | Size of the screen. |
The vertex shader also gets the usual three.js names: position, normal, uv, modelViewMatrix, projectionMatrix, normalMatrix.
Your own settings
Any uniform float or uniform vec3 you declare, apart from those above, becomes a field on the material: a number for float, a colour for vec3. GLSL cannot give a uniform a value in the source, so write the starting value in a comment after it:
uniform float uSpeed; // 1.5
uniform vec3 uGlow; // #4cc3ff
Without a comment a float starts at 0 and a colour at white. A uniform declared in both the vertex and the fragment shader is one setting.
See-through shaders
Add a line // @transparent to the fragment shader and it blends with what is behind it, using the alpha you output (gl_FragColor = vec4(colour, alpha)). Without it, a material draws solid unless its Opacity is below 1. For more control (glows that add light, multiply, drawing through walls) use the Render tab below.
Render settings
The shader editor's Render tab sets how the shader is drawn, with the same names as Unity's ShaderLab:

| Setting | Choices | What it does |
|---|---|---|
| Blend | Auto, Off, Alpha, Premultiplied, Additive, Multiply | How its pixels mix with what is already drawn. Additive adds light: glows, auras, fire, force fields. Multiply darkens: shadows, stains. Auto = Alpha for a // @transparent shader or a see-through material, else Off. |
| ZWrite | Auto, On, Off | Whether it hides what is drawn after it. Auto = On for solid shaders, Off for blended ones. |
| ZTest | LEqual, Less, Equal, GEqual, Greater, NotEqual, Always | When a pixel is drawn compared to what is in front. Always draws through walls (x-ray outlines); Greater draws only the hidden part. |
| Cull | Back, Front, Off | Which side of the faces is skipped. Front shows only the inside: the usual trick for a glowing shell around a character. Off draws both sides (so does the material's double-sided setting). |
| Queue | Background 1000, Geometry 2000, AlphaTest 2450, Transparent 3000, Overlay 4000, or a number | Draw order: lower first. Above 2500 it is drawn with the see-through objects, back to front. From Blend = 3000 when it blends, else 2000. |
A material with a custom shader also has Render queue: From Shader, or a number of its own (Unity's material Render Queue), to put one material in front of another.
Aura around a character: a copy of the character (or a slightly bigger sphere) with a Fresnel-style shader set to Blend → Additive, Cull → Front, Queue → 3100.
Errors
If the shader does not compile, the error is shown in the shader editor.
Change a setting while the game runs
The Set shader uniform block (category Object) changes one setting of the object's shader: pick the object, the uniform, and a value. A number for a float, a colour as text for a vec3:
Player is hurt → Set Player shader uniform uGlow to "#ff0000"
Enemy died → Set Enemy shader uniform uAmount to 0.6 (Dissolve with Speed 0)
In a script: entity.setUniform('uAmount', 0.7) or entity.setUniform('uGlow', '#ff0000'). It returns false when the object's shader has no uniform of that name (the block reports it in the console).
- Only that object changes, even if other objects use the same material.
- It sets the value now. To change it over time, set it again each frame from a script or an event that runs every frame.
- For Dissolve, set Speed to 0 first, otherwise it keeps burning on its own.
Good to know
- A custom shader does not get scene lighting, shadows or fog by itself. The starters fake a light from one direction. A shader is drawn with the object's shape, so it works on any shape.
- Shaders are not shared between materials: each material makes its own.
- Not there yet: tweening a shader uniform, and a visual node editor.