#define GENERATOR_VERSION 1
#include "includes.cg.px"
#include "CustomizeOutColor.cg.px"

void Node_1_oCFile2dGraphNode50(in float3 WorldPos, in float3 WorldNormal, in float FresnelPower, out float Fresnel)
{
float3 viewDir = normalize(viewPos - WorldPos);//viewMatrix._m00_m11_m22;
float fcbias = 0.20373; // FRESNEL CALCS 0.20373;
float facing = saturate(1.0 - max(dot( normalize(viewDir), normalize(WorldNormal)), 0.0));
float refl2Refr = max(fcbias + (1.0-fcbias) * pow(facing, FresnelPower), 0); 
Fresnel = refl2Refr;

  //half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
  //o.Emission = _RimColor.rgb * pow (rim, _RimPower);
}

void Node_2_RGBA_Color51(in float R, in float G, in float B, in float A, out float4 Clr)
{
Clr = float4(R, G, B, A);
}

void Node_3_Float3_XYZ61(in float3 Float3, out float X, out float Y, out float Z)
{
X = Float3.x;
Y = Float3.y;
Z = Float3.z;
}

void Node_4_XY_Float263(in float X, in float Y, out float2 Float2)
{
Float2 = float2(X, Y);
}

void Node_5_oCFile2dGraphNode65(in float4 V1, in float4 V2, out float4 Mul)
{
Mul = V1 * V2;
}

void Node_6_userflags_1(in float4 Value, in float4 Default, out float4 Output)
{
#ifdef SH_USERFLAG1
Output = Value;
#else
Output = Default;
#endif // SH_USERFLAG1

}

void Node_7_userflags_1(in float4 Value, in float4 Default, out float4 Output)
{
#ifdef SH_USERFLAG1
Output = Value;
#else
Output = Default;
#endif // SH_USERFLAG1

}

void Node_8_sub_float(in float V, in float Minus, out float Result)
{
Result = V - Minus;
}

void Node_9_add_float(in float V1, in float V2, out float Sum)
{
Sum = V1 + V2;
}

void Node_10_modulate_normal(in sampler2D NormalMap, in float2 UV, in float3 InNormal, in float3 InTangent, out float3 OutNormal)
{

float3 binormal = cross(InNormal, InTangent);
float3x3 tbn = float3x3(InTangent, binormal, InNormal);
float3 normalMap = tex2D(NormalMap, UV) - 0.5;
normalMap = mul(normalMap, tbn);
OutNormal = normalize(normalMap);


}

void Node_11_mul_float(in float V1, in float V2, out float Mul)
{
Mul = V1 * V2;
}

void Node_12_mul_float(in float V1, in float V2, out float Mul)
{
Mul = V1 * V2;
}

void Node_13_MultiplyFloat(in float A, in float B, out float R)
{
R = A * B;
}

void Node_14_SubFloat(in float A, in float B, out float R)
{
R = A - B;
}

void Node_15_MultiplyFloat(in float A, in float B, out float R)
{
R = A * B;
}

#define Node_16_MultiplyColor(c1, c2, r) r = c1 * c2;

void Node_17_FloatClamp(in float A, in float inMin, in float inMax, out float R)
{
R = clamp(A, inMin, inMax);
}

void Node_18_SubFloat(in float A, in float B, out float R)
{
R = A - B;
}

void Node_19_FloatClamp(in float A, in float inMin, in float inMax, out float R)
{
R = clamp(A, inMin, inMax);
}

void Node_20_AddFloat(in float A, in float B, out float R)
{
R = A + B;
}

void Node_21_MultiplyFloat(in float A, in float B, out float R)
{
R = A * B;
}

void Node_22_MultiplyFloat(in float A, in float B, out float R)
{
R = A * B;
}

void Node_23_MultiplyFloat(in float A, in float B, out float R)
{
R = A * B;
}

void Node_24_MaterialPixelShader(in float2 inUVs, in float3 inWorldPos, in float3 inNormal3, in float4 inColor, in float time, in float4 u_ShieldColor, in float u_opacity, in sampler2D u_NRM, in float3 inTangent3, in sampler2D u_Env, out float4 outDiffuse, out float4 outNormal, out float4 outSpec, out float4 outEmissive, out float4 outGlow)
{
float Node_3_Float3_XYZ61_X;
float Node_3_Float3_XYZ61_Y;
float Node_3_Float3_XYZ61_Z;
Node_3_Float3_XYZ61(inWorldPos, Node_3_Float3_XYZ61_X, Node_3_Float3_XYZ61_Y, Node_3_Float3_XYZ61_Z);

float Node_9_add_float_Sum;
Node_9_add_float(time, Node_3_Float3_XYZ61_X, Node_9_add_float_Sum);

float Node_12_mul_float_Mul;
Node_12_mul_float(Node_3_Float3_XYZ61_Z, 0.100000, Node_12_mul_float_Mul);

float Node_11_mul_float_Mul;
Node_11_mul_float(Node_9_add_float_Sum, 0.125000, Node_11_mul_float_Mul);

float2 Node_4_XY_Float263_Float2;
Node_4_XY_Float263(Node_11_mul_float_Mul, Node_12_mul_float_Mul, Node_4_XY_Float263_Float2);

float3 Node_10_modulate_normal_OutNormal;
Node_10_modulate_normal(u_NRM, Node_4_XY_Float263_Float2, inNormal3, inTangent3, Node_10_modulate_normal_OutNormal);

float Node_23_MultiplyFloat_R;
Node_23_MultiplyFloat(u_opacity, u_opacity, Node_23_MultiplyFloat_R);

float Node_18_SubFloat_R;
Node_18_SubFloat(1.500000, Node_23_MultiplyFloat_R, Node_18_SubFloat_R);

float Node_1_oCFile2dGraphNode50_Fresnel;
Node_1_oCFile2dGraphNode50(inWorldPos, Node_10_modulate_normal_OutNormal, Node_18_SubFloat_R, Node_1_oCFile2dGraphNode50_Fresnel);

float Node_14_SubFloat_R;
Node_14_SubFloat(1.000000, Node_1_oCFile2dGraphNode50_Fresnel, Node_14_SubFloat_R);

float Node_20_AddFloat_R;
Node_20_AddFloat(Node_23_MultiplyFloat_R, 0.500000, Node_20_AddFloat_R);

float Node_15_MultiplyFloat_R;
Node_15_MultiplyFloat(Node_14_SubFloat_R, 10.000000, Node_15_MultiplyFloat_R);

float Node_17_FloatClamp_R;
Node_17_FloatClamp(Node_15_MultiplyFloat_R, 0.000000, 1.000000, Node_17_FloatClamp_R);

float Node_19_FloatClamp_R;
Node_19_FloatClamp(Node_20_AddFloat_R, 0.000000, 1.000000, Node_19_FloatClamp_R);

float Node_8_sub_float_Result;
Node_8_sub_float(Node_1_oCFile2dGraphNode50_Fresnel, 0.300000, Node_8_sub_float_Result);

float4 Node_5_oCFile2dGraphNode65_Mul;
Node_5_oCFile2dGraphNode65(u_ShieldColor, Node_8_sub_float_Result, Node_5_oCFile2dGraphNode65_Mul);

float Node_13_MultiplyFloat_R;
Node_13_MultiplyFloat(Node_19_FloatClamp_R, Node_17_FloatClamp_R, Node_13_MultiplyFloat_R);

float4 Node_16_MultiplyColor_R;
Node_16_MultiplyColor(Node_13_MultiplyFloat_R, Node_5_oCFile2dGraphNode65_Mul, Node_16_MultiplyColor_R);

float4 Node_6_userflags_1_Output;
Node_6_userflags_1(float4(0.000000, 0.000000, 0.000000, 0.000000), float4(0.000000, 0.000000, 0.000000, 0.000000), Node_6_userflags_1_Output);

float4 Node_2_RGBA_Color51_Clr;
Node_2_RGBA_Color51(0.000000, 0.000000, 0.000000, 1.000000, Node_2_RGBA_Color51_Clr);

float4 Node_7_userflags_1_Output;
Node_7_userflags_1(float4(0.000000, 0.000000, 0.000000, 0.000000), Node_16_MultiplyColor_R, Node_7_userflags_1_Output);

outDiffuse = Node_6_userflags_1_Output;
outNormal = float4(1.000000, 1.000000, 1.000000, 1.000000);
outSpec = Node_2_RGBA_Color51_Clr;
outEmissive = Node_7_userflags_1_Output;
outGlow = float4(0.000000, 0.000000, 0.000000, 255.000000);
}


void main_f(
	float4 inTexCoord:TEXCOORD0
	, float4 oWorldPosition:TEXCOORD1
	, float4 inNormal:TEXCOORD2
	, float4 inColor:TEXCOORD3
#ifndef SH_NOVXTRANSFORM
#ifdef SH_NORMALMAP
	, float4 inTangent:TEXCOORD4
#endif
#endif //SH_NOVXTRANSFORM
	, out float4 outColor:COLOR
	, uniform sampler2D Texture0

		, uniform float time
	, uniform float4 u_ShieldColor
	, uniform float u_opacity
	, uniform sampler2D u_NRM
	, uniform sampler2D u_Env

	)
{
	float4 userColor;
#ifdef SH_PARTICLE
	float2 inUVs = inTexCoord.xy;
	float fSlide = inTexCoord.z * f2ParticleTextureUvHeight.x;
	float2 f2SlideUVs = float2(fmod(fSlide, 1), floor(fSlide) * f2ParticleTextureUvHeight.y);
	inUVs = inUVs.xy * f2ParticleTextureUvHeight + f2SlideUVs;
#else //SH_PARTICLE
	float2 inUVs = inTexCoord.xy;
#endif //SH_PARTICLE
	sampler2D inTexture = Texture0;
	float3 inWorldPos = oWorldPosition.xyz;
	float3 inNormal3 = inNormal.xyz;
	float3 inTangent3;
#ifdef SH_NORMALMAP
	inTangent3 = inTangent.xyz;
#endif
	float4 userNormal;
	float4 userSpec;
	float4 userEmissive = 0;
	float4 userGlow = 0;
	Node_24_MaterialPixelShader(inUVs, inWorldPos, inNormal3, inColor, time, u_ShieldColor, u_opacity, u_NRM, inTangent3, u_Env
		, userColor
		//#ifdef SH_NORMALMAP
		, userNormal
		//#endif
		//#ifdef SH_SPECULARMAP
		, userSpec
		//#endif
		, userEmissive, userGlow
	);
	ComputeLightingParams params;
	params.oWorldPosition = oWorldPosition;
	params.inNormal = inNormal;
	params.userColor = userColor;
#ifdef SH_NORMALMAP
	params.userNormal = userNormal;
	params.tangent = inTangent;
#endif
#ifdef SH_SPECULAR
	params.userSpec = userSpec;
#endif

	//outColor = ComputeLightning(params) + userEmissive;
	outColor = ComputeLightning(params) + userEmissive;
	outColor.a = saturate(userColor.a + userEmissive.a);
	
#ifdef SH_CUSTOMIZEOUTCLR
	outColor = UserCustomizeOutColor(outColor);
#endif // SH_CUSTOMIZEOUTCLR	
}
