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 );
}
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.
Can you provide the textures ?
I don’t know what I’m doing, but it doesn’t seemt to work in Godot 4.2.
I changed the values “hint_albedo” for “source_color” and “hint_black” for “hint_default_black”. That’s what I found in Godot’s official documentation.
It doesn’t throw any errors now, but there is no visible effect on the mesh. (I’m using a flat plane)
Ok, so for anyone who is having trouble with this:
1) First make sure to adapt the shader to Godot 4:
Change the values “hint_albedo” for “source_color” and “hint_black” for “hint_default_black”.
2) Then create a QuadMesh, set its size to 1000 x 1000.
3) Subdivide its width and depth by 100. Make sure orientation is Face Y.
4) Then go to Geometry -> Material override -> New ShaderMaterial
5) Assign this shader. Set the Height to at least 50.
6) Assign whatever textures you want for the mountains and sand.
7) Create a New Noise texture and alter it however you want.