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.

64 lines
1.4 KiB

  1. // DYNAMIC: "ALPHACLIP" "0..1"
  2. // STATIC: "COLOR_DEPTH" "0..1"
  3. const float g_AlphaThreshold : register( c0 );
  4. struct PS_INPUT
  5. {
  6. #ifdef _PS3
  7. float unused; // empty structures not supported on Cg??
  8. #endif // _PS3
  9. #if ALPHACLIP
  10. float2 texCoord0 : TEXCOORD0;
  11. #endif
  12. #if 0
  13. #if !defined( _X360 ) && !defined( _PS3 ) && defined(SHADER_MODEL_PS_3_0)
  14. float2 vScreenPos : VPOS;
  15. #endif
  16. #endif
  17. #if COLOR_DEPTH
  18. float4 vWorldPos_projPosZ : TEXCOORD1;
  19. #endif
  20. };
  21. sampler BaseTextureSampler : register( s0 );
  22. float4 main( PS_INPUT i ) : COLOR
  23. {
  24. float4 color = float4( 1, 0, 0, 1 ); // opaque alpha....the color doesn't matter for this shader
  25. #if ALPHACLIP
  26. {
  27. color = tex2D( BaseTextureSampler, i.texCoord0 );
  28. float threshold = g_AlphaThreshold;
  29. #if 0
  30. // rg - shadow buffer dithering - experimental, but shows promise on large transparent shadow casters. May put this on a combo in CS:GO.
  31. #if !defined( _X360 ) && !defined( _PS3 ) && defined(SHADER_MODEL_PS_3_0)
  32. {
  33. float2 vScreenPos = frac( i.vScreenPos * .5f ) * 2.0f;
  34. threshold = ( ( vScreenPos.y * 3.0f + ( vScreenPos.y * 2.0f - 1.0f ) * vScreenPos.x * -2.0f ) - 2.0f ) * ( 1.0f / 4.0f );
  35. threshold = lerp( min( .4f, g_AlphaThreshold ), .9f, threshold );
  36. }
  37. #endif
  38. #endif
  39. clip( color.a - threshold );
  40. }
  41. #endif
  42. #if ( COLOR_DEPTH == 1 )
  43. return float4( i.vWorldPos_projPosZ.z / i.vWorldPos_projPosZ.w , 1.0, 1.0, 1.0 );
  44. #else
  45. return color;
  46. #endif
  47. }