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.

286 lines
7.0 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. #if defined( _X360 )
  3. void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump,
  4. float3 coords, float2 bumpcoords,
  5. float3 vWeights,
  6. out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
  7. {
  8. vResultBase = 0;
  9. vResultBase2 = 0;
  10. vResultBump = 0;
  11. if ( !bBump )
  12. {
  13. vResultBump = float4(0, 0, 1, 1);
  14. }
  15. #if SEAMLESS
  16. vWeights = max( vWeights - 0.3, 0 );
  17. vWeights *= 1.0f / dot( vWeights, float3(1,1,1) );
  18. [branch]
  19. if (vWeights.x > 0)
  20. {
  21. vResultBase += vWeights.x * tex2D( base, coords.zy );
  22. if ( bBase2 )
  23. {
  24. vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
  25. }
  26. if ( bBump )
  27. {
  28. vResultBump += vWeights.x * tex2D( bump, coords.zy );
  29. }
  30. }
  31. [branch]
  32. if (vWeights.y > 0)
  33. {
  34. vResultBase += vWeights.y * tex2D( base, coords.xz );
  35. if ( bBase2 )
  36. {
  37. vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
  38. }
  39. if ( bBump )
  40. {
  41. vResultBump += vWeights.y * tex2D( bump, coords.xz );
  42. }
  43. }
  44. [branch]
  45. if (vWeights.z > 0)
  46. {
  47. vResultBase += vWeights.z * tex2D( base, coords.xy );
  48. if ( bBase2 )
  49. {
  50. vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
  51. }
  52. if ( bBump )
  53. {
  54. vResultBump += vWeights.z * tex2D( bump, coords.xy );
  55. }
  56. }
  57. #if ( SHADER_SRGB_READ == 1 )
  58. // Do this after the blending to save shader ops
  59. #if defined( CSTRIKE15 )
  60. // [mariod] - for CSTRIKE15 we are not using any PWL textures but gamma 2.2 reads of srgb textures
  61. vResultBase.rgb = GammaToLinear( vResultBase.rgb );
  62. vResultBase2.rgb = GammaToLinear( vResultBase2.rgb );
  63. #else
  64. vResultBase.rgb = X360GammaToLinear( vResultBase.rgb );
  65. vResultBase2.rgb = X360GammaToLinear( vResultBase2.rgb );
  66. #endif
  67. #endif
  68. #else // not seamless
  69. vResultBase = tex2Dsrgb( base, coords.xy );
  70. if ( bBase2 )
  71. {
  72. vResultBase2 = tex2Dsrgb( base2, coords.xy );
  73. }
  74. if ( bBump )
  75. {
  76. vResultBump = tex2D( bump, bumpcoords.xy );
  77. }
  78. #endif
  79. }
  80. #else // PC
  81. void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump,
  82. float3 coords, float3 coords2, float2 bumpcoords, HALF3 vWeights,
  83. out HALF4 vResultBase, out HALF4 vResultBase2, out HALF4 vResultBump )
  84. {
  85. vResultBase = 0;
  86. vResultBase2 = 0;
  87. vResultBump = 0;
  88. if ( !bBump )
  89. {
  90. vResultBump = HALF4(0, 0, 1, 1);
  91. }
  92. #if SEAMLESS
  93. vResultBase += vWeights.x * h4tex2D( base, coords.zy );
  94. if ( bBase2 )
  95. {
  96. vResultBase2 += vWeights.x * h4tex2D( base2, coords.zy );
  97. }
  98. if ( bBump )
  99. {
  100. vResultBump += vWeights.x * h4tex2D( bump, coords.zy );
  101. }
  102. vResultBase += vWeights.y * h4tex2D( base, coords.xz );
  103. if ( bBase2 )
  104. {
  105. vResultBase2 += vWeights.y * h4tex2D( base2, coords.xz );
  106. }
  107. if ( bBump )
  108. {
  109. vResultBump += vWeights.y * h4tex2D( bump, coords.xz );
  110. }
  111. vResultBase += vWeights.z * h4tex2D( base, coords.xy );
  112. if ( bBase2 )
  113. {
  114. vResultBase2 += vWeights.z * h4tex2D( base2, coords.xy );
  115. }
  116. if ( bBump )
  117. {
  118. vResultBump += vWeights.z * h4tex2D( bump, coords.xy );
  119. }
  120. #else // not seamless
  121. vResultBase = h4tex2D( base, coords.xy );
  122. if ( bBase2 )
  123. {
  124. vResultBase2 = h4tex2D( base2, coords2.xy );
  125. }
  126. if ( bBump )
  127. {
  128. vResultBump = h4tex2D( bump, bumpcoords.xy );
  129. }
  130. #endif
  131. }
  132. #endif
  133. HALF4 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
  134. {
  135. #if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
  136. {
  137. HALF4 sample = h4tex2D( LightmapSampler, vTexCoord );
  138. return sample;
  139. }
  140. #else
  141. {
  142. #if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
  143. {
  144. float4 sample = tex2D( LightmapSampler, vTexCoord );
  145. return HALF4( sample.rgb * sample.a, 1.0 );
  146. }
  147. #else
  148. {
  149. float4 Weights;
  150. float4 samples_0; //no arrays allowed in inline assembly
  151. float4 samples_1;
  152. float4 samples_2;
  153. float4 samples_3;
  154. asm {
  155. tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  156. tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  157. tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  158. tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
  159. getWeights2D Weights, vTexCoord.xy, LightmapSampler
  160. };
  161. Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
  162. float3 result;
  163. result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
  164. result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
  165. result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
  166. result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
  167. return float4( result, 1.0 );
  168. }
  169. #endif
  170. }
  171. #endif
  172. }
  173. #ifdef PIXELSHADER
  174. #define VS_OUTPUT PS_INPUT
  175. #endif
  176. struct VS_OUTPUT
  177. {
  178. #ifndef PIXELSHADER
  179. float4 projPos : POSITION;
  180. #if !defined( _X360 ) && !defined( SHADER_MODEL_VS_3_0 )
  181. float fog : FOG;
  182. #endif
  183. #endif
  184. #if SEAMLESS
  185. float3 SeamlessTexCoord : TEXCOORD0;
  186. #else
  187. float4 baseTexCoord_blendmodulateTexCoord : TEXCOORD0;
  188. #endif
  189. float4 detailTexCoord_EnvmapMaskTexCoord : TEXCOORD1;
  190. float4 lightmapTexCoord1And2 : TEXCOORD2_centroid;
  191. float4 lightmapTexCoord3_bumpTexCoord : TEXCOORD3_centroid;
  192. float4 worldPos_projPosZ : TEXCOORD4;
  193. float4 tangentSpaceTranspose0_vertexBlendX : TEXCOORD5;
  194. float4 tangentSpaceTranspose1_bumpTexCoord2u : TEXCOORD6;
  195. float4 tangentSpaceTranspose2_bumpTexCoord2v : TEXCOORD7;
  196. #if defined ( SHADER_MODEL_VS_3_0 ) || defined ( SHADER_MODEL_PS_3_0 )
  197. float4 baseTexCoord2_detailTexCoord2 : TEXCOORD8;
  198. #endif
  199. float4 vertexColor : COLOR0;
  200. // Extra iterators on 360, used in flashlight combo
  201. #if ( defined( _X360 ) || defined( _PS3 ) ) && FLASHLIGHT
  202. float4 flashlightSpacePos : TEXCOORD8;
  203. float4 vProjPos : TEXCOORD9;
  204. #endif
  205. #if defined( PIXELSHADER ) && defined( _X360 )
  206. float2 vScreenPos : VPOS;
  207. #endif
  208. };
  209. // base
  210. #if SEAMLESS
  211. // don't use BASETEXCOORD in the SEAMLESS case
  212. #else
  213. #define BASETEXCOORD baseTexCoord_blendmodulateTexCoord.xy
  214. #if defined ( SHADER_MODEL_VS_3_0 ) || defined ( SHADER_MODEL_PS_3_0 )
  215. #define BASETEXCOORD2 baseTexCoord2_detailTexCoord2.xy
  216. #else
  217. #define BASETEXCOORD2 baseTexCoord_blendmodulateTexCoord.xy
  218. #endif
  219. #endif
  220. // detail
  221. #define DETAILCOORD detailTexCoord_EnvmapMaskTexCoord.xy
  222. #if defined ( SHADER_MODEL_VS_3_0 ) || defined ( SHADER_MODEL_PS_3_0 )
  223. #define DETAILCOORD2 baseTexCoord2_detailTexCoord2.zw
  224. #endif
  225. // bump
  226. #define BUMPCOORD lightmapTexCoord3_bumpTexCoord.zw
  227. #define BUMPCOORD2U tangentSpaceTranspose1_bumpTexCoord2u.w
  228. #define BUMPCOORD2V tangentSpaceTranspose2_bumpTexCoord2v.w
  229. #define ENVMAPMASKCOORD detailTexCoord_EnvmapMaskTexCoord.zw
  230. #if !SEAMLESS
  231. #define BLENDMODULATECOORD baseTexCoord_blendmodulateTexCoord.zw
  232. #endif