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.

196 lines
6.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "screenspaceeffect_vs11.inc"
  9. DEFINE_FALLBACK_SHADER( screenspace_general, screenspace_general_dx8 )
  10. BEGIN_VS_SHADER_FLAGS( screenspace_general_dx8, "Help for screenspace_general", SHADER_NOT_EDITABLE )
  11. BEGIN_SHADER_PARAMS
  12. SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","")
  13. SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
  14. SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
  15. SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","")
  16. SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","")
  17. SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
  18. SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
  19. SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","")
  20. SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","")
  21. SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
  22. SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
  23. SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","")
  24. SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","")
  25. SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
  26. SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
  27. SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","")
  28. SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" )
  29. SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","")
  30. SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","")
  31. SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  32. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  33. SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  34. SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  35. SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  36. SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  37. SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  38. SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","")
  39. END_SHADER_PARAMS
  40. SHADER_INIT
  41. {
  42. if ( params[BASETEXTURE]->IsDefined() )
  43. {
  44. LoadTexture( BASETEXTURE );
  45. }
  46. if ( params[TEXTURE1]->IsDefined() )
  47. {
  48. LoadTexture( TEXTURE1 );
  49. }
  50. if ( params[TEXTURE2]->IsDefined() )
  51. {
  52. LoadTexture( TEXTURE2 );
  53. }
  54. if ( params[TEXTURE3]->IsDefined() )
  55. {
  56. LoadTexture( TEXTURE3 );
  57. }
  58. }
  59. SHADER_FALLBACK
  60. {
  61. if ( g_pHardwareConfig->GetDXSupportLevel() < 80 )
  62. {
  63. return "Wireframe";
  64. }
  65. return 0;
  66. }
  67. SHADER_DRAW
  68. {
  69. SHADOW_STATE
  70. {
  71. pShaderShadow->EnableDepthWrites( false );
  72. if (params[BASETEXTURE]->IsDefined())
  73. {
  74. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  75. ITexture *txtr=params[BASETEXTURE]->GetTextureValue();
  76. ImageFormat fmt=txtr->GetImageFormat();
  77. if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  78. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false);
  79. else
  80. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() );
  81. }
  82. if (params[TEXTURE1]->IsDefined())
  83. {
  84. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  85. ITexture *txtr=params[TEXTURE1]->GetTextureValue();
  86. ImageFormat fmt=txtr->GetImageFormat();
  87. if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  88. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false);
  89. else
  90. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() );
  91. }
  92. if (params[TEXTURE2]->IsDefined())
  93. {
  94. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  95. ITexture *txtr=params[TEXTURE2]->GetTextureValue();
  96. ImageFormat fmt=txtr->GetImageFormat();
  97. if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  98. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false);
  99. else
  100. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() );
  101. }
  102. if (params[TEXTURE3]->IsDefined())
  103. {
  104. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  105. ITexture *txtr=params[TEXTURE3]->GetTextureValue();
  106. ImageFormat fmt=txtr->GetImageFormat();
  107. if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  108. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false);
  109. else
  110. pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() );
  111. }
  112. int fmt = VERTEX_POSITION;
  113. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  114. // maybe convert from linear to gamma on write.
  115. bool srgb_write=true;
  116. if (params[LINEARWRITE]->GetFloatValue())
  117. srgb_write=false;
  118. pShaderShadow->EnableSRGBWrite( srgb_write );
  119. // Pre-cache shaders
  120. DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  121. SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  122. if (params[DISABLE_COLOR_WRITES]->GetIntValue())
  123. {
  124. pShaderShadow->EnableColorWrites(false);
  125. }
  126. // if (params[ALPHATESTED]->GetFloatValue())
  127. {
  128. pShaderShadow->EnableAlphaTest(true);
  129. pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0);
  130. }
  131. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  132. {
  133. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  134. }
  135. pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  136. }
  137. DYNAMIC_STATE
  138. {
  139. if (params[BASETEXTURE]->IsDefined())
  140. {
  141. BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  142. }
  143. if (params[TEXTURE1]->IsDefined())
  144. {
  145. BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
  146. }
  147. if (params[TEXTURE2]->IsDefined())
  148. {
  149. BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
  150. }
  151. if (params[TEXTURE3]->IsDefined())
  152. {
  153. BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
  154. }
  155. float c0[]={
  156. params[C0_X]->GetFloatValue(),
  157. params[C0_Y]->GetFloatValue(),
  158. params[C0_Z]->GetFloatValue(),
  159. params[C0_W]->GetFloatValue(),
  160. params[C1_X]->GetFloatValue(),
  161. params[C1_Y]->GetFloatValue(),
  162. params[C1_Z]->GetFloatValue(),
  163. params[C1_W]->GetFloatValue(),
  164. params[C2_X]->GetFloatValue(),
  165. params[C2_Y]->GetFloatValue(),
  166. params[C2_Z]->GetFloatValue(),
  167. params[C2_W]->GetFloatValue(),
  168. params[C3_X]->GetFloatValue(),
  169. params[C3_Y]->GetFloatValue(),
  170. params[C3_Z]->GetFloatValue(),
  171. params[C3_W]->GetFloatValue()
  172. };
  173. pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 );
  174. pShaderAPI->SetVertexShaderIndex( 0 );
  175. pShaderAPI->SetPixelShaderIndex( 0 );
  176. DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  177. SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 );
  178. }
  179. Draw();
  180. }
  181. END_SHADER