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.

95 lines
3.3 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "SELF_ILLUM_FRESNEL" "0..1"
  3. // STATIC: "PRE_PASS" "0..1"
  4. // STATIC: "NORMALMAP" "0..1"
  5. // STATIC: "MOVING_PULSES" "0..1"
  6. #include "common_ps_fxc.h"
  7. #include "common_vertexlitgeneric_dx9.h"
  8. #include "shader_constant_register_map.h"
  9. // SAMPLERS
  10. sampler g_tBase : register( s0 );
  11. sampler g_tNormal : register( s1 );
  12. // SHADER CONSTANTS
  13. const float4 g_cArmColor : register( c19 );
  14. const float3 g_vLightCube[6] : register( PSREG_AMBIENT_CUBE );
  15. const float4 g_vSelfIllumFresnelParams : register( c26 );
  16. #define g_flSelfIllumScale g_vSelfIllumFresnelParams.x
  17. #define g_flSelfIllumBias g_vSelfIllumFresnelParams.y
  18. #define g_flSelfIllumExp g_vSelfIllumFresnelParams.z
  19. #define g_flSelfIllumBrightness g_vSelfIllumFresnelParams.w
  20. const float4 g_cSelfIllumTint : register( c27 );
  21. const float3 g_vEyePos : register( PSREG_EYEPOS_SPEC_EXPONENT );
  22. // INPUT STRUCT
  23. struct PS_INPUT
  24. {
  25. float4 vWorldNormal : TEXCOORD0; // w is proj. z coord (for depth stuff)
  26. float3 vWorldTangent : TEXCOORD1;
  27. float3 vWorldBinormal : TEXCOORD2;
  28. float3 vWorldPos : TEXCOORD3;
  29. float2 vUV : TEXCOORD4;
  30. float4 vColor : TEXCOORD5;
  31. };
  32. float4 main( PS_INPUT i ) : COLOR
  33. {
  34. float4 cBase = tex2D( g_tBase, i.vUV );
  35. float4 cOut;
  36. #if PRE_PASS == 1
  37. return cBase; // First pass: output texture to alpha so that we can fill depth using alpha-to-coverage or alpha test
  38. #endif
  39. // The 2nd pass does full shading and can output depth using the destalpha channel.
  40. #if NORMALMAP == 1
  41. float3 vNormalTS = tex2D( g_tNormal, i.vUV );
  42. //return vNormalTS.rgbb;
  43. #else
  44. // make up some tubey looking normal
  45. float3 vNormalTS = float3( 0, (2*i.vUV.y-1) * 3.0, 1.0 );
  46. #endif
  47. float3x3 mTan;
  48. mTan[0] = i.vWorldTangent;
  49. mTan[1] = i.vWorldBinormal;
  50. mTan[2] = i.vWorldNormal;
  51. float3 vNormal = normalize( mul( vNormalTS, mTan ) );
  52. float3 vView = normalize( g_vEyePos.xyz - i.vWorldPos.xyz );
  53. // diffuse lighting using baked light cube
  54. float3 cDiffuse = PixelShaderAmbientLight( vNormal, g_vLightCube );
  55. // selfillum
  56. #if SELF_ILLUM_FRESNEL == 1
  57. float flSelfIllumFresnel = ( pow( saturate( dot( vView.xyz, vNormal.xyz ) ), g_flSelfIllumExp ) * g_flSelfIllumScale ) + g_flSelfIllumBias;
  58. float3 cSelfIllumComponent = g_cSelfIllumTint * g_flSelfIllumBrightness;
  59. cDiffuse.rgb = lerp( cDiffuse.rgb, cSelfIllumComponent.rgb, saturate( flSelfIllumFresnel ) );
  60. #endif
  61. // the u coord -- which is 0 at the root and 1 at the tip -- works well as an occlusion factor
  62. cOut = float4( i.vUV.x * cDiffuse * g_cArmColor.rgb * cBase.rgb, 1 );
  63. // pulse
  64. float flPulseWidth = 0.4;
  65. #if MOVING_PULSES == 1
  66. float flPulse = smoothstep( i.vColor.a, i.vColor.a - flPulseWidth, i.vUV.x );// * ( 1 - smoothstep( i.vColor.a + flPulseWidth, i.vColor.a, i.vUV.x ) );
  67. flPulse *= 1 - smoothstep( i.vColor.a, i.vColor.a - flPulseWidth, i.vUV.x );// * ( 1 - smoothstep( i.vColor.a + flPulseWidth, i.vColor.a, i.vUV.x ) );
  68. #else
  69. float flPulse = max( 0.0, i.vColor.a );
  70. #endif
  71. cOut.rgb = lerp( 1.0 * cOut.rgb, 3 * i.vColor.rgb, flPulse );
  72. //cOut.rgb *= float3( 1.0, 0.1, 0.1 );
  73. //cOut = float4( fmod( i.vUV, 1.0 ), 0, 0 );
  74. //float4 cOut = 0.5 * i.vWorldTangent.xyzz + 0.5;//float4( i.vUV, 0, 0 );
  75. return FinalOutput( cOut, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, true, i.vWorldNormal.w );
  76. }