Sky Flat Ground Texture
Draw a flat ground texture to a worldspace position using sky shaders
Shader code
shader_type sky;
uniform sampler2D ground_sample : source_color;
uniform vec3 ground_position = vec3(0.0);
uniform float ground_size = 1.0;
uniform bool ground_tiling = false;
void ground_texture( inout vec3 set, in vec3 eyedir, in vec3 position) {
vec3 cam = position - ground_position;
vec2 euv = eyedir.xz / abs( eyedir.y );
vec2 cuv = -cam.xz / cam.y;
float camDist = length(cam);
float absy = abs(normalize(cam).y);
vec2 tuv = (euv-cuv) * camDist * absy / ground_size;
if ( eyedir.y < 0.0 && position.y > ground_position.y )
if ( ground_tiling || max(abs(tuv.x),abs(tuv.y)) < 0.5 )
set = texture(ground_sample,tuv+vec2(0.5)).rgb;
}
void sky() {
float m = step(0.0, EYEDIR.y);
m = sqrt(smoothstep(0.0,-0.05,EYEDIR.y));
vec3 set = mix(vec3(0.38,0.45,0.55), vec3(0.2,0.16,0.13), m);
ground_texture(set, EYEDIR, POSITION);
COLOR = set;
}