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.

72 lines
2.5 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "DIFFUSELIGHTING" "0..1"
  3. // STATIC: "HALFLAMBERT" "0..1"
  4. // DYNAMIC: "AMBIENT_LIGHT" "0..1"
  5. // DYNAMIC: "NUM_LIGHTS" "0..2" [ps20]
  6. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b]
  7. #define HDRTYPE HDR_TYPE_NONE
  8. #include "common_vertexlitgeneric_dx9.h"
  9. const float4 g_OverbrightFactor : register( c4 );
  10. const float3 cAmbientCube[6] : register( c6 );
  11. PixelShaderLightInfo cLightInfo[3] : register(c13);
  12. sampler BumpmapSampler : register( s0 );
  13. sampler NormalizeSampler : register( s1 );
  14. #if defined( _PS3 )
  15. // Causes the Cg compiler to automatically produce _bx2 modifier on the texture load instead of producing a MAD to range expand the vector, saving one instruction.
  16. #pragma texsign BumpmapSampler
  17. #pragma texformat BumpmapSampler RGBA8
  18. #endif
  19. struct PS_INPUT
  20. {
  21. float2 baseTexCoord : TEXCOORD0;
  22. // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords.
  23. float2 detailOrBumpTexCoord : TEXCOORD1;
  24. // bump mapping and a separate envmap mask texture are mutually exclusive.
  25. float2 envmapMaskTexCoord : TEXCOORD2;
  26. float3 worldVertToEyeVector : TEXCOORD3;
  27. float3x3 tangentSpaceTranspose : TEXCOORD4;
  28. float4 worldPos_projPosZ : TEXCOORD5;
  29. float2 lightAtten01 : TEXCOORD6;
  30. float2 lightAtten23 : TEXCOORD7;
  31. };
  32. float4 main( PS_INPUT i ) : COLOR
  33. {
  34. bool bDiffuseLighting = DIFFUSELIGHTING ? true : false;
  35. bool bHalfLambert = HALFLAMBERT ? true : false;
  36. bool bAmbientLight = AMBIENT_LIGHT ? true : false;
  37. int nNumLights = NUM_LIGHTS;
  38. float4 vLightAtten = float4( i.lightAtten01, i.lightAtten23 );
  39. float3 tangentSpaceNormal = float3( 0.0f, 0.0f, 1.0f );
  40. float4 normalTexel = 1.0f;
  41. float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  42. normalTexel = tex2D( BumpmapSampler, i.detailOrBumpTexCoord );
  43. tangentSpaceNormal = 2.0f * normalTexel - 1.0f;
  44. float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f );
  45. if( bDiffuseLighting )
  46. {
  47. float3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal );
  48. float3 staticLightingColor = float3( 0.0f, 0.0f, 0.0f );
  49. diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal,
  50. float3( 0.0f, 0.0f, 0.0f ), false, bAmbientLight,
  51. vLightAtten, cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert,
  52. false, NormalizeSampler );
  53. // multiply by .5 since we want a 50% (in gamma space) reflective surface)
  54. diffuseLighting *= pow( 0.5f, 2.2f );
  55. }
  56. return FinalOutput( float4( diffuseLighting, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  57. }