World Space Gradient in Next-Pass (Y-Axis)

ℹ️ As this is a Next Pass shader it will not overwrite your current material / textures

This is a simple next-pass shader which you can use to apply a gradient.

The origin is based on the real origin of the object. Use the top and bottom color using the alpha value for strength.

Setup:

  1. Navigate to your Material where you want to apply the shader
  2. In Next Pass choose New ShaderMaterial
  3. Apply the shader code
  4. Fine tune in Shader Parameters
Shader code
shader_type spatial;

uniform vec4 color_bottom : source_color = vec4(0.0, 0.0, 0.0, 0.8);
uniform vec4 color_top    : source_color = vec4(0.0, 0.0, 0.0, 0.0);

uniform float min_height = 0.0;
uniform float max_height = 3.0;

varying vec3 world_position;

void vertex() {
	world_position = (MODEL_MATRIX * vec4(VERTEX.xy, 0.0, 1.0)).xyz;
}

void fragment() {
	float height = world_position.y - NODE_POSITION_WORLD.y;

	float factor = clamp((height - min_height) / (max_height - min_height), 0.0, 1.0);

	ALBEDO = mix(color_bottom.rgb, color_top.rgb, factor);
	ALPHA = mix(color_bottom.a, color_top.a, factor);
}
Tags
gradient, next, world-space
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from DevUndead

Triplanar Stochastic Terrain Shader

Stencil / Masking in 3D

Related shaders

QoS Style World Space Blue Noise Dither Effect

Muzzle flash Z-axis billboard

World Coordinate Edge Fade

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments