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.

95 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "BaseVSShader.h"
  8. #include "waterdudv_vs11.inc"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. BEGIN_VS_SHADER( Water_DuDv, "Help for Water_DuDv" )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "", "dudv bump map" )
  14. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  15. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  16. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" )
  17. SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. }
  22. SHADER_FALLBACK
  23. {
  24. return 0;
  25. }
  26. SHADER_INIT
  27. {
  28. if ( params[BUMPMAP]->IsDefined() )
  29. {
  30. LoadTexture( BUMPMAP );
  31. }
  32. if( !params[REFRACTTINT]->IsDefined() )
  33. {
  34. params[REFRACTTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  35. }
  36. }
  37. SHADER_DRAW
  38. {
  39. SHADOW_STATE
  40. {
  41. pShaderShadow->EnableAlphaWrites( true );
  42. pShaderShadow->EnableColorWrites( true );
  43. pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true );
  44. int fmt = VERTEX_POSITION | VERTEX_NORMAL;
  45. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0, 0 );
  46. pShaderShadow->SetVertexShader( "WaterDuDv_vs11", 0 );
  47. pShaderShadow->SetPixelShader( "WaterDuDv_ps11", 0 );
  48. DisableFog();
  49. }
  50. DYNAMIC_STATE
  51. {
  52. waterdudv_vs11_Dynamic_Index vshIndex;
  53. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  54. vshIndex.SetDOFOG( pShaderAPI->GetSceneFogMode() != MATERIAL_FOG_NONE );
  55. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  56. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM );
  57. Vector4D vec;
  58. const float *pTint = params[REFRACTTINT]->GetVecValue();
  59. float flAverage = ( pTint[0] + pTint[1] + pTint[2] ) / 3.0f;
  60. vec.Init( flAverage, flAverage, flAverage, 1.0f );
  61. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vec.Base() );
  62. // Amount to refract
  63. SetPixelShaderConstant( 0, REFRACTAMOUNT );
  64. // Used to renormalize
  65. vec.Init( 1.0f, 1.0f, 1.0f, 1.0f );
  66. pShaderAPI->SetPixelShaderConstant( 1, vec.Base() );
  67. // Used to deal with the red channel
  68. vec.Init( 0.0f, 1.0f, 1.0f, 1.0f );
  69. pShaderAPI->SetPixelShaderConstant( 2, vec.Base() );
  70. vec.Init( 1.0f, 0.0f, 0.0f, 0.0f );
  71. pShaderAPI->SetPixelShaderConstant( 3, vec.Base() );
  72. BindTexture( SHADER_TEXTURE_STAGE0, BUMPMAP, BUMPFRAME );
  73. }
  74. Draw();
  75. }
  76. END_SHADER