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.

83 lines
2.4 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. HALF3 BlendDiffuseLightmapWithCSM( HALF3 diffuseLighting, HALF a, float3 worldPos,
  3. out float flShadow, out float flSunAmount )
  4. {
  5. HALF3 blendedDiffuseLighting = diffuseLighting;
  6. flShadow = 1.0f;
  7. flSunAmount = 0.0f;
  8. #if ( ( CSM_BLENDING == 1 ) && ( CASCADED_SHADOW_MAPPING ) && ( CASCADE_SIZE > 0 ) )
  9. {
  10. #if !defined( _X360 ) && !defined( _PS3 ) && !defined( SHADER_MODEL_PS_2_B )
  11. if ( g_bCSMEnabled )
  12. {
  13. #endif
  14. flSunAmount = a;
  15. // Can't enable dynamic jumps around the Fetch4 shader, because it can't use tex2dlod()
  16. #if ( CSM_MODE != CSM_MODE_ATI_FETCH4 ) && !defined( SHADER_MODEL_PS_2_B )
  17. [branch]
  18. #endif
  19. if ( flSunAmount > 0.0f )
  20. {
  21. flShadow = CSMComputeShadowing( worldPos );
  22. float3 direct = a * g_vCSMLightColor.rgb;
  23. float3 indirect = diffuseLighting.rgb - direct;
  24. // Apply csm shadows
  25. blendedDiffuseLighting.rgb = ( direct * flShadow ) + indirect;
  26. }
  27. #if !defined( _X360 ) && !defined( _PS3 ) && !defined( SHADER_MODEL_PS_2_B )
  28. }
  29. #endif
  30. }
  31. #endif
  32. return blendedDiffuseLighting;
  33. }
  34. HALF3 BlendBumpDiffuseLightmapWithCSM( HALF3 diffuseLighting, HALF a1, HALF a2, HALF a3, HALF3 dp, float3 worldPos,
  35. out float flShadow, out float flSunAmount )
  36. {
  37. HALF3 blendedDiffuseLighting = diffuseLighting;
  38. flShadow = 1.0f;
  39. flSunAmount = 0.0f;
  40. // modify/correct diffuse lighting using CSM
  41. #if ( ( CSM_BLENDING == 1 ) && ( CASCADED_SHADOW_MAPPING ) && ( CASCADE_SIZE > 0 ) )
  42. {
  43. #if !defined( _X360 ) && !defined( _PS3 ) && !defined( SHADER_MODEL_PS_2_B )
  44. if ( g_bCSMEnabled )
  45. {
  46. #endif
  47. flSunAmount = ( a1 + a2 + a3 );
  48. // Can't enable dynamic jumps around the Fetch4 shader, because it can't use tex2dlod()
  49. #if ( CSM_MODE != CSM_MODE_ATI_FETCH4 ) && !defined( SHADER_MODEL_PS_2_B )
  50. [branch]
  51. #endif
  52. if ( flSunAmount > 0.0f )
  53. {
  54. flShadow = CSMComputeShadowing( worldPos );
  55. // reconstruct direct lighting from CSM light in the bump basis
  56. float3 directCSM = g_vCSMLightColor.rgb * ( dp.x * a1 + dp.y * a2 + dp.z * a3 );
  57. // blend CSM shadows with static lighting by removing the direct CSM light where there is CSM shadow
  58. blendedDiffuseLighting -= directCSM * ( 1.0f - flShadow );
  59. }
  60. #if !defined( _X360 ) && !defined( _PS3 ) && !defined( SHADER_MODEL_PS_2_B )
  61. }
  62. #endif
  63. }
  64. #endif
  65. return blendedDiffuseLighting;
  66. }