// NOTE: Shader automatically converted from Godot Engine 4.4.stable.mono's StandardMaterial3D.

shader_type spatial;
render_mode blend_add, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx, unshaded;

#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc"
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Light.gdshaderinc"

uniform vec4 albedo : source_color;
uniform vec4 albedo2 : source_color;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform float grow : hint_range(0, 0.2);
uniform sampler2D texture_grow : repeat_enable;
uniform float fresnelFade : hint_range(0,100) = 0.1;
uniform float fadeStart : hint_range(0,1) = 0.1;
uniform float fadeEnd : hint_range(0,1) = 0.3;
uniform float fadeOffset : hint_range(-1, 1);
uniform float fadePower : hint_range(0, 20);
uniform float fadeScale : hint_range(-10, 10);

uniform vec3 uv1_scale;
uniform vec2 uv1_speed;

uniform vec3 uv2_scale;
uniform vec2 uv2_speed;

varying vec2 originalUV;

void vertex()
{
  originalUV = UV;
	UV = UV * uv1_scale.xy + uv1_speed * TIME;

  vec2 uv2 = UV * uv2_scale.xy + uv2_speed * TIME;

  float growSampled = texture(texture_grow, uv2).r * 2.0 - 1.0;
	VERTEX += NORMAL * grow * growSampled;
}

void fragment()
{
	vec2 base_uv = UV;

	vec4 albedo_tex = texture(texture_albedo, base_uv);
  vec4 mixedAlbedo = mix( albedo, albedo2, originalUV.y );
	ALBEDO = mixedAlbedo.rgb * albedo_tex.rgb;

  float f = 1.0 - fresnel( NORMAL, vec3(0,0,1), fresnelFade );
  float fade = 1.0 - originalUV.y;
  fade = pow( fade + fadeOffset, fadePower );
  fade = clamp( fade * fadeScale, 0, 1 );
  fade = fade * mapClamped( originalUV.y, fadeStart, fadeEnd, 0, 1 );
	ALPHA *= albedo.a * albedo_tex.a * fade * f;
}
