mirror of
https://port.numenaute.org/aleajactaest/khanat-client.git
synced 2024-11-10 01:10:05 +00:00
114 lines
3.5 KiB
GLSL
114 lines
3.5 KiB
GLSL
shader_type spatial;
|
|
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
|
|
uniform vec4 albedo : hint_color;
|
|
uniform sampler2D texture_albedo : hint_albedo;
|
|
uniform sampler2D texture_grass_2 : hint_albedo;
|
|
uniform sampler2D texture_albedo_2 : hint_albedo;
|
|
uniform sampler2D texture_albedo_hsv : hint_white;
|
|
uniform sampler2D texture_albedo_mix : hint_black;
|
|
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;
|
|
uniform vec4 roughness_texture_channel;
|
|
uniform sampler2D texture_normal : hint_normal;
|
|
uniform float normal_scale : hint_range(-16,16);
|
|
uniform sampler2D texture_ambient_occlusion : hint_white;
|
|
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;
|
|
|
|
varying vec2 base_uv;
|
|
varying vec2 rotated_uv;
|
|
varying vec2 rotated_uv_mask;
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
void vertex() {
|
|
base_uv=UV*uv1_scale.xy+uv1_offset.xy;
|
|
rotated_uv = rotateUVmatrinx(base_uv, vec2(0.5), (VERTEX.x));
|
|
rotated_uv = base_uv;
|
|
rotated_uv_mask = rotateUVmatrinx(UV, vec2(0.5), (VERTEX.x));
|
|
rotated_uv_mask = UV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fragment() {
|
|
// vec2 base_uv = UV;
|
|
vec4 albedo_tex = texture(texture_albedo,rotated_uv);
|
|
vec4 grass_2_tex = texture(texture_grass_2,rotated_uv);
|
|
vec4 albedo_2_tex = texture(texture_albedo_2,rotated_uv);
|
|
vec4 albedo_hsv_tex = texture(texture_albedo_hsv,rotated_uv_mask);
|
|
vec4 albedo_mix_tex = texture(texture_albedo_mix,rotated_uv_mask);
|
|
ALBEDO = albedo.rgb * albedo_tex.rgb;
|
|
|
|
// ALBEDO = mix( ALBEDO, grass_2_tex.rgb, 0.5 );
|
|
|
|
vec3 hsv_albedo = rgb2hsv(ALBEDO);
|
|
vec3 hsv_mask = rgb2hsv( albedo_hsv_tex.rgb );
|
|
hsv_albedo.x = hsv_mask.x;
|
|
hsv_albedo.y = hsv_mask.y;
|
|
hsv_albedo.z *= hsv_mask.z;
|
|
ALBEDO = hsv2rgb( hsv_albedo );
|
|
|
|
ALBEDO = mix( ALBEDO, albedo_2_tex.rgb, min( 1.0, max(-1.0, albedo_mix_tex.r-grass_level)) );
|
|
|
|
METALLIC = metallic;
|
|
float roughness_tex = dot(texture(texture_roughness,rotated_uv),roughness_texture_channel);
|
|
ROUGHNESS = roughness_tex * roughness;
|
|
SPECULAR = specular;
|
|
NORMALMAP = texture(texture_normal,rotated_uv).rgb;
|
|
NORMALMAP_DEPTH = normal_scale;
|
|
AO = dot(texture(texture_ambient_occlusion,rotated_uv),ao_texture_channel);
|
|
AO_LIGHT_AFFECT = ao_light_affect;
|
|
}
|