Counter Strike : Global Offensive Source Code
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.

175 lines
5.6 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. void GetBaseTextureAndNormal( sampler base, sampler base2, sampler base3, sampler base4, sampler bump, bool bBump,
  3. float3 coords, float2 bumpcoords, float4 uvScales23, float2 uvScales4, HALF3 vWeights,
  4. out HALF4 vResultBase, out HALF4 vResultBase2, out HALF4 vResultBase3, out HALF4 vResultBase4, out HALF4 vResultBump )
  5. {
  6. vResultBase = 0;
  7. vResultBase2 = 0;
  8. vResultBase3 = 0;
  9. vResultBase4 = 0;
  10. vResultBump = 0;
  11. if ( !bBump )
  12. {
  13. vResultBump = HALF4(0, 0, 1, 1);
  14. }
  15. #if SEAMLESS
  16. vResultBase += vWeights.x * h4tex2D( base, coords.zy );
  17. vResultBase2 += vWeights.x * h4tex2D( base2, coords.zy * uvScales23.xy );
  18. vResultBase3 += vWeights.x * h4tex2D( base3, coords.zy * uvScales23.zw );
  19. vResultBase4 += vWeights.x * h4tex2D( base4, coords.zy * uvScales4.xy );
  20. if ( bBump )
  21. {
  22. vResultBump += vWeights.x * h4tex2D( bump, coords.zy );
  23. }
  24. vResultBase += vWeights.y * h4tex2D( base, coords.xz );
  25. vResultBase2 += vWeights.y * h4tex2D( base2, coords.xz * uvScales23.xy );
  26. vResultBase3 += vWeights.y * h4tex2D( base3, coords.xz * uvScales23.zw );
  27. vResultBase4 += vWeights.y * h4tex2D( base4, coords.xz * uvScales4.xy );
  28. if ( bBump )
  29. {
  30. vResultBump += vWeights.y * h4tex2D( bump, coords.xz );
  31. }
  32. vResultBase += vWeights.z * h4tex2D( base, coords.xy );
  33. vResultBase2 += vWeights.z * h4tex2D( base2, coords.xy * uvScales23.xy );
  34. vResultBase3 += vWeights.z * h4tex2D( base3, coords.xy * uvScales23.zw );
  35. vResultBase4 += vWeights.z * h4tex2D( base4, coords.xy * uvScales4.xy );
  36. if ( bBump )
  37. {
  38. vResultBump += vWeights.z * h4tex2D( bump, coords.xy );
  39. }
  40. #else // not seamless
  41. vResultBase = h4tex2D( base, coords.xy );
  42. vResultBase2 = h4tex2D( base2, coords.xy * uvScales23.xy );
  43. vResultBase3 = h4tex2D( base3, coords.xy * uvScales23.zw );
  44. vResultBase4 = h4tex2D( base4, coords.xy * uvScales4.xy );
  45. if ( bBump )
  46. {
  47. vResultBump = h4tex2D( bump, bumpcoords.xy );
  48. }
  49. #endif
  50. }
  51. HALF4 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
  52. {
  53. #if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
  54. {
  55. HALF4 sample = h4tex2D( LightmapSampler, vTexCoord );
  56. return sample;
  57. }
  58. #else
  59. {
  60. #if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
  61. {
  62. float4 sample = tex2D( LightmapSampler, vTexCoord );
  63. return HALF4( sample.rgb * sample.a, 1.0 );
  64. }
  65. #else
  66. {
  67. float4 Weights;
  68. float4 samples_0; //no arrays allowed in inline assembly
  69. float4 samples_1;
  70. float4 samples_2;
  71. float4 samples_3;
  72. asm {
  73. tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  74. tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  75. tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  76. tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  77. getWeights2D Weights, vTexCoord.xy, LightmapSampler
  78. };
  79. Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
  80. float3 result;
  81. result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
  82. result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
  83. result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
  84. result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
  85. return float4( result, 1.0 );
  86. }
  87. #endif
  88. }
  89. #endif
  90. }
  91. #ifdef PIXELSHADER
  92. #define VS_OUTPUT PS_INPUT
  93. #endif
  94. struct VS_OUTPUT
  95. {
  96. #ifndef PIXELSHADER
  97. float4 projPos : POSITION;
  98. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  99. float fog : FOG;
  100. #endif
  101. #endif
  102. #if SEAMLESS
  103. #if HARDWAREFOGBLEND || DOPIXELFOG
  104. float3 SeamlessTexCoord_fogFactorW : TEXCOORD0; // zy xz
  105. #else
  106. float4 SeamlessTexCoord_fogFactorW : TEXCOORD0; // zy xz
  107. #endif
  108. #else
  109. #if HARDWAREFOGBLEND || DOPIXELFOG
  110. float2 baseTexCoord_fogFactorZ : TEXCOORD0;
  111. #else
  112. float3 baseTexCoord_fogFactorZ : TEXCOORD0;
  113. #endif
  114. #endif
  115. // Detail textures and bumpmaps are mutually exclusive so that we have enough texcoords.
  116. float4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; // envmap mask
  117. float4 lightmapTexCoord1And2 : TEXCOORD2_centroid;
  118. float4 lightmapTexCoord3 : TEXCOORD3_centroid;
  119. float4 worldPos_projPosZ : TEXCOORD4;
  120. float3x3 tangentSpaceTranspose : TEXCOORD5;
  121. // tangentSpaceTranspose : TEXCOORD6
  122. // tangentSpaceTranspose : TEXCOORD7
  123. float4 vertexColor : COLOR0;
  124. float4 vertexBlend : COLOR1;
  125. // Extra iterators on 360, used in flashlight combo
  126. #if ( defined( _X360 ) || defined( _PS3 ) ) && FLASHLIGHT
  127. float4 flashlightSpacePos : TEXCOORD8;
  128. float4 vProjPos : TEXCOORD9;
  129. #endif
  130. #if defined( PIXELSHADER ) && defined( _X360 )
  131. float2 vScreenPos : VPOS;
  132. #endif
  133. };
  134. #define DETAILCOORDS detailOrBumpAndEnvmapMaskTexCoord.xy
  135. #define DETAILORBUMPCOORDS DETAILCOORDS
  136. #define ENVMAPMASKCOORDS detailOrBumpAndEnvmapMaskTexCoord.wz
  137. #if DETAILTEXTURE && BUMPMAP && !SELFILLUM
  138. #define BUMPCOORDS lightmapTexCoord3.wz
  139. #elif DETAILTEXTURE
  140. #define BUMPCOORDS baseTexCoord_fogFactorZ.xy
  141. #else
  142. // This is the SEAMLESS case too since we skip SEAMLESS && DETAILTEXTURE
  143. #define BUMPCOORDS detailOrBumpAndEnvmapMaskTexCoord.xy
  144. #endif
  145. #if SEAMLESS
  146. // don't use BASETEXCOORD in the SEAMLESS case
  147. #else
  148. #define BASETEXCOORD baseTexCoord_fogFactorZ.xy
  149. #endif