khanat-client/assets/decors/vegets/grass/grass.shader

60 lines
1.7 KiB
GLSL

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_hue : hint_albedo;
uniform sampler2D texture_lightness : hint_white;
uniform sampler2D texture_saturation : hint_white;
uniform sampler2D texture_alpha : hint_black;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform float point_size : hint_range(0,128);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
VERTEX.x += cos(TIME)*VERTEX.y/4.0;
VERTEX.z += sin(TIME)*VERTEX.y/4.0;
}
void fragment() {
vec2 base_uv = UV;
vec4 hue_tex = texture(texture_hue,base_uv);
vec4 lightness_tex = texture(texture_lightness,base_uv);
vec4 saturation_tex = texture(texture_saturation,base_uv);
vec4 alpha_tex = texture(texture_alpha,base_uv);
ALBEDO = albedo.rgb;
vec3 hsv = vec3( hue_tex.r, saturation_tex.r, lightness_tex.r );
ALBEDO *= hsv2rgb(hsv);
METALLIC = metallic;
ROUGHNESS = roughness;
SPECULAR = specular;
ALPHA = albedo.a * alpha_tex.r;
ALPHA_SCISSOR = 0.1;
}