2020-03-29 11:29:57 +00:00
|
|
|
shader_type spatial;
|
|
|
|
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
|
|
|
|
uniform vec4 albedo : hint_color;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_grass : hint_albedo;
|
2020-04-04 09:29:45 +00:00
|
|
|
uniform sampler2D texture_grass_25 : hint_albedo;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_grass_height : hint_white;
|
|
|
|
uniform sampler2D texture_dirt : hint_albedo;
|
|
|
|
uniform sampler2D texture_dirt_height : hint_black;
|
|
|
|
uniform sampler2D texture_hsv_mask : hint_white;
|
|
|
|
uniform sampler2D texture_hsv2_mask : hint_white;
|
2020-03-29 11:29:57 +00:00
|
|
|
uniform sampler2D texture_albedo_mix : hint_black;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_mix_gradiant : hint_black;
|
|
|
|
uniform sampler2D texture_mix_border : hint_black;
|
|
|
|
|
|
|
|
uniform sampler2D texture_albedo_mix2 : hint_black;
|
2020-03-29 11:29:57 +00:00
|
|
|
uniform float specular;
|
|
|
|
uniform float metallic;
|
|
|
|
uniform float roughness : hint_range(0,1);
|
|
|
|
uniform float point_size : hint_range(0,128);
|
|
|
|
uniform sampler2D texture_roughness : hint_white;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_roughness_dirt : hint_white;
|
2020-03-29 11:29:57 +00:00
|
|
|
uniform vec4 roughness_texture_channel;
|
|
|
|
uniform sampler2D texture_normal : hint_normal;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_normal_dirt : hint_normal;
|
2020-03-29 11:29:57 +00:00
|
|
|
uniform float normal_scale : hint_range(-16,16);
|
|
|
|
uniform sampler2D texture_ambient_occlusion : hint_white;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform sampler2D texture_ambient_occlusion_dirt : hint_white;
|
2020-03-29 11:29:57 +00:00
|
|
|
uniform vec4 ao_texture_channel;
|
|
|
|
uniform float ao_light_affect;
|
|
|
|
uniform vec3 uv1_scale;
|
|
|
|
uniform vec3 uv1_offset;
|
|
|
|
uniform vec3 uv2_scale;
|
|
|
|
uniform vec3 uv2_offset;
|
|
|
|
|
|
|
|
uniform vec3 hsv;
|
|
|
|
uniform float grass_level = 1.0;
|
2020-03-30 10:31:39 +00:00
|
|
|
uniform float angle = 0.0;
|
2020-03-29 11:29:57 +00:00
|
|
|
|
|
|
|
varying vec2 base_uv;
|
|
|
|
varying vec2 rotated_uv;
|
|
|
|
varying vec2 rotated_uv_mask;
|
2020-04-04 09:29:45 +00:00
|
|
|
varying float v_index;
|
2020-03-29 11:29:57 +00:00
|
|
|
|
|
|
|
vec2 rotateUVmatrinx(vec2 uv, vec2 pivot, float rotation)
|
|
|
|
{
|
|
|
|
mat2 rotation_matrix=mat2( vec2(sin(rotation),-cos(rotation)),
|
|
|
|
vec2(cos(rotation),sin(rotation))
|
|
|
|
);
|
|
|
|
uv -= pivot;
|
|
|
|
uv= uv*rotation_matrix;
|
|
|
|
uv += pivot;
|
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
vec2 rotateUV(vec2 uv, vec2 pivot, float rotation) {
|
|
|
|
float sine = sin(rotation);
|
|
|
|
float cosine = cos(rotation);
|
|
|
|
|
|
|
|
uv -= pivot;
|
|
|
|
uv.x = uv.x * cosine - uv.y * sine;
|
|
|
|
uv.y = uv.x * sine + uv.y * cosine;
|
|
|
|
uv += pivot;
|
|
|
|
|
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-30 10:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void vertex()
|
|
|
|
{
|
2020-04-08 12:38:05 +00:00
|
|
|
v_index = mod(VERTEX.x, 1024.0/200.0);
|
2020-03-29 11:29:57 +00:00
|
|
|
base_uv=UV*uv1_scale.xy+uv1_offset.xy;
|
2020-04-08 12:38:05 +00:00
|
|
|
rotated_uv = rotateUVmatrinx(base_uv, vec2(0.5), (v_index));
|
2020-03-30 10:31:39 +00:00
|
|
|
// rotated_uv = base_uv;
|
2020-04-08 12:38:05 +00:00
|
|
|
rotated_uv_mask = rotateUVmatrinx(UV, vec2(0.5), (v_index));
|
2020-03-30 10:31:39 +00:00
|
|
|
// rotated_uv_mask = UV;
|
|
|
|
|
2020-03-29 11:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-30 10:31:39 +00:00
|
|
|
void fragment()
|
|
|
|
{
|
2020-03-29 11:29:57 +00:00
|
|
|
// vec2 base_uv = UV;
|
2020-03-30 10:31:39 +00:00
|
|
|
vec4 grass_tex = texture(texture_grass,base_uv);
|
2020-04-04 09:29:45 +00:00
|
|
|
vec4 grass_25_tex = texture(texture_grass_25,base_uv);
|
2020-03-30 10:31:39 +00:00
|
|
|
vec4 grass_height_tex = texture(texture_grass_height,base_uv);
|
|
|
|
vec4 dirt_tex = texture(texture_dirt,base_uv);
|
|
|
|
vec4 dirt_height_tex = texture(texture_dirt_height,base_uv);
|
|
|
|
vec4 dirt_height_hsv_tex = texture(texture_dirt_height,rotated_uv_mask);
|
|
|
|
vec4 hsv_mask_tex = texture(texture_hsv_mask,UV);
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 hsv2_mask_tex = texture(texture_hsv2_mask,UV*vec2(1.0,1.0));
|
2020-04-04 09:29:45 +00:00
|
|
|
vec4 albedo_mix_tex;
|
|
|
|
// if ( abs(v_index) > 1.28 )
|
|
|
|
// {
|
|
|
|
// albedo_mix_tex = texture(texture_hsv_mask,UV);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
{
|
|
|
|
albedo_mix_tex = texture(texture_albedo_mix,UV);
|
|
|
|
}
|
2020-03-30 10:31:39 +00:00
|
|
|
vec4 mix_gradiant_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex.r, albedo_mix_tex.r ));
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 albedo_mix_tex_low = texture(texture_albedo_mix,UV*vec2(50.0,50.0));
|
2020-03-30 10:31:39 +00:00
|
|
|
vec4 mix_gradiant_low_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex_low.r, albedo_mix_tex_low.r ));
|
|
|
|
vec4 mix_gradiant_border = texture(texture_mix_border,vec2( albedo_mix_tex_low.r, albedo_mix_tex_low.r ));
|
|
|
|
vec4 albedo_mix_tex2 = texture(texture_albedo_mix2,base_uv);
|
|
|
|
vec4 mix_gradiant2_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex2.r, albedo_mix_tex2.r ));
|
2020-04-08 12:38:05 +00:00
|
|
|
// ALBEDO = albedo.rgb * grass_tex.rgb;
|
|
|
|
//
|
|
|
|
// vec3 hsv_albedo = rgb2hsv(ALBEDO);
|
2020-03-30 10:31:39 +00:00
|
|
|
vec3 hsv_mask = rgb2hsv( hsv_mask_tex.rgb );
|
|
|
|
vec3 hsv2_mask = rgb2hsv( hsv2_mask_tex.rgb );
|
2020-04-08 12:38:05 +00:00
|
|
|
// hsv_albedo.x *= hsv.x;
|
|
|
|
// hsv_albedo.y = hsv.y;
|
|
|
|
// hsv_albedo.z *= hsv.z * (hsv_mask.z * hsv2_mask.z*2.0);
|
|
|
|
// ALBEDO = hsv2rgb( hsv_albedo );
|
2020-03-29 11:29:57 +00:00
|
|
|
|
2020-03-30 10:31:39 +00:00
|
|
|
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 mix_mix = mix( mix_gradiant_tex, mix_gradiant_border, 0.5 );
|
2020-03-30 10:31:39 +00:00
|
|
|
|
2020-04-08 12:38:05 +00:00
|
|
|
float mix_level = clamp( mix_gradiant_tex.r-grass_level, 0.0, 1.0 );
|
|
|
|
// float mix_level = clamp( mix_gradiant_tex.r*mix_gradiant_border.r-grass_level, 0.0, 1.0 );
|
2020-03-30 10:31:39 +00:00
|
|
|
|
|
|
|
// if ( grass_height_tex.r > 0.5 )
|
|
|
|
// {
|
|
|
|
//// mix_level = 0.0;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// mix_level = 1.0;
|
|
|
|
// }
|
|
|
|
if ( mix_level > 0.0 && mix_level < 1.0 )
|
|
|
|
{
|
|
|
|
if ( grass_height_tex.r < dirt_height_tex.r )
|
|
|
|
{
|
2020-04-08 12:38:05 +00:00
|
|
|
// mix_level = 0.0;
|
2020-03-30 10:31:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-08 12:38:05 +00:00
|
|
|
// mix_level = 1.0;
|
2020-03-30 10:31:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-08 12:38:05 +00:00
|
|
|
// mix_level *= mix_level;
|
|
|
|
// mix_level *= mix_level;
|
|
|
|
// mix_level *= mix_level;
|
|
|
|
|
2020-03-30 10:31:39 +00:00
|
|
|
vec3 hsv_dirt = rgb2hsv(dirt_tex.rgb);
|
2020-04-08 12:38:05 +00:00
|
|
|
// hsv_dirt.x += (hsv_mask.z)*0.1;
|
|
|
|
hsv_dirt.y = hsv.y*(hsv_mask.z * hsv2_mask.z *2.0);
|
|
|
|
hsv_dirt.z *= hsv.z*(hsv_mask.z * hsv2_mask.z *2.0);
|
2020-03-30 10:31:39 +00:00
|
|
|
dirt_tex.rgb = hsv2rgb( hsv_dirt );
|
2020-04-08 12:38:05 +00:00
|
|
|
|
|
|
|
vec3 hsv_grass = rgb2hsv(grass_tex.rgb);
|
|
|
|
// hsv_grass.x *= hsv.x;
|
|
|
|
hsv_grass.y = hsv.y*(hsv_mask.z * hsv2_mask.z *2.0);
|
|
|
|
hsv_grass.z *= hsv.z*(hsv_mask.z * hsv2_mask.z *2.0);
|
|
|
|
grass_tex.rgb = hsv2rgb( hsv_grass );
|
|
|
|
|
|
|
|
vec3 hsv_grass_25 = rgb2hsv(grass_25_tex.rgb);
|
|
|
|
hsv_grass_25.y = hsv.y*(hsv_mask.z * hsv2_mask.z *2.0);
|
|
|
|
hsv_grass_25.z *= hsv.z*(hsv_mask.z * hsv2_mask.z *2.0);
|
|
|
|
grass_25_tex.rgb = hsv2rgb( hsv_grass_25 );
|
|
|
|
|
|
|
|
ALBEDO = dirt_tex.rgb;
|
2020-04-04 09:29:45 +00:00
|
|
|
if ( mix_level >= 1.0 )
|
|
|
|
{
|
2020-04-08 12:38:05 +00:00
|
|
|
// ALBEDO = mix( ALBEDO, grass_tex.rgb, mix_level);
|
2020-04-04 09:29:45 +00:00
|
|
|
}
|
2020-04-08 12:38:05 +00:00
|
|
|
else if ( mix_level >= 0.5 )
|
2020-04-04 09:29:45 +00:00
|
|
|
{
|
2020-04-08 12:38:05 +00:00
|
|
|
// ALBEDO = mix( ALBEDO, grass_25_tex.rgb, mix_gradiant_border.r*mix_level );
|
2020-04-04 09:29:45 +00:00
|
|
|
ALBEDO = mix( ALBEDO, grass_25_tex.rgb, mix_level );
|
|
|
|
}
|
2020-04-08 12:38:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// ALBEDO = mix( ALBEDO, grass_25_tex.rgb, mix_level );
|
|
|
|
}
|
|
|
|
ALBEDO = mix( ALBEDO, grass_tex.rgb, mix_level*mix_level*mix_level*mix_level);
|
2020-03-29 11:29:57 +00:00
|
|
|
METALLIC = metallic;
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 final_roughness = mix( texture(texture_roughness_dirt,base_uv),texture(texture_roughness,base_uv), mix_level );
|
2020-03-30 10:31:39 +00:00
|
|
|
ROUGHNESS = dot(final_roughness, roughness_texture_channel) * roughness;
|
2020-03-29 11:29:57 +00:00
|
|
|
SPECULAR = specular;
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 final_normal = mix( texture(texture_normal_dirt,base_uv),texture(texture_normal,base_uv), mix_level );
|
2020-03-30 10:31:39 +00:00
|
|
|
NORMALMAP = final_normal.rgb;
|
2020-03-29 11:29:57 +00:00
|
|
|
NORMALMAP_DEPTH = normal_scale;
|
2020-04-08 12:38:05 +00:00
|
|
|
vec4 final_ao = mix( texture(texture_ambient_occlusion_dirt,base_uv), texture(texture_ambient_occlusion,base_uv), mix_level );
|
2020-03-30 10:31:39 +00:00
|
|
|
AO = dot(final_ao,ao_texture_channel);
|
|
|
|
AO_LIGHT_AFFECT = ao_light_affect;
|
2020-03-29 11:29:57 +00:00
|
|
|
}
|