Gradient Map Shader v1.0.0

Download on Asset Store

1.1. Overview

Gradient 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.

1.2. Installation

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.

1.3. Quickstart

  1. Create a material: Assets → Create → Material.
  2. Set its shader to Octopus Game Lab → Gradient Map Shader → Basic.
  3. In the Shading section, click the Gradient field and pick your colors.
  4. Drag the material onto an object in the scene.
To learn how to add keys and change blend modes in the Gradient field, see Rich Gradient Editor Basics.
Gradient Map Shader Basic material in the Inspector
A Basic material in the Inspector. The Gradient field is in the Shading section.

Try a few colors and rotate the Directional Light to see the result change.

A gradient and the object it colors
The same object with two different gradients.

1.4. Requirements

  • Unity 2022.3 or newer
  • Universal Render Pipeline (URP) 14 or newer
  • Works in both Linear and Gamma color space projects

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.

2.1. Transparency

  • Surface Type: Opaque surfaces are solid. Transparent surfaces let what is behind them show through. In Transparent, the alpha of the gradient is used too.
  • Render Face: Which sides of the mesh are drawn: Front, Back or Both.
  • Alpha Clipping: Cuts holes where the Alpha Map is below the Threshold. Shadows and baked lighting get the same holes.
Opaque surface
Opaque
Transparent surface
Transparent
Only the Alpha Map cuts holes. The alpha of the gradient does not.

2.2. Shading

  • Gradient Map: When off, the surface shows grayscale shading instead of the gradient colors. Useful to check the shading on its own.
  • Gradient: Colors of the surface. See Gradient Modes for how the colors blend.
  • Shade Type: How the surface picks colors from the gradient: Light, View, Depth or Flat.
Gradient Map off
Gradient Map off
Gradient Map on
Gradient Map on

2.2.1. Light

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.

Shade Type Light

2.2.2. View

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.

Shade Type View

2.2.3. Depth

Follows how deep the scene is behind the surface, like water. Shallow areas are lighter, deep areas darker.

  • Depth Size: How deep the gradient spreads, in meters.
  • Depth Strength: Brightness of shallow areas. 0 = the whole surface uses the dark end, 1 = full gradient.
Depth needs Surface Type set to Transparent and Depth Texture enabled on the URP Asset.
Shade Type Depth

2.2.4. Flat

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.

Shade Type Flat

2.3. Maps

Textures that add detail to the surface. Each map has its own Enable toggle.

2.3.1. Alpha Map

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 off
Alpha Map off
Alpha Map on with Alpha Clipping
Alpha Map on, with Alpha Clipping
Alpha Map only works when Surface Type is Transparent or Alpha Clipping is on.

2.3.2. Normal Map

Adds bumps and dents to the shading, Rim and Specular. Strength sets how strong the bumps are.

Normal Map off
Normal Map off
Normal Map on
Normal Map on
Normal Map works with the Light and View shade types. Set the texture's Texture Type to Normal map in its import settings.

2.3.3. Darken Map

Dark areas of the texture darken the surface. Use it for dirt, cracks or painted details. Strength sets how strong the darkening is.

Darken Map off
Darken Map off
Darken Map on
Darken Map on

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 mapping
Planar
Triplanar mapping
Triplanar

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.

2.3.4. Lighten Map

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.

Lighten Map off
Lighten Map off
Lighten Map on
Lighten Map on

2.4. Additional Effects

Extra effects on top of the gradient colors, and the shadow settings of the object.

2.4.1. Fill

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.

  • Color: The fill color.
  • Range: The fill color fades in between the two values. 0 is the side the Direction points to, 1 is the opposite side.
  • Direction: Direction of the fill in the world. Pitch sets its height, Yaw turns it around.
Fill off
Fill off
Fill on
Fill on
The direction is in world space, so the fill does not turn when the object rotates.

2.4.2. Rim

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.

Rim off
Rim off
Rim on
Rim on
Rim with Normal Map
Rim with Normal Map

2.4.3. Specular

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.

Specular off
Specular off
Specular on
Specular on
The highlight disappears in shadow. With the View shade type, it uses the View light instead of the scene lights.

2.4.4. Outline

Draws a colored line around the object. Width sets its thickness in meters.

Outline off
Outline off
Outline on
Outline on
Outline only works on Opaque surfaces without Alpha Clipping. On meshes with hard edges, the line breaks at the corners.

2.4.5. Shadow

  • Cast Shadows: The object casts shadows on other objects.
  • Receive Shadows: Shadows darken the surface.
Receive Shadows off
Receive Shadows off
Receive Shadows on
Receive Shadows on
For shadows on Transparent surfaces, enable Transparent Receive Shadows on the URP Renderer.

2.5. Advanced Options

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 shader in a scene
Water with Wave and Perlin Noise.

3.1. Shading

  • Gradient: Colors of the water.
  • Depth Size: How deep the gradient spreads, in meters.
  • Depth Strength: Brightness of shallow areas. 0 = the whole surface uses the dark end, 1 = full gradient.
Low Depth Size
Low Depth Size
High Depth Size
High Depth Size
Water needs Depth Texture enabled on the URP Asset.

3.2. Mapping

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.

3.3. Wave

A moving pattern that lightens the water.

  • Wave Map and Tiling: The pattern and its size.
  • Speed: How fast the waves move (X and Y).
  • Strength: How strong the waves are. 0 = none, 1 = full.
Wave off
Wave off
Wave on
Wave on

3.4. Perlin Noise

A moving pattern for foam or spots on the water.

  • Perlin Map and Tiling: The pattern and its size.
  • Limit: Areas of the map brighter than this are shown. Higher values give fewer spots.
  • Distortion: How much the spots wobble. 0 = no wobble.
  • Speed: How fast the spots move (X and Y).
  • Strength: Brightness of the spots. 0 = darkest, 1 = lightest.
Low Limit
Low Limit
High Limit
High Limit
Low Distortion
Low Distortion
High Distortion
High Distortion
For Wave and Perlin maps, a black and white map is recommended. Only the red channel is used.

3.5. Notes

  • Only opaque objects under the water count toward its depth.
  • The water is not visible from below.
  • Water has no lighting, shadows, Rim, Specular or Outline.
  • Advanced Options are the same as in the Basic shader.

The Sprite shader recolors 2D sprites with a gradient. Assign the material to a Sprite Renderer.

4.1. Shading

Pick the colors in the Gradient field. The Color of the Sprite Renderer tints the result, and the sprite's alpha is kept.

Original sprite
Original sprite
Sprite with Gradient Map Shader
With Gradient Map Shader
A black and white sprite is recommended. Only the red channel is used. See Grayscale Image.

4.2. Notes

  • Works with the 2D Renderer and the regular URP renderers.
  • Sprite flipping, Sprite Masks, Sorting Groups and 2D Animation (skinned sprites) work.
  • Sprites get no lighting, including 2D lights.

The Skybox shader fills the sky with a gradient.

5.1. Setup

  1. Create a material with the Octopus Game Lab → Gradient Map Shader → Skybox shader.
  2. Open Window → Rendering → Lighting → Environment.
  3. Assign the material to Skybox Material.

5.2. Shading

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.

Skybox direction pointing up
Pitch 90 (default)
Skybox direction tilted
Tilted direction

6.1. Grayscale Image

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.

Create Grayscale Image menu in the Project window
Create → Grayscale Image in the Project window.

You don't need this chapter to use the shaders. Read it to understand how they work and what they support.

7.1. How It Works

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:

  1. Shade Type sets the starting value (Light, View, Depth or Flat).
  2. Shadows and SSAO move it toward 0.
  3. Baked lighting moves it toward 1.
  4. Darken Map moves it toward 0, Lighten Map toward 1.
  5. The gradient turns the value into a color.
  6. Fill, Rim and Specular add their colors on top.
  7. Fog is applied last.
Shading value mapped to the gradient
The grayscale shading (Gradient Map off) and the same shading through a gradient.

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.

7.2. Lighting

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.

7.3. Baked Lighting

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.

  • Ambient light lightens shadows a little, like in Lit. For darker shadows, set Environment Lighting to black.
  • Bounced light takes the average color of the gradient.
  • Moving objects get baked light from light probes.

7.4. Performance Tips

With the default settings, the Basic shader costs about the same as URP's Lit and Simple Lit shaders on mobile.

  • Turn off features you don't use. Disabled features cost nothing.
  • Use Planar instead of Triplanar when the map only needs to look right from above.
  • Outline draws the object a second time.
  • Specular costs more with many lights. Use it only where needed.

7.5. Tested Versions

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.

7.6. Rendering Features

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.

7.7. Project Settings

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.

7.8. Not Supported

  • Built-in Render Pipeline and HDRP. The package is made for URP only.
  • Entities Graphics (DOTS). Objects are not visible. With GPU Resident Drawer, objects are drawn the regular way.
  • Motion Vectors. Moving objects can leave trails with TAA, Motion Blur and STP.
  • DBuffer Decals. The decal color would replace the gradient colors. Use Screen Space decals.
  • Reflection Probes and Realtime GI.
  • Particles, Terrain and UI. These need their own shaders.

8.1. Set Gradient

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.
  • You can call it every frame. It does not allocate memory.
  • A material copied from one that used SetGradient shares its gradient. Call SetGradient on the copy to give it its own.
  • For a Unity Gradient, use RichGradient.FromGradient(gradient). See the Rich Gradient API.
  • If your scripts have their own Assembly Definition, add OctopusGameLab.GradientMapShader and OctopusGameLab.RichGradient to its references.

8.2. Gradient Asset

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.

Gradient asset under a material in the Project window
The Gradient asset under its material.

From code, it is a GradientTextureSo. Set its Gradient to change the gradient saved in the material:

[SerializeField] private GradientTextureSo _gradientAsset;

_gradientAsset.Gradient = newGradient;

8.3. Which One to Use?

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 as renderer.sharedMaterial, is saved like any other change to a material asset. Use renderer.material to avoid this.

8.4. Other Material Values

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).

8.5. Memory

  • renderer.material creates a copy of the material. Destroy it with Destroy(material) when you no longer need it, as with any Unity material.
  • The first 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.
  • There is no separate method to release anything.

9.1. FAQ

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.

9.2. Limitations

  • Fill uses world axes. It does not rotate with the object.
  • Fill, Rim and Specular are not affected by Darken Map and Lighten Map.
  • Outline can break at the corners of hard-edged meshes.
  • Normal Map works only with Light and View shade types.
  • Water is not visible from below.
  • Sprite and Skybox shaders have no lighting or shadows.
  • A material copied from one that used SetGradient shares its gradient until SetGradient is called on the copy.
  • For unsupported pipelines and features, see Not Supported.

9.3. Changelog

Release notes for Gradient Map Shader are maintained in the package changelog.

View Changelog

9.4. Contact

Have a question, found a bug, or have feedback? Send us an email.

octopusgamelab@gmail.com