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.

153 lines
5.7 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "mathlib/vmatrix.h"
  4. #include "proto_ice_helper.h"
  5. #include "convar.h"
  6. // Auto generated inc files
  7. #include "proto_ice_vs20.inc"
  8. #include "proto_ice_ps20b.inc"
  9. void InitParamsProtoIce( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ProtoIceVars_t &info )
  10. {
  11. // Set material flags
  12. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  13. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  14. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  15. // Set material parameter default values
  16. if ( ( info.m_nBaseTextureFrame != -1 ) && !params[info.m_nBaseTextureFrame]->IsDefined() )
  17. {
  18. params[ info.m_nBaseTextureFrame ]->SetIntValue( 0 );
  19. }
  20. if ( ( info.m_nBumpFrame != -1 ) && !params[info.m_nBumpFrame]->IsDefined() )
  21. {
  22. params[ info.m_nBumpFrame ]->SetIntValue( 0 );
  23. }
  24. if ( ( info.m_nSsBump != -1 ) && !params[ info.m_nSsBump ]->IsDefined() )
  25. {
  26. params[ info.m_nSsBump ]->SetIntValue( 0 );
  27. }
  28. }
  29. void InitProtoIce( CBaseVSShader *pShader, IMaterialVar** params, ProtoIceVars_t &info )
  30. {
  31. // Load textures
  32. if ( (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsDefined() )
  33. {
  34. pShader->LoadTexture( info.m_nBaseTexture );
  35. }
  36. if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
  37. {
  38. pShader->LoadTexture( info.m_nBumpmap );
  39. }
  40. }
  41. void DrawProtoIce( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  42. IShaderShadow* pShaderShadow, ProtoIceVars_t &info, VertexCompressionType_t vertexCompression )
  43. {
  44. SHADOW_STATE
  45. {
  46. // Set stream format (note that this shader supports compression)
  47. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  48. bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  49. bool bHasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
  50. if ( bHasVertexColor || bHasVertexAlpha )
  51. flags |= VERTEX_COLOR;
  52. bool hasBump = ( params[info.m_nBumpmap]->IsTexture() ) && g_pConfig->UseBumpmapping();
  53. bool hasSSBump = hasBump && (info.m_nSsBump != -1) && ( params[ info.m_nSsBump ]->GetIntValue() );
  54. int combo_BUMPMAP = hasSSBump ? 2 : hasBump;
  55. int nTexCoordCount = 1;
  56. int userDataSize = 0;
  57. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  58. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  59. // Vertex Shader
  60. DECLARE_STATIC_VERTEX_SHADER( proto_ice_vs20 );
  61. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha );
  62. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  63. SET_STATIC_VERTEX_SHADER( proto_ice_vs20 );
  64. // Pixel Shader
  65. DECLARE_STATIC_PIXEL_SHADER( proto_ice_ps20b );
  66. SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha );
  67. SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, combo_BUMPMAP );
  68. SET_STATIC_PIXEL_SHADER( proto_ice_ps20b );
  69. // Textures
  70. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Color texture
  71. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  72. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump
  73. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB
  74. pShaderShadow->EnableSRGBWrite( true );
  75. // Blending
  76. //pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  77. //pShaderShadow->EnableAlphaWrites( false );
  78. // !!! We need to turn this back on because EnableAlphaBlending() above disables it!
  79. //pShaderShadow->EnableDepthWrites( true );
  80. pShader->PI_BeginCommandBuffer();
  81. pShader->PI_SetPixelShaderAmbientLightCube( 3 );
  82. pShader->PI_SetPixelShaderLocalLighting( 9 );
  83. pShader->PI_SetVertexShaderAmbientLightCube();
  84. pShader->PI_EndCommandBuffer();
  85. }
  86. DYNAMIC_STATE
  87. {
  88. LightState_t lightState = { 0, false, false };
  89. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  90. // Set Vertex Shader Combos
  91. DECLARE_DYNAMIC_VERTEX_SHADER( proto_ice_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( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  95. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  96. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  97. SET_DYNAMIC_VERTEX_SHADER( proto_ice_vs20 );
  98. // Set Vertex Shader Constants
  99. pShaderAPI->GetDX9LightState( &lightState );
  100. // Set Pixel Shader Combos
  101. DECLARE_DYNAMIC_PIXEL_SHADER( proto_ice_ps20b );
  102. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  103. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  104. SET_DYNAMIC_PIXEL_SHADER( proto_ice_ps20b );
  105. // Bind textures
  106. pShader->BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nBaseTexture, info.m_nBaseTextureFrame );
  107. bool bBumpMapping = ( ( info.m_nBumpmap == -1 ) || !params[info.m_nBumpmap]->IsTexture() ) ? false : true;
  108. if ( bBumpMapping )
  109. {
  110. pShader->BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, info.m_nBumpmap, info.m_nBumpFrame );
  111. }
  112. // Set c0 and c1 to contain first two rows of ViewProj matrix
  113. VMatrix mView, mProj;
  114. pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] );
  115. pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] );
  116. VMatrix mViewProj = mView * mProj;
  117. mViewProj = mViewProj.Transpose3x3();
  118. pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 2 );
  119. // Camera pos
  120. float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  121. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos );
  122. pShaderAPI->SetPixelShaderConstant( 2, vEyePos, 1 );
  123. }
  124. pShader->Draw();
  125. }