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.

532 lines
20 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "cpp_shader_constant_register_map.h"
  8. #include "teeth_vs20.inc"
  9. #include "teeth_flashlight_vs20.inc"
  10. #include "teeth_bump_vs20.inc"
  11. #include "teeth_ps20.inc"
  12. #include "teeth_ps20b.inc"
  13. #include "teeth_flashlight_ps20.inc"
  14. #include "teeth_flashlight_ps20b.inc"
  15. #include "teeth_bump_ps20.inc"
  16. #include "teeth_bump_ps20b.inc"
  17. #if !defined( _X360 ) && !defined( _PS3 )
  18. #include "teeth_vs30.inc"
  19. #include "teeth_ps30.inc"
  20. #include "teeth_bump_vs30.inc"
  21. #include "teeth_bump_ps30.inc"
  22. #include "teeth_flashlight_vs30.inc"
  23. #include "teeth_flashlight_ps30.inc"
  24. #endif
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. DEFINE_FALLBACK_SHADER( Teeth, Teeth_DX9 )
  28. BEGIN_VS_SHADER( Teeth_DX9, "Help for Teeth_DX9" )
  29. BEGIN_SHADER_PARAMS
  30. SHADER_PARAM( ILLUMFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to darken or brighten the teeth" )
  31. SHADER_PARAM( FORWARD, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Forward direction vector for teeth lighting" )
  32. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  33. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "100", "phong exponent" )
  34. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  35. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  36. END_SHADER_PARAMS
  37. SHADER_INIT_PARAMS()
  38. {
  39. params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );
  40. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  41. }
  42. SHADER_FALLBACK
  43. {
  44. return 0;
  45. }
  46. SHADER_INIT
  47. {
  48. LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
  49. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  50. if( params[BUMPMAP]->IsDefined() )
  51. {
  52. LoadTexture( BUMPMAP );
  53. }
  54. }
  55. void DrawUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, VertexCompressionType_t vertexCompression )
  56. {
  57. bool hasBump = params[BUMPMAP]->IsTexture();
  58. BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
  59. bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
  60. SHADOW_STATE
  61. {
  62. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base map
  63. int flags = VERTEX_POSITION | VERTEX_NORMAL;
  64. int nTexCoordCount = 1;
  65. int userDataSize = 0;
  66. if ( hasBump )
  67. {
  68. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump map
  69. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false );
  70. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Normalization sampler for per-pixel lighting
  71. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, false );
  72. userDataSize = 4; // tangent S
  73. }
  74. // This shader supports compressed vertices, so OR in that flag:
  75. flags |= VERTEX_FORMAT_COMPRESSED;
  76. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  77. if ( hasBump )
  78. {
  79. #if !defined( _X360 ) && !defined( _PS3 )
  80. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  81. #endif
  82. {
  83. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  84. DECLARE_STATIC_VERTEX_SHADER( teeth_bump_vs20 );
  85. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  86. SET_STATIC_VERTEX_SHADER( teeth_bump_vs20 );
  87. // ps_2_b version which does phong
  88. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  89. {
  90. DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps20b );
  91. SET_STATIC_PIXEL_SHADER( teeth_bump_ps20b );
  92. }
  93. else
  94. {
  95. DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps20 );
  96. SET_STATIC_PIXEL_SHADER( teeth_bump_ps20 );
  97. }
  98. }
  99. #if !defined( _X360 ) && !defined( _PS3 )
  100. else
  101. {
  102. // The vertex shader uses the vertex id stream
  103. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  104. DECLARE_STATIC_VERTEX_SHADER( teeth_bump_vs30 );
  105. SET_STATIC_VERTEX_SHADER( teeth_bump_vs30 );
  106. DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps30 );
  107. SET_STATIC_PIXEL_SHADER( teeth_bump_ps30 );
  108. }
  109. #endif
  110. }
  111. else
  112. {
  113. #if !defined( _X360 ) && !defined( _PS3 )
  114. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  115. #endif
  116. {
  117. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  118. DECLARE_STATIC_VERTEX_SHADER( teeth_vs20 );
  119. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  120. SET_STATIC_VERTEX_SHADER( teeth_vs20 );
  121. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  122. {
  123. DECLARE_STATIC_PIXEL_SHADER( teeth_ps20b );
  124. SET_STATIC_PIXEL_SHADER( teeth_ps20b );
  125. }
  126. else
  127. {
  128. DECLARE_STATIC_PIXEL_SHADER( teeth_ps20 );
  129. SET_STATIC_PIXEL_SHADER( teeth_ps20 );
  130. }
  131. }
  132. #if !defined( _X360 ) && !defined( _PS3 )
  133. else
  134. {
  135. // The vertex shader uses the vertex id stream
  136. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  137. DECLARE_STATIC_VERTEX_SHADER( teeth_vs30 );
  138. SET_STATIC_VERTEX_SHADER( teeth_vs30 );
  139. DECLARE_STATIC_PIXEL_SHADER( teeth_ps30 );
  140. SET_STATIC_PIXEL_SHADER( teeth_ps30 );
  141. }
  142. #endif
  143. }
  144. // On DX9, do sRGB
  145. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  146. pShaderShadow->EnableSRGBWrite( true );
  147. FogToFogColor();
  148. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  149. // Lighting constants
  150. PI_BeginCommandBuffer();
  151. PI_SetPixelShaderAmbientLightCube( PSREG_AMBIENT_CUBE );
  152. PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY );
  153. // For non-bumped case, ambient cube is computed in the vertex shader
  154. if ( !hasBump )
  155. {
  156. PI_SetVertexShaderAmbientLightCube();
  157. }
  158. PI_EndCommandBuffer();
  159. }
  160. DYNAMIC_STATE
  161. {
  162. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE, FRAME );
  163. if ( hasBump )
  164. {
  165. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, BUMPMAP );
  166. }
  167. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  168. Vector4D lighting;
  169. params[FORWARD]->GetVecValue( lighting.Base(), 3 );
  170. lighting[3] = params[ILLUMFACTOR]->GetFloatValue();
  171. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lighting.Base() );
  172. LightState_t lightState = {0, false, false};
  173. pShaderAPI->GetDX9LightState( &lightState );
  174. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  175. float vEyePos_SpecExponent[4];
  176. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  177. vEyePos_SpecExponent[3] = 0.0f;
  178. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  179. if ( hasBump )
  180. {
  181. #if !defined( _X360 ) && !defined( _PS3 )
  182. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  183. #endif
  184. {
  185. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  186. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_bump_vs20 );
  187. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  188. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  189. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  190. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  191. SET_DYNAMIC_VERTEX_SHADER( teeth_bump_vs20 );
  192. // ps_2_b version which does Phong
  193. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  194. {
  195. Vector4D vSpecExponent;
  196. vSpecExponent[3] = params[PHONGEXPONENT]->GetFloatValue();
  197. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vSpecExponent.Base(), 1 );
  198. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20b );
  199. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  200. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  201. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  202. SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20b );
  203. }
  204. else
  205. {
  206. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20 );
  207. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  208. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  209. SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20 );
  210. }
  211. }
  212. #if !defined( _X360 ) && !defined( _PS3 )
  213. else
  214. {
  215. SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 );
  216. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_bump_vs30 );
  217. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  218. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  219. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  220. SET_DYNAMIC_VERTEX_SHADER( teeth_bump_vs30 );
  221. Vector4D vSpecExponent;
  222. vSpecExponent[3] = params[PHONGEXPONENT]->GetFloatValue();
  223. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vSpecExponent.Base(), 1 );
  224. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps30 );
  225. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  226. SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 );
  227. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  228. SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps30 );
  229. }
  230. #endif
  231. }
  232. else
  233. {
  234. #if !defined( _X360 ) && !defined( _PS3 )
  235. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  236. #endif
  237. {
  238. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  239. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_vs20 );
  240. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  241. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  242. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  243. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  244. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  245. SET_DYNAMIC_VERTEX_SHADER( teeth_vs20 );
  246. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  247. {
  248. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps20b );
  249. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  250. SET_DYNAMIC_PIXEL_SHADER( teeth_ps20b );
  251. }
  252. else
  253. {
  254. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps20 );
  255. SET_DYNAMIC_PIXEL_SHADER( teeth_ps20 );
  256. }
  257. }
  258. #if !defined( _X360 ) && !defined( _PS3 )
  259. else
  260. {
  261. SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 );
  262. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_vs30 );
  263. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  264. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  265. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  266. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  267. SET_DYNAMIC_VERTEX_SHADER( teeth_vs30 );
  268. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps30 );
  269. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  270. SET_DYNAMIC_PIXEL_SHADER( teeth_ps30 );
  271. }
  272. #endif
  273. }
  274. }
  275. Draw();
  276. }
  277. void DrawFlashlight( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, VertexCompressionType_t vertexCompression )
  278. {
  279. SHADOW_STATE
  280. {
  281. // Be sure not to write to dest alpha
  282. pShaderShadow->EnableAlphaWrites( false );
  283. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base map
  284. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  285. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Flashlight spot
  286. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  287. // Additive blend the teeth, lit by the flashlight
  288. s_pShaderShadow->EnableAlphaTest( false );
  289. s_pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  290. s_pShaderShadow->EnableBlending( true );
  291. // Set stream format (note that this shader supports compression)
  292. int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  293. int nTexCoordCount = 1;
  294. int userDataSize = 0;
  295. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  296. ShadowFilterMode_t nShadowFilterMode = SHADOWFILTERMODE_DEFAULT;
  297. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  298. {
  299. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // shadow depth map
  300. //pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER2 );
  301. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // shadow noise
  302. nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode( false /*bForceLowQuality */, g_pHardwareConfig->HasFastVertexTextures() && !IsPlatformX360() && !IsPlatformPS3() /* bPS30 */ ); // Based upon vendor and device dependent formats
  303. }
  304. #if !defined( _X360 ) && !defined( _PS3 )
  305. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  306. #endif
  307. {
  308. DECLARE_STATIC_VERTEX_SHADER( teeth_flashlight_vs20 );
  309. SET_STATIC_VERTEX_SHADER( teeth_flashlight_vs20 );
  310. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  311. {
  312. DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps20b );
  313. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  314. SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps20b );
  315. }
  316. else
  317. {
  318. DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps20 );
  319. SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps20 );
  320. }
  321. }
  322. #if !defined( _X360 ) && !defined( _PS3 )
  323. else
  324. {
  325. // The vertex shader uses the vertex id stream
  326. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  327. DECLARE_STATIC_VERTEX_SHADER( teeth_flashlight_vs30 );
  328. SET_STATIC_VERTEX_SHADER( teeth_flashlight_vs30 );
  329. DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps30 );
  330. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  331. SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps30 );
  332. }
  333. #endif
  334. // On DX9, do sRGB
  335. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  336. pShaderShadow->EnableSRGBWrite( true );
  337. FogToFogColor();
  338. }
  339. DYNAMIC_STATE
  340. {
  341. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE, FRAME );
  342. // State for spotlight projection, attenuation etc
  343. SetFlashlightVertexShaderConstants( false, -1, false, -1, true );
  344. VMatrix worldToTexture;
  345. ITexture *pFlashlightDepthTexture;
  346. FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  347. SetFlashLightColorFromState( flashlightState, pShaderAPI, false, PSREG_FLASHLIGHT_COLOR );
  348. bool bFlashlightShadows = g_pHardwareConfig->SupportsPixelShaders_2_b() ? ( flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ) ) : false;
  349. if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows )
  350. {
  351. BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_SHADOWDEPTH, pFlashlightDepthTexture, 0 );
  352. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_NONE, TEXTURE_SHADOW_NOISE_2D );
  353. }
  354. Vector4D lighting;
  355. params[FORWARD]->GetVecValue( lighting.Base(), 3 );
  356. lighting[3] = params[ILLUMFACTOR]->GetFloatValue();
  357. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, lighting.Base() );
  358. float atten[4], pos[4], tweaks[4];
  359. SetFlashLightColorFromState( flashlightState, pShaderAPI, false, PSREG_FLASHLIGHT_COLOR );
  360. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame );
  361. atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
  362. atten[1] = flashlightState.m_fLinearAtten;
  363. atten[2] = flashlightState.m_fQuadraticAtten;
  364. atten[3] = flashlightState.m_FarZAtten;
  365. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
  366. pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
  367. pos[1] = flashlightState.m_vecLightOrigin[1];
  368. pos[2] = flashlightState.m_vecLightOrigin[2];
  369. pos[3] = flashlightState.m_FarZ;
  370. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); // steps on rim boost
  371. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
  372. // Tweaks associated with a given flashlight
  373. tweaks[0] = ShadowFilterFromState( flashlightState );
  374. tweaks[1] = ShadowAttenFromState( flashlightState );
  375. HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
  376. pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
  377. // Dimensions of screen, used for screen-space noise map sampling
  378. float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
  379. int nWidth, nHeight;
  380. pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
  381. int nTexWidth, nTexHeight;
  382. pShaderAPI->GetStandardTextureDimensions( &nTexWidth, &nTexHeight, TEXTURE_SHADOW_NOISE_2D );
  383. vScreenScale[0] = (float) nWidth / nTexWidth;
  384. vScreenScale[1] = (float) nHeight / nTexHeight;
  385. vScreenScale[2] = 1.0f / flashlightState.m_flShadowMapResolution;
  386. vScreenScale[3] = 2.0f / flashlightState.m_flShadowMapResolution;
  387. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
  388. float vFlashlightPos[4];
  389. pShaderAPI->GetWorldSpaceCameraPosition( vFlashlightPos );
  390. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, vFlashlightPos, 1 );
  391. if ( IsX360() )
  392. {
  393. pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 );
  394. }
  395. #if !defined( _X360 ) && !defined( _PS3 )
  396. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  397. #endif
  398. {
  399. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs20 );
  400. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  401. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  402. SET_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs20 );
  403. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  404. {
  405. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20b );
  406. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  407. SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20b );
  408. }
  409. else
  410. {
  411. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20 );
  412. SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20 );
  413. }
  414. }
  415. #if !defined( _X360 ) && !defined( _PS3 )
  416. else
  417. {
  418. SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 );
  419. DECLARE_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs30 );
  420. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  421. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  422. SET_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs30 );
  423. DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps30 );
  424. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  425. SET_DYNAMIC_PIXEL_SHADER_COMBO( UBERLIGHT, flashlightState.m_bUberlight );
  426. SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps30 );
  427. SetupUberlightFromState( pShaderAPI, flashlightState );
  428. }
  429. #endif
  430. }
  431. Draw();
  432. }
  433. SHADER_DRAW
  434. {
  435. SHADOW_STATE
  436. {
  437. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  438. }
  439. bool hasFlashlight = UsingFlashlight( params );
  440. if ( !hasFlashlight || ( IsX360() || IsPS3() ) )
  441. {
  442. DrawUsingVertexShader( params, pShaderAPI, pShaderShadow, vertexCompression );
  443. SHADOW_STATE
  444. {
  445. SetInitialShadowState();
  446. }
  447. }
  448. if( hasFlashlight )
  449. {
  450. DrawFlashlight( params, pShaderAPI, pShaderShadow, vertexCompression );
  451. }
  452. }
  453. END_SHADER