|
|
|
|
shader_type spatial;
|
|
|
|
|
uniform bool is_target = false;
|
|
|
|
|
uniform bool is_focus = false;
|
|
|
|
|
uniform vec3 target_position = vec3(0, 1.28, 1);
|
|
|
|
|
uniform vec3 focus_min = vec3(0,0,0);
|
|
|
|
|
uniform vec3 focus_max = vec3(0,0,0);
|
|
|
|
|
varying vec3 world_position;
|
|
|
|
|
varying vec2 uv1;
|
|
|
|
|
varying vec2 uv2;
|
|
|
|
|
varying vec2 uv3;
|
|
|
|
|
uniform sampler2D tex_noise1 : source_color;
|
|
|
|
|
uniform sampler2D tex_noise2 : source_color;
|
|
|
|
|
uniform sampler2D tex_noise3 : source_color;
|
|
|
|
|
|
|
|
|
|
void vertex()
|
|
|
|
|
{
|
|
|
|
|
world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
|
|
|
|
|
vec2 local_uv = vec2(world_position.x,world_position.y + world_position.z);
|
|
|
|
|
uv1 = local_uv / 32.0;
|
|
|
|
|
uv2 = local_uv / 32.0;
|
|
|
|
|
uv3 = local_uv / 8.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_in_focus(vec3 f_min,vec3 f_max){
|
|
|
|
|
if(world_position.z>f_max.z){return false;}
|
|
|
|
|
if(world_position.y>f_max.y){return false;}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fragment() {
|
|
|
|
|
if (is_focus && !is_in_focus(focus_min,focus_max)){
|
|
|
|
|
discard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec3 c = COLOR.rgb;
|
|
|
|
|
if(c.r+c.g+c.b<0.1){
|
|
|
|
|
ALBEDO = vec3(0.0);
|
|
|
|
|
}else if(c.r+c.g+c.b>2.9){
|
|
|
|
|
discard;
|
|
|
|
|
}else{
|
|
|
|
|
float brightness = 1.0;
|
|
|
|
|
if(is_target){
|
|
|
|
|
float offset_y = abs(floor((world_position.y-target_position.y) / 0.02) * 0.02);
|
|
|
|
|
offset_y = max(0.0,offset_y-0.64);
|
|
|
|
|
float rate = clamp(1.0-offset_y/4.48,0.0,1.0);
|
|
|
|
|
brightness = rate;
|
|
|
|
|
}else{
|
|
|
|
|
brightness = 1.0;
|
|
|
|
|
}
|
|
|
|
|
vec3 world_normal = (INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
|
|
|
|
bool is_light = c.r+c.g+c.b>2.8;
|
|
|
|
|
if(!is_light && world_normal.y<0.1){
|
|
|
|
|
brightness = brightness*0.6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float noise_value1 = texture(tex_noise1,floor(uv1 /0.02) *0.02).r;
|
|
|
|
|
float discrete_noise_value1 = floor(noise_value1 / 0.5) * 0.5;
|
|
|
|
|
float noise_value2 = texture(tex_noise2,floor(uv2 /0.02) *0.02).r;
|
|
|
|
|
float discrete_noise_value2 = floor(noise_value2 / 0.5) * 0.5;
|
|
|
|
|
float noise_value3 = texture(tex_noise3,floor(uv3 /0.02) *0.02).r;
|
|
|
|
|
float discrete_noise_value3 = floor(noise_value3 / 0.1) * 0.1;
|
|
|
|
|
c -= discrete_noise_value1 * 0.2;
|
|
|
|
|
c += discrete_noise_value2 * 0.2;
|
|
|
|
|
c -= discrete_noise_value3 * 0.08;
|
|
|
|
|
c.rgb = mix(vec3(0.0), c.rgb, brightness);
|
|
|
|
|
ALBEDO = c.rgb;
|
|
|
|
|
if(is_light){
|
|
|
|
|
EMISSION = c.rgb * 2.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void light() {
|
|
|
|
|
vec3 c = ALBEDO.rgb;
|
|
|
|
|
float rgb_sum = c.r+c.g+c.b;
|
|
|
|
|
if (!(rgb_sum<0.1 || rgb_sum>2.9)){
|
|
|
|
|
DIFFUSE_LIGHT += clamp(dot(NORMAL, LIGHT), 0.0, 1.0) * ATTENUATION * LIGHT_COLOR;
|
|
|
|
|
}
|
|
|
|
|
}
|