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.

128 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Lightmap only shader
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "lightmappedgeneric_decal.inc"
  10. #include "mathlib/bumpvects.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. BEGIN_VS_SHADER( LightmappedGeneric_Decal,
  14. "Help for LightmappedGeneric_Decal" )
  15. BEGIN_SHADER_PARAMS
  16. END_SHADER_PARAMS
  17. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  18. SHADER_INIT_PARAMS()
  19. {
  20. params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );
  21. // No texture means no self-illum or env mask in base alpha
  22. if ( !params[BASETEXTURE]->IsDefined() )
  23. {
  24. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  25. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  26. }
  27. SET_FLAGS( MATERIAL_VAR_DECAL );
  28. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  29. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  30. }
  31. SHADER_FALLBACK
  32. {
  33. return 0;
  34. }
  35. SHADER_INIT
  36. {
  37. LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
  38. if (params[BASETEXTURE]->IsDefined())
  39. {
  40. LoadTexture( BASETEXTURE );
  41. if ( !params[BASETEXTURE]->GetTextureValue()->IsTranslucent() )
  42. {
  43. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  44. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  45. }
  46. }
  47. // Don't alpha test if the alpha channel is used for other purposes
  48. if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  49. {
  50. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  51. }
  52. }
  53. void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow )
  54. {
  55. if( IsSnapshotting() )
  56. {
  57. // Be sure not to write to dest alpha
  58. pShaderShadow->EnableAlphaWrites( false );
  59. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  60. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  61. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  62. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  63. SetNormalBlendingShadowState( BASETEXTURE, true );
  64. int pTexCoords[3] = { 2, 2, 1 };
  65. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 );
  66. lightmappedgeneric_decal_Static_Index vshIndex;
  67. pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() );
  68. pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" );
  69. FogToFogColor();
  70. }
  71. else
  72. {
  73. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  74. // Load the z^2 components of the lightmap coordinate axes only
  75. // This is (N dot basis)^2
  76. Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z );
  77. vecZValues *= vecZValues;
  78. Vector4D basis[3];
  79. basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f );
  80. basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f );
  81. basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f );
  82. pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 );
  83. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED );
  84. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  85. SetModulationPixelShaderDynamicState( 3 );
  86. lightmappedgeneric_decal_Dynamic_Index vshIndex;
  87. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  88. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  89. }
  90. Draw();
  91. }
  92. SHADER_DRAW
  93. {
  94. if( UsingFlashlight( params ) )
  95. {
  96. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
  97. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 );
  98. }
  99. else
  100. {
  101. DrawDecal( params, pShaderAPI, pShaderShadow );
  102. }
  103. }
  104. END_SHADER