#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
#include "../../Common/Template Shader/Define.hlsl"
#include "../../Common/Template Shader/Transforms.hlsl"
#include "HLSLToon_ChangeTex.hlsl"
#include "../../Environment/Sky&Fog/VolumetricFogForObject.hlsl"
#include "../../../../../Plugins/Giant/GiantEngine/BakedAnimations/ShaderLibrary/GiantEngine-BakedAnimation.hlsl"

uniform sampler2D _MainTex;
sampler2D _BumpMap;
//uniform float4 _Color;
uniform sampler2D _MaskTex;
uniform sampler2D _LightMaskTex;
uniform sampler2D _RampTex;
uniform float4 _RampColor;
uniform sampler2D _FlashTex;

uniform float _HighLight;
uniform float4 _HighLightColor;
uniform float _BrightnessFactor;
uniform float _LightMaskParam;
uniform float _LightMask_Off,_Billboard;
uniform float _LightMaskBackParam;

uniform float4 _LightColor;
uniform float _BrightnessRatio;
uniform float _BrightnessIncrease;
//uniform half4 _FlashFactor;
//uniform half _FlashStrength;

uniform half _NewRamp;
uniform half _RampNum;

uniform half _IsColoration;
uniform half _WhiteChannel;

//#ifdef DISSOLVE 
uniform sampler2D _DissolveTex;
//uniform half3 _DissolveFactor;
//uniform half3 _DissColor;
//#endif
half _SpecSmooth;
half _Shininess;
uniform float4 _env_shadow_color;
uniform float _shadowFalloff;
//uniform float4 _IlluminColor;
//uniform float4 _RimColor,_BackRimColor;
//uniform float _RimWidth,_BackRimWidth;
uniform float4 _BackRimColor;
uniform float _BackRimWidth;
sampler2D _EmissionTex;
//half _IlluminStrength,_TimeScale,_Illumin_On;
uniform half4 _SpecColor;
uniform float _SpecStrength;

uniform half4	_Coloration;
float _HueShiftG;
float _SatG;
float _ValG;
uniform half4	_ColorationG;
uniform float _BloomFactor,_Cutoff,_AlphaClip;
float _Gamma;

float _RT_Reflection;
uniform half _RoleBloomFactor;

#ifdef _GIANT_BAKED_ANIMATION_ON

	

	UNITY_INSTANCING_BUFFER_START(Props)
		UNITY_DEFINE_INSTANCED_PROP(float4, _Color)

		UNITY_DEFINE_INSTANCED_PROP(half, _Illumin_On)
		UNITY_DEFINE_INSTANCED_PROP(half, _TimeScale)
		UNITY_DEFINE_INSTANCED_PROP(half, _IlluminStrength)
		UNITY_DEFINE_INSTANCED_PROP(float4, _IlluminColor)

		UNITY_DEFINE_INSTANCED_PROP(float4, _RimColor)
		//UNITY_DEFINE_INSTANCED_PROP(float4, _BackRimColor)
		UNITY_DEFINE_INSTANCED_PROP(float, _RimWidth)
		//UNITY_DEFINE_INSTANCED_PROP(float, _BackRimWidth)

		UNITY_DEFINE_INSTANCED_PROP(half4, _FlashFactor)
		UNITY_DEFINE_INSTANCED_PROP(half, _FlashStrength)

		UNITY_DEFINE_INSTANCED_PROP(half4, _DissolveFactor)
		UNITY_DEFINE_INSTANCED_PROP(half3, _DissColor)
		UNITY_DEFINE_INSTANCED_PROP(half, _Dissolve_on)
	UNITY_INSTANCING_BUFFER_END(Props)

	#define	GIANT_ACCESS_INSTANCED_PROP(Value) UNITY_ACCESS_INSTANCED_PROP(Props,Value)
#else
	
	uniform float4 _Color;
	uniform float4 _IlluminColor;
	uniform float4 _RimColor;
	uniform float _RimWidth;
	half _IlluminStrength,_TimeScale,_Illumin_On;
	uniform half4 _FlashFactor;
	uniform half _FlashStrength;

	uniform half4 _DissolveFactor;
	uniform half3 _DissColor;
	uniform half _Dissolve_on;
	#define	GIANT_ACCESS_INSTANCED_PROP(Value) Value
#endif


struct appdata {
	float4 vertex : POSITION;
	float3 normal : NORMAL;
	half4 color : COLOR;
	float2 uv : TEXCOORD0;
	float2 uv2 : TEXCOORD1;
	float2 uv3 : TEXCOORD2;
	float4 tangent : TANGENT;
	UNITY_VERTEX_INPUT_INSTANCE_ID 
	GIANT_BAKED_ANIMATION_VERTEX_ATTRIBUTES
};

struct v2f_basic
{
	float4 pos:SV_POSITION;
	half4 color:COLOR;
	half2 uv : TEXCOORD0;
	float2 uv2 : TEXCOORD6;
	float3 worldPos : TEXCOORD1;
	float3 worldNormal : TEXCOORD2;
	float4 shadowCoord : TEXCOORD3;
	float3 normalWS : TEXCOORD4;
    float4 fogCoord : TEXCOORD5;
	float3x3 tangentTransform:TEXCOORD7;
	UNITY_VERTEX_INPUT_INSTANCE_ID	
};

v2f_basic BasicVert(appdata v)
{
	v2f_basic o;
    UNITY_SETUP_INSTANCE_ID(v); 
    UNITY_TRANSFER_INSTANCE_ID(v, o); 
    GIANT_BAKED_ANIMATION_SKIN(v.vertex,v.normal,v.tangent,v); 
	
	VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
	o.pos = vertexInput.positionCS;
	o.worldPos = vertexInput.positionWS;

	o.uv = v.uv;
	o.uv2 = v.uv2;
	o.color = v.color;
	VertexNormalInputs normalInput = GetVertexNormalInputs(v.normal, v.tangent);
	o.normalWS = normalInput.normalWS;
	o.tangentTransform = float3x3(normalInput.tangentWS, normalInput.bitangentWS, normalInput.normalWS);	
 	o.worldNormal = normalize(v.normal);
	o.shadowCoord = GetShadowCoord(vertexInput);
    o.fogCoord = VolumetricFog_GetFogCoord(vertexInput.positionNDC, vertexInput.positionVS.z);
	
	return o;
}