ConnectionLine.fx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //-----------------------------------------------------------------------------
  2. // ©2006 Electronic Arts Inc
  3. //-----------------------------------------------------------------------------
  4. #include "Common.fxh"
  5. //----------------------------------------------------------------------------
  6. // Transforms
  7. //----------------------------------------------------------------------------
  8. float4x4 View : View;
  9. #if defined(_WW3D_)
  10. #if !defined(USE_INDIRECT_CONSTANT)
  11. float4x4 ViewProjection
  12. <
  13. string UIWidget = "None";
  14. string SasBindAddress = "Sas.Camera.WorldToProjection";
  15. >;
  16. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  17. float4x4 GetViewProjection()
  18. {
  19. return ViewProjection;
  20. }
  21. #else // #if defined(_WW3D_)
  22. float4x4 Projection : Projection;
  23. float4x4 GetViewProjection()
  24. {
  25. return mul(View, Projection);
  26. }
  27. #endif // #if defined(_WW3D_)
  28. float Time : Time;
  29. //----------------------------------------------------------------------------
  30. // Connection Parameters
  31. //----------------------------------------------------------------------------
  32. float4 HouseColor
  33. <
  34. string UIWidget = "None";
  35. string SasBindAddress = "ConnectionLine.HouseColor";
  36. int WW3DDynamicSet = DS_CUSTOM_FIRST;
  37. > = float4( 1, 1, 1, 1 );
  38. float LineLength
  39. <
  40. string UIWidget = "None";
  41. string SasBindAddress = "ConnectionLine.LineLength";
  42. int WW3DDynamicSet = DS_CUSTOM_FIRST;
  43. > = 2.5;
  44. static float LineWidth
  45. <
  46. string UIName = "Line Width";
  47. string UIWidget = "Slider";
  48. float UIMin = 0;
  49. float UIMax = 100;
  50. > = 2.5;
  51. static float UVWorldSize
  52. <
  53. string UIName = "UV World Size";
  54. string UIWidget = "Slider";
  55. float UIMin = 0;
  56. float UIMax = 100;
  57. > = 15.0;
  58. static const float TextureScrollSpeed
  59. <
  60. string UIName = "Texture Scroll Speed";
  61. string UIWidget = "Slider";
  62. float UIMin = 0;
  63. float UIMax = 100;
  64. > = 4;
  65. //----------------------------------------------------------------------------
  66. // LineTexture
  67. //----------------------------------------------------------------------------
  68. SAMPLER_2D_BEGIN( LineTexture,
  69. string UIWidget = "None";
  70. )
  71. MinFilter = Linear;
  72. MagFilter = Linear;
  73. MipFilter = Linear;
  74. AddressU = Wrap;
  75. AddressV = Wrap;
  76. SAMPLER_2D_END
  77. //----------------------------------------------------------------------------
  78. // Shroud
  79. //----------------------------------------------------------------------------
  80. ShroudSetup Shroud
  81. <
  82. string UIWidget = "None";
  83. string SasBindAddress = "Terrain.Shroud";
  84. > = DEFAULT_SHROUD;
  85. SAMPLER_2D_BEGIN( ShroudTexture,
  86. string UIWidget = "None";
  87. string SasBindAddress = "Terrain.Shroud.Texture";
  88. string ResourceName = "ShaderPreviewShroud.dds";
  89. )
  90. MinFilter = Linear;
  91. MagFilter = Linear;
  92. MipFilter = Linear;
  93. AddressU = Clamp;
  94. AddressV = Clamp;
  95. SAMPLER_2D_END
  96. //-----------------------------------------------------------------------------
  97. // Vertex Shader structure
  98. //-----------------------------------------------------------------------------
  99. struct VSInput
  100. {
  101. float3 Position : POSITION;
  102. float3 Normal : NORMAL;
  103. float3 Binormal : BINORMAL;
  104. float3 Tangent : TANGENT;
  105. float2 NormalizedTexCoord : TEXCOORD0;
  106. };
  107. struct VSOutput
  108. {
  109. float4 Position : POSITION;
  110. float2 DiffuseTexCoord : TEXCOORD0;
  111. float2 DiffuseTexCoord1 : TEXCOORD1;
  112. float2 ShroudTexCoord : TEXCOORD2;
  113. };
  114. //-----------------------------------------------------------------------------
  115. // Billboard Edge
  116. //-----------------------------------------------------------------------------
  117. #if 1
  118. float3 BillboardEdge( float3 world_pos_center, float normalized_offset, float3 world_tangent )
  119. {
  120. LineWidth = 10;
  121. float3 view_out = float3( View[0][2], View[1][2], View[2][2] );
  122. float3 world_offset = cross( world_tangent, view_out );
  123. world_offset *= ( normalized_offset - 0.5 ) * LineWidth;
  124. return world_pos_center + world_offset;
  125. }
  126. #else
  127. float3 BillboardEdge( float3 world_pos_center, float normalized_offset, float3 world_tangent )
  128. {
  129. float3 view_up = float3( View[0][1], View[1][1], View[2][1] );
  130. float3 view_out = float3( View[0][2], View[1][2], View[2][2] );
  131. float3 world_offset_up = cross( world_tangent, view_out );
  132. float3 world_offset_right = cross( world_tangent, view_up );
  133. // Blend between "up" and "right" from tangent in view space
  134. // based on the angle between the camera and the edge's tangent
  135. float parrallelism = abs( dot( world_tangent, view_out ) );
  136. float3 world_offset = normalize( lerp( world_offset_up, world_offset_right, parrallelism ) );
  137. world_offset *= ( normalized_offset - 0.5 ) * LineWidth;
  138. return world_pos_center + world_offset;
  139. }
  140. #endif
  141. //-----------------------------------------------------------------------------
  142. // Vertex Shader
  143. //-----------------------------------------------------------------------------
  144. VSOutput VS( VSInput Input )
  145. {
  146. UVWorldSize =150;
  147. VSOutput Output;
  148. // Get the final vertex position
  149. float3 world_pos = BillboardEdge( Input.Position, Input.NormalizedTexCoord.x, Input.Tangent );
  150. Output.Position = mul( float4( world_pos, 1 ), GetViewProjection() );
  151. // Calculate UVs
  152. Output.DiffuseTexCoord = Input.NormalizedTexCoord;
  153. Output.DiffuseTexCoord.y *= LineLength / UVWorldSize;
  154. Output.DiffuseTexCoord.y -= Time * TextureScrollSpeed;
  155. // Calculate UVs
  156. Output.DiffuseTexCoord1 = Input.NormalizedTexCoord;
  157. Output.DiffuseTexCoord1.y *= LineLength / UVWorldSize;
  158. Output.DiffuseTexCoord1.y -= (Time * 0.2) * TextureScrollSpeed;
  159. // Calculate Shroud UVs
  160. Output.ShroudTexCoord = CalculateShroudTexCoord( Shroud, world_pos );
  161. return Output;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Pixel Shader
  165. //-----------------------------------------------------------------------------
  166. float4 PS( VSOutput Input ) : Color
  167. {
  168. float4 color = tex2D( SAMPLER(LineTexture), Input.DiffuseTexCoord );
  169. color += tex2D( SAMPLER(LineTexture), Input.DiffuseTexCoord1);
  170. color *= HouseColor;
  171. // Apply shroud
  172. float shroud = tex2D( SAMPLER(ShroudTexture), Input.ShroudTexCoord ).x;
  173. color.xyz *= shroud;
  174. return color;
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Techniques
  178. //-----------------------------------------------------------------------------
  179. technique Default
  180. {
  181. pass pass0
  182. {
  183. VertexShader = compile VS_2_0 VS();
  184. PixelShader = compile PS_2_0 PS();
  185. ZEnable = true;
  186. ZWriteEnable = false;
  187. ZFunc = ZFUNC_INFRONT;
  188. AlphaBlendEnable = true;
  189. CullMode = None;
  190. SrcBlend = ONE;
  191. DestBlend = ONE;
  192. }
  193. }