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.

186 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Lightmap only shader
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "shaderlib/CShader.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // FIXME!! Need to make dx9 version so that "CENTROID" flags can be added!
  12. BEGIN_SHADER( LightmappedTwoTexture,
  13. "Help for LightmappedTwoTexture" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/Detail", "detail" )
  16. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "detail scale" )
  17. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  18. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "Frame for animated envmap" )
  19. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  20. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  21. SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" )
  22. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  23. END_SHADER_PARAMS
  24. SHADER_INIT_PARAMS()
  25. {
  26. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  27. if( !params[ENVMAPMASKSCALE]->IsDefined() )
  28. params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f );
  29. if( !params[DETAILSCALE]->IsDefined() )
  30. params[DETAILSCALE]->SetFloatValue( 1.0f );
  31. if( !params[ENVMAPTINT]->IsDefined() )
  32. params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  33. // No texture means no self-illum or env mask in base alpha
  34. if ( !params[BASETEXTURE]->IsDefined() )
  35. {
  36. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  37. }
  38. // If in decal mode, no debug override...
  39. if (IS_FLAG_SET(MATERIAL_VAR_DECAL))
  40. {
  41. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  42. }
  43. }
  44. SHADER_INIT
  45. {
  46. if (params[BASETEXTURE]->IsDefined())
  47. {
  48. LoadTexture( BASETEXTURE );
  49. if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent())
  50. {
  51. if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK))
  52. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  53. }
  54. }
  55. if (params[DETAIL]->IsDefined())
  56. {
  57. LoadTexture( DETAIL );
  58. }
  59. // Don't alpha test if the alpha channel is used for other purposes
  60. if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  61. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  62. if (params[ENVMAP]->IsDefined())
  63. {
  64. if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) )
  65. LoadCubeMap( ENVMAP );
  66. else
  67. LoadTexture( ENVMAP );
  68. if( !g_pHardwareConfig->SupportsCubeMaps() )
  69. {
  70. SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE );
  71. }
  72. if (params[ENVMAPMASK]->IsDefined())
  73. LoadTexture( ENVMAPMASK );
  74. }
  75. }
  76. SHADER_FALLBACK
  77. {
  78. // The only thing we can't do here is masked env-mapped
  79. if (g_pHardwareConfig->GetSamplerCount() < 2)
  80. {
  81. return "LightmappedTwoTexture_DX5";
  82. }
  83. return 0;
  84. }
  85. /*
  86. // FIXME: I didn't remove this because it's modulating against the detail alpha!
  87. // This seems very strange and isn't what FixedFunctionBaseTimesDetailPass does.
  88. // Should it!?!? If so, I want to move this to the FixedFunctionBaseTimesDetailPass.
  89. void DrawBaseTimesDetail( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow )
  90. {
  91. // Base
  92. SHADOW_STATE
  93. {
  94. // alpha test
  95. pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );
  96. // Alpha blending, enable alpha blending if the detail texture is translucent
  97. bool detailIsTranslucent = TextureIsTranslucent( DETAIL, false );
  98. if ( detailIsTranslucent )
  99. {
  100. if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
  101. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  102. else
  103. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  104. }
  105. else
  106. {
  107. SetDefaultBlendingShadowState( BASETEXTURE, true );
  108. }
  109. // independently configure alpha and color
  110. pShaderShadow->EnableAlphaPipe( true );
  111. // Here's the color states (NOTE: SHADER_DRAW_COLOR == use Vertex Color)
  112. pShaderShadow->EnableConstantColor( IsColorModulating() );
  113. pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true );
  114. pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true );
  115. // Here's the alpha states
  116. pShaderShadow->EnableConstantAlpha( IsAlphaModulating() );
  117. pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) );
  118. pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, TextureIsTranslucent(BASETEXTURE, true) );
  119. pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, detailIsTranslucent );
  120. int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SECONDARY_TEXCOORD1;
  121. if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR))
  122. flags |= SHADER_DRAW_COLOR;
  123. pShaderShadow->DrawFlags( flags );
  124. DefaultFog();
  125. }
  126. DYNAMIC_STATE
  127. {
  128. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM );
  129. SetFixedFunctionTextureScale( MATERIAL_TEXTURE1, DETAILSCALE );
  130. BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME );
  131. BindTexture( SHADER_TEXTURE_STAGE1, DETAIL );
  132. SetModulationDynamicState();
  133. }
  134. Draw();
  135. SHADOW_STATE
  136. {
  137. pShaderShadow->EnableAlphaPipe( false );
  138. }
  139. }
  140. */
  141. SHADER_DRAW
  142. {
  143. // Pass 1 : Base + detail
  144. FixedFunctionBaseTimesDetailPass(
  145. BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE );
  146. // Pass 2 : * lightmap
  147. FixedFunctionMultiplyByLightmapPass( BASETEXTURE, FRAME, BASETEXTURETRANSFORM );
  148. // Pass 3 : + env
  149. bool envDefined = params[ENVMAP]->IsTexture();
  150. if (envDefined)
  151. {
  152. FixedFunctionAdditiveMaskedEnvmapPass(
  153. ENVMAP, ENVMAPMASK, BASETEXTURE,
  154. ENVMAPFRAME, ENVMAPMASKFRAME, FRAME,
  155. BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT );
  156. }
  157. }
  158. END_SHADER