Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type spatial;
- // Fragment shader
- uniform sampler2D grass_texture;
- uniform sampler2D stone_texture;
- uniform sampler2D earth_texture;
- // Define scaling factors for each texture (adjust as needed)
- uniform float grass_scale = 300;
- uniform float stone_scale = 75;
- uniform float earth_scale = 75;
- // Stone vs Grass
- uniform float min_stone_slope:hint_range(0.0, 1.0) = 0.80;
- uniform float max_grass_slope:hint_range(0.0, 1.0) = 0.81;
- // Earth vs StoneGrass
- uniform float min_stonegrass_height = -0.5;
- uniform float max_earth_height = 0;
- varying float normal_y;
- varying float vertex_y;
- void vertex(){
- // Called for every vertex the material is visible on.
- normal_y = NORMAL.y;
- vertex_y = VERTEX.y;
- }
- void fragment() {
- // Called for every pixel the material is visible on.
- vec3 grass_albedo = texture(grass_texture, UV * grass_scale).xyz;
- vec3 stone_albedo = texture(stone_texture, UV * stone_scale).xyz;
- vec3 earth_albedo = texture(earth_texture, UV * earth_scale).xyz;
- // Weights
- float stone_grass_weight = normal_y;
- float earth_stonegrass_weight = vertex_y;
- // Calculating Stone/Grass Weight
- stone_grass_weight = max(min_stone_slope, stone_grass_weight);
- stone_grass_weight = min(max_grass_slope, stone_grass_weight);
- stone_grass_weight -= min_stone_slope;
- stone_grass_weight /= max_grass_slope - min_stone_slope;
- // Calculating Earth/StoneGrass Weight
- earth_stonegrass_weight = max(min_stonegrass_height, earth_stonegrass_weight);
- earth_stonegrass_weight = min(max_earth_height, earth_stonegrass_weight);
- earth_stonegrass_weight -= min_stonegrass_height;
- earth_stonegrass_weight /= max_earth_height - min_stonegrass_height;
- vec3 stonegrass_albedo = mix(stone_albedo, grass_albedo, stone_grass_weight);
- ALBEDO = mix(earth_albedo, stonegrass_albedo, earth_stonegrass_weight);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement