//const float4x4 GbxVisualPrCamera; todo: convert shaders... //const float4x3 GbxVisualToWorld; //const float4 GbxEyeInVisual; const float4 GbxLightAmbient; const float4 GbxLightDirRgb0; const float4 GbxLightDirRgbDblSided0; const float4 GbxLightDirDir0; const float4 GbxVisualToFogTnL; const float4 GbxPrelight_ScaleTrans; //////// static inline float3 LightAD_Dir1(in float3 Normal) { return saturate(GbxLightAmbient + GbxLightDirRgb0*max(0, dot(Normal, -GbxLightDirDir0))); } static inline float3x3 TangentToVisual_FromTBN(in float3 TangentU, in float3 TangentV, in float3 Normal) { return float3x3( TangentU.x, TangentU.y, TangentU.z, TangentV.x, TangentV.y, TangentV.z, Normal.x, Normal.y, Normal.z ); } static inline float3 Matrix_GetColumnX(float3x3 Matrix) {return Matrix._11_21_31;} static inline float4 Matrix_GetColumnX(float4x4 Matrix) {return Matrix._11_21_31_41;} static inline float3 Matrix_GetColumnY(float3x3 Matrix) {return Matrix._12_22_32;} static inline float4 Matrix_GetColumnY(float4x4 Matrix) {return Matrix._12_22_32_42;} static inline float3 Matrix_GetColumnZ(float3x3 Matrix) {return Matrix._13_23_33;} static inline float4 Matrix_GetColumnW(float4x4 Matrix) {return Matrix._14_24_34_44;} #ifndef DGbxVSetDeclPC3_Shadow_Count3 #define DGbxVSetDeclPC3_Shadow_Count3 #endif #ifndef DGbxVGenLoadPC3_Shadow #define DGbxVGenLoadPC3_Shadow #endif #ifndef DGbxVGenCodePC3_Shadow #define DGbxVGenCodePC3_Shadow #endif #ifndef DGbxVGenLoadPC3_Projector #define DGbxVGenLoadPC3_Projector #endif #ifndef DGbxVGenCodePC3_Projector #define DGbxVGenCodePC3_Projector #endif #ifndef DGbxVGenLoadPC3_Projector_TcInPS #define DGbxVGenLoadPC3_Projector_TcInPS #endif #ifndef DGbxVGenCodePC3_Projector_TcInPS #define DGbxVGenCodePC3_Projector_TcInPS #endif #ifndef DGbxVGenLoadPC3_Projector_NoDot #define DGbxVGenLoadPC3_Projector_NoDot #endif #ifndef DGbxVGenCodePC3_Projector_NoDot #define DGbxVGenCodePC3_Projector_NoDot #endif #ifndef DGbxVGenOutputPC3_MrtEffects #define DGbxVGenOutputPC3_MrtEffects #endif #ifndef DGbxVGenLoadPC3_MrtEffects #define DGbxVGenLoadPC3_MrtEffects #endif #ifndef DGbxVGenCodePC3_MrtEffects #define DGbxVGenCodePC3_MrtEffects #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt0 #define DGbxVGlobalSet_ExtraTexCoordStartAt0 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt1 #define DGbxVGlobalSet_ExtraTexCoordStartAt1 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt2 #define DGbxVGlobalSet_ExtraTexCoordStartAt2 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt3 #define DGbxVGlobalSet_ExtraTexCoordStartAt3 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt4 #define DGbxVGlobalSet_ExtraTexCoordStartAt4 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt5 #define DGbxVGlobalSet_ExtraTexCoordStartAt5 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt6 #define DGbxVGlobalSet_ExtraTexCoordStartAt6 #endif #ifndef DGbxVGlobalSet_ExtraTexCoordStartAt7 #define DGbxVGlobalSet_ExtraTexCoordStartAt7 #endif // By default, Color0 is a (material.diffuse) color to be modulated #ifndef DGbxVGenCodePC2_Prelight #define DGbxVGenCodePC2_Prelight \ Output.Color0.rgb = v.Color0*(GbxLightAmbient+LightAD_Dir1(v.Normal)); #endif // By default, Color0 is a (material.diffuse) color to be modulated #ifndef DGbxVGenCodePC3_Prelight #define DGbxVGenCodePC3_Prelight \ Output.Color0.rgb = v.Color0*GbxLightAmbient; \ Output.Color1.rgb = v.Color0*LightAD_Dir1(v.Normal); #endif // By default, Color0 is a (material.diffuse) color to be modulated #ifndef DGbxVGenCodePC3_Prelight_NoDot #define DGbxVGenCodePC3_Prelight_NoDot \ Output.Color0.rgb = v.Color0*GbxLightAmbient; \ Output.Color1.rgb = v.Color0*saturate(GbxLightAmbient+GbxLightDirRgbDblSided0); #endif #ifndef DGbxVGenCodePC3_TransTreeMip #define DGbxVGenCodePC3_TransTreeMip \ Output.Color0.a = 1; \ Output.Color1.a = 1; #endif // TAG TO REMOVE #ifndef DGbxGenLoadPC3_VS_Shadow #define DGbxGenLoadPC3_VS_Shadow #endif #ifndef DGbxGenCodePC3_VS_Shadow #define DGbxGenCodePC3_VS_Shadow #endif #ifndef DGbxGenCodePC3_PrelightCV #define DGbxGenCodePC3_PrelightCV \ Output.Color0.rgb = v.Color0*GbxLightAmbient; \ Output.Color1.rgb = v.Color0*LightAD_Dir1(v.Normal); #endif // By default, Color0 is a (material.diffuse) color to be modulated #ifndef DGbxGenCodePC3_PrelightCV_DblSidedAmbient #define DGbxGenCodePC3_PrelightCV_DblSidedAmbient \ Output.Color0.rgb = v.Color0*GbxLightAmbient; \ Output.Color1.rgb = v.Color0*saturate(GbxLightAmbient+GbxLightDirRgb0); #endif // TAG END //////////////////////////////////// // Multiple lighting struct SLightBall { float4 Rgb_IRad2; float4 Pos_ICosRange; }; struct SLightSpot { SLightBall Ball; float4 Dir_CosOuter; }; // I've difficulties with Dx9.0b & Dx9.0c HLSL compiler : // I'm not able to make it generates loop/endloop instruction (using aL register) // when compiling an array of struct (SLightBall or SLightSpot), it's like // he's always assuming iX.z==1 // Then to save instruction slots I've split the light arrays into float4 arrays // => more LoadIds to handle... int GbxLight2BallCount = 2; SLightBall GbxLight2Balls[2]; float4 GbxLight2Balls_Rgb_IRad2[2]; float4 GbxLight2Balls_Pos_Rad2[2]; int GbxLight4BallCount = 4; SLightBall GbxLight4Balls[4]; float4 GbxLight4Balls_Rgb_IRad2[4]; float4 GbxLight4Balls_Pos_Rad2[4]; int GbxLight8BallCount = 8; SLightBall GbxLight8Balls[8]; float4 GbxLight8Balls_Rgb_IRad2[8]; float4 GbxLight8Balls_Pos_Rad2[8]; int GbxLight2SpotCount = 2; SLightSpot GbxLight2Spots[2]; float4 GbxLight2Spots_Rgb_IRad2[2]; float4 GbxLight2Spots_Pos_ICosR[2]; float4 GbxLight2Spots_Dir_CosOt[2]; int GbxLight4SpotCount = 4; SLightSpot GbxLight4Spots[4]; float4 GbxLight4Spots_Rgb_IRad2[4]; float4 GbxLight4Spots_Pos_ICosR[4]; float4 GbxLight4Spots_Dir_CosOt[4]; int GbxLight8SpotCount = 8; SLightSpot GbxLight8Spots[8]; float4 GbxLight8Spots_Rgb_IRad2[8]; float4 GbxLight8Spots_Pos_ICosR[8]; float4 GbxLight8Spots_Dir_CosOt[8]; float3 DoLightBall_GetEye(in SLightBall _Ball, in float4 _Position, in float3 _Normal, out float3 _Eye) { float3 PosToBall = _Ball.Pos_ICosRange-_Position; float3 PosToBallLen2 = dot(PosToBall,PosToBall); float3 BallAtt = max(0,_Position.w-PosToBallLen2*_Ball.Rgb_IRad2.w); _Eye = PosToBall*rsqrt(PosToBallLen2); float EyeDotN = max(0,dot(_Normal,_Eye)); return EyeDotN*BallAtt*_Ball.Rgb_IRad2; } float3 DoLightBall(SLightBall _Ball, float4 _Position, float3 _Normal) { float3 Eye; return DoLightBall_GetEye(_Ball, _Position, _Normal, Eye); } float3 DoLightBall2(int _iBall, float4 _Position, float3 _Normal) { SLightBall Ball; Ball.Rgb_IRad2 = GbxLight2Balls_Rgb_IRad2[_iBall]; Ball.Pos_ICosRange = GbxLight2Balls_Pos_Rad2[_iBall]; return DoLightBall(Ball, _Position, _Normal); } float3 DoLightBall4(int _iBall, float4 _Position, float3 _Normal) { SLightBall Ball; Ball.Rgb_IRad2 = GbxLight4Balls_Rgb_IRad2[_iBall]; Ball.Pos_ICosRange = GbxLight4Balls_Pos_Rad2[_iBall]; return DoLightBall(Ball, _Position, _Normal); } float3 DoLightBall8(int _iBall, float4 _Position, float3 _Normal) { SLightBall Ball; Ball.Rgb_IRad2 = GbxLight8Balls_Rgb_IRad2[_iBall]; Ball.Pos_ICosRange = GbxLight8Balls_Pos_Rad2[_iBall]; return DoLightBall(Ball, _Position, _Normal); } float3 DoLightSpot(SLightSpot _Spot, float4 _Position, float3 _Normal) { SLightBall Ball = _Spot.Ball; float3 Eye; float3 BallLight = DoLightBall_GetEye(Ball, _Position, _Normal, Eye); float EyeDotDir = dot(Eye, -_Spot.Dir_CosOuter); float Falloff = saturate( (EyeDotDir-_Spot.Dir_CosOuter.w)*Ball.Pos_ICosRange.w ); float3 SpotLight = BallLight*Falloff; return SpotLight; } float3 DoLightSpot2(int _iSpot, float4 _Position, float3 _Normal) { SLightSpot Spot; Spot.Ball.Rgb_IRad2 = GbxLight2Spots_Rgb_IRad2[_iSpot]; Spot.Ball.Pos_ICosRange = GbxLight2Spots_Pos_ICosR[_iSpot]; Spot.Dir_CosOuter = GbxLight2Spots_Dir_CosOt[_iSpot]; float3 Eye; return DoLightSpot(Spot, _Position, _Normal); } float3 DoLightSpot4(int _iSpot, float4 _Position, float3 _Normal) { SLightSpot Spot; Spot.Ball.Rgb_IRad2 = GbxLight4Spots_Rgb_IRad2[_iSpot]; Spot.Ball.Pos_ICosRange = GbxLight4Spots_Pos_ICosR[_iSpot]; Spot.Dir_CosOuter = GbxLight4Spots_Dir_CosOt[_iSpot]; float3 Eye; return DoLightSpot(Spot, _Position, _Normal); } float3 DoLightSpot8(int _iSpot, float4 _Position, float3 _Normal) { SLightSpot Spot; Spot.Ball.Rgb_IRad2 = GbxLight8Spots_Rgb_IRad2[_iSpot]; Spot.Ball.Pos_ICosRange = GbxLight8Spots_Pos_ICosR[_iSpot]; Spot.Dir_CosOuter = GbxLight8Spots_Dir_CosOt[_iSpot]; float3 Eye; return DoLightSpot(Spot, _Position, _Normal); }