Team Fortress 2 Source Code as on 22/4/2020
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.

102 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #include "rift_vs11.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. BEGIN_VS_SHADER( Rift_DX8,
  13. "Help for Rift_DX8" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "second texture" )
  16. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" )
  17. SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  22. }
  23. SHADER_INIT
  24. {
  25. if (params[BASETEXTURE]->IsDefined())
  26. {
  27. LoadTexture( BASETEXTURE );
  28. }
  29. if (params[TEXTURE2]->IsDefined())
  30. {
  31. LoadTexture( TEXTURE2 );
  32. }
  33. }
  34. SHADER_DRAW
  35. {
  36. SHADOW_STATE
  37. {
  38. pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true );
  39. pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true );
  40. // Either we've got a constant modulation
  41. bool isTranslucent = IsAlphaModulating();
  42. // Or we've got a texture alpha on either texture
  43. isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) ||
  44. TextureIsTranslucent( TEXTURE2, true );
  45. if ( isTranslucent )
  46. {
  47. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  48. {
  49. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  50. }
  51. else
  52. {
  53. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  54. }
  55. }
  56. else
  57. {
  58. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  59. {
  60. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  61. }
  62. }
  63. int fmt = VERTEX_POSITION;
  64. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  65. pShaderShadow->SetVertexShader( "rift_vs11", 0 );
  66. pShaderShadow->SetPixelShader( "rift_ps11", 0 );
  67. DefaultFog();
  68. }
  69. DYNAMIC_STATE
  70. {
  71. BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME );
  72. pShaderAPI->SetTextureTransformDimension( 0, 3, true );
  73. BindTexture( SHADER_TEXTURE_STAGE1, TEXTURE2, FRAME2 );
  74. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, TEXTURE2TRANSFORM );
  75. // used to invert y
  76. float c[4] = { 0.0f, 0.0f, 0.0f, -1.0f };
  77. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 );
  78. SetModulationPixelShaderDynamicState( 0 );
  79. rift_vs11_Dynamic_Index vshIndex;
  80. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  81. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  82. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  83. }
  84. Draw();
  85. }
  86. END_SHADER