Gradient Map Shader v1.0.0
Download on Asset StoreGradient Map Shader is a set of stylized shaders for the Universal Render Pipeline. Every color on the surface comes from a gradient you pick: dark areas use the left end of the gradient, light areas use the right end. Lights, shadows and textures only decide where on the gradient a surface is — never its color. What you see on screen is always your palette.
Gradients are edited with Rich Gradient, which is included in the package.
The package has four shaders:
| Shader | Use it for |
|---|---|
| Basic | 3D objects: characters, props, buildings, terrain meshes. |
| Water | Water surfaces that get darker as they get deeper. |
| Sprite | 2D sprites. |
| Skybox | A gradient sky. |
Each feature can be turned off in the Inspector, so you only pay for what you use. Continue with Installation or jump straight to Quickstart.
Import Gradient Map Shader from the Unity Asset Store. The package files are added under:
Assets/Octopus Game Lab/Gradient Map Shader
Rich Gradient is included in the package. It is the gradient type the materials use, with up to 32 color keys. No Renderer Feature is needed. Some features need a URP setting, see Project Settings.
To learn how to add keys and change blend modes in the Gradient field, see Rich Gradient Editor Basics.
Try a few colors and rotate the Directional Light to see the result change.
See Technical Details for tested versions and supported URP features.
The Basic shader is for 3D objects. Its Inspector is split into sections. This chapter follows the same order. Most sections have an Enable toggle; turn off what you don't need.
Only the Alpha Map cuts holes. The alpha of the gradient does not.
Follows the lights in the scene. The side facing a light is lighter, the other side darker. Point and Spot lights, light cookies and baked lighting all work.
Uses its own light that turns with the camera, so the object always looks the same from any angle. Scene lights are ignored. This works like a matcap and is great for shiny metal looks. Direction sets where this light comes from: Pitch sets its height, Yaw turns it around.
Follows how deep the scene is behind the surface, like water. Shallow areas are lighter, deep areas darker.
Depth needs Surface Type set to Transparent and Depth Texture enabled on the URP Asset.
The whole surface uses one color. Luminance picks it: 0 = left end of the gradient, 1 = right end. Shadows, SSAO, Darken Map and Lighten Map still affect it.
Textures that add detail to the surface. Each map has its own Enable toggle.
Transparent areas of the texture make the surface see-through. With Alpha Clipping, they are cut out. Use it for leaves, fences and cut-out shapes. Only the alpha channel is used, and it follows the mesh UVs. For a black and white map, set Alpha Source to From Gray Scale in its import settings.
Alpha Map only works when Surface Type is Transparent or Alpha Clipping is on.
Adds bumps and dents to the shading, Rim and Specular. Strength sets how strong the bumps are.
Normal Map works with the Light and View shade types. Set the texture's Texture Type to Normal map in its import settings.
Dark areas of the texture darken the surface. Use it for dirt, cracks or painted details. Strength sets how strong the darkening is.
Mapping sets how the map is placed on the object:
| Mapping | Description |
|---|---|
| UV | Uses the mesh UVs. |
| Planar | Projects the map from above. Side faces stretch. |
| Triplanar | Projects the map from all sides without stretching. Costs more than Planar. |
Planar and Triplanar don't need UVs, so they work on any mesh. The map stays in place when the object moves and scales with the object.
A black and white map is recommended. Only the red channel is used. See Grayscale Image.
Light areas of the texture lighten the surface. Use it for highlights, glow or painted details. It has the same Mapping and Strength settings as Darken Map.
Extra effects on top of the gradient colors, and the shadow settings of the object.
Fades a color over the object along a direction in the world. Use it for snow on top, moss at the bottom or a height fade.
The direction is in world space, so the fill does not turn when the object rotates.
Adds a color to the edges of the object, as seen from the camera. Range sets where the rim fades in, from the area facing the camera (0) to the edges (1). Raise the left value for a thinner rim. With a Normal Map, the rim follows its bumps too.
Adds a shiny highlight where the light reflects toward the camera. Range sets its size: lower values give a wider highlight, higher values a smaller one.
The highlight disappears in shadow. With the View shade type, it uses the View light instead of the scene lights.
Draws a colored line around the object. Width sets its thickness in meters.
Outline only works on Opaque surfaces without Alpha Clipping. On meshes with hard edges, the line breaks at the corners.
For shadows on Transparent surfaces, enable Transparent Receive Shadows on the URP Renderer.
The standard Unity material options: Render Queue, Enable GPU Instancing and Double Sided Global Illumination.
The Water shader colors water by depth: shallow areas are lighter, deep areas darker. Moving patterns add waves and foam. Water is always transparent.
Water needs Depth Texture enabled on the URP Asset.
Sets how the Wave and Perlin maps are placed on the water. Planar projects them from above and suits flat water. Triplanar projects them from all sides and suits sloped water, like a waterfall. If the water is flat, Planar gives the same result with better performance.
A moving pattern that lightens the water.
A moving pattern for foam or spots on the water.
For Wave and Perlin maps, a black and white map is recommended. Only the red channel is used.
The Sprite shader recolors 2D sprites with a gradient. Assign the material to a Sprite Renderer.
Pick the colors in the Gradient field. The Color of the Sprite Renderer tints the result, and the sprite's alpha is kept.
A black and white sprite is recommended. Only the red channel is used. See Grayscale Image.
The Skybox shader fills the sky with a gradient.
Direction sets the direction of the sky gradient. The side it points to is lightest, the opposite side darkest, and the horizon is in between. By default, the sky is light at the top and dark at the bottom.
Maps and sprites work best in black and white. To make a black and white copy of an image, right-click a PNG or JPG in the Project window and choose Create → Grayscale Image.
The copy keeps the import settings of the original, including sprite slices, and keeps the alpha.
You don't need this chapter to use the shaders. Read it to understand how they work and what they support.
Every pixel first gets a value between 0 and 1: 0 is the left (dark) end of the gradient, 1 is the right (light) end. Then the gradient color at that value is drawn. Each feature just moves this value. In the Basic shader, the steps are:
This is why Fill, Rim and Specular are not affected by Darken Map or Lighten Map, and Fill and Rim are not affected by shadows: they are added after the gradient.
Lights only make a surface lighter or darker. Their color is never used. The same is true for light cookies, baked lighting, light probes and ambient light. This way, no color that isn't in your gradient appears on screen.
Otherwise, lights behave like in URP's Lit shader: shadows, SSAO, light layers and additional light shadows all work the same way.
The Basic shader with the Light shade type supports baked lightmaps, baked shadows and light probes. All lighting modes work: Baked Indirect, Subtractive and Shadowmask.
With the default settings, the Basic shader costs about the same as URP's Lit and Simple Lit shaders on mobile.
| Unity | URP |
|---|---|
| 2022.3 | 14 |
| 2023.2 | 16 |
| 6000.0 | 17.0 |
| 6000.3 (LTS) | 17.3 |
Tested in the Editor on macOS, and in builds on iOS and Android.
| Feature | Notes |
|---|---|
| Forward, Forward+ | Supported. |
| Deferred | Supported. Gradient Map Shader objects are drawn forward, so the per-object light limit of Forward applies. Use Forward+ for many lights. |
| Render Graph | Supported, on and off. |
| SRP Batcher, GPU Instancing | Supported. |
| Additional lights | Per Pixel and Per Vertex. Per Vertex lights affect only the Light shade type. |
| Shadows | Main and additional light shadows, cascades, soft shadows, Screen Space Shadows. |
| Light Layers, Light Cookies | Supported in the Basic shader. |
| Depth Priming, Depth Texture, Depth Normals | Supported, including Normal Map. |
| SSAO | Supported. Occluded areas get darker. |
| Decals | Screen Space technique in Forward and Forward+. |
| Fog | Basic (including Outline) and Water. |
| Lightmaps, Light Probes, APV | Basic shader, Light shade type. See Baked Lighting. |
| LOD Cross Fade | Supported in the Basic shader. |
| Post-processing, MSAA, HDR | Supported. Gradient colors stay between 0 and 1, so keep the Bloom Threshold low. |
| Orthographic camera | Supported. |
| 2D Renderer | Sprite shader only. |
The package never changes your project settings. Some features need a setting enabled by you:
| Feature | Setting |
|---|---|
| Depth shade type, Water | Depth Texture on the URP Asset. |
| Shadows on Transparent surfaces | Transparent Receive Shadows on the URP Renderer. |
| Additional light shadows | Additional light shadows on the URP Asset and Shadow Type on the light. |
| Light Cookies | Light Cookies on the URP Asset. |
| LOD Cross Fade | LOD Cross Fade on the URP Asset (on by default) and Fade Mode Cross Fade on the LOD Group. |
| Decals | Technique Screen Space on the Decal Renderer Feature. |
Use SetGradient to change a material's gradient from
code. It is in the OctopusGameLab.GradientMapShader
namespace.
using OctopusGameLab.GradientMapShader;
using OctopusGameLab.RichGradient;
using UnityEngine;
public class GradientChanger : MonoBehaviour
{
[SerializeField] private RichGradient _gradient;
private void Start()
{
GetComponent<Renderer>().material.SetGradient(_gradient);
}
}
renderer.material changes only that object.
renderer.sharedMaterial changes every object that uses
the material.
Gradient, use
RichGradient.FromGradient(gradient). See the
Rich Gradient API.
OctopusGameLab.GradientMapShader and
OctopusGameLab.RichGradient to its references.
Each material saves its gradient in a small asset inside the material file, named <Material Name> Gradient. The Gradient field in the Inspector edits this asset.
From code, it is a GradientTextureSo. Set its
Gradient to change the gradient saved in the material:
[SerializeField] private GradientTextureSo _gradientAsset;
_gradientAsset.Gradient = newGradient;
| SetGradient | Gradient Asset | |
|---|---|---|
| Changes | The material while the game runs | The gradient saved in the material file |
| Change is saved | No | Yes |
| Use it for | Gameplay, effects, color changes | Editor tools |
In most cases, use SetGradient.
In the Editor, SetGradient on a material asset, such asrenderer.sharedMaterial, is saved like any other change to a material asset. Userenderer.materialto avoid this.
Values such as colors, strengths and sizes can be changed from code
with Unity's SetFloat, SetColor,
SetVector and SetTexture:
material.SetColor("_RimColor", Color.cyan);
material.SetFloat("_OutlineWidth", 0.1f);
| Shader | Property | Type |
|---|---|---|
| All | _GradientMapEnabled |
Float (0 = off, 1 = on) |
| Basic | _Cutoff |
Float (0–1) |
_ViewAxis, _FillAxis |
Vector (direction) | |
_DepthSize |
Float | |
_DepthStrength, _FlatLuminance |
Float (0–1) | |
_NormalMap, _DarkenMap, _LightenMap |
Texture | |
_NormalMapStrength, _DarkenMapStrength, _LightenMapStrength |
Float (0–1) | |
_FillColor |
Color | |
_FillStart, _FillEnd |
Float | |
_RimColor |
Color | |
_RimMin, _RimMax |
Float | |
_SpecularColor |
Color | |
_SpecularMin, _SpecularMax |
Float | |
_OutlineColor, _OutlineWidth |
Color, Float | |
| Water | _DepthSize |
Float |
_DepthStrength |
Float (0–1) | |
_WaveMap, _PerlinMap |
Texture | |
_WaveSpeed, _PerlinSpeed |
Vector (x, y) | |
_WaveStrength, _PerlinLimit, _PerlinDistortion, _PerlinStrength |
Float (0–1) | |
| Sprite | _Color |
Color (Tint) |
| Skybox | _DirectionAxis |
Vector (direction) |
The direction values take a direction vector, such as
Vector3.up. The Pitch and Yaw fields in the Inspector
are not updated when you change them from code.
Some settings only work when changed in the Inspector: Surface Type,
Alpha Clipping, Shade Type, Mapping, Alpha Map, Cast
Shadows, Receive Shadows and every Enable toggle.
Changing them from code does not turn the effect on or off. The same
is true for URP's Lit shader. To create a material from code, copy
one you set up in the Inspector: new Material(existingMaterial).
renderer.material creates a copy of the material.
Destroy it with Destroy(material) when you no longer
need it, as with any Unity material.
SetGradient call on a material creates a
small gradient texture (128×1) for it. Later calls draw into the
same texture. It is freed when Unity unloads unused assets, for
example when a new scene loads.
Depth mode or the Water shader looks flat. Why?
Turn on Depth Texture on the URP Asset. Depth mode also needs the material's Surface Type set to Transparent.
Why are Outline or Alpha Map grayed out?
Outline works on Opaque materials with Alpha Clipping off. Alpha Map works on Transparent materials or with Alpha Clipping on. Your Enable setting is kept and comes back when the condition is met.
My transparent object doesn't receive shadows.
Turn on Transparent Receive Shadows on the URP Renderer.
My sprite colors look wrong.
The Sprite shader reads only the red channel. Use a black and white sprite. You can make one with Grayscale Image.
Can I use HDR colors in the gradient?
Not currently. See Rich Gradient Limitations.
SetGradient changed every object. How do I change only one?
Call it on renderer.material instead of
renderer.sharedMaterial.
SetGradient
shares its gradient until SetGradient is called on the
copy.
Release notes for Gradient Map Shader are maintained in the package changelog.
View ChangelogHave a question, found a bug, or have feedback? Send us an email.