I have just built a shader in 3ds Max using shaderfx. It exports to HLSL 3 and 5.
Now the problem is that so far I haven't worked out how to get the code working in irrlicht for shaders. I have tried pulling apart tutorial 10 and trying to load my shader into it, but I think I am doing it wrong anyway. I haven't pasted my code yet as I think I had it so wrong it would be embarrassing.
Also I know even if a shader is in HLSL format it might not be compatible with the irrlicht engine. So I am wondering if there are any shader experts who can tell me if my shader will work, or how it needs to be modified to work in irrlicht. I am making a game where I need a shader with normalmaps and five light sources. I think the one I made here has only 3 light sources at the moment. I have been watching tutorials on shaders, but I have limited understanding on how they work.
PS. I keep reading on the forum that there is no such thing as an irrlicht shader and go and learn HLSL. Well the problem is that when you have an HLSL shader you can't load it in. Surely if a shader has the HLSL standard and irrlicht is supposed to work with HLSL why should it be changed before it will work in irrlicht. The other problem I am finding is that there is no documentation anywhere on how to make an HLSL work in irrlight apart from tutorial 10 and that does not say what works and what doesn't work in irrlicht at all. So how do I make my shader work with little or no documentation?
Code: Select all
// ----------------------------------- Per Frame --------------------------------------
float4x4 viewI : ViewInverse < string UIType = "None"; >;
// --------------------------------------- Per Object -----------------------------------------
int texcoord0 : Texcoord <int Texcoord = 0; int MapChannel = 1;> = 0;
float4x4 world : World < string UIType = "None"; >;
int ClampDynamicLights
<
float UIMin = 0;
float UISoftMin = 0;
float UIMax = 99;
float UISoftMax = 99;
float UIStep = 1;
string UIName = "ClampDynamicLights";
string UIType = "IntSpinner";
> = 99;
float4x4 wvp : WorldViewProjection < string UIType = "None"; >;
// ----------------------------------- Lights --------------------------------------
int Light0Type : LIGHTTYPE
<
string UIName = "Light 0 Type (2:spot 3:omni 4:dir)";
float UIMin = 0;
float UIMax = 5;
float UIStep = 1;
int LightRef = 1;
> = {3};
int Light1Type : LIGHTTYPE
<
string UIName = "Light 1 Type (2:spot 3:omni 4:dir)";
float UIMin = 0;
float UIMax = 5;
float UIStep = 1;
int LightRef = 2;
> = {3};
int Light2Type : LIGHTTYPE
<
string UIName = "Light 2 Type (2:spot 3:omni 4:dir)";
float UIMin = 0;
float UIMax = 5;
float UIStep = 1;
int LightRef = 3;
> = {3};
float3 Light0Color : LIGHTCOLOR
<
string UIType = "None";
int LightRef = 1;
> = { 1.0, 1.0, 1.0};
float3 Light1Color : LIGHTCOLOR
<
string UIType = "None";
int LightRef = 2;
> = { 1.0, 1.0, 1.0};
float3 Light2Color : LIGHTCOLOR
<
string UIType = "None";
int LightRef = 3;
> = { 1.0, 1.0, 1.0};
float Light0Intensity : LIGHTINTENSITY
<
float UIMin = 0;
float UIStep = 0.1;
string UIType = "None";
int LightRef = 1;
> = 1.0;
float Light1Intensity : LIGHTINTENSITY
<
float UIMin = 0;
float UIStep = 0.1;
string UIType = "None";
int LightRef = 2;
> = 1.0;
float Light2Intensity : LIGHTINTENSITY
<
float UIMin = 0;
float UIStep = 0.1;
string UIType = "None";
int LightRef = 3;
> = 1.0;
float3 Light0Pos : POSITION
<
string UIName = "Light 0 Position";
string Space = "World";
string UIType = "None";
int RefID = 1;
string Object = "PointLight";
> = {1.0, 1.0, 1.0};
float3 Light1Pos : POSITION
<
string UIName = "Light 1 Position";
string Space = "World";
string UIType = "None";
int RefID = 2;
string Object = "PointLight";
> = {1.0, 1.0, 1.0};
float3 Light2Pos : POSITION
<
string UIName = "Light 2 Position";
string Space = "World";
string UIType = "None";
int RefID = 3;
string Object = "PointLight";
> = {1.0, 1.0, 1.0};
float3 Light0Dir : DIRECTION
<
string UIName = "Light 0 Direction";
string Space = "World";
string UIType = "None";
int RefID = 100;
string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
float3 Light1Dir : DIRECTION
<
string UIName = "Light 1 Direction";
string Space = "World";
string UIType = "None";
int RefID = 101;
string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
float3 Light2Dir : DIRECTION
<
string UIName = "Light 2 Direction";
string Space = "World";
string UIType = "None";
int RefID = 102;
string Object = "TargetLight";
> = {0.0, -1.0, 0.0};
float Light0Attenuation
<
float UIMin = 0;
float UIStep = 1;
string UIType = "None";
int LightRef = 1;
> = 0.0;
float Light1Attenuation
<
float UIMin = 0;
float UIStep = 1;
string UIType = "None";
int LightRef = 2;
> = 0.0;
float Light2Attenuation
<
float UIMin = 0;
float UIStep = 1;
string UIType = "None";
int LightRef = 3;
> = 0.0;
float Light0ConeAngle : LightHotSpot
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string Space = "World";
string UIType = "None";
int LightRef = 1;
> = 0.46;
float Light1ConeAngle : LightHotSpot
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string Space = "World";
string UIType = "None";
int LightRef = 2;
> = 0.46;
float Light2ConeAngle : LightHotSpot
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string Space = "World";
string UIType = "None";
int LightRef = 3;
> = 0.46;
float Light0Falloff : LightFallOff
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string UIType = "None";
int LightRef = 1;
> = 0.7;
float Light1Falloff : LightFallOff
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string UIType = "None";
int LightRef = 2;
> = 0.7;
float Light2Falloff : LightFallOff
<
float UIMin = 0;
float UIMax = 1.571;
float UIStep = 0.05;
string UIType = "None";
int LightRef = 3;
> = 0.7;
bool Light0ShadowOn : SHADOWFLAG
<
string UIType = "None";
int LightRef = 1;
> = true;
bool Light1ShadowOn : SHADOWFLAG
<
string UIType = "None";
int LightRef = 2;
> = true;
bool Light2ShadowOn : SHADOWFLAG
<
string UIType = "None";
int LightRef = 3;
> = true;
float4x4 Light0ViewPrj : SHADOWMAPMATRIX
<
string Object = "Light 0";
string UIName = "Light 0 Matrix";
string UIType = "None";
>;
float4x4 Light1ViewPrj : SHADOWMAPMATRIX
<
string Object = "Light 1";
string UIName = "Light 1 Matrix";
string UIType = "None";
>;
float4x4 Light2ViewPrj : SHADOWMAPMATRIX
<
string Object = "Light 2";
string UIName = "Light 2 Matrix";
string UIType = "None";
>;
float3 Light0ShadowColor : SHADOWCOLOR
<
string UIType = "None";
int LightRef = 1;
> = {0, 0, 0};
float3 Light1ShadowColor : SHADOWCOLOR
<
string UIType = "None";
int LightRef = 2;
> = {0, 0, 0};
float3 Light2ShadowColor : SHADOWCOLOR
<
string UIType = "None";
int LightRef = 3;
> = {0, 0, 0};
// ---------------------------------------- Textures -----------------------------------------
Texture2D Diffuse2copytga
<
string ResourceName = "Diffuse.tga";
string ResourceType = "2D";
string UIType = "Bitmap";
>;
sampler2D Diffuse2copytgaSampler = sampler_state
{
Texture = <Diffuse2copytga>;
MinFilter = Linear;
MagFilter = Linear;
AddressU = WRAP;
AddressV = WRAP;
AddressW = WRAP;
};
Texture2D nrmtga
<
string ResourceName = "nrm.tga";
string ResourceType = "2D";
string UIType = "Bitmap";
>;
sampler2D nrmtgaSampler = sampler_state
{
Texture = <nrmtga>;
MinFilter = Linear;
MagFilter = Linear;
AddressU = WRAP;
AddressV = WRAP;
AddressW = WRAP;
};
Texture2D Light0ShadowMap : SHADOWMAP
<
string ResourceName = "";
string ResourceType = "2D";
string UIType = "None";
int LightRef = 1;
>;
Texture2D Light1ShadowMap : SHADOWMAP
<
string ResourceName = "";
string ResourceType = "2D";
string UIType = "None";
int LightRef = 2;
>;
Texture2D Light2ShadowMap : SHADOWMAP
<
string ResourceName = "";
string ResourceType = "2D";
string UIType = "None";
int LightRef = 3;
>;
sampler2D Light0ShadowMapSampler = sampler_state
{
Texture = <Light0ShadowMap>;
MinFilter = Point;
MagFilter = Point;
AddressU = BORDER;
AddressV = BORDER;
AddressW = BORDER;
BorderColor = float4(1.0,1.0,1.0,1.0);
};
sampler2D Light1ShadowMapSampler = sampler_state
{
Texture = <Light1ShadowMap>;
MinFilter = Point;
MagFilter = Point;
AddressU = BORDER;
AddressV = BORDER;
AddressW = BORDER;
BorderColor = float4(1.0,1.0,1.0,1.0);
};
sampler2D Light2ShadowMapSampler = sampler_state
{
Texture = <Light2ShadowMap>;
MinFilter = Point;
MagFilter = Point;
AddressU = BORDER;
AddressV = BORDER;
AddressW = BORDER;
BorderColor = float4(1.0,1.0,1.0,1.0);
};
// ---------------------------------------- Functions -----------------------------------------
int GetLightType(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Type;
else if (ActiveLightIndex == 1)
return Light1Type;
else
return Light2Type;
}
float3 GetLightColor(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Color;
else if (ActiveLightIndex == 1)
return Light1Color;
else
return Light2Color;
}
float GetLightIntensity(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Intensity;
else if (ActiveLightIndex == 1)
return Light1Intensity;
else
return Light2Intensity;
}
float3 GetLightPos(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Pos;
else if (ActiveLightIndex == 1)
return Light1Pos;
else
return Light2Pos;
}
float3 GetLightDir(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Dir;
else if (ActiveLightIndex == 1)
return Light1Dir;
else
return Light2Dir;
}
float GetLightAttenuation(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Attenuation;
else if (ActiveLightIndex == 1)
return Light1Attenuation;
else
return Light2Attenuation;
}
float GetLightConeAngle(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0ConeAngle;
else if (ActiveLightIndex == 1)
return Light1ConeAngle;
else
return Light2ConeAngle;
}
float GetLightFalloff(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0Falloff;
else if (ActiveLightIndex == 1)
return Light1Falloff;
else
return Light2Falloff;
}
bool GetLightShadowOn(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0ShadowOn;
else if (ActiveLightIndex == 1)
return Light1ShadowOn;
else
return Light2ShadowOn;
}
float4x4 GetLightViewPrj(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0ViewPrj;
else if (ActiveLightIndex == 1)
return Light1ViewPrj;
else
return Light2ViewPrj;
}
Texture2D GetLightShadowMap(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0ShadowMap;
else if (ActiveLightIndex == 1)
return Light1ShadowMap;
else
return Light2ShadowMap;
}
float4 SampleFromShadowMap( int ActiveLightIndex, float2 UVs)
{
if (ActiveLightIndex == 0)
return tex2Dlod(Light0ShadowMapSampler, float4(UVs, 0.0, 0.0) );
else if (ActiveLightIndex == 1)
return tex2Dlod(Light1ShadowMapSampler, float4(UVs, 0.0, 0.0) );
else
return tex2Dlod(Light2ShadowMapSampler, float4(UVs, 0.0, 0.0) );
}
float3 GetLightShadowColor(int ActiveLightIndex)
{
if (ActiveLightIndex == 0)
return Light0ShadowColor;
else if (ActiveLightIndex == 1)
return Light1ShadowColor;
else
return Light2ShadowColor;
}
// -------------------------------------- APP and DATA --------------------------------------
struct APPDATA
{
float3 Position : POSITION;
float2 map1 : TEXCOORD0;
float3 Tangent : TANGENT;
float3 Normal : NORMAL;
float3 BiNormal : BINORMAL;
};
struct SHADERDATA
{
float4 Position : POSITION;
float4 map1 : TEXCOORD0;
float4 Tangent : TEXCOORD1;
float4 Normal : TEXCOORD2;
float4 WorldPosition : TEXCOORD3;
};
// -------------------------------------- ExpandRangeFunction --------------------------------------
struct ExpandRangeOutput
{
float3 ExpandedVector;
};
ExpandRangeOutput ExpandRangeFunction(float3 Vector)
{
ExpandRangeOutput OUT;
float3 NormalMap = (Vector * 2.0);
float3 NormalMap1363 = (NormalMap - 1.0);
OUT.ExpandedVector = NormalMap1363;
return OUT;
}
// -------------------------------------- TangentWorldConvertFunction --------------------------------------
struct TangentWorldConvertOutput
{
float3 Vector;
};
TangentWorldConvertOutput TangentWorldConvertFunction(float TangentDirection, float3 Normal, float3 Tangent, float3 Vector)
{
TangentWorldConvertOutput OUT;
float3 Bn = (cross(Normal, Tangent) * TangentDirection);
float3x3 toWorld = float3x3(Tangent, Bn, Normal);
float3 TangentToWorld = mul(Vector, toWorld);
OUT.Vector = TangentToWorld;
return OUT;
}
// -------------------------------------- AmbientLightFunction --------------------------------------
struct AmbientLightOutput
{
float3 LightColor;
};
AmbientLightOutput AmbientLightFunction(int ActiveLightIndex, float3 AlbedoColor, float3 LightColor, float LightIntensity)
{
AmbientLightOutput OUT;
float3 MulOp = (LightIntensity * (AlbedoColor * LightColor));
OUT.LightColor = MulOp;
return OUT;
}
// -------------------------------------- GetLightVectorFunction --------------------------------------
struct GetLightVectorOutput
{
float3 Result;
};
GetLightVectorOutput GetLightVectorFunction(int ActiveLightIndex, float3 LightPosition, float3 VertexWorldPosition, int LightType, float3 LightDirection)
{
GetLightVectorOutput OUT;
bool IsDirectionalLight = (LightType == 4);
float3 LerpOp = lerp((LightPosition - VertexWorldPosition), -(LightDirection), IsDirectionalLight);
OUT.Result = LerpOp;
return OUT;
}
// -------------------------------------- LambertDiffuseFunction --------------------------------------
struct LambertDiffuseOutput
{
float3 Color;
};
LambertDiffuseOutput LambertDiffuseFunction(int ActiveLightIndex, float3 AlbedoColor, float3 Normal, float3 LightVector)
{
LambertDiffuseOutput OUT;
float SatOp = saturate(dot(Normal, LightVector));
float3 Diffuse = (AlbedoColor * SatOp);
OUT.Color = Diffuse;
return OUT;
}
// -------------------------------------- LightDecayFunction --------------------------------------
struct LightDecayOutput
{
float Attenuation;
};
LightDecayOutput LightDecayFunction(int ActiveLightIndex, float3 LightVectorUN, float Attenuation)
{
LightDecayOutput OUT;
bool IsAttenuationUsed = (Attenuation > 0.001);
float DecayContribution459 = 0.0;
if (IsAttenuationUsed)
{
float PowOp = pow(length(LightVectorUN), Attenuation);
float DivOp = (1.0 / PowOp);
DecayContribution459 = DivOp;
}
else
{
DecayContribution459 = 1.0;
}
OUT.Attenuation = DecayContribution459;
return OUT;
}
// -------------------------------------- LightConeAngleFunction --------------------------------------
struct LightConeAngleOutput
{
float ConeAngle;
};
LightConeAngleOutput LightConeAngleFunction(int ActiveLightIndex, float3 LightVector, float3 LightDirection, float ConeAngle, float ConeFalloff)
{
LightConeAngleOutput OUT;
float CosOp = cos(max(ConeFalloff, ConeAngle));
float DotOp = dot(LightVector, -(LightDirection));
float SmoothStepOp = smoothstep(CosOp, cos(ConeAngle), DotOp);
OUT.ConeAngle = SmoothStepOp;
return OUT;
}
// -------------------------------------- ShadowMapFunction --------------------------------------
struct ShadowMapOutput
{
float LightGain;
};
ShadowMapOutput ShadowMapFunction(int ActiveLightIndex, float4x4 LightViewPrj, float ShadowMapBias, float3 VertexWorldPosition)
{
ShadowMapOutput OUT;
float IfElseOp542 = 0.0;
float4 VectorConstruct = float4(VertexWorldPosition.x, VertexWorldPosition.y, VertexWorldPosition.z, 1.0);
float4 MulOp = mul(VectorConstruct, LightViewPrj);
float3 DivOp = (MulOp.xyz / MulOp.w);
if (DivOp.x > -1.0 && DivOp.x < 1.0 && DivOp.y > -1.0 && DivOp.y < 1.0 && DivOp.z > 0.0 && DivOp.z < 1.0)
{
float Val = 0.5;
float2 AddOp = ((DivOp.xy * Val) + Val);
float SubOp = (DivOp.z - (ShadowMapBias / MulOp.w));
float ShadowTotal = 0.0;
for(int i=0; i<10; i+=1)
{
Texture2D _LightShadowMap = GetLightShadowMap(ActiveLightIndex);
float2 MulOp582 = (float2(1.0, 1.0) * 0.00195313);
float4 Sampler = SampleFromShadowMap(ActiveLightIndex, (AddOp + MulOp582));
float IfElseOp536 = ((SubOp - Sampler.x) >= 0.0) ? (0.0) : (0.1);
ShadowTotal += IfElseOp536;
}
IfElseOp542 = ShadowTotal;
}
else
{
IfElseOp542 = 1.0;
}
OUT.LightGain = IfElseOp542;
return OUT;
}
// -------------------------------------- LightContributionFunction --------------------------------------
struct LightContributionOutput
{
float3 Light;
};
LightContributionOutput LightContributionFunction(int ActiveLightIndex, float3 VertexWorldPosition, float3 LightVectorUN)
{
LightContributionOutput OUT;
float _LightIntensity = GetLightIntensity(ActiveLightIndex);
int _LightType = GetLightType(ActiveLightIndex);
bool IsDirectionalLight = (_LightType == 4);
float DecayMul505 = 0.0;
if (IsDirectionalLight)
{
DecayMul505 = 1.0;
}
else
{
float LightAttenuation = GetLightAttenuation(ActiveLightIndex);
LightDecayOutput LightDecay453 = LightDecayFunction(ActiveLightIndex, LightVectorUN, LightAttenuation);
DecayMul505 = LightDecay453.Attenuation;
}
bool IsSpotLight = (_LightType == 2);
float ConeMul507 = 1.0;
if (IsSpotLight)
{
float3 NormOp = normalize(LightVectorUN);
float3 _LightDir = GetLightDir(ActiveLightIndex);
float _LightConeAngle = GetLightConeAngle(ActiveLightIndex);
float _LightFalloff = GetLightFalloff(ActiveLightIndex);
LightConeAngleOutput LightConeAngle395 = LightConeAngleFunction(ActiveLightIndex, NormOp, -_LightDir, _LightConeAngle, _LightFalloff);
ConeMul507 = LightConeAngle395.ConeAngle;
}
bool _LightShadowOn = GetLightShadowOn(ActiveLightIndex);
float ShadowMul508 = 1.0;
if (_LightShadowOn)
{
float4x4 _LightViewPrj = GetLightViewPrj(ActiveLightIndex);
ShadowMapOutput ShadowMap521 = ShadowMapFunction(ActiveLightIndex, _LightViewPrj, 0.01, VertexWorldPosition);
float3 _LightShadowColor = GetLightShadowColor(ActiveLightIndex);
float ShadowColorMix = lerp(ShadowMap521.LightGain, 1.0, _LightShadowColor.x);
ShadowMul508 = ShadowColorMix;
}
float DecayShadowConeMul = (DecayMul505 * (ConeMul507 * ShadowMul508));
float3 LightColor = GetLightColor(ActiveLightIndex);
float3 MulItensity = (_LightIntensity * (DecayShadowConeMul * LightColor));
OUT.Light = MulItensity;
return OUT;
}
// -------------------------------------- BlinnSpecularFunction --------------------------------------
struct BlinnSpecularOutput
{
float3 SpecularColor;
};
BlinnSpecularOutput BlinnSpecularFunction(int ActiveLightIndex, float3 LightVector, float3 Normal, float3 CameraVector, float SpecularPower, float3 SpecularColor)
{
BlinnSpecularOutput OUT;
float3 NormOp = normalize((LightVector + CameraVector));
float SatOp = saturate(dot(Normal, NormOp));
float3 BlinnSpec = (pow(SatOp, SpecularPower) * SpecularColor);
float SatOp970 = saturate(dot(Normal, LightVector));
float3 MulOp = (BlinnSpec * SatOp970);
OUT.SpecularColor = MulOp;
return OUT;
}
// -------------------------------------- DesaturateColorFunction --------------------------------------
struct DesaturateColorOutput
{
float DesaturateColor;
};
DesaturateColorOutput DesaturateColorFunction(int ActiveLightIndex, float3 Color)
{
DesaturateColorOutput OUT;
float3 Col = float3(0.300008,0.6,0.100008);
float DotOp = dot(saturate(Color), Col.xyz);
OUT.DesaturateColor = DotOp;
return OUT;
}
// -------------------------------------- DesaturateColorFunction --------------------------------------
DesaturateColorOutput DesaturateColorFunction(float3 Color)
{
DesaturateColorOutput OUT;
float3 Col = float3(0.300008,0.6,0.100008);
float DotOp = dot(saturate(Color), Col.xyz);
OUT.DesaturateColor = DotOp;
return OUT;
}
// -------------------------------------- ShaderVertex --------------------------------------
SHADERDATA ShaderVertex(APPDATA IN)
{
SHADERDATA OUT;
OUT.Position = float4(IN.Position, 1);
float4 OutUVs = float4(IN.map1.x, IN.map1.y, 0.0, 0.0);
OUT.map1 = OutUVs;
float3 MulOp = mul(IN.Tangent, ((float3x3)world));
float3 TangentNorm = normalize(MulOp);
float4 WorldTangent = float4(TangentNorm.x, TangentNorm.y, TangentNorm.z, 1.0);
OUT.Tangent = WorldTangent;
float DotOp = dot(cross(IN.Normal, IN.Tangent), IN.BiNormal);
float BiNormalDir1297 = (DotOp < 0.0) ? (-1.0) : (1.0);
float4 VectorConstruct = float4(OUT.Tangent.xyz.x, OUT.Tangent.xyz.y, OUT.Tangent.xyz.z, BiNormalDir1297);
OUT.Tangent = VectorConstruct;
float3 MulOp1325 = mul(IN.Normal, ((float3x3)world));
float3 NormalN = normalize(MulOp1325);
float4 WorldNormal = float4(NormalN.x, NormalN.y, NormalN.z, 1.0);
OUT.Normal = WorldNormal;
float4 WorldPos = mul(OUT.Position, world);
OUT.WorldPosition = WorldPos;
float4 WVSpace = mul(OUT.Position, wvp);
OUT.Position = WVSpace;
return OUT;
}
// -------------------------------------- ShaderPixel --------------------------------------
struct PIXELDATA
{
float4 Color : COLOR0;
};
PIXELDATA ShaderPixel(SHADERDATA IN, bool FrontFace : VFACE)
{
PIXELDATA OUT;
float InvertSatMask = (1.0 - saturate(0.0));
float4 Sampler = tex2D(Diffuse2copytgaSampler, float2(IN.map1.xy.x, 1-IN.map1.xy.y));
float3 ReplaceDiffuseWithReflection = (InvertSatMask * Sampler.xyz);
float3 NormOp = normalize(IN.Normal.xyz);
float3 NormOp1344 = normalize(IN.Tangent.xyz);
float4 Sampler1472 = tex2D(nrmtgaSampler, float2(IN.map1.xy.x, 1-IN.map1.xy.y));
ExpandRangeOutput ExpandRange1359 = ExpandRangeFunction(Sampler1472.xyz);
float3 VectorConstruct = float3(1.0, 1.0, 1.0);
float3 NormalMapH = (ExpandRange1359.ExpandedVector * VectorConstruct.xyz);
TangentWorldConvertOutput TangentWorldConvert1346 = TangentWorldConvertFunction(IN.Tangent.w, NormOp, NormOp1344, NormalMapH);
float3 TangentSpace = normalize(TangentWorldConvert1346.Vector);
float3 FlippedNormals = lerp(-(TangentSpace), TangentSpace, !FrontFace);
float ClampOpacity = saturate(1.0);
float3 CameraPosition = viewI[3].xyz;
float3 CamVec = (CameraPosition - IN.WorldPosition.xyz);
float3 CamVecNorm = normalize(CamVec);
float4 LightLoopTotal11 = float4(0,0,0,0);
for (int ActiveLightIndex = 0; ActiveLightIndex < 3; ++ActiveLightIndex)
{
if (ActiveLightIndex >= ClampDynamicLights) {continue;}
int _LightType = GetLightType(ActiveLightIndex);
bool IsAmbientLight = (_LightType == 5);
float4 IfAmbientLight380 = float4(0, 0, 0, 0);
if (IsAmbientLight)
{
float3 LightColor = GetLightColor(ActiveLightIndex);
float _LightIntensity = GetLightIntensity(ActiveLightIndex);
AmbientLightOutput AmbientLight385 = AmbientLightFunction(ActiveLightIndex, ReplaceDiffuseWithReflection, LightColor, _LightIntensity);
float3 AmbientLightAndAO = (1.0 * AmbientLight385.LightColor);
float4 VectorConstruct665 = float4(AmbientLightAndAO.x, AmbientLightAndAO.y, AmbientLightAndAO.z, 0.0);
IfAmbientLight380 = VectorConstruct665;
}
else
{
float3 NoTranslucency = float3(0.0,0.0,0.0);
float3 _LightPos = GetLightPos(ActiveLightIndex);
float3 _LightDir = GetLightDir(ActiveLightIndex);
GetLightVectorOutput GetLightVector840 = GetLightVectorFunction(ActiveLightIndex, _LightPos, IN.WorldPosition.xyz, _LightType, -_LightDir);
float3 LightVecNorm = normalize(GetLightVector840.Result);
LambertDiffuseOutput LambertDiffuse815 = LambertDiffuseFunction(ActiveLightIndex, ReplaceDiffuseWithReflection, FlippedNormals, LightVecNorm);
LightContributionOutput LightContribution393 = LightContributionFunction(ActiveLightIndex, IN.WorldPosition.xyz, GetLightVector840.Result);
float3 AddTranslucency = (NoTranslucency.xyz + (LambertDiffuse815.Color * LightContribution393.Light));
BlinnSpecularOutput BlinnSpecular958 = BlinnSpecularFunction(ActiveLightIndex, LightVecNorm, FlippedNormals, CamVecNorm, 20.0, Sampler.xyz);
float3 SpecLightIntensity = (LightContribution393.Light * BlinnSpecular958.SpecularColor);
float3 Diffuse_Spec = ((AddTranslucency * ClampOpacity) + SpecLightIntensity);
DesaturateColorOutput DesaturateColor656 = DesaturateColorFunction(ActiveLightIndex, SpecLightIntensity);
float4 Color_Alpha = float4(Diffuse_Spec.x, Diffuse_Spec.y, Diffuse_Spec.z, DesaturateColor656.DesaturateColor);
IfAmbientLight380 = Color_Alpha;
}
float4 ApplyWeight391 = IfAmbientLight380;
LightLoopTotal11 += ApplyWeight391;
}
float3 NoReflection = float3(0.0,0.0,0.0);
float3 ReflectXmask = (0.0 * NoReflection.xyz);
float3 DefaultEmissiveColor = float3(0.0,0.0,0.0);
float3 DefaultIBLColor = float3(0.0,0.0,0.0);
float3 PreMultipliedAlpha = ((DefaultEmissiveColor.xyz + DefaultIBLColor.xyz) * ClampOpacity);
float3 AddReflection = (ReflectXmask + PreMultipliedAlpha);
DesaturateColorOutput DesaturateColor359 = DesaturateColorFunction(ReflectXmask);
float OpacityAndReflection = (ClampOpacity + DesaturateColor359.DesaturateColor);
float4 TotalAmbientAndOpacity = float4(AddReflection.x, AddReflection.y, AddReflection.z, OpacityAndReflection);
float4 LightLoopAndAfterLoop = (LightLoopTotal11 + TotalAmbientAndOpacity);
float SatOp = saturate(LightLoopAndAfterLoop.w);
float4 VectorConstruct31 = float4(LightLoopAndAfterLoop.xyz.x, LightLoopAndAfterLoop.xyz.y, LightLoopAndAfterLoop.xyz.z, SatOp);
OUT.Color = VectorConstruct31;
return OUT;
}
// -------------------------------------- technique T0 ---------------------------------------
technique T0
{
pass P0
{
VertexShader = compile vs_3_0 ShaderVertex();
PixelShader = compile ps_3_0 ShaderPixel();
}
}