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.

111 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "jellyfish.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. BEGIN_VS_SHADER( JellyFish,
  13. "Help for JellyFish" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( GRADIENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "1D texture for silhouette glowy bits" )
  16. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cubemap", "envmap" )
  17. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmaptint" )
  18. SHADER_PARAM( PULSERATE, SHADER_PARAM_TYPE_FLOAT, "1", "blah" )
  19. END_SHADER_PARAMS
  20. SHADER_INIT_PARAMS()
  21. {
  22. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  23. }
  24. SHADER_INIT
  25. {
  26. LoadTexture( GRADIENTTEXTURE );
  27. LoadTexture( BASETEXTURE );
  28. if( params[ENVMAP]->IsDefined() )
  29. {
  30. LoadCubeMap( ENVMAP );
  31. }
  32. if( !params[ENVMAPTINT]->IsDefined() )
  33. {
  34. params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  35. }
  36. if( !params[PULSERATE]->IsDefined() )
  37. {
  38. params[PULSERATE]->SetFloatValue( 0.0f );
  39. }
  40. }
  41. SHADER_DRAW
  42. {
  43. // fixme
  44. if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() )
  45. {
  46. return;
  47. }
  48. SHADOW_STATE
  49. {
  50. pShaderShadow->EnableDepthWrites( false );
  51. pShaderShadow->EnableBlending( true );
  52. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  53. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  54. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  55. pShaderShadow->VertexShaderVertexFormat(
  56. VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 0 );
  57. jellyfish_Static_Index vshIndex;
  58. pShaderShadow->SetVertexShader( "JellyFish", vshIndex.GetIndex() );
  59. pShaderShadow->SetPixelShader( "JellyFish" );
  60. FogToBlack();
  61. }
  62. DYNAMIC_STATE
  63. {
  64. float time[4];
  65. time[0] = pShaderAPI->CurrentTime() * params[PULSERATE]->GetFloatValue();
  66. BindTexture( SHADER_SAMPLER0, GRADIENTTEXTURE );
  67. BindTexture( SHADER_SAMPLER1, BASETEXTURE );
  68. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, time, 1 );
  69. LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 );
  70. jellyfish_Dynamic_Index vshIndex;
  71. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  72. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  73. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  74. }
  75. Draw();
  76. if( params[ENVMAP]->IsTexture() )
  77. {
  78. SHADOW_STATE
  79. {
  80. SetInitialShadowState( );
  81. pShaderShadow->EnableDepthWrites( false );
  82. pShaderShadow->EnableBlending( true );
  83. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  84. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  85. pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR );
  86. pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true );
  87. pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_NORMAL );
  88. pShaderShadow->EnableConstantColor( true );
  89. FogToFogColor();
  90. }
  91. DYNAMIC_STATE
  92. {
  93. SetColorState( ENVMAPTINT );
  94. LoadCameraToWorldTransform( MATERIAL_TEXTURE0 );
  95. BindTexture( SHADER_SAMPLER0, ENVMAP );
  96. }
  97. Draw();
  98. }
  99. }
  100. END_SHADER