Counter Strike : Global Offensive Source Code
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.

294 lines
9.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #if 0
  9. #include "particlelitgeneric_dx9_helper.h"
  10. #include "BaseVSShader.h"
  11. #include "particlelit_generic_vs30.inc"
  12. #include "particlelit_generic_ps30.inc"
  13. #include "convar.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Initialize shader parameters
  18. //-----------------------------------------------------------------------------
  19. void InitParamsParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ParticleLitGeneric_DX9_Vars_t &info )
  20. {
  21. // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
  22. Assert( info.m_nFlashlightTexture >= 0 );
  23. params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );
  24. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  25. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  26. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  27. if( (info.m_nBumpFrame != -1) && !params[info.m_nBumpFrame]->IsDefined() )
  28. {
  29. params[info.m_nBumpFrame]->SetIntValue( 0 );
  30. }
  31. if( (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() )
  32. {
  33. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  34. }
  35. else
  36. {
  37. CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK );
  38. }
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Initialize shader
  42. //-----------------------------------------------------------------------------
  43. void InitParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, ParticleLitGeneric_DX9_Vars_t &info )
  44. {
  45. Assert( info.m_nFlashlightTexture >= 0 );
  46. pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
  47. bool bIsBaseTextureTranslucent = false;
  48. if ( params[info.m_nBaseTexture]->IsDefined() )
  49. {
  50. pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
  51. if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() )
  52. {
  53. bIsBaseTextureTranslucent = true;
  54. }
  55. }
  56. // No alpha channel in any of the textures? No self illum or envmapmask
  57. if ( !bIsBaseTextureTranslucent )
  58. {
  59. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  60. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  61. }
  62. if ( g_pConfig->UseBumpmapping() )
  63. {
  64. if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() )
  65. {
  66. pShader->LoadBumpMap( info.m_nBumpmap );
  67. SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL );
  68. }
  69. }
  70. // Don't alpha test if the alpha channel is used for other purposes
  71. if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  72. {
  73. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Draws the shader
  78. //-----------------------------------------------------------------------------
  79. void DrawParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params,
  80. IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, ParticleLitGeneric_DX9_Vars_t &info )
  81. {
  82. bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture();
  83. bool hasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture();
  84. bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  85. bool hasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
  86. bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
  87. bool bNoFog = IS_FLAG_SET( MATERIAL_VAR_NOFOG );
  88. HDRType_t hdrType = g_pHardwareConfig->GetHDRType();
  89. BlendType_t blendType = pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true );
  90. if( pShader->IsSnapshotting() )
  91. {
  92. // look at color and alphamod stuff.
  93. // Unlit generic never uses the flashlight
  94. bool hasFlashlight = CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT );
  95. bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT );
  96. // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState
  97. pShaderShadow->EnableAlphaTest( bIsAlphaTested );
  98. if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f )
  99. {
  100. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() );
  101. }
  102. if( hasFlashlight )
  103. {
  104. pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
  105. if( bIsAlphaTested )
  106. {
  107. // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to
  108. // be the same on both the regular pass and the flashlight pass.
  109. pShaderShadow->EnableAlphaTest( false );
  110. pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL );
  111. }
  112. pShaderShadow->EnableBlending( true );
  113. pShaderShadow->EnableDepthWrites( false );
  114. }
  115. else
  116. {
  117. pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true );
  118. }
  119. unsigned int flags = VERTEX_POSITION;
  120. int userDataSize = 0;
  121. if( hasBaseTexture )
  122. {
  123. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  124. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  125. }
  126. if( hasFlashlight )
  127. {
  128. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true );
  129. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true );
  130. userDataSize = 4; // tangent S
  131. }
  132. if( hasBump )
  133. {
  134. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  135. userDataSize = 4; // tangent S
  136. // Normalizing cube map
  137. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  138. }
  139. if( hasVertexColor || hasVertexAlpha )
  140. {
  141. flags |= VERTEX_COLOR;
  142. }
  143. pShaderShadow->EnableSRGBWrite( true );
  144. // texcoord0 : base texcoord
  145. int pTexCoordCount[2] = { 2, 3 };
  146. pShaderShadow->VertexShaderVertexFormat(
  147. flags, 2, pTexCoordCount, 0, userDataSize );
  148. DECLARE_STATIC_VERTEX_SHADER( particlelit_generic_vs30 );
  149. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  150. SET_STATIC_VERTEX_SHADER( particlelit_generic_vs30 );
  151. DECLARE_STATIC_PIXEL_SHADER( particlelit_generic_ps30 );
  152. SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert);
  153. // SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight );
  154. SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, hdrType );
  155. SET_STATIC_PIXEL_SHADER( particlelit_generic_ps30 );
  156. if( hasFlashlight )
  157. {
  158. pShader->FogToBlack();
  159. }
  160. else
  161. {
  162. pShader->DefaultFog();
  163. }
  164. // HACK HACK HACK - enable alpha writes all the time so that we have them for
  165. // underwater stuff
  166. if( blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested )
  167. {
  168. pShaderShadow->EnableAlphaWrites( true );
  169. }
  170. }
  171. else
  172. {
  173. bool hasFlashlight = pShaderAPI->InFlashlightMode();
  174. if( hasBaseTexture )
  175. {
  176. pShader->BindTexture( SHADER_SAMPLER0, true, info.m_nBaseTexture, info.m_nBaseTextureFrame );
  177. }
  178. if( !g_pConfig->m_bFastNoBump )
  179. {
  180. if( hasBump )
  181. {
  182. pShader->BindTexture( SHADER_SAMPLER3, false, info.m_nBumpmap, info.m_nBumpFrame );
  183. }
  184. }
  185. else
  186. {
  187. if( hasBump )
  188. {
  189. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, false, TEXTURE_NORMALMAP_FLAT );
  190. }
  191. }
  192. if( hasFlashlight )
  193. {
  194. Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
  195. pShader->BindTexture( SHADER_SAMPLER7, true, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
  196. }
  197. LightState_t lightState = { 0, false, false };
  198. if( !hasFlashlight )
  199. pShaderAPI->GetDX9LightState( &lightState );
  200. MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode();
  201. // int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0;
  202. DECLARE_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 );
  203. SET_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 );
  204. DECLARE_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 );
  205. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  206. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  207. SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  208. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z &&
  209. blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested );
  210. SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, pShader->IsHDREnabled() );
  211. SET_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 );
  212. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform );
  213. if( hasBump )
  214. {
  215. pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform );
  216. }
  217. if( hasBump )
  218. {
  219. pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, false, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  220. pShaderAPI->SetPixelShaderStateAmbientLightCube( 5 );
  221. pShaderAPI->CommitPixelShaderLighting( 13 );
  222. }
  223. float eyePos[4];
  224. pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  225. pShaderAPI->SetPixelShaderConstant( 20, eyePos, 1 );
  226. pShaderAPI->SetPixelShaderFogParams( 21 );
  227. // flashlightfixme: put this in common code.
  228. if( hasFlashlight )
  229. {
  230. VMatrix worldToTexture;
  231. const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture );
  232. // Set the flashlight attenuation factors
  233. float atten[4];
  234. atten[0] = flashlightState.m_fConstantAtten;
  235. atten[1] = flashlightState.m_fLinearAtten;
  236. atten[2] = flashlightState.m_fQuadraticAtten;
  237. atten[3] = flashlightState.m_FarZAtten;
  238. pShaderAPI->SetPixelShaderConstant( 22, atten, 1 );
  239. // Set the flashlight origin
  240. float pos[4];
  241. pos[0] = flashlightState.m_vecLightOrigin[0];
  242. pos[1] = flashlightState.m_vecLightOrigin[1];
  243. pos[2] = flashlightState.m_vecLightOrigin[2];
  244. pos[3] = flashlightState.m_FarZ; // didn't have this in main. . probably need this?
  245. pShaderAPI->SetPixelShaderConstant( 23, pos, 1 );
  246. pShaderAPI->SetPixelShaderConstant( 24, worldToTexture.Base(), 4 );
  247. }
  248. }
  249. pShader->Draw();
  250. }
  251. // Commenting out this entire file
  252. #endif