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.

163 lines
5.1 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. #include "unlitgeneric_vs20.inc"
  11. #include "unlitgeneric_ps20.inc"
  12. #include "unlitgeneric_ps20b.inc"
  13. #if !defined( _X360 ) && !defined( _PS3 )
  14. #include "unlitgeneric_ps30.inc"
  15. #include "unlitgeneric_vs30.inc"
  16. #endif
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. static ConVar mat_displacementmap( "mat_displacementmap", "1", FCVAR_CHEAT );
  20. BEGIN_VS_SHADER_FLAGS( DebugNormalMap, "Help for DebugNormalMap", SHADER_NOT_EDITABLE )
  21. BEGIN_SHADER_PARAMS
  22. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldDiffuseBumpMap_bump", "bump map" )
  23. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  24. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  25. END_SHADER_PARAMS
  26. SHADER_INIT_PARAMS()
  27. {
  28. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  29. }
  30. SHADER_INIT
  31. {
  32. }
  33. SHADER_FALLBACK
  34. {
  35. return 0;
  36. }
  37. SHADER_DRAW
  38. {
  39. SHADOW_STATE
  40. {
  41. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  42. // Set stream format (note that this shader supports compression)
  43. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  44. int nTexCoordCount = 1;
  45. int userDataSize = 0;
  46. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  47. #if !defined( _X360 ) && !defined( _PS3 )
  48. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  49. #endif
  50. {
  51. DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs20 );
  52. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, 0 );
  53. SET_STATIC_VERTEX_SHADER( unlitgeneric_vs20 );
  54. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  55. {
  56. DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20b );
  57. SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20b );
  58. }
  59. else
  60. {
  61. DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20 );
  62. SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20 );
  63. }
  64. }
  65. #if !defined( _X360 ) && !defined( _PS3 )
  66. else
  67. {
  68. DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs30 );
  69. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, 0 );
  70. SET_STATIC_VERTEX_SHADER( unlitgeneric_vs30 );
  71. DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps30 );
  72. SET_STATIC_PIXEL_SHADER( unlitgeneric_ps30 );
  73. }
  74. #endif
  75. }
  76. DYNAMIC_STATE
  77. {
  78. if ( params[BUMPMAP]->IsTexture() )
  79. {
  80. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BUMPMAP, BUMPFRAME );
  81. }
  82. else
  83. {
  84. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALMAP_FLAT );
  85. }
  86. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BUMPTRANSFORM );
  87. #if !defined( _X360 ) && !defined( _PS3 )
  88. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  89. #endif
  90. {
  91. DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 );
  92. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  93. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  94. SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, 0 );
  95. SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 );
  96. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  97. {
  98. DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b );
  99. SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b );
  100. }
  101. else
  102. {
  103. DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 );
  104. SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 );
  105. }
  106. }
  107. #if !defined( _X360 ) && !defined( _PS3 )
  108. else
  109. {
  110. TessellationMode_t nTessellationMode = pShaderAPI->GetTessellationMode();
  111. if ( nTessellationMode != TESSELLATION_MODE_DISABLED )
  112. {
  113. pShaderAPI->BindStandardVertexTexture( SHADER_VERTEXTEXTURE_SAMPLER1, TEXTURE_SUBDIVISION_PATCHES );
  114. bool bHasDisplacement = false; // TODO
  115. float vSubDDimensions[4] = { 1.0f/pShaderAPI->GetSubDHeight(), bHasDisplacement && mat_displacementmap.GetBool()? 1.0f : 0.0f, 0.0f, 0.0f };
  116. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, vSubDDimensions );
  117. // JasonM - revisit this later...requires plumbing in a separate vertex texture param type??
  118. // bool bHasDisplacement = (info.m_nDisplacementMap != -1) && params[info.m_nDisplacementMap]->IsTexture();
  119. // if( bHasDisplacement )
  120. // {
  121. // pShader->BindVertexTexture( SHADER_VERTEXTEXTURE_SAMPLER2, info.m_nDisplacementMap );
  122. // }
  123. // else
  124. // {
  125. // pShaderAPI->BindStandardVertexTexture( SHADER_VERTEXTEXTURE_SAMPLER2, VERTEX_TEXTURE_BLACK );
  126. // }
  127. }
  128. DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs30 );
  129. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  130. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  131. SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, nTessellationMode );
  132. SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs30 );
  133. DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps30 );
  134. SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps30 );
  135. }
  136. #endif
  137. }
  138. Draw();
  139. }
  140. END_SHADER