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.

145 lines
4.7 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "VERTEXCOLOR" "0..1"
  3. // STATIC: "BUMPMAP" "0..2"
  4. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b]
  5. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps30]
  6. // DYNAMIC: "AMBIENT_LIGHT" "0..1"
  7. // Includes =======================================================================================
  8. #include "common_vertexlitgeneric_dx9.h"
  9. // Texture Samplers ===============================================================================
  10. sampler g_tColorSampler : register( s0 );
  11. sampler g_tBumpSampler : register( s1 );
  12. sampler g_tDummySampler : register( s2 );
  13. // Shaders Constants and Globals ==================================================================
  14. const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix
  15. const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix
  16. const float4 g_vCameraPosition : register( c2 );
  17. const float3 g_ambientCube[6] : register( c3 );
  18. //: register( c4 );
  19. //: register( c5 );
  20. //: register( c6 );
  21. //: register( c7 );
  22. //: register( c8 );
  23. PixelShaderLightInfo g_lightInfo[3] : register( c9 ); // 2 registers each - 6 registers total
  24. //: register( c10 );
  25. //: register( c11 );
  26. //: register( c12 );
  27. //: register( c13 );
  28. //: register( c14 );
  29. // new-UP
  30. static const float3 upBumpBasis[3] = {
  31. float3( 0.0f, 0.81649661064147949f, OO_SQRT_3 ),
  32. float3( -0.70710676908493042f, -0.40824833512306213f, OO_SQRT_3 ),
  33. float3( 0.7071068286895752f, -0.40824821591377258f, OO_SQRT_3 )
  34. };
  35. // Interpolated values ============================================================================
  36. struct PS_INPUT
  37. {
  38. float3 vUv0 : TEXCOORD0;
  39. float3 vWorldNormal : TEXCOORD1;
  40. float3 vWorldTangent : TEXCOORD2;
  41. float3 vWorldBinormal : TEXCOORD3;
  42. float3 vWorldPosition : TEXCOORD4;
  43. float4 vLightAtten : TEXCOORD5;
  44. float4 vSpecularPack1 : TEXCOORD6;
  45. float4 vSpecularPack2 : TEXCOORD7;
  46. #if ( VERTEXCOLOR )
  47. float4 vVertexColor : COLOR0;
  48. #endif
  49. };
  50. // Main ===========================================================================================
  51. float4 main( PS_INPUT i ) : COLOR
  52. {
  53. // Unpack lighting information
  54. float3 vSpecularN1 = i.vSpecularPack1.xyz;
  55. float3 vSpecularN2 = i.vSpecularPack2.xyz;
  56. float3 vSpecularN3;
  57. vSpecularN3.x = i.vSpecularPack1.w;
  58. vSpecularN3.y = i.vSpecularPack2.w;
  59. vSpecularN3.z = i.vUv0.z;
  60. // Color
  61. float4 cBaseColor = tex2D( g_tColorSampler, i.vUv0.xy );
  62. #if BUMPMAP == 0
  63. // non-bumped case
  64. float3 vTangentNormal = float3( 0, 0, 1 );
  65. #elif BUMPMAP == 1
  66. // Combine bump layers into tangent normal
  67. float4 vBumpTexel = tex2D( g_tBumpSampler, i.vUv0.xy );
  68. float3 vTangentNormal = ( vBumpTexel * 2.0f ) - 1.0f;
  69. #elif BUMPMAP == 2
  70. // ssbump case
  71. float4 vBumpTexel = tex2D( g_tBumpSampler, i.vUv0.xy );
  72. float3 vTangentNormal = vBumpTexel;
  73. #endif
  74. // Lighting
  75. float3 cDiffuse = float3( 0.0f, 0.0f, 0.0f );
  76. #if ( VERTEXCOLOR )
  77. {
  78. // Use interpolated vertex colors
  79. cDiffuse.rgb = i.vVertexColor.rgb;
  80. }
  81. #else
  82. {
  83. // Compute lighting
  84. // cDiffuse.rgb = PixelShaderDoLighting( i.vWorldPosition.xyz, normalize( vWorldNormal.xyz ),
  85. // float3( 0.0f, 0.0f, 0.0f ), false, AMBIENT_LIGHT, i.vLightAtten.xyzw,
  86. // g_ambientCube, g_tDummySampler, NUM_LIGHTS, g_lightInfo, false,
  87. // false, g_tDummySampler );
  88. #if BUMPMAP == 0
  89. cDiffuse.rgb = ( vSpecularN1 + vSpecularN2 + vSpecularN3 ) / 3.0f;
  90. #elif BUMPMAP == 1
  91. float3 dp;
  92. dp.x = saturate( dot( vTangentNormal, upBumpBasis[0] ) );
  93. dp.y = saturate( dot( vTangentNormal, upBumpBasis[1] ) );
  94. dp.z = saturate( dot( vTangentNormal, upBumpBasis[2] ) );
  95. dp *= dp;
  96. cDiffuse.rgb = dp.x * vSpecularN1 + dp.y * vSpecularN2 + dp.z * vSpecularN3;
  97. #elif BUMPMAP == 2
  98. float3 dp;
  99. dp.x = saturate( dot( vTangentNormal, upBumpBasis[0] ) );
  100. dp.y = saturate( dot( vTangentNormal, upBumpBasis[1] ) );
  101. dp.z = saturate( dot( vTangentNormal, upBumpBasis[2] ) );
  102. dp *= dp;
  103. cDiffuse.rgb = dp.x * vSpecularN1 + dp.y * vSpecularN2 + dp.z * vSpecularN3;
  104. // ssbump case needs to construct tangent normal from ssbump vector
  105. vTangentNormal.xyz = normalize( bumpBasis[0]*vTangentNormal.x +
  106. bumpBasis[1]*vTangentNormal.y + bumpBasis[2]*vTangentNormal.z);
  107. #endif
  108. }
  109. #endif
  110. #if 0
  111. // Transform normal into world space
  112. float3 vWorldNormal = Vec3TangentToWorld( vTangentNormal.xyz, i.vWorldNormal.xyz, i.vWorldTangent.xyz, i.vWorldBinormal.xyz );
  113. #endif
  114. //===============//
  115. // Combine terms //
  116. //===============//
  117. float4 result;
  118. result.rgb = cBaseColor.rgb;
  119. result.rgb *= cDiffuse.rgb;
  120. // Set alpha to...
  121. result.a = 0.0f;
  122. return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); //go back to final output when it'll fit.
  123. }