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.

169 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "bumpmappedenvmap.inc"
  9. #include "lightmappedgeneric_vs11.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // FIXME: Need to make a dx9 version so that "CENTROID" works.
  13. BEGIN_VS_SHADER( GooInGlass,
  14. "Help for GooInGlass" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass", "Base texture", 0 )
  17. SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  18. SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE )
  19. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_normal", "bump map" )
  20. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bump texcoord transform" )
  21. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_env", "envmap" )
  22. SHADER_PARAM( GLASSENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_envglass", "Glass Envmap" )
  23. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  24. SHADER_PARAM( GLASSENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  25. SHADER_PARAM( TRANSLUCENTGOO, SHADER_PARAM_TYPE_BOOL, "0", "whether or not goo is translucent" )
  26. END_SHADER_PARAMS
  27. SHADER_INIT
  28. {
  29. LoadBumpMap( BUMPMAP );
  30. LoadTexture( BASETEXTURE );
  31. LoadCubeMap( ENVMAP );
  32. LoadCubeMap( GLASSENVMAP );
  33. if( !params[ENVMAPTINT]->IsDefined() )
  34. {
  35. params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  36. }
  37. if( !params[GLASSENVMAPTINT]->IsDefined() )
  38. {
  39. params[GLASSENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  40. }
  41. if( !params[TRANSLUCENTGOO]->IsDefined() )
  42. {
  43. params[TRANSLUCENTGOO]->SetIntValue( 0 );
  44. }
  45. }
  46. SHADER_DRAW
  47. {
  48. // + MASKED BUMPED CUBEMAP * ENVMAPTINT
  49. SHADOW_STATE
  50. {
  51. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  53. if( params[TRANSLUCENTGOO]->GetIntValue() )
  54. {
  55. pShaderShadow->EnableBlending( true );
  56. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  57. }
  58. // FIXME: Remove the normal (needed for tangent space gen)
  59. pShaderShadow->VertexShaderVertexFormat(
  60. VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S |
  61. VERTEX_TANGENT_T, 1, 0, 0 );
  62. bumpmappedenvmap_Static_Index vshIndex;
  63. pShaderShadow->SetVertexShader( "BumpmappedEnvmap", vshIndex.GetIndex() );
  64. pShaderShadow->SetPixelShader( "BumpmappedEnvmap" );
  65. FogToBlack();
  66. }
  67. DYNAMIC_STATE
  68. {
  69. BindTexture( SHADER_SAMPLER0, BUMPMAP );
  70. BindTexture( SHADER_SAMPLER3, ENVMAP );
  71. float constantColor[4];
  72. params[ENVMAPTINT]->GetVecValue( constantColor, 3 );
  73. constantColor[3] = 0.0f;
  74. pShaderAPI->SetPixelShaderConstant( 0, constantColor, 1 );
  75. // handle scrolling of bump texture
  76. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BUMPTRANSFORM );
  77. bumpmappedenvmap_Dynamic_Index vshIndex;
  78. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  79. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  80. }
  81. Draw();
  82. // glass envmap
  83. SHADOW_STATE
  84. {
  85. SetInitialShadowState( );
  86. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  87. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  88. pShaderShadow->EnableBlending( true );
  89. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  90. // FIXME: Remove the normal (needed for tangent space gen)
  91. pShaderShadow->VertexShaderVertexFormat(
  92. VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S |
  93. VERTEX_TANGENT_T, 1, 0, 0 );
  94. bumpmappedenvmap_Static_Index vshIndex;
  95. pShaderShadow->SetVertexShader( "BumpmappedEnvmap", vshIndex.GetIndex() );
  96. pShaderShadow->SetPixelShader( "BumpmappedEnvMap" );
  97. FogToBlack();
  98. }
  99. DYNAMIC_STATE
  100. {
  101. // fixme: doesn't support camera space envmapping!!!!!!
  102. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT );
  103. BindTexture( SHADER_SAMPLER3, GLASSENVMAP );
  104. float constantColor[4];
  105. params[GLASSENVMAPTINT]->GetVecValue( constantColor, 3 );
  106. constantColor[3] = 0.0f;
  107. pShaderAPI->SetPixelShaderConstant( 0, constantColor, 1 );
  108. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BUMPTRANSFORM );
  109. bumpmappedenvmap_Dynamic_Index vshIndex;
  110. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  111. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  112. }
  113. Draw();
  114. // BASE TEXTURE * LIGHTMAP
  115. SHADOW_STATE
  116. {
  117. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  118. SetInitialShadowState( );
  119. pShaderShadow->EnableBlending( true );
  120. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  121. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  122. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  123. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 );
  124. lightmappedgeneric_vs11_Static_Index vshIndex;
  125. vshIndex.SetDETAIL( false );
  126. vshIndex.SetENVMAP( false );
  127. vshIndex.SetENVMAPCAMERASPACE( false );
  128. vshIndex.SetENVMAPSPHERE( false );
  129. vshIndex.SetVERTEXCOLOR( false );
  130. pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() );
  131. pShaderShadow->SetPixelShader( "LightmappedGeneric" );
  132. FogToFogColor();
  133. }
  134. DYNAMIC_STATE
  135. {
  136. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  137. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  138. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  139. EnablePixelShaderOverbright( true, 0, true );
  140. lightmappedgeneric_vs11_Dynamic_Index vshIndex;
  141. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  142. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  143. }
  144. Draw();
  145. }
  146. END_SHADER