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.

206 lines
6.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "shaderlib/cshader.h"
  8. #include "worldvertextransition_dx6_helper.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. void InitParamsWorldVertexTransition_DX6( IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info )
  12. {
  13. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  14. // FLASHLIGHTFIXME
  15. params[info.m_nFlashlightTextureVar]->SetStringValue( "effects/flashlight001" );
  16. }
  17. void InitWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info )
  18. {
  19. // FLASHLIGHTFIXME
  20. if ( params[info.m_nFlashlightTextureVar]->IsDefined() )
  21. {
  22. pShader->LoadTexture( info.m_nFlashlightTextureVar );
  23. }
  24. if ( params[info.m_nBaseTextureVar]->IsDefined() )
  25. {
  26. pShader->LoadTexture( info.m_nBaseTextureVar );
  27. }
  28. if ( params[info.m_nBaseTexture2Var]->IsDefined() )
  29. {
  30. pShader->LoadTexture( info.m_nBaseTexture2Var );
  31. }
  32. }
  33. static void DrawFlashlightPass( CBaseShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, int nPass, WorldVertexTransition_DX6_Vars_t &info )
  34. {
  35. SHADOW_STATE
  36. {
  37. SET_FLAGS2( MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT );
  38. pShaderShadow->EnableDepthWrites( false );
  39. pShaderShadow->EnableAlphaWrites( false );
  40. pShaderShadow->SetDiffuseMaterialSource( SHADER_MATERIALSOURCE_COLOR1 );
  41. if( nPass == 0 )
  42. {
  43. pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  44. }
  45. else
  46. {
  47. pShader->EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_ONE );
  48. }
  49. int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_COLOR | SHADER_DRAW_NORMAL;
  50. pShaderShadow->DrawFlags( flags );
  51. pShader->FogToBlack();
  52. pShaderShadow->EnableLighting( true );
  53. pShaderShadow->EnableCustomPixelPipe( true );
  54. pShaderShadow->CustomTextureStages( 2 );
  55. // color stage 0
  56. // projected texture * vertex color (lighting)
  57. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  58. SHADER_TEXCHANNEL_COLOR,
  59. SHADER_TEXOP_MODULATE,
  60. SHADER_TEXARG_TEXTURE,
  61. SHADER_TEXARG_VERTEXCOLOR );
  62. // color stage 1
  63. // * base texture
  64. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  65. SHADER_TEXCHANNEL_COLOR,
  66. SHADER_TEXOP_MODULATE,
  67. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE );
  68. // alpha stage 0
  69. // get alpha from constant alpha * vertex color
  70. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  71. SHADER_TEXCHANNEL_ALPHA,
  72. SHADER_TEXOP_MODULATE,
  73. SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_VERTEXCOLOR );
  74. // alpha stage 1
  75. // get alpha from $basetexture
  76. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  77. SHADER_TEXCHANNEL_ALPHA,
  78. SHADER_TEXOP_MODULATE,
  79. SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE );
  80. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  81. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  82. // Shove the view position into texcoord 0 before the texture matrix.
  83. pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR );
  84. pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true );
  85. }
  86. DYNAMIC_STATE
  87. {
  88. pShader->SetFlashlightFixedFunctionTextureTransform( MATERIAL_TEXTURE0 );
  89. // NOTE: This has to come after the loadmatrix since the loadmatrix screws with the
  90. // transform flags!!!!!!
  91. // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader.
  92. // NOTE Tried to divide XY by Z, but doesn't work.
  93. pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 3, true );
  94. pShader->BindTexture( SHADER_SAMPLER0, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME );
  95. if( nPass == 0 )
  96. {
  97. pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture2Var, -1 );
  98. }
  99. else
  100. {
  101. pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTextureVar, info.m_nBaseTextureFrameVar );
  102. }
  103. }
  104. pShader->Draw();
  105. }
  106. void DrawWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, WorldVertexTransition_DX6_Vars_t &info )
  107. {
  108. bool bHasFlashlight = pShader->UsingFlashlight( params );
  109. if( bHasFlashlight )
  110. {
  111. DrawFlashlightPass( pShader, params, pShaderAPI, pShaderShadow, 0, info );
  112. DrawFlashlightPass( pShader, params, pShaderAPI, pShaderShadow, 1, info );
  113. return;
  114. }
  115. SHADOW_STATE
  116. {
  117. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  118. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  119. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  120. pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT );
  121. pShaderShadow->DrawFlags( SHADER_DRAW_COLOR | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 );
  122. pShader->FogToFogColor();
  123. }
  124. DYNAMIC_STATE
  125. {
  126. //pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_NEAREST );
  127. //pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_NEAREST );
  128. pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTextureVar );
  129. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP );
  130. }
  131. pShader->Draw();
  132. SHADOW_STATE
  133. {
  134. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  135. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  136. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  137. pShaderShadow->EnableBlending( true );
  138. pShaderShadow->EnableCustomPixelPipe( true );
  139. pShaderShadow->CustomTextureStages( 2 );
  140. // alpha and color stage 0
  141. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  142. SHADER_TEXCHANNEL_ALPHA,
  143. SHADER_TEXOP_SELECTARG1,
  144. SHADER_TEXARG_TEXTURE,
  145. SHADER_TEXARG_TEXTURE );
  146. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0,
  147. SHADER_TEXCHANNEL_COLOR,
  148. SHADER_TEXOP_SELECTARG1,
  149. SHADER_TEXARG_TEXTURE,
  150. SHADER_TEXARG_TEXTURE );
  151. // alpha and color stage 1
  152. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  153. SHADER_TEXCHANNEL_ALPHA,
  154. SHADER_TEXOP_MODULATE,
  155. SHADER_TEXARG_TEXTURE,
  156. SHADER_TEXARG_VERTEXCOLOR );
  157. pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1,
  158. SHADER_TEXCHANNEL_COLOR,
  159. SHADER_TEXOP_MODULATE2X,
  160. SHADER_TEXARG_PREVIOUSSTAGE,
  161. SHADER_TEXARG_TEXTURE );
  162. // Looks backwards, but this is done so that lightmap alpha = 1 when only
  163. // using 1 texture (needed for translucent displacements).
  164. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  165. pShaderShadow->DrawFlags( SHADER_DRAW_COLOR | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 );
  166. pShader->FogToFogColor();
  167. }
  168. DYNAMIC_STATE
  169. {
  170. pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture2Var );
  171. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP );
  172. }
  173. pShader->Draw();
  174. }