giants-godot/assets/terrain.gdshader

40 lines
876 B
Plaintext
Raw Normal View History

2021-09-08 18:36:41 +02:00
shader_type spatial;
uniform float slope_factor = 8.0;
uniform float blend_value = 0.5;
uniform sampler2D light_map;
uniform sampler2D grass_tex;
uniform vec2 grass_scale;
uniform sampler2D dirt_tex;
uniform vec2 dirt_scale;
varying float height_val;
varying vec3 normal;
void vertex(){
height_val = VERTEX.y;
normal = NORMAL;
}
float get_slope_of_terrain(float height_normal){
float slope = 1.0-height_normal;
slope *= slope;
return (slope*slope_factor);
}
void fragment(){
vec3 dirt = vec3(texture(dirt_tex, UV*dirt_scale).rgb);
vec3 grass = vec3(texture(grass_tex, UV*grass_scale).rgb);
float slope = clamp(get_slope_of_terrain(normal.y), 0.0, 1.0);
vec3 mixin = mix(grass, dirt, slope);
vec3 lightmap = vec3(texture(light_map, UV).rgb)*0.5;
vec3 final_mix = mix(lightmap, mixin, vec3(blend_value, blend_value, blend_value));
ALBEDO = final_mix;
}