ConnectionLine.fx 6.5 KB

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