Mountain Background Shader.

Mountain Background Shader.

Shader code
/*
	遠景山シェーダー by あるる(きのもと 結衣) @arlez80
	Background Mountain Shader by Yui Kinomoto

	MIT License
*/

shader_type spatial;
render_mode unshaded, shadows_disabled;

uniform float mountain_distance = 2000.0;
uniform sampler2D mountain_texture : hint_albedo;
uniform sampler2D sand_texture : hint_albedo;
uniform sampler2D height_map : hint_black;
uniform float height = 11.0;
uniform vec4 aerial_perspective_color : hint_color = vec4( 0.1411764705882353, 0.41568627450980394, 0.6705882352941176, 1.0 );
uniform vec2 mountain_uv_scale = vec2( 25.0, 25.0 );
uniform vec2 sand_uv_scale = vec2( 100.0, 100.0 );

void vertex( )
{
	float r = atan( VERTEX.z, VERTEX.x );
	VERTEX.y = texture( height_map, UV ).r * height * length( UV - vec2( 0.5, 0.5 ) );
	NORMAL = vec3( 0.0, 1.0, 0.0 );
}

void fragment( )
{
	float dist = length( UV - vec2( 0.5, 0.5 ) );
	ALBEDO = mix(
		mix(
			texture( mountain_texture, UV * mountain_uv_scale )
		,	texture( sand_texture, UV * sand_uv_scale )
		,	clamp( pow( texture( height_map, UV * 1.1 ).r * 1.4, 6.0 ), 0.0, 1.0 )
		).rgb
	,	aerial_perspective_color.rgb
	,	dist * 0.8
	);
	DEPTH = clamp( 0.99999 + dist * 0.00001, 0.0, 1.0 );
}
Tags
background, mountain
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from arlez80

Procedural Grain Wood Shader

Procedural Marble Shader

Sobel with Gaussian filter

Related shaders

Earthbound-like battle background shader w/scroll effect and palette cycling

background shader

Scrolling background

guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
gdeavid
gdeavid
2 months ago

Very nice shader!

What kind of mesh should you put it on? I put it on a subdivided plane mesh, but am wondering if that’s the intended way.

ZErt
ZErt
1 month ago

Can you provide the textures ?