Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #if defined( _X360 )
  3. void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
  4. out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
  5. {
  6. vResultBase = 0;
  7. vResultBase2 = 0;
  8. vResultBump = 0;
  9. if ( !bBump )
  10. {
  11. vResultBump = float4(0, 0, 1, 1);
  12. }
  13. #if SEAMLESS
  14. vWeights = max( vWeights - 0.3, 0 );
  15. vWeights *= 1.0f / dot( vWeights, float3(1,1,1) );
  16. [branch]
  17. if (vWeights.x > 0)
  18. {
  19. vResultBase += vWeights.x * tex2D( base, coords.zy );
  20. if ( bBase2 )
  21. {
  22. vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
  23. }
  24. if ( bBump )
  25. {
  26. vResultBump += vWeights.x * tex2D( bump, coords.zy );
  27. }
  28. }
  29. [branch]
  30. if (vWeights.y > 0)
  31. {
  32. vResultBase += vWeights.y * tex2D( base, coords.xz );
  33. if ( bBase2 )
  34. {
  35. vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
  36. }
  37. if ( bBump )
  38. {
  39. vResultBump += vWeights.y * tex2D( bump, coords.xz );
  40. }
  41. }
  42. [branch]
  43. if (vWeights.z > 0)
  44. {
  45. vResultBase += vWeights.z * tex2D( base, coords.xy );
  46. if ( bBase2 )
  47. {
  48. vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
  49. }
  50. if ( bBump )
  51. {
  52. vResultBump += vWeights.z * tex2D( bump, coords.xy );
  53. }
  54. }
  55. #else // not seamless
  56. vResultBase = tex2D( base, coords.xy );
  57. if ( bBase2 )
  58. {
  59. vResultBase2 = tex2D( base2, coords.xy );
  60. }
  61. if ( bBump )
  62. {
  63. vResultBump = tex2D( bump, coords.xy );
  64. }
  65. #endif
  66. }
  67. #else // PC
  68. void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
  69. out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
  70. {
  71. vResultBase = 0;
  72. vResultBase2 = 0;
  73. vResultBump = 0;
  74. if ( !bBump )
  75. {
  76. vResultBump = float4(0, 0, 1, 1);
  77. }
  78. #if SEAMLESS
  79. vResultBase += vWeights.x * tex2D( base, coords.zy );
  80. if ( bBase2 )
  81. {
  82. vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
  83. }
  84. if ( bBump )
  85. {
  86. vResultBump += vWeights.x * tex2D( bump, coords.zy );
  87. }
  88. vResultBase += vWeights.y * tex2D( base, coords.xz );
  89. if ( bBase2 )
  90. {
  91. vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
  92. }
  93. if ( bBump )
  94. {
  95. vResultBump += vWeights.y * tex2D( bump, coords.xz );
  96. }
  97. vResultBase += vWeights.z * tex2D( base, coords.xy );
  98. if ( bBase2 )
  99. {
  100. vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
  101. }
  102. if ( bBump )
  103. {
  104. vResultBump += vWeights.z * tex2D( bump, coords.xy );
  105. }
  106. #else // not seamless
  107. vResultBase = tex2D( base, coords.xy );
  108. if ( bBase2 )
  109. {
  110. vResultBase2 = tex2D( base2, coords.xy );
  111. }
  112. if ( bBump )
  113. {
  114. vResultBump = tex2D( bump, coords.xy );
  115. }
  116. #endif
  117. }
  118. #endif
  119. float3 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
  120. {
  121. # if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
  122. {
  123. float3 sample = tex2D( LightmapSampler, vTexCoord );
  124. return sample;
  125. }
  126. # else
  127. {
  128. # if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
  129. {
  130. float4 sample = tex2D( LightmapSampler, vTexCoord );
  131. return sample.rgb * sample.a;
  132. }
  133. # else
  134. {
  135. float4 Weights;
  136. float4 samples_0; //no arrays allowed in inline assembly
  137. float4 samples_1;
  138. float4 samples_2;
  139. float4 samples_3;
  140. asm {
  141. tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  142. tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  143. tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  144. tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  145. getWeights2D Weights, vTexCoord.xy, LightmapSampler
  146. };
  147. Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
  148. float3 result;
  149. result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
  150. result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
  151. result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
  152. result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
  153. return result;
  154. }
  155. # endif
  156. }
  157. # endif
  158. }