GlobalParameters.fxh 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2008 Electronic Arts Inc
  3. //
  4. // Global parameters
  5. //////////////////////////////////////////////////////////////////////////////
  6. #ifndef _GLOBALLIGHTING_FXH_
  7. #define _GLOBALLIGHTING_FXH_
  8. // Use these defines to indicate whether features are needed for the specific shaders
  9. // #define SUPPORT_GLOBAL_LIGHTS 1
  10. // #define SUPPORT_LOCAL_LIGHTS 1
  11. #include "RegisterMap.fxh"
  12. //////////////////////////////////////////////////////////////////////////////
  13. // Global Light - Ambient and Directional Light
  14. //////////////////////////////////////////////////////////////////////////////
  15. #if defined(USE_INDIRECT_CONSTANT) || SUPPORT_GLOBAL_LIGHTS
  16. // Ambient light
  17. REGISTER_BIND( REGISTER_AMBIENT_LIGHT_COLOR,
  18. float3, AmbientLightColor,
  19. string SasBindAddress = "Sas.AmbientLight[0].Color";
  20. string UIWidget = "None";,
  21. = float3(0.3, 0.3, 0.3));
  22. // Directional Light
  23. #define NumDirectionalLights 3
  24. REGISTER_BIND_ARRAY( REGISTER_DIRECTIONAL_LIGHTS_FIRST,
  25. SasDirectionalLight, DirectionalLight, NumDirectionalLights,
  26. string SasBindAddress = "Sas.DirectionalLight[*]";
  27. string UIWidget = "None"; ,
  28. NO_INITIALIZER)
  29. #if defined(USE_INITIALIZERS) && !defined(EA_PLATFORM_PS3) // Crashes 'sce-cgc' if initialized
  30. // This initializer is too complex to be part of the macro
  31. =
  32. {
  33. {
  34. DEFAULT_DIRECTIONAL_LIGHT_1,
  35. DEFAULT_DIRECTIONAL_LIGHT_2,
  36. DEFAULT_DIRECTIONAL_LIGHT_3
  37. }
  38. }
  39. #endif
  40. ;
  41. #if defined(USE_INTERACTIVE_LIGHTS)
  42. DECLARE_DIRECTIONAL_LIGHT_INTERACTIVE(DirectionalLight, 0);
  43. #endif
  44. #endif // #if define(USE_INDIRECT_CONSTANT) || SUPPORT_GLOBAL_LIGHTS
  45. //////////////////////////////////////////////////////////////////////////////
  46. // Local Light - Point Light
  47. //////////////////////////////////////////////////////////////////////////////
  48. #if defined(USE_INDIRECT_CONSTANT) || SUPPORT_LOCAL_LIGHTS
  49. #if defined(EA_PLATFORM_WINDOWS)
  50. #if SUPPORT_LOCAL_LIGHTS
  51. // Don't make NumPointLights into an indirect constant on windows as it is
  52. // sometimes used in integer and sometimes in float registers
  53. // and the D3DX skipConstants code does not understand dual register bindings
  54. int NumPointLights
  55. <
  56. string SasBindAddress = "Sas.NumPointLights";
  57. string UIWidget = "None";
  58. > = 0;
  59. #endif
  60. #else
  61. // Point Light
  62. REGISTER_BIND_INT( IREGISTER_NUM_POINT_LIGHTS,
  63. int, NumPointLights,
  64. string SasBindAddress = "Sas.NumPointLights";
  65. string UIWidget = "None"; ,
  66. = 0);
  67. #endif
  68. // Default MaxNumPointLights to 8 unless the shader specifed it
  69. #if !defined(MaxNumPointLights)
  70. #define MaxNumPointLights 8
  71. #endif // #if !defined(MaxNumPointLights)
  72. REGISTER_BIND_ARRAY( REGISTER_POINT_LIGHTS_FIRST,
  73. SasPointLight, PointLight, MaxNumPointLights,
  74. string SasBindAddress = "Sas.PointLight[*]";
  75. string UIWidget = "None"; ,
  76. NO_INITIALIZER);
  77. #endif // #if define(USE_INDIRECT_CONSTANT) || SUPPORT_LOCAL_LIGHTS
  78. //////////////////////////////////////////////////////////////////////////////
  79. // Cloud
  80. //////////////////////////////////////////////////////////////////////////////
  81. #if defined(USE_INDIRECT_CONSTANT) || SUPPORT_CLOUDS
  82. REGISTER_BIND( REGISTER_CLOUD_SETUP,
  83. CloudSetup, Cloud,
  84. string UIWidget = "None";
  85. string SasBindAddress = "Terrain.Cloud"; ,
  86. = DEFAULT_CLOUD);
  87. // Cloud information for NoCloudMultiplier
  88. REGISTER_BIND( REGISTER_NO_CLOUD_MULTIPLIER,
  89. float3, NoCloudMultiplier,
  90. string UIWidget = "None";
  91. string SasBindAddress = "Terrain.Cloud.NoCloudMultiplier"; ,
  92. = float3(1, 1, 1));
  93. #endif // #if define(USE_INDIRECT_CONSTANT) || SUPPORT_CLOUDS
  94. //////////////////////////////////////////////////////////////////////////////
  95. // Recolor
  96. //////////////////////////////////////////////////////////////////////////////
  97. #if SUPPORT_RECOLORING || defined(__cplusplus)
  98. #if defined(_3DSMAX_)
  99. bool HasRecolorColors
  100. <
  101. string UIName = "Preview House Color Enable";
  102. bool ExportValue = false;
  103. > = false;
  104. float3 RecolorColor
  105. <
  106. string UIName = "Preview House Color";
  107. string UIWidget = "Color";
  108. bool ExportValue = false;
  109. > = float3(.7, .05, .05);
  110. #else // #if defined(_3DSMAX_)
  111. // HasRecolorColors cannot be an indirect constant on Windows, as it is used in array expressions.
  112. // Declare it regularly, just don't declare it at all outside the shaders
  113. #if defined(EA_PLATFORM_WINDOWS)
  114. #if !defined(__cplusplus)
  115. bool HasRecolorColors
  116. <
  117. string UIWidget = "None";
  118. string SasBindAddress = "WW3D.HasRecolorColors";
  119. bool ExportValue = false;
  120. > = false;
  121. #endif
  122. #else
  123. REGISTER_BIND_BOOL( BREGISTER_HAS_RECOLOR_COLORS,
  124. bool, HasRecolorColors,
  125. string UIWidget = "None";
  126. string SasBindAddress = "WW3D.HasRecolorColors";
  127. bool ExportValue = false; ,
  128. = false);
  129. #endif
  130. REGISTER_BIND( REGISTER_RECOLOR_COLOR,
  131. float3, RecolorColor,
  132. string UIWidget = "None";
  133. string SasBindAddress = "WW3D.RecolorColor[0]";
  134. bool ExportValue = false; ,
  135. = float3(0, 0, 0));
  136. #endif // #if defined(_3DSMAX_)
  137. #else // #if SUPPORT_RECOLORING
  138. // Special case when SUPPORT_RECOLORING is not supported, we want to make these static const to optimize the shader better
  139. static const bool HasRecolorColors = false;
  140. static const float3 RecolorColor = float3(0, 0, 0);
  141. // Need to declare these dummy variables to block the registers
  142. #if defined(USE_INDIRECT_CONSTANT)
  143. #if !defined(EA_PLATFORM_WINDOWS)
  144. REGISTER_BIND_BOOL( BREGISTER_HAS_RECOLOR_COLORS,
  145. bool, HasRecolorColorsDummy,
  146. string UIWidget = "None";
  147. string SasBindAddress = "WW3D.HasRecolorColors";
  148. bool ExportValue = false; ,
  149. = 0);
  150. #endif
  151. REGISTER_BIND( REGISTER_RECOLOR_COLOR,
  152. float3, RecolorColorDummy,
  153. string UIWidget = "None";
  154. string SasBindAddress = "WW3D.RecolorColor[0]";
  155. bool ExportValue = false; ,
  156. = float3(0, 0, 0));
  157. #endif // #if defined(USE_INDIRECT_CONSTANT)
  158. #endif // #if SUPPORT_RECOLORING
  159. //////////////////////////////////////////////////////////////////////////////
  160. // These are the indirect constant that need to be declare across all shaders
  161. //////////////////////////////////////////////////////////////////////////////
  162. #if defined(USE_INDIRECT_CONSTANT) && !defined(EA_PLATFORM_WINDOWS)
  163. // Indicate whether shadow is turn on for the pass
  164. REGISTER_BIND_BOOL( BREGISTER_HAS_SHADOW,
  165. bool, HasShadow,
  166. string UIWidget = "None";
  167. string SasBindAddress = "Sas.HasShadow"; ,
  168. = false);
  169. #endif
  170. #if defined(USE_INDIRECT_CONSTANT)
  171. // Shadowmap transformation matrix
  172. REGISTER_BIND( REGISTER_MAT_WORLD_TO_SHADOW,
  173. float4x4, ShadowMapWorldToShadow,
  174. string UIWidget = "None";
  175. string SasBindAddress = "Sas.Shadow[0].WorldToShadow"; ,
  176. NO_INITIALIZER);
  177. // Color Information
  178. REGISTER_BIND( REGISTER_OPACITY_OVERRIDE,
  179. float, OpacityOverride,
  180. string UIWidget = "None";
  181. string SasBindAddress = "WW3D.OpacityOverride"; ,
  182. = 1.0);
  183. REGISTER_BIND( REGISTER_TINT_COLOR,
  184. float3, TintColor,
  185. string UIWidget = "None";
  186. string SasBindAddress = "WW3D.TintColor"; ,
  187. = float3(1, 1, 1));
  188. // Camera related
  189. REGISTER_BIND( REGISTER_CAMERA_POSITION,
  190. float3, EyePosition,
  191. string UIWidget = "None";
  192. string SasBindAddress = "Sas.Camera.Position"; ,
  193. NO_INITIALIZER);
  194. REGISTER_BIND( REGISTER_VIEWPROJECTION_MATRIX_FIRST,
  195. float4x4, ViewProjection,
  196. string UIWidget = "None";
  197. string SasBindAddress = "Sas.Camera.WorldToProjection"; ,
  198. NO_INITIALIZER);
  199. #endif // #if define(USE_INDIRECT_CONSTANT)
  200. //////////////////////////////////////////////////////////////////////////////
  201. // These are the indirect constant that don't have to be defined, as every draw call will re-apply them anyway
  202. //////////////////////////////////////////////////////////////////////////////
  203. #if defined(USE_INDIRECT_CONSTANT) && !defined(NO_SKINNING_MATRICES)
  204. // Bone transformations
  205. REGISTER_BIND_ARRAY_VS(REGISTER_SKINNING_BONE_TRANSFORMS,
  206. float4, WorldBones, MaxSkinningBones * 2,
  207. string UIWidget = "None";
  208. string SasBindAddress = "Sas.Skeleton.MeshToJointToWorld[*]"; ,
  209. NO_INITIALIZER);
  210. #endif
  211. #endif // #define _GLOBALLIGHTING_FXH_