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:
- Navigate to your Material where you want to apply the shader
- In
Next Pass
chooseNew ShaderMaterial
- Apply the shader code
- 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);
}