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.

166 lines
5.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "BaseVSShader.h"
  8. #include "projected_dx9_helper.h"
  9. #include "..\shaderapidx9\locald3dtypes.h"
  10. #include "convar.h"
  11. #include "cpp_shader_constant_register_map.h"
  12. #include "projected_vs20.inc"
  13. #include "projected_vs30.inc"
  14. #include "projected_ps20.inc"
  15. #include "projected_ps20b.inc"
  16. #include "projected_ps30.inc"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. void InitParamsProjected_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Projected_DX9_Vars_t &info )
  20. {
  21. }
  22. void InitProjected_DX9( CBaseVSShader *pShader, IMaterialVar** params, Projected_DX9_Vars_t &info )
  23. {
  24. if ( params[ info.m_nBaseTexture ]->IsDefined() )
  25. {
  26. pShader->LoadTexture( info.m_nBaseTexture );
  27. }
  28. }
  29. void DrawProjected_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  30. IShaderShadow* pShaderShadow, Projected_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  31. {
  32. bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL );
  33. SHADOW_STATE
  34. {
  35. pShader->SetInitialShadowState( );
  36. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Always SRGB read on base map 1
  37. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  38. pShaderShadow->EnableSRGBWrite( true );
  39. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  40. int nTexCoordCount = 0;
  41. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, 0 );
  42. #ifndef _X360
  43. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  44. #endif
  45. {
  46. DECLARE_STATIC_VERTEX_SHADER( projected_vs20 );
  47. SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel );
  48. SET_STATIC_VERTEX_SHADER( projected_vs20 );
  49. // Bind ps_2_b shader so we can get Phong terms
  50. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  51. {
  52. DECLARE_STATIC_PIXEL_SHADER( projected_ps20b );
  53. SET_STATIC_PIXEL_SHADER( projected_ps20b );
  54. }
  55. else
  56. {
  57. DECLARE_STATIC_PIXEL_SHADER( projected_ps20 );
  58. SET_STATIC_PIXEL_SHADER( projected_ps20 );
  59. }
  60. }
  61. #ifndef _X360
  62. else
  63. {
  64. // The vertex shader uses the vertex id stream
  65. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  66. DECLARE_STATIC_VERTEX_SHADER( projected_vs30 );
  67. SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel );
  68. SET_STATIC_VERTEX_SHADER( projected_vs30 );
  69. // Bind ps_2_b shader so we can get Phong terms
  70. DECLARE_STATIC_PIXEL_SHADER( projected_ps30 );
  71. SET_STATIC_PIXEL_SHADER( projected_ps30 );
  72. }
  73. #endif
  74. pShader->DefaultFog();
  75. pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
  76. pShaderShadow->EnableBlending( true );
  77. // Lighting constants
  78. pShader->PI_BeginCommandBuffer();
  79. pShader->PI_SetPixelShaderAmbientLightCube( PSREG_AMBIENT_CUBE );
  80. pShader->PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY );
  81. pShader->PI_EndCommandBuffer();
  82. }
  83. DYNAMIC_STATE
  84. {
  85. pShaderAPI->SetDefaultState();
  86. // Bind textures
  87. pShader->BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nBaseTexture ); // Base Map 1
  88. LightState_t lightState = {0, false, false};
  89. pShaderAPI->GetDX9LightState( &lightState );
  90. #ifndef _X360
  91. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  92. #endif
  93. {
  94. DECLARE_DYNAMIC_VERTEX_SHADER( projected_vs20 );
  95. SET_DYNAMIC_VERTEX_SHADER( projected_vs20 );
  96. // Bind ps_2_b shader so we can get Phong, rim and a cloudier refraction
  97. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  98. {
  99. DECLARE_DYNAMIC_PIXEL_SHADER( projected_ps20b );
  100. SET_DYNAMIC_PIXEL_SHADER( projected_ps20b );
  101. }
  102. else
  103. {
  104. DECLARE_DYNAMIC_PIXEL_SHADER( projected_ps20 );
  105. SET_DYNAMIC_PIXEL_SHADER( projected_ps20 );
  106. }
  107. }
  108. #ifndef _X360
  109. else
  110. {
  111. DECLARE_DYNAMIC_VERTEX_SHADER( projected_vs30 );
  112. SET_DYNAMIC_VERTEX_SHADER( projected_vs30 );
  113. DECLARE_DYNAMIC_PIXEL_SHADER( projected_ps30 );
  114. SET_DYNAMIC_PIXEL_SHADER( projected_ps30 );
  115. }
  116. #endif
  117. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, info.m_nBaseTextureTransform );
  118. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  119. VMatrix worldToTexture;
  120. FlashlightState_t state = pShaderAPI->GetFlashlightState( worldToTexture );
  121. Vector4D vLightDir;
  122. vLightDir.AsVector3D() = state.m_vecLightOrigin;
  123. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vLightDir.Base() );
  124. Vector4D vProjectionSize( state.m_flProjectionSize, state.m_flProjectionRotation, 0.0f, 0.0f );
  125. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vProjectionSize.Base() );
  126. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_COLOR, &state.m_Color[ 0 ], 1 );
  127. // Set c0 and c1 to contain first two rows of ViewProj matrix
  128. VMatrix matView, matProj, matViewProj;
  129. pShaderAPI->GetMatrix( MATERIAL_VIEW, matView.m[0] );
  130. pShaderAPI->GetMatrix( MATERIAL_PROJECTION, matProj.m[0] );
  131. matViewProj = matView * matProj;
  132. pShaderAPI->SetPixelShaderConstant( 0, matViewProj.m[0], 2 );
  133. }
  134. pShader->Draw();
  135. }