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

shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, 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/Transform.gdshaderinc"
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc"
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc"

uniform vec4 tint : source_color;
uniform float colorScale = 0.24;
uniform float normalWrap = 1;
uniform float normalShift = 0.465;
uniform float weight = 1;

uniform float normalWrap2 = 5.525;
uniform float normalShift2 = 0;
uniform float weight2 = 0.181;

uniform float normalWrap3 = 0.1;
uniform float normalShift3 = 2.655;
uniform float weight3 = 0.315;

varying vec3 worldNormal;

void vertex()
{
	worldNormal = NORMAL * MODEL_NORMAL_MATRIX;

}

vec3 rainbow( float hue )
{
  return HSLtoRGB( vec3( hue, 1.0, 0.5 ) );
}

void fragment()
{
  float dotP = mod( dot( worldNormal, VIEW ) * normalWrap + normalShift, 1 );
  float dotP2 = mod( dot( -NORMAL, -VIEW ) * normalWrap2 + normalShift2, 1 );
  float dotP3 = mod( dot( -NORMAL, -VIEW ) * normalWrap3 + normalShift3, 1 );

	vec3 rainbowColor = rainbow( dotP ) * weight
                    + rainbow( dotP2 ) * weight2
                    + rainbow( dotP3 ) * weight3;

	ALBEDO = tint.rgb * rainbowColor * colorScale;

}
