| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228 |
- //////////////////////////////////////////////////////////////////////////////
- // ©2008 Electronic Arts Inc
- //
- // FX Shader for vehicles and structures. Infantry should use Infantry.fx
- //////////////////////////////////////////////////////////////////////////////
- //#define SUPPORT_RECOLORING 1 // Defined only in faction specific versions
- //#define SUPPORT_SPECMAP 1 // Define for objects shader with specularity/envmap/self illumination map
- //#define SUPPORT_LIGHTMAP 1 // Define for objects that use a lightmap (supports HDR)
- //#define SPECIFY_CUSTOM_ENVMAP 1 // Define to allow environment cube map to be specified in art tool instead of taken from code binding
- //#define SUPPORT_DAMAGETEXTURE 1 // Define to allow blending between a damage texture and pristine texture based on vertex or bone based alpha values
- //#define SUPPORT_FILLDAMAGETEXTURE 1 // Define to allow blending between a damage texture and pristine texture based on vertex or bone based alpha values
- //#define SUPPORT_JAPANBUILDUP 1 // Defined for Japanese Building Construction Shader
- //#define SUPPORT_FROZEN 1 // Defined to change appearance of object to ice
- //#define SUPPORT_TESLA 1
- //#define SUPPORT_ALTMAPPING 1 // Defined to change mapping coords if using Iron Curtain or Chrono Rift
- //#define SUPPORT_IRONCURTAIN 1 // Defined to change appearance of object to invulnerable
- //#define SUPPORT_CHRONORIFT 1 // Defined to change appearance of object to phased
- //#define SUPPORT_FORMATIONPREVIEW 1 // Defined to change appearance of object for formation preview
- //#define SUPPORT_TREAD_SCROLLING 1 // Defined for animating the texcoord 0 based on the bone opacity, used for tank tread animation
- //#define SUPPORT_SSAO
- #define USE_INTERACTIVE_LIGHTS 1
- #define PER_PIXEL_POINT_LIGHT
- #define SUPPORT_CLOUDS 1
- #define SUPPORT_FOG 1
- #define SUPPORT_GLOBAL_LIGHTS 1
- #define SUPPORT_LOCAL_LIGHTS 1
- #define MaxNumPointLights 8
- #define FIRSTPASS 0
- #define FROZENPASS 1
- #define TESLAPASS 2
- #include "Common.fxh"
- #include "Gamma.fxh"
- #include "SSAO.fxh"
- #include "ShadowMap.fxh"
- #include "MacroTexture.fxh"
- int _SasGlobal : SasGlobal
- <
- string UIWidget = "None";
- int3 SasVersion = int3(1, 0, 0);
- #if defined(SUPPORT_FORMATIONPREVIEW)
- string RenderBin = "StaticSort1";
- #endif
- int MaxLocalLights = MaxNumPointLights;
- int MaxSupportedInstancingMode = INSTANCING_MODE_ONE_PER_DRAW_CALL;
- > = 0;
- #if defined(EA_PLATFORM_WINDOWS) && defined(_3DSMAX_)
- // ----------------------------------------------------------------------------
- // SAMPLER : nhendricks : had to pull these in here for MAX to compile
- // ----------------------------------------------------------------------------
- #define SAMPLER_2D_BEGIN(samplerName, annotations) \
- texture samplerName \
- < \
- annotations \
- >; \
- sampler2D samplerName##Sampler = sampler_state \
- { \
- Texture = < samplerName >;
-
- #define SAMPLER_2D_END };
- #define SAMPLER( samplerName ) samplerName##Sampler
- #define SAMPLER_CUBE_BEGIN(samplerName, annotations) \
- texture samplerName \
- < \
- annotations \
- >; \
- samplerCUBE samplerName##Sampler = sampler_state \
- { \
- Texture = < samplerName >;
-
- #define SAMPLER_CUBE_END };
- #if defined(_3DSMAX_)
- #define DECLARE_MAPPING_TEXCOORD(texcoordIndex) \
- int _3DSTexcoordMapping##texcoordIndex : Texcoord \
- < \
- int Texcoord = texcoordIndex; \
- int MapChannel = 1 + texcoordIndex; \
- string UIWidget = "None"; \
- >;
-
- #define DECLARE_VERTEXCOLOR_INPUT(variableName, firstTexcoordIndex, secondTexCoordIndex) \
- float3 _3DSVertexColor : TEXCOORD##firstTexcoordIndex, \
- float _3DSVertexAlpha : TEXCOORD##secondTexCoordIndex
- #define DECLARE_VERTEXCOLOR_INPUT_STRUCT(variableName, firstTexcoordIndex, secondTexCoordIndex) \
- float3 _3DSVertexColor : TEXCOORD##firstTexcoordIndex; \
- float _3DSVertexAlpha : TEXCOORD##secondTexCoordIndex
- #endif
- #endif
- DECLARE_MAPPING_TEXCOORD(0)
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- DECLARE_MAPPING_TEXCOORD(1)
- DECLARE_MAPPING_VERTEXCOLOR(2, 3)
- #else
- DECLARE_MAPPING_VERTEXCOLOR(1, 2)
- #endif
- #if defined(SUPPORT_DAMAGETEXTURE)
- #define EXPRESSION_EVALUATOR_NAME "Buildings"
- #else
- #define EXPRESSION_EVALUATOR_NAME "Objects"
- #endif
- // ----------------------------------------------------------------------------
- // Skinning
- // ----------------------------------------------------------------------------
- #define MaxSkinningBonesPerVertex 1
- #include "Skinning.fxh"
- // ----------------------------------------------------------------------------
- // Light sources
- // ----------------------------------------------------------------------------
- #define NumDirectionalLightsPerPixel 2
- #define NumDirectionalLightsPerPixel_M 1
- // ----------------------------------------------------------------------------
- // Cloud layer
- // ----------------------------------------------------------------------------
- SAMPLER_2D_BEGIN( CloudTexture,
- string UIWidget = "None";
- string SasBindAddress = "Terrain.Cloud.Texture";
- string ResourceName = "ShaderPreviewCloud.dds";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- // ----------------------------------------------------------------------------
- // Environment map
- // ----------------------------------------------------------------------------
- SAMPLER_CUBE_BEGIN( EnvironmentTexture,
- string UIWidget = "None";
- string SasBindAddress = "Objects.LightSpaceEnvironmentMap";
- string ResourceType = "Cube";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- SAMPLER_CUBE_END
- // ----------------------------------------------------------------------------
- // Japanese Building Construction Mask
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_JAPANBUILDUP)
- SAMPLER_2D_BEGIN( JapanBuildMaskTexture,
- string UIWidget = "None";
- string SasBindAddress = "WW3D.FXJapanBuildMask";
- )
- MipFilter = Linear;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = WRAP;
- AddressV = WRAP;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Frozen shader ice normal map
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_FROZEN) || defined(SUPPORT_TESLA)
- SAMPLER_2D_BEGIN( FractalNormalMap,
- string UIWidget = "None";
- string SasBindAddress = "WW3D.FXDistortionFractal";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Iron Curtain texture map
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_IRONCURTAIN)
- SAMPLER_2D_BEGIN( IronCurtainTexture,
- string UIWidget = "None";
- string SasBindAddress = "WW3D.FXIronCurtain";
- )
- MipFilter = Linear;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = WRAP;
- AddressV = WRAP;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Chrono Rift texture map
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_CHRONORIFT)
- SAMPLER_2D_BEGIN( ChronoRiftTexture,
- string UIWidget = "None";
- string SasBindAddress = "WW3D.FXChronoRift";
- )
- MipFilter = Linear;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = WRAP;
- AddressV = WRAP;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Tesla Hit Effect texture map
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_TESLA)
- SAMPLER_2D_BEGIN( TeslaTexture,
- string UIWidget = "None";
- string SasBindAddress = "WW3D.FXLightningTeslaHit";
- )
- MipFilter = Linear;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = WRAP;
- AddressV = WRAP;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Editable parameters
- // ----------------------------------------------------------------------------
- SAMPLER_2D_BEGIN( DiffuseTexture,
- string UIName = "Diffuse Texture";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- SAMPLER_2D_BEGIN( NormalMap,
- string UIName = "Normal Texture";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- #if defined(SUPPORT_SPECMAP)
- SAMPLER_2D_BEGIN( SpecMap,
- string UIName = "Specular Map";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- #endif
- // ----------------------------------------------------------------------------
- // Light map
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_LIGHTMAP)
- SAMPLER_2D_BEGIN( LightMap,
- string UIName = "Light Map";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- #endif
- #if defined(SUPPORT_DAMAGETEXTURE)
- SAMPLER_2D_BEGIN( DamagedTexture,
- string UIName = "Damaged Texture";
- )
- MinFilter = MinFilterBest;
- MagFilter = MagFilterBest;
- MipFilter = MipFilterBest;
- MaxAnisotropy = 8;
- AddressU = Wrap;
- AddressV = Wrap;
- SAMPLER_2D_END
- #if defined(_3DSMAX_)
- bool PreviewFullyDamaged
- <
- string UIName = "Preview Fully Damaged";
- bool ExportValue = false;
- > = false;
- #endif // defined(_3DSMAX_)
- #endif // defined(SUPPORT_DAMAGETEXTURE)
- #if defined(MATERIAL_PARAMS_ALLIED)
- // Fixed material parameters for ALLIED
- static const float BumpScale = 1.5;
- static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
- static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
- static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
- static const float SpecularExponent = 50.0;
- #elif defined(MATERIAL_PARAMS_SOVIET)
- // Fixed material parameters for SOVIET
- static const float BumpScale = 1.5;
- static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
- static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
- static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
- static const float SpecularExponent = 45.0;
- #elif defined(MATERIAL_PARAMS_JAPAN)
- // Fixed material parameters for JAPAN
- static const float BumpScale = 1.5;
- static const float3 AmbientColor = float3(0.1, 0.1, 0.1);
- static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
- static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
- static const float SpecularExponent = 50.0;
- #elif defined(SUPPORT_FROZEN)
- // Fixed material parameters for frozen objects
- static const float BumpScale = 3;
- static const float3 AmbientColor = float3(1, 1, 1);
- static const float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
- static const float3 SpecularColor = float3(0.8, 0.8, 0.8);
- static const float SpecularExponent = 50.0;
- #else
- // Material parameters defined by UI
- float BumpScale
- <
- string UIName = "Bump Height";
- string UIWidget = "Slider";
- float UIMin = 0.0;
- float UIMax = 10.0;
- float UIStep = 0.1;
- > = 1.0;
- float3 AmbientColor
- <
- string UIName = "Ambient Color";
- string UIWidget = "Color";
- > = float3(0.4, 0.4, 0.4);
- float4 DiffuseColor
- <
- string UIName = "Diffuse Color";
- string UIWidget = "Color";
- > = float4(1.0, 1.0, 1.0, 1.0);
- float3 SpecularColor
- <
- string UIName = "Specular Color";
- string UIWidget = "Color";
- > = float3(0.8, 0.8, 0.8);
- float SpecularExponent
- <
- string UIName = "Specular Exponent";
- string UIWidget = "Slider";
- float UIMax = 200.0f;
- float UIMin = 0;
- float UIStep = 1.0f;
- > = 50.0;
- #endif // Material parameters defined by UI
- #if defined(SUPPORT_SPECMAP)
- float EnvMult
- <
- string UIName = "Reflection Multiplier";
- string UIWidget = "Slider";
- float UIMax = 1.0f;
- float UIMin = 0;
- float UIStep = 0.01f;
- > = 1.0;
- #endif
- #if defined(SUPPORT_DAMAGETEXTURE)
- // For damage texture rendering we always need alpha testing to be enabled. So don't offer it as configuration option.
- const bool AlphaTestEnable = true;
- #else
- bool AlphaTestEnable
- <
- string UIName = "Alpha Test Enable";
- > = false;
- #endif
- // ----------------------------------------------------------------------------
- // Shroud
- // ----------------------------------------------------------------------------
- ShroudSetup Shroud
- <
- string UIWidget = "None";
- string SasBindAddress = "Terrain.Shroud";
- > = DEFAULT_SHROUD;
- SAMPLER_2D_BEGIN( ShroudTexture,
- string UIWidget = "None";
- string SasBindAddress = "Terrain.Shroud.Texture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- #if !defined(USE_INDIRECT_CONSTANT)
- float OpacityOverride
- <
- string UIWidget = "None";
- string SasBindAddress = "WW3D.OpacityOverride";
- > = 1.0;
- float3 TintColor
- <
- string UIWidget = "None";
- string SasBindAddress = "WW3D.TintColor";
- > = float3(1, 1, 1);
- #endif // #if !defined(USE_INDIRECT_CONSTANT)
- // ----------------------------------------------------------------------------
- // Transformations (world transformations are in skinning header)
- // ----------------------------------------------------------------------------
- #if defined(_WW3D_)
- #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 ViewProjection
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.WorldToProjection";
- >;
- float3 EyePosition
- <
- string UIWidget = "None";
- string SasBindAddress = "Sas.Camera.Position";
- >;
- #endif // #if !defined(USE_INDIRECT_CONSTANT)
- float4x4 GetViewProjection()
- {
- return ViewProjection;
- }
- float3 GetEyePosition()
- {
- return EyePosition;
- }
- #else // #if defined(_WW3D_)
- float4x4 View : View;
- float4x3 ViewI : ViewInverse;
- float4x4 Projection : Projection;
- float4x4 GetViewProjection()
- {
- return mul(View, Projection);
- }
- float3 GetEyePosition()
- {
- return ViewI[3];
- }
- #endif // #if defined(_WW3D_)
- // Time (ie. material is animated)
- float Time : Time;
- // ----------------------------------------------------------------------------
- // SHADER: Default High LOD
- // ----------------------------------------------------------------------------
- struct VSOutput_H
- {
- float4 Position : POSITION;
- float4 TexCoord0_TexCoord1 : TEXCOORD0;
- float3x3 TangentToWorldSpace : TEXCOORD1_CENTROID;
- float3 WorldPosition : TEXCOORD4;
- float4 ShadowMapTexCoord : TEXCOORD5;
- float4 ShroudTexCoord_CloudTexCoord : TEXCOORD6;
- float4 Color : COLOR0;
- };
- // ----------------------------------------------------------------------------
- // SHADER: VS
- // ----------------------------------------------------------------------------
- #if defined(EA_PLATFORM_PS3)
- VSOutput_H VS_H(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 TexCoord1 : TEXCOORD1,
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
- #else
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
- #endif
- uniform int numJointsPerVertex,
- uniform int isMultiPass)
- {
- VSOutput_H Out;
- float3 worldPosition = 0;
- float3 worldNormal = 0;
- float3 worldTangent = 0;
- float3 worldBinormal = 0;
- CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex, worldPosition, worldNormal, worldTangent, worldBinormal);
- // Get the skins opacity value
- VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
- #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
- if (PreviewFullyDamaged)
- {
- VertexColor.w = 0.0;
- }
- #endif
- #if !defined(SUPPORT_ALTMAPPING)
- Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
- Out.Color *= VertexColor;
- #endif // SUPPORT_ALTMAPPING
-
- Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
- Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
- Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
- return Out;
- }
- #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
- VSOutput_H VS_H(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 TexCoord1 : TEXCOORD1,
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
- #else
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
- #endif
- uniform int numJointsPerVertex,
- uniform int isMultiPass)
- {
- USE_VERTEXCOLOR(VertexColor);
- USE_TEXCOORD(TexCoord0);
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- USE_TEXCOORD(TexCoord1);
- #endif
- USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
- VSOutput_H Out;
- float3 worldPosition = 0;
- float3 worldNormal = 0;
- float3 worldTangent = 0;
- float3 worldBinormal = 0;
- CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
- worldPosition, worldNormal, worldTangent, worldBinormal);
- // Get the skins opacity value
- VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
- #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
- if (PreviewFullyDamaged)
- {
- VertexColor.w = 0.0;
- }
- #endif
- #if defined(SUPPORT_TREAD_SCROLLING)
- // Tread scrolling uses the vertex color opacity for animating the U coordinate
- TexCoord0.x += VertexColor.w;
- // Don't use it for opacity then.
- VertexColor.w = 1.0f;
- #endif
- if (isMultiPass == FROZENPASS)
- {
- // Extrude geo to create a shell for the ice
- worldPosition += worldNormal * 1.5;
- }
-
- // Build 3x3 tranform from object to tangent space
- Out.TangentToWorldSpace = float3x3(-worldBinormal, -worldTangent, worldNormal);
- #if !defined(SUPPORT_ALTMAPPING)
- Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
- // Compute remaining directional lights per vertex, others will be done in pixel shader
- float3 diffuseLight = 0;
- for (int i = NumDirectionalLightsPerPixel; i < NumDirectionalLights; i++)
- {
- diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
- }
- Out.Color.xyz += diffuseLight * DiffuseColor;
- Out.Color.xyz /= 2; // Prevent clamping in interpolator
- Out.Color *= VertexColor;
- #endif // SUPPORT_ALTMAPPING
- Out.WorldPosition = worldPosition;
- Out.ShadowMapTexCoord = CalculateShadowMapTexCoord(worldPosition);
- if (isMultiPass == TESLAPASS)
- {
- // Hi-jack shadow coords as we dont use them in this pass
- Out.ShadowMapTexCoord.xy = (TexCoord0 * .003) + (worldPosition.xy * .003);
- Out.ShadowMapTexCoord.wz = (TexCoord0 * .5);
- Out.ShadowMapTexCoord.wz += Time * .15;
- }
-
- // pass texture coordinates for fetching the diffuse and normal maps
- Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
- if (isMultiPass == FROZENPASS)
- {
- // Use world coords when mapping
- Out.TexCoord0_TexCoord1.xy = worldPosition.xy * .015;
- }
- // transform position to projection space
- ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 texCoord1 = TexCoord1;
- #else
- float2 texCoord1 = TexCoord0;
- #endif
- Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
- #if defined (SUPPORT_ALTMAPPING)
- // -------------------------------------------------------------------------------
- // -- Texture Coords and Mapping -------------------------------------------------
- // -------------------------------------------------------------------------------
- // Build Tex coords, animate and scale ---------------------------------------
- float texScalar = .75; // Scale
- float texSpeed = Time * .3; // animate coords as a multiplier of Time
- float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
- // Use the tex coords on the model but offset them slightly based on world
- // coords to keep multiple units from animating in sync
- float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
- // Build Texture Rotation Matrix And Convert Degrees to Radians --
- float cosAngle = 0;
- float sinAngle = 0;
- float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
- sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
-
- // Build Rotation
- uvCoordRotate[0][0] = cosAngle;
- uvCoordRotate[0][1] = -sinAngle;
- uvCoordRotate[1][1] = uvCoordRotate[0][0];
- uvCoordRotate[1][0] = -uvCoordRotate[0][1];
- // Rotate and Animate Divergence Texture Coords --------------------
- float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
- TexCoordsDiverge.x += texSpeed;
- float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
- TexCoordsDivergeInv.x += texSpeed;
-
-
- Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
- Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
-
- //Hi-jack shadow coords for this shader since we dont use them
- Out.ShadowMapTexCoord.xy = TexCoord0;
-
- Out.Color = 0;
-
- #endif //SUPPORT_ALTMAPPING
-
- Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
- Out.ShroudTexCoord_CloudTexCoord.zw = CalculateCloudTexCoord(Cloud, worldPosition, Time);
-
- return Out;
- }
- #endif
- // ----------------------------------------------------------------------------
- // SHADER: VS_Xenon
- // ----------------------------------------------------------------------------
- VSOutput_H VS_Xenon(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 TexCoord1 : TEXCOORD1,
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
- #else
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
- #endif
- uniform int isMultiPass)
- {
- int joints = NumJointsPerVertex;
- return VS_H( InSkin, TexCoord0,
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- TexCoord1,
- #endif
- PASS_THROUGH_VERTEXCOLOR(VertexColor), min(joints, 1), isMultiPass);
- }
- // ----------------------------------------------------------------------------
- // SHADER: PS
- // ----------------------------------------------------------------------------
- #if defined(EA_PLATFORM_PS3)
- float4 PS_H(VSOutput_H In, uniform bool hasShadow, uniform bool recolorEnabled,
- float2 vPos : PIXELLOC, uniform int isMultiPass) COLORTARGET
- {
- USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
- float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
- float2 shroudTexCoord = In.ShroudTexCoord_CloudTexCoord.xy;
- // Get diffuse color
- float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
- #if defined(SUPPORT_RECOLORING)
- if (recolorEnabled)
- {
- float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
- baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
- baseTexture.w = 1;
- }
- #endif //defined(SUPPORT_RECOLORING)
- float4 color = baseTexture;
- color.w = In.Color.w;
-
- color.xyz *= tex2D(SAMPLER(ShroudTexture), shroudTexCoord).x;
- return(color);
- }
- #else // EA_PLATFORM_WINDOWS || EA_PLATFORM_XENON
- float4 PS_H(VSOutput_H In, uniform bool hasShadow, uniform bool recolorEnabled,
- float2 vPos : PIXELLOC, uniform int isMultiPass) COLORTARGET
- {
- USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
- float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
- float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
- float2 shroudTexCoord = In.ShroudTexCoord_CloudTexCoord.xy;
- float2 cloudTexCoord = In.ShroudTexCoord_CloudTexCoord.zw;
- float3 worldEyeDir = normalize(GetEyePosition() - In.WorldPosition);
- // Get diffuse color
- float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
-
- #if defined(SUPPORT_RECOLORING)
- if (recolorEnabled)
- {
- float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
- baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
- }
- #endif //defined(SUPPORT_RECOLORING)
- baseTexture.xyz = GammaToLinear(baseTexture.xyz);
- float3 diffuse = baseTexture.xyz * DiffuseColor;
- // Get bump map normal
- float3 bumpNormal;
- bumpNormal = (float3)tex2D(SAMPLER(NormalMap), texCoord0) * 2.0 - 1.0;
-
- #if defined(SUPPORT_FROZEN)
- if (isMultiPass == FROZENPASS)
- {
- bumpNormal = (float3)tex2D(SAMPLER(FractalNormalMap), texCoord0) * 2.0 - 1.0;
- }
- #endif
- #if defined(SUPPORT_ALTMAPPING)
- bumpNormal = (float3)tex2D(SAMPLER(NormalMap), In.ShadowMapTexCoord.xy) * 2.0 - 1.0;
- #endif
- // Scale normal to increase/decrease bump effect
- bumpNormal.xy *= BumpScale;
-
- // Bring bump normal into world space
- bumpNormal = mul(bumpNormal, In.TangentToWorldSpace);
- bumpNormal = normalize(bumpNormal);
-
- float4 color = baseTexture;
- color.xyz *= In.Color.xyz;
- float3 specularColor = SpecularColor;
-
- float shadowSampler = 1;
- if (hasShadow)
- {
- shadowSampler = shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord );
- }
- #if defined(SUPPORT_SPECMAP)
- // Read spec map
- float4 specTexture = tex2D(SAMPLER(SpecMap), texCoord0);
- float specularStrength = specTexture.x; // Specular lighting mask
-
- if (isMultiPass == FROZENPASS)
- {
- specularStrength = 1;
- color.xyz = float3(0, 0, 0);
- diffuse.xyz = float3(.13, .33, .5);
- // color.xyz *= float3(.13, .33, .5);
- }
-
- // the cubemap is in light space so we can bake all lighting calculations to the Cube map
-
- // Compute view direction in world space
- float3 reflVect = -reflect(worldEyeDir,bumpNormal);
- // Although not technically correct, since we use the Cubemap to fake specular, multiply against the shadow map and add to color
- float3 envcolor = texCUBE( SAMPLER(EnvironmentTexture), reflVect).xyz;
-
- color.xyz += envcolor.xyz * DirectionalLight[0].Color * specularStrength * shadowSampler;
- #endif // SUPPORT_SPECMAP
- #if !defined(SUPPORT_ALTMAPPING)
- if (isMultiPass != TESLAPASS)
- {
- for (int i = 0; i < NumDirectionalLightsPerPixel; i++)
- {
- // Compute lighting
-
- float3 cloud = float3(1, 1, 1);
- if (i == 0)
- {
- #if defined(_WW3D_) && !defined(_W3DVIEW_)
- cloud = GammaToLinear(tex2D( SAMPLER(CloudTexture), cloudTexCoord));
- #endif
- cloud *= shadowSampler;
- }
- float4 diffuseTerm = dot(bumpNormal, DirectionalLight[i].Direction);
- float diffuseLighting = max(0, diffuseTerm);
-
- color.xyz += DirectionalLight[i].Color * cloud * (diffuse * diffuseLighting);
- }
- // Compute point lights
- float3 diffuseLight = 0;
-
- #if !defined(EA_PLATFORM_PS3) // PS3 TODO - 'sce-cgc.exe' does not like this for some reason :(
- for (int i = 0; i < NumPointLights; i++)
- {
- diffuseLight += CalculatePointLightDiffuse(PointLight[i], In.WorldPosition, bumpNormal);
- }
- #endif
- #if defined(SUPPORT_LIGHTMAP)
- float3 lightMapTexture = GammaToLinear(tex2D(SAMPLER(LightMap), texCoord1));
- diffuseLight += lightMapTexture.xyz * 10;
- #endif
- color.xyz += diffuseLight * diffuse;
- } // (isMultiPass == FIRSTPASS)
- #endif // SUPPORT_ALTMAPPING
- #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- color *= damagedTexture * (1 - In.Color.w);
- #elif defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
- #elif !defined(SUPPORT_JAPANBUILDUP) && !defined(SUPPORT_ALTMAPPING)
- color.w *= In.Color.w;
- #endif
- #if defined(SUPPORT_IRONCURTAIN)
- float3 Texture0 = GammaToLinear(tex2D( SAMPLER(IronCurtainTexture), texCoord0 * 1));
- float3 Texture1 = GammaToLinear(tex2D( SAMPLER(IronCurtainTexture), texCoord1 * 1));
- color.xyz = Texture0 * Texture1 * 30;
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 4.0);
- color.xyz += (float3(2.0,0.05,0.025) * fresnelDiffuse);
- color.w = 1;
- #endif // SUPPORT_IRONCURTAIN
- #if defined(SUPPORT_CHRONORIFT)
- float3 Texture0 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), texCoord0*2));
- float3 Texture1 = GammaToLinear(tex2D( SAMPLER(ChronoRiftTexture), texCoord1*2));
- color.xyz = Texture0 * Texture1 * 50;
-
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 2.0);
- color.xyz += fresnelDiffuse * float3(0.3,0.6,3.0);
- color.xyz = min(color.xyz,2);
- color.w = 1;
- #endif // SUPPORT_CHRONORIFT
- #if defined(SUPPORT_FORMATIONPREVIEW)
- color.xyz = float3(0.0,0.055,0.045);
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 2.5);
- color.xyz += (float3(0.0,1.0,0.0) * fresnelDiffuse * 3);
- color.xyz = min(color.xyz,2);
- color.w = OpacityOverride;
- #endif // SUPPORT_FORMATIONPREVIEW
- #if defined(SUPPORT_JAPANBUILDUP)
- // Get Buildup Mask
- float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
- float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
- buildupTexture = pow(buildupTexture,3)*6;
- float3 maskColor = buildupTexture * float3(.9,3,.9);
- color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
- clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
- #endif
- if (isMultiPass == FIRSTPASS)
- {
- color.xyz *= TintColor;
- }
-
- #if defined(SUPPORT_TESLA)
- if (isMultiPass == TESLAPASS)
- {
- float3 Texture0 = GammaToLinear(tex2D( SAMPLER(FractalNormalMap), In.ShadowMapTexCoord.xy));
- Texture0 = Texture0 * 2 - 1;
- float3 Texture1 = GammaToLinear(tex2D( SAMPLER(TeslaTexture), In.ShadowMapTexCoord.zw * 1.5 + (Texture0.xy * .04)));
- Texture1 *= GammaToLinear(tex2D( SAMPLER(TeslaTexture), In.ShadowMapTexCoord.wz * 3 + (Texture0.xy * .04)));
- color.xyz = Texture1 * 50;
-
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( worldEyeDir, bumpNormal), 4.0);
- color.xyz += fresnelDiffuse * float3(0.07,0.15,.75);
- color.xyz = min(color.xyz,4);
- color.w = 1;
- }
- #endif // SUPPORT_TESLA
- #if defined(_WW3D_) && !defined(_W3DVIEW_)
- color.xyz *= tex2D(SAMPLER(ShroudTexture), shroudTexCoord);
- #endif
- #if SUPPORT_SSAO
- color.xyz *= ComputeSSAO(vPos);
- #endif
- return CorrectForFrameBufferGamma(color);
- }
- #endif
- // ----------------------------------------------------------------------------
- // SHADER: PS_Xenon
- // ----------------------------------------------------------------------------
- float4 PS_Xenon( VSOutput_H In, float2 vPos : PIXELLOC, uniform int isMultiPass) : COLOR
- {
- return PS_H( In, HasShadow, HasRecolorColors, vPos, isMultiPass);
- }
- // ----------------------------------------------------------------------------
- // Arrays: Default_H
- // ----------------------------------------------------------------------------
- DEFINE_ARRAY_MULTIPLIER( VS_H_Multiplier_Final = 2 );
- #define VS_H_NumJointsPerVertex(isMultiPass) \
- compile VS_3_0 VS_H(0, isMultiPass), \
- compile VS_3_0 VS_H(1, isMultiPass)
- #if SUPPORTS_SHADER_ARRAYS
- vertexshader VS_H_Array[VS_H_Multiplier_Final] =
- {
- VS_H_NumJointsPerVertex(FIRSTPASS)
- };
- #if defined(SUPPORT_FROZEN)
- vertexshader VS_H_Frozen_Array[VS_H_Multiplier_Final] =
- {
- VS_H_NumJointsPerVertex(FROZENPASS)
- };
- #endif // SUPPORT_FROZEN
-
- #if defined(SUPPORT_TESLA)
- vertexshader VS_H_Tesla_Array[VS_H_Multiplier_Final] =
- {
- VS_H_NumJointsPerVertex(TESLAPASS)
- };
- #endif // SUPPORT_TESLA
-
- #endif // SUPPORTS_SHADER_ARRAYS
- DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_NumShadows = 1 );
- #define PS_H_NumShadows(recolorEnabled, isMultiPass) \
- compile PS_3_0 PS_H(0, recolorEnabled, isMultiPass), \
- compile PS_3_0 PS_H(1, recolorEnabled, isMultiPass)
- DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_RecolorEnabled = PS_H_Multiplier_NumShadows * 2 );
-
- #define PS_H_RecolorEnabled(isMultiPass) \
- PS_H_NumShadows(false, isMultiPass), \
- PS_H_NumShadows(true, isMultiPass)
- DEFINE_ARRAY_MULTIPLIER( PS_H_Multiplier_Final = PS_H_Multiplier_RecolorEnabled * 2 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_H_Array[PS_H_Multiplier_Final] =
- {
- PS_H_RecolorEnabled(FIRSTPASS)
- };
- #if defined(SUPPORT_FROZEN)
- pixelshader PS_H_Frozen_Array[PS_H_Multiplier_Final] =
- {
- PS_H_RecolorEnabled(FROZENPASS)
- };
- #endif // SUPPORT_FROZEN
-
- #if defined(SUPPORT_TESLA)
- pixelshader PS_H_Tesla_Array[PS_H_Multiplier_Final] =
- {
- PS_H_RecolorEnabled(TESLAPASS)
- };
- #endif // SUPPORT_TESLA
-
- #endif // SUPPORTS_SHADER_ARRAYS
- // ----------------------------------------------------------------------------
- // Technique: Default
- // ----------------------------------------------------------------------------
- technique Default
- {
- pass p0
- #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT)
- <
- USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
- >
- #endif
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_H_Array,
- min(NumJointsPerVertex, 1),
- compile VS_VERSION VS_Xenon(false) );
- PixelShader = ARRAY_EXPRESSION_PS( PS_H_Array,
- HasShadow * PS_H_Multiplier_NumShadows
- + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
- compile PS_VERSION PS_Xenon(false) );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = true;
- CullMode = CW;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaBlendEnable = false;
-
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaBlendEnable = ( OpacityOverride < 0.99);
- #endif
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- #endif
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaTestEnable = true;
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaTestEnable = false;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaTestEnable = ( AlphaTestEnable );
- #endif
- #endif
- }
- #if defined(SUPPORT_FROZEN)
- pass p1
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_H_Frozen_Array,
- min(NumJointsPerVertex, 1),
- compile VS_VERSION VS_Xenon(FROZENPASS) );
- PixelShader = ARRAY_EXPRESSION_PS( PS_H_Frozen_Array,
- HasShadow * PS_H_Multiplier_NumShadows
- + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
- compile PS_VERSION PS_Xenon(FROZENPASS) );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = CW;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
-
- StencilEnable = false;
- }
- #endif // SUPPORT_FROZEN
- #if defined(SUPPORT_TESLA)
- pass p1
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_H_Tesla_Array,
- min(NumJointsPerVertex, 1),
- compile VS_VERSION VS_Xenon(TESLAPASS) );
- PixelShader = ARRAY_EXPRESSION_PS( PS_H_Tesla_Array,
- HasShadow * PS_H_Multiplier_NumShadows
- + HasRecolorColors * PS_H_Multiplier_RecolorEnabled,
- compile PS_VERSION PS_Xenon(TESLAPASS) );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = CW;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
-
- StencilEnable = false;
- }
- #endif // SUPPORT_TESLA
- }
- #if ENABLE_LOD
- // ----------------------------------------------------------------------------
- // SHADER: DEFAULT (Medium)
- // ----------------------------------------------------------------------------
- struct VSOutput_M {
- float4 Position : POSITION;
- float4 TexCoord0_TexCoord1 : TEXCOORD0;
- float4 LightVector[NumDirectionalLightsPerPixel_M] : TEXCOORD1_CENTROID;
- float3 HalfEyeLightVector : TEXCOORD2_CENTROID;
- float4 ShroudTexCoord_CloudTexCoord : TEXCOORD3;
- float4 ShadowMapTexCoord : TEXCOORD4;
- float2 MacroTexCoord : TEXCOORD5;
- #if defined(SUPPORT_ALTMAPPING) || defined(SUPPORT_TESLA)
- float3 WorldTangentEyeDir : TEXCOORD6;
- #endif
- #if defined(SUPPORT_TESLA)
- float4 TeslaTexCoord : TEXCOORD7;
- #endif
- float4 Color : COLOR0;
- };
- // ----------------------------------------------------------------------------
- // SHADER: VS
- // ----------------------------------------------------------------------------
- VSOutput_M VS_M(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 TexCoord1 : TEXCOORD1,
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
- #else
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
- #endif
- uniform int numJointsPerVertex,
- uniform int isMultiPass)
- {
- USE_VERTEXCOLOR(VertexColor);
- USE_TEXCOORD(TexCoord0);
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- USE_TEXCOORD(TexCoord1);
- #endif
- USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
- VSOutput_M Out;
- float3 worldPosition = 0;
- float3 worldNormal = 0;
- float3 worldTangent = 0;
- float3 worldBinormal = 0;
- CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
- worldPosition, worldNormal, worldTangent, worldBinormal);
- // Get the skins opacity value
- VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
- #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
- if (PreviewFullyDamaged)
- {
- VertexColor.w = 0.0;
- }
- #endif
- #if defined(SUPPORT_TREAD_SCROLLING)
- // Tread scrolling uses the vertex color opacity for animating the U coordinate
- TexCoord0.x += VertexColor.w;
- // Don't use it for opacity then.
- VertexColor.w = 1.0f;
- #endif
- if (isMultiPass == FROZENPASS)
- {
- // Extrude geo to create a shell for the ice
- worldPosition += worldNormal * 1.5;
- }
-
- // transform position to projection space
- Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
-
- // Compute view direction in world space
- float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
- // Build 3x3 tranform from object to tangent space
- float3x3 worldToTangentSpace = transpose(float3x3(-worldBinormal, -worldTangent, worldNormal));
- for (int i = 0; i < NumDirectionalLightsPerPixel_M; i++)
- {
- // Compute lighting direction in tangent space
- Out.LightVector[i] = float4(mul(DirectionalLight[i].Direction, worldToTangentSpace), 0);
- }
- // Compute half direction between view and light direction in tangent space
- Out.HalfEyeLightVector.xyz = normalize(mul(DirectionalLight[0].Direction + worldEyeDir, worldToTangentSpace));
- #if !defined(SUPPORT_ALTMAPPING)
- Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
- // Compute remaining directional lights per vertex, others will be done in pixel shader
- float3 diffuseLight = 0;
- for (int i = NumDirectionalLightsPerPixel_M; i < NumDirectionalLights; i++)
- {
- diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
- }
-
- Out.Color.xyz += diffuseLight * DiffuseColor;
- Out.Color *= VertexColor;
- #endif // SUPPORT_ALTMAPPING
- // pass texture coordinates for fetching the diffuse and normal maps
- Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
- if (isMultiPass == FROZENPASS)
- {
- // Use world coords when mapping
- Out.TexCoord0_TexCoord1.xy = worldPosition.xy * .015;
- }
- #if defined(SUPPORT_DAMAGETEXTURE) || defined(SUPPORT_LIGHTMAP)
- float2 texCoord1 = TexCoord1;
- #else
- float2 texCoord1 = TexCoord0;
- #endif
- Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
-
- Out.ShadowMapTexCoord = CalculateShadowMapTexCoord(worldPosition);
- #if defined (SUPPORT_ALTMAPPING)
- // -------------------------------------------------------------------------------
- // -- Texture Coords and Mapping -------------------------------------------------
- // -------------------------------------------------------------------------------
- // Build Tex coords, animate and scale ---------------------------------------
- float texScalar = .75; // Scale
- float texSpeed = Time * .3; // animate coords as a multiplier of Time
- float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
- // Use the tex coords on the model but offset them slightly based on world
- // coords to keep multiple units from animating in sync
- float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
- // Build Texture Rotation Matrix And Convert Degrees to Radians --
- float cosAngle = 0;
- float sinAngle = 0;
- float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
- sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
-
- // Build Rotation
- uvCoordRotate[0][0] = cosAngle;
- uvCoordRotate[0][1] = -sinAngle;
- uvCoordRotate[1][1] = uvCoordRotate[0][0];
- uvCoordRotate[1][0] = -uvCoordRotate[0][1];
- // Rotate and Animate Divergence Texture Coords --------------------
- float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
- TexCoordsDiverge.x += texSpeed;
- float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
- TexCoordsDivergeInv.x += texSpeed;
-
-
- Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
- Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
-
- //Hi-jack shadow coords for this shader since we dont use them
- Out.ShadowMapTexCoord.xy = TexCoord0;
- Out.WorldTangentEyeDir = mul(worldEyeDir, worldToTangentSpace);
-
- Out.Color = 0;
-
- #endif //SUPPORT_ALTMAPPING
-
- #if defined(SUPPORT_TESLA)
- Out.WorldTangentEyeDir = mul(worldEyeDir, worldToTangentSpace);
- Out.TeslaTexCoord.xy = (TexCoord0 * .003) + (worldPosition.xy * .003);
- Out.TeslaTexCoord.wz = (TexCoord0 * .5);
- Out.TeslaTexCoord.wz += Time * .15;
- #endif
-
- Out.ShroudTexCoord_CloudTexCoord.xy = CalculateShroudTexCoord(Shroud, worldPosition);
- Out.ShroudTexCoord_CloudTexCoord.zw = CalculateCloudTexCoord(Cloud, worldPosition, Time);
- Out.MacroTexCoord = CalculateMacroTexCoord(worldPosition);
-
- return Out;
- }
- // ----------------------------------------------------------------------------
- // SHADER: PS
- // ----------------------------------------------------------------------------
- // This will save us .5ms on the GPU on a 6800 card. Worth it and there is no visual difference.
- #define float4 half4
- #define float3 half3
- #define float2 half2
- #define float half
- float4 PS_M(VSOutput_M In, uniform bool hasShadow, uniform bool recolorEnabled, uniform int isMultiPass) COLORTARGET
- {
- float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
- #if defined(SUPPORT_JAPANBUILDUP)
- // Get Buildup Mask. The pixel can be clipped early to save processing instead of at the end.
- float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
- clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
- #endif
- float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
- float2 cloudTexCoord = In.ShroudTexCoord_CloudTexCoord.zw;
- // Get diffuse color
- float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
-
- float3 specularColor = SpecularColor;
- // ngavalas
- // Yes there is duplicate code here, but duplicating it makes it slightly more understandable
- // as to what is going on. Basically, if we are support recoloring and specular mapping,
- // we can save a texture read since they use the same texture.
- // If we are using one or the other then we just do the texture read and calculate
- // the values normally.
- #if defined(SUPPORT_RECOLORING) && defined(SUPPORT_SPECMAP)
- float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
- float specularStrength = specTexture.x; // Specular lighting mask
- specularColor = SpecularColor * specularStrength;
- if (recolorEnabled)
- {
- baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, specTexture.z);
- }
- #elif defined(SUPPORT_SPECMAP)
- float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
- float specularStrength = specTexture.x; // Specular lighting mask
- specularColor = SpecularColor * specularStrength;
- #elif defined(SUPPORT_RECOLORING)
- float4 specTexture = tex2D( SAMPLER(SpecMap), texCoord0);
- if (recolorEnabled)
- {
- baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, specTexture.z);
- }
- #endif
- float3 diffuse = baseTexture.xyz * DiffuseColor;
- // Get bump map normal
- float3 bumpNormal = (float3)tex2D( SAMPLER(NormalMap), texCoord0) * 2.0 - 1.0;
- #if defined(SUPPORT_FROZEN)
- if (isMultiPass == FROZENPASS)
- {
- bumpNormal = (float3)tex2D(SAMPLER(FractalNormalMap), texCoord0) * 2.0 - 1.0;
- }
- #endif
- #if defined(SUPPORT_ALTMAPPING)
- bumpNormal = (float3)tex2D(SAMPLER(NormalMap), In.ShadowMapTexCoord.xy) * 2.0 - 1.0;
- #endif
- // Scale normal to increase/decrease bump effect
- bumpNormal.xy *= BumpScale;
- bumpNormal = normalize(bumpNormal);
-
- float4 color = baseTexture;
- color.xyz *= In.Color.xyz;
- #if defined(SUPPORT_FROZEN)
- if (isMultiPass == FROZENPASS)
- {
- specularStrength = 1;
- color.xyz = float3(0, 0, 0);
- diffuse.xyz = float3(.13, .33, .5);
- }
- #endif
- #if !defined(SUPPORT_ALTMAPPING)
- for (int i = 0; i < NumDirectionalLightsPerPixel_M; i++)
- {
- // Compute lighting
- float3 lightVec = In.LightVector[i].xyz;
- float3 halfVec = In.HalfEyeLightVector.xyz;
- float4 diffuseTerm = dot( bumpNormal, lightVec );
- float4 specularTerm = dot( bumpNormal, halfVec );
- float4 lighting = lit( diffuseTerm, specularTerm, SpecularExponent );
-
- if (i == 0)
- {
- if (hasShadow)
- {
- lighting.yz *= shadow( SAMPLER(ShadowMap), In.ShadowMapTexCoord );
- }
-
- float3 cloud = float3(1, 1, 1);
- #if defined(_WW3D_) && !defined(_W3DVIEW_)
- cloud = tex2D( SAMPLER(CloudTexture), cloudTexCoord);
- #endif
- color.xyz += DirectionalLight[0].Color * cloud * (diffuse * lighting.y + specularColor * lighting.z);
- }
- else
- {
- color.xyz += DirectionalLight[i].Color * (diffuse * lighting.y);
- }
- }
- #endif
- #if defined(SUPPORT_LIGHTMAP)
- float3 lightMapTexture = tex2D(SAMPLER(LightMap), texCoord1);
- float3 diffuseLight = lightMapTexture.xyz * 10;
- color.xyz += diffuseLight * diffuse;
- #endif
- // this is ugly but I couldn't think of a better way to do it. -Sean
- #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- // color *= lerp(damagedTexture, float4(1.0, 1.0, 1.0, 0.0) , ( In.Color.w));
- color *= damagedTexture * (1 - In.Color.w);
- #elif defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
- #elif !defined(SUPPORT_JAPANBUILDUP)
- color.w *= In.Color.w;
- #endif
- #if defined(SUPPORT_IRONCURTAIN)
- float3 Texture0 = tex2D( SAMPLER(IronCurtainTexture), texCoord0);
- float3 Texture1 = tex2D( SAMPLER(IronCurtainTexture), texCoord1);
- color.xyz = Texture0 * Texture1 * 5;
-
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 4.0);
- color.xyz += (float3(2.0,0.05,0.025) * fresnelDiffuse);
- color.w = 1;
- #endif // SUPPORT_IRONCURTAIN
- #if defined(SUPPORT_CHRONORIFT)
- float3 Texture0 = tex2D( SAMPLER(ChronoRiftTexture), texCoord0*2);
- float3 Texture1 = tex2D( SAMPLER(ChronoRiftTexture), texCoord1*2);
- color.xyz = Texture0 * Texture1 * 2;
-
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 2.0);
- color.xyz += fresnelDiffuse * float3(0.3,0.6,3.0);
- color.xyz = min(color.xyz,2);
- color.w = 1;
-
- #endif // SUPPORT_CHRONORIFT
- #if defined(SUPPORT_FORMATIONPREVIEW)
- color.xyz = float3(0.0,0.055,0.045);
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot( In.WorldTangentEyeDir, bumpNormal), 2.5);
- color.xyz += (float3(0.0,1.0,0.0) * fresnelDiffuse * 3);
- color.xyz = min(color.xyz,2);
- color.w = OpacityOverride;
- #endif // SUPPORT_FORMATIONPREVIEW
- #if defined(SUPPORT_JAPANBUILDUP)
- float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
- buildupTexture = pow(buildupTexture,3)*6;
- float3 maskColor = buildupTexture * float3(.9,3,.9);
- color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
- #endif
- #if defined(SUPPORT_TESLA)
- float3 Texture0 = tex2D( SAMPLER(FractalNormalMap), In.TeslaTexCoord.xy);
- Texture0 = Texture0 * 2 - 1;
- float3 Texture1 = tex2D( SAMPLER(TeslaTexture), In.TeslaTexCoord.zw * 1.5 + (Texture0.xy * .04));
- Texture1 *= tex2D( SAMPLER(TeslaTexture), In.TeslaTexCoord.wz * 3 + (Texture0.xy * .04));
- color.xyz += Texture1 * 20;
-
- // Compute view direction in world space
- float fresnelDiffuse = pow( 1-dot(In.WorldTangentEyeDir, bumpNormal), 4.0);
- color.xyz += fresnelDiffuse * float3(0.07,0.15,.75);
- color.xyz = min(color.xyz,4);
- color.w = 1;
- #endif // SUPPORT_TESLA
- if (isMultiPass == FIRSTPASS)
- {
- color.xyz *= TintColor;
- }
- #if defined(_WW3D_) && !defined(_W3DVIEW_)
- color.xyz *= tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord_CloudTexCoord.xy );
- #endif
- return color;
- }
- // We only want to do this for the really expensive part. The rest of the shader can be normal.
- #undef float4
- #undef float3
- #undef float2
- #undef float
- // ----------------------------------------------------------------------------
- // Arrays: Default_M
- // ----------------------------------------------------------------------------
- DEFINE_ARRAY_MULTIPLIER( VS_M_Multiplier_Final = 2 );
- #define VS_M_NumJointsPerVertex(isMultiPass) \
- compile VS_3_0 VS_M(0, isMultiPass), \
- compile VS_3_0 VS_M(1, isMultiPass)
- #if SUPPORTS_SHADER_ARRAYS
- vertexshader VS_M_Array[VS_M_Multiplier_Final] =
- {
- VS_M_NumJointsPerVertex(FIRSTPASS)
- };
- #if defined(SUPPORT_FROZEN)
- vertexshader VS_M_Frozen_Array[VS_M_Multiplier_Final] =
- {
- VS_M_NumJointsPerVertex(FROZENPASS)
- };
- #endif // SUPPORT_FROZEN
-
- #endif
- DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_HasShadow = 1 );
- #define PS_M_HasShadow(recolorEnabled, isMultiPass) \
- compile PS_3_0 PS_M(false, recolorEnabled, isMultiPass), \
- compile PS_3_0 PS_M(true, recolorEnabled, isMultiPass)
- DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_RecolorEnabled = PS_M_Multiplier_HasShadow * 2 );
-
- #define PS_M_RecolorEnabled(isMultiPass) \
- PS_M_HasShadow(false, isMultiPass), \
- PS_M_HasShadow(true, isMultiPass)
- DEFINE_ARRAY_MULTIPLIER( PS_M_Multiplier_Final = PS_M_Multiplier_RecolorEnabled * 2 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_M_Array[PS_M_Multiplier_Final] =
- {
- PS_M_RecolorEnabled(FIRSTPASS)
- };
- #if defined(SUPPORT_FROZEN)
- pixelshader PS_M_Frozen_Array[PS_M_Multiplier_Final] =
- {
- PS_M_RecolorEnabled(FROZENPASS)
- };
- #endif // SUPPORT_FROZEN
- #endif
- // ----------------------------------------------------------------------------
- // Technique: Default_M
- // ----------------------------------------------------------------------------
- technique Default_M
- {
- pass p0
- #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT)
- <
- USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
- >
- #endif
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_M_Array,
- min(NumJointsPerVertex, 1),
- NO_ARRAY_ALTERNATIVE);
- PixelShader = ARRAY_EXPRESSION_PS( PS_M_Array,
- HasShadow * PS_M_Multiplier_HasShadow
- + HasRecolorColors * PS_M_Multiplier_RecolorEnabled,
- NO_ARRAY_ALTERNATIVE);
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = true;
- CullMode = CW;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaBlendEnable = false;
-
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaBlendEnable = ( OpacityOverride < 0.99);
- #endif
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- #endif
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaTestEnable = true;
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaTestEnable = false;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaTestEnable = ( AlphaTestEnable );
- #endif
- #endif
- }
- #if defined(SUPPORT_FROZEN)
- pass p1
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_M_Frozen_Array,
- min(NumJointsPerVertex, 1),
- NO_ARRAY_ALTERNATIVE);
- PixelShader = ARRAY_EXPRESSION_PS( PS_M_Frozen_Array,
- HasShadow * PS_M_Multiplier_HasShadow
- + HasRecolorColors * PS_M_Multiplier_RecolorEnabled,
- NO_ARRAY_ALTERNATIVE);
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = false;
- CullMode = CW;
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- AlphaTestEnable = false;
-
- StencilEnable = false;
- }
- #endif // SUPPORT_FROZEN
- }
- // ----------------------------------------------------------------------------
- // SHADER: Low
- // ----------------------------------------------------------------------------
- struct VSOutput_L
- {
- float4 Position : POSITION;
- float4 Color : COLOR0;
- float4 TexCoord0_TexCoord1 : TEXCOORD0;
- float2 ShroudTexCoord : TEXCOORD1;
- #if defined(SUPPORT_ALTMAPPING)
- float3 FallOffColor : TEXCOORD2;
- #endif
- };
- // ----------------------------------------------------------------------------
- // SHADER: VS
- // ----------------------------------------------------------------------------
- VSOutput_L VS_L(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE)
- float2 TexCoord1 : TEXCOORD1,
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 2, 3),
- #else
- DECLARE_VERTEXCOLOR_INPUT(VertexColor, 1, 2),
- #endif
- uniform int numJointsPerVertex)
- {
- USE_VERTEXCOLOR(VertexColor);
- USE_TEXCOORD(TexCoord0);
- #if defined(SUPPORT_DAMAGETEXTURE)
- USE_TEXCOORD(TexCoord1);
- #endif
- USE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
- VSOutput_L Out;
- float3 worldPosition = 0;
- float3 worldNormal = 0;
- float3 worldTangent = 0;
- float3 worldBinormal = 0;
- CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
- worldPosition, worldNormal, worldTangent, worldBinormal);
- // Get the skins opacity value
- VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
- #if defined(_3DSMAX_) && defined(SUPPORT_DAMAGETEXTURE)
- if (PreviewFullyDamaged)
- {
- VertexColor.w = 0.0;
- }
- #endif
- #if defined(SUPPORT_TREAD_SCROLLING)
- // Tread scrolling uses the vertex color opacity for animating the U coordinate
- TexCoord0.x += VertexColor.w;
- // Don't use it for opacity then.
- VertexColor.w = 1.0f;
- #endif
- // transform position to projection space
- Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
- #if !defined (SUPPORT_ALTMAPPING)
- Out.Color = float4(AmbientLightColor * AmbientColor, OpacityOverride);
-
- // Compute remaining directional lights per vertex, others will be done in pixel shader
- float3 diffuseLight = 0;
- for (int i = 0; i < NumDirectionalLights; i++)
- {
- diffuseLight += DirectionalLight[i].Color * max(0, dot(worldNormal, DirectionalLight[i].Direction));
- }
-
- Out.Color.xyz += diffuseLight * DiffuseColor;
-
- Out.Color *= VertexColor;
- #endif // SUPPORT_ALTMAPPING
- // pass texture coordinates for fetching the diffuse and normal maps
- Out.TexCoord0_TexCoord1.xy = TexCoord0.xy;
- #if defined(SUPPORT_DAMAGETEXTURE)
- float2 texCoord1 = TexCoord1;
- #else
- float2 texCoord1 = TexCoord0;
- #endif
- #if defined (SUPPORT_ALTMAPPING)
- // -------------------------------------------------------------------------------
- // -- Texture Coords and Mapping -------------------------------------------------
- // -------------------------------------------------------------------------------
- // Build Tex coords, animate and scale ---------------------------------------
- float texScalar = .75; // Scale
- float texSpeed = Time * .3; // animate coords as a multiplier of Time
- float texDivergenceAngle = 55; // this is the angle difference between the 2 coords
- // Use the tex coords on the model but offset them slightly based on world
- // coords to keep multiple units from animating in sync
- float2 TexCoords = (TexCoord0 + (worldPosition.xy * .003)) * texScalar;
- // Build Texture Rotation Matrix And Convert Degrees to Radians --
- float cosAngle = 0;
- float sinAngle = 0;
- float2x2 uvCoordRotate = { 1.0f, 0.0f, 1.0f, 0.0f };
- sincos (texDivergenceAngle * .017453, sinAngle, cosAngle);
-
- // Build Rotation
- uvCoordRotate[0][0] = cosAngle;
- uvCoordRotate[0][1] = -sinAngle;
- uvCoordRotate[1][1] = uvCoordRotate[0][0];
- uvCoordRotate[1][0] = -uvCoordRotate[0][1];
- // Rotate and Animate Divergence Texture Coords --------------------
- float2 TexCoordsDiverge = mul(TexCoords, uvCoordRotate);
- TexCoordsDiverge.x += texSpeed;
- float2 TexCoordsDivergeInv = mul(TexCoords, transpose(uvCoordRotate));
- TexCoordsDivergeInv.x += texSpeed;
-
-
- Out.TexCoord0_TexCoord1.xy = TexCoordsDiverge;
- Out.TexCoord0_TexCoord1.zw = TexCoordsDivergeInv;
-
- Out.Color = 0;
-
- // Compute view direction in world space
- float3 worldEyeDir = normalize(GetEyePosition() - worldPosition);
-
- #endif //SUPPORT_ALTMAPPING
- #if defined(SUPPORT_IRONCURTAIN)
- float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
-
- // Compute view direction in world space
- Out.FallOffColor = pow(worldTangentEyeDir, 4.0) * float3(2.0,0.05,0.025);
- #endif // SUPPORT_IRONCURTAIN
- #if defined(SUPPORT_CHRONORIFT)
- float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
-
- // Compute view direction in world space
- Out.FallOffColor = pow(worldTangentEyeDir, 2.0) * float3(0.3,0.6,3.0);
- #endif // SUPPORT_CHRONORIFT
- #if defined(SUPPORT_FORMATIONPREVIEW)
-
- float worldTangentEyeDir = 1 - dot(worldEyeDir, worldNormal);
-
- // Compute view direction in world space
- Out.FallOffColor = pow(worldTangentEyeDir, 2.5) * float3(0.0,1.05,0.0);
- #endif // SUPPORT_FORMATIONPREVIEW
- Out.TexCoord0_TexCoord1.zw = texCoord1.yx;
- Out.ShroudTexCoord = CalculateShroudTexCoord(Shroud, worldPosition);
-
- return Out;
- }
- // ----------------------------------------------------------------------------
- // SHADER: PS
- // ----------------------------------------------------------------------------
- float4 PS_L(VSOutput_L In, uniform bool recolorEnabled) COLORTARGET
- {
- float2 texCoord0 = In.TexCoord0_TexCoord1.xy;
- float2 texCoord1 = In.TexCoord0_TexCoord1.wz;
- // Get diffuse color
- float4 baseTexture = tex2D( SAMPLER(DiffuseTexture), texCoord0);
-
- #if defined(SUPPORT_RECOLORING)
- if (recolorEnabled)
- {
- float4 recolorColor = tex2D( SAMPLER(SpecMap), texCoord0);
- baseTexture.xyz = lerp(baseTexture.xyz, baseTexture.xyz * RecolorColor * 2, recolorColor.z);
- }
- #endif //defined(SUPPORT_RECOLORING)
- float4 color = baseTexture;
- color.xyz *= In.Color.xyz;
- // this is ugly but I couldn't think of a better way to do it. -Sean
- #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- color *= damagedTexture * (1 - In.Color.w);
- #elif defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float4 damagedTexture = tex2D(SAMPLER(DamagedTexture), texCoord1);
- color *= lerp(damagedTexture, 1.0.xxxx, In.Color.w);
- #elif !defined(SUPPORT_JAPANBUILDUP)
- color.w *= In.Color.w;
- #endif
- #if defined(SUPPORT_IRONCURTAIN)
- float3 Texture0 = tex2D( SAMPLER(IronCurtainTexture), texCoord0);
- float3 Texture1 = tex2D( SAMPLER(IronCurtainTexture), texCoord1);
- color.xyz = Texture0 * Texture1 * 5;
-
- // Compute view direction in world space
- color.xyz += In.FallOffColor;
- color.w = 1;
- #endif // SUPPORT_IRONCURTAIN
- #if defined(SUPPORT_CHRONORIFT)
- float3 Texture0 = tex2D( SAMPLER(ChronoRiftTexture), texCoord0);
- float3 Texture1 = tex2D( SAMPLER(ChronoRiftTexture), texCoord1);
- color.xyz = Texture0 * Texture1 * 2;
-
- color.xyz += In.FallOffColor;
- color.w = 1;
- #endif // SUPPORT_CHRONORIFT
- #if defined(SUPPORT_FORMATIONPREVIEW)
- color.xyz = float3(0.0,0.22,0.18);
- color.xyz += In.FallOffColor;
- color.xyz = min(color.xyz,2);
- color.w = OpacityOverride;
- #endif // SUPPORT_CHRONORIFT
- color.xyz *= TintColor;
- #if defined(_WW3D_) && !defined(_W3DVIEW_)
- color.xyz *= tex2D( SAMPLER(ShroudTexture), In.ShroudTexCoord );
- #endif
- #if defined(SUPPORT_JAPANBUILDUP)
- // Get Buildup Mask
- float Mask = smoothstep(.3,.51,texCoord0.y + (In.Color.w * 1.2) - .65);
- float buildupTexture = tex2D( SAMPLER(JapanBuildMaskTexture), texCoord0 * 50).x + .5;
- buildupTexture = pow(buildupTexture,3)*6;
- float3 maskColor = buildupTexture * float3(.9,3,.9);
- color.xyz = lerp(maskColor,color.xyz, clamp(1,0,Mask));
- clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
- #endif
- return color;
- }
- // ----------------------------------------------------------------------------
- // Arrays: Default_L
- // ----------------------------------------------------------------------------
- DEFINE_ARRAY_MULTIPLIER( VS_L_Multiplier_Final = 2 );
- #define VS_L_NumJointsPerVertex \
- compile VS_2_0 VS_L(0), \
- compile VS_2_0 VS_L(1)
- #if SUPPORTS_SHADER_ARRAYS
- vertexshader VS_L_Array[VS_L_Multiplier_Final] =
- {
- VS_L_NumJointsPerVertex
- };
- #endif
- DEFINE_ARRAY_MULTIPLIER( PS_L_Multiplier_RecolorEnabled = 1 );
-
- #define PS_L_RecolorEnabled \
- compile PS_2_0 PS_L(false), \
- compile PS_2_0 PS_L(true)
- DEFINE_ARRAY_MULTIPLIER( PS_L_Multiplier_Final = PS_L_Multiplier_RecolorEnabled * 2 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PS_L_Array[PS_L_Multiplier_Final] =
- {
- PS_L_RecolorEnabled
- };
- #endif
- // ----------------------------------------------------------------------------
- // Technique: Default_L
- // ----------------------------------------------------------------------------
- technique Default_L
- {
- pass p0
- #if !defined(SUPPORT_DAMAGETEXTURE) && !defined(SUPPORT_CHRONORIFT)
- <
- USE_EXPRESSION_EVALUATOR(EXPRESSION_EVALUATOR_NAME)
- >
- #endif
- {
- VertexShader = ARRAY_EXPRESSION_VS( VS_L_Array,
- min(NumJointsPerVertex, 1),
- NO_ARRAY_ALTERNATIVE);
- PixelShader = ARRAY_EXPRESSION_PS( PS_L_Array,
- HasRecolorColors * PS_L_Multiplier_RecolorEnabled,
- NO_ARRAY_ALTERNATIVE);
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = true;
- CullMode = CW;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaBlendEnable = false;
-
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaBlendEnable = ( OpacityOverride < 0.99);
- #endif
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
- #endif
- AlphaFunc = GreaterEqual;
- AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
- #if defined(SUPPORT_DAMAGETEXTURE)
- AlphaTestEnable = true;
- #elif defined(SUPPORT_CHRONORIFT)
- AlphaTestEnable = false;
- #else
- #if !EXPRESSION_EVALUATOR_ENABLED
- AlphaTestEnable = ( AlphaTestEnable );
- #endif
- #endif
- }
- }
- #endif // ENABLE_LOD
- // ----------------------------------------------------------------------------
- // SHADER: CreateShadowMapVS
- // ----------------------------------------------------------------------------
- struct VSOutput_CreateShadowMap
- {
- float4 Position : POSITION;
- float2 TexCoord0 : TEXCOORD0;
- #if defined(SUPPORT_DAMAGETEXTURE)
- float2 TexCoord1 : TEXCOORD2;
- #endif
- float Depth : TEXCOORD1;
- float Opacity : COLOR0;
- };
- // ----------------------------------------------------------------------------
- VSOutput_CreateShadowMap CreateShadowMapVS(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord0 : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE)
- float2 TexCoord1 : TEXCOORD1,
- #endif
- float4 VertexColor: COLOR0,
- uniform int numJointsPerVertex)
- {
- VSOutput_CreateShadowMap Out;
- float3 worldPosition = 0;
- float3 worldNormal = 0;
- float3 worldTangent = 0;
- float3 worldBinormal = 0;
- CalculatePositionAndTangentFrame(InSkin, numJointsPerVertex,
- worldPosition, worldNormal, worldTangent, worldBinormal);
- // Get the skins opacity value, used later as blend factor for the damage texture
- VertexColor.w *= GetOpacity(InSkin, numJointsPerVertex);
- #if defined(_3DSMAX_)
- // Default vertex color is 0 in Max, that's bad.
- VertexColor = 1.0;
- #endif
- #if defined(SUPPORT_TREAD_SCROLLING)
- // Tread scrolling uses the vertex color opacity for animating the U coordinate
- TexCoord0.x += VertexColor.w;
- // Don't use it for opacity then.
- VertexColor.w = 1.0f;
- #endif
- // Transform position to projection space
- ISOLATE Out.Position = mul(float4(worldPosition, 1), GetViewProjection());
- Out.Depth = Out.Position.z / Out.Position.w;
- Out.Opacity = OpacityOverride * VertexColor.w;
- Out.TexCoord0 = TexCoord0;
- #if defined(SUPPORT_DAMAGETEXTURE)
- Out.TexCoord1 = TexCoord1;
- #endif
- return Out;
- }
- // ----------------------------------------------------------------------------
- float4 CreateShadowMapPS(VSOutput_CreateShadowMap In, uniform bool alphaTestEnable) COLORTARGET
- {
- #if defined(SUPPORT_JAPANBUILDUP)
- // Get Buildup Mask
- float Mask = smoothstep(.4,.51,In.TexCoord0.y + (In.Opacity * 1.2) - .65);
- clip(Mask - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
- #else
- float opacity = tex2D(SAMPLER(DiffuseTexture), In.TexCoord0).w;
-
- #if defined(SUPPORT_FILLDAMAGETEXTURE) && defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float damagedTexture = tex2D(SAMPLER(DamagedTexture), In.TexCoord1).w;
- opacity *= damagedTexture * (1 - In.Opacity);
- #elif defined(SUPPORT_DAMAGETEXTURE)
- // Get Damaged Texture on 2nd UV Coords
- float damagedTexture = tex2D(SAMPLER(DamagedTexture), In.TexCoord1).w;
- opacity *= lerp(damagedTexture, 1.0, In.Opacity);
- #elif !defined(SUPPORT_JAPANBUILDUP)
- opacity *= In.Opacity;
- #endif
- if (alphaTestEnable)
- {
- // Simulate alpha testing for floating point render target
- clip(opacity - ((float)DEFAULT_ALPHATEST_THRESHOLD / 255));
- }
- #endif //SUPPORT_JAPANBUILDUP
- return In.Depth;
- }
- // ----------------------------------------------------------------------------
- // SHADER: CreateShadowMapVS_Xenon
- // ----------------------------------------------------------------------------
- VSOutput_CreateShadowMap CreateShadowMapVS_Xenon(VSInputSkinningOneBoneTangentFrame InSkin,
- float2 TexCoord : TEXCOORD0,
- #if defined(SUPPORT_DAMAGETEXTURE)
- float2 TexCoord1 : TEXCOORD1,
- #endif
- float4 VertexColor: COLOR0)
- {
- return CreateShadowMapVS( InSkin,
- TexCoord,
- #if defined(SUPPORT_DAMAGETEXTURE)
- TexCoord1,
- #endif
- VertexColor, min(NumJointsPerVertex, 1) );
- }
- // ----------------------------------------------------------------------------
- float4 CreateShadowMapPS_Xenon(VSOutput_CreateShadowMap In) : COLOR
- {
- return CreateShadowMapPS(In, AlphaTestEnable);
- }
- // ----------------------------------------------------------------------------
- // Technique _CreateShadowMap
- // ----------------------------------------------------------------------------
- DEFINE_ARRAY_MULTIPLIER( VSCreateShadowMap_Multiplier_Final = 2 );
- #define VSCreateShadowMap_NumJointsPerVertex \
- compile VS_2_0 CreateShadowMapVS(0), \
- compile VS_2_0 CreateShadowMapVS(1)
- #if SUPPORTS_SHADER_ARRAYS
- vertexshader VSCreateShadowMap_Array[VSCreateShadowMap_Multiplier_Final] =
- {
- VSCreateShadowMap_NumJointsPerVertex
- };
- #endif
- #define PSCreateShadowMap_AlphaTestEnable \
- compile PS_2_0 CreateShadowMapPS(false), \
- compile PS_2_0 CreateShadowMapPS(true)
- DEFINE_ARRAY_MULTIPLIER( PSCreateShadowMap_Multiplier_Final = 2 );
- #if SUPPORTS_SHADER_ARRAYS
- pixelshader PSCreateShadowMap_Array[PSCreateShadowMap_Multiplier_Final] =
- {
- PSCreateShadowMap_AlphaTestEnable
- };
- #endif
- // ----------------------------------------------------------------------------
- #if defined(SUPPORT_FORMATIONPREVIEW) || defined(SUPPORT_CHRONORIFT)
- technique _CreateDepthMap // Don't cast a shadow, but still render to the depth map
- #else
- technique _CreateShadowMap
- #endif
- {
- pass p0
- {
- VertexShader = ARRAY_EXPRESSION_VS( VSCreateShadowMap_Array,
- min(NumJointsPerVertex, 1),
- compile VS_VERSION CreateShadowMapVS_Xenon() );
-
- PixelShader = ARRAY_EXPRESSION_PS( PSCreateShadowMap_Array,
- AlphaTestEnable,
- compile PS_VERSION CreateShadowMapPS_Xenon() );
- ZEnable = true;
- ZFunc = ZFUNC_INFRONT;
- ZWriteEnable = true;
- CullMode = CW;
-
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- }
- }
|