Added bloom shader and screenspace effect helpers as examples for the SDK.
authorJoe Ludwig <joe@valvesoftware.com>
Tue Jul 30 15:10:15 2013 -0700 (2013-07-30)
changeset 14d5aadd140e8d
parent 13 3cb177155521
child 15 4de0151ff6a3
Added bloom shader and screenspace effect helpers as examples for the SDK.
materialsystem/stdshaders/Bloom.cpp
materialsystem/stdshaders/SDK_Bloom_ps2x.fxc
materialsystem/stdshaders/SDK_bloomadd_ps11.fxc
materialsystem/stdshaders/SDK_bloomadd_ps2x.fxc
materialsystem/stdshaders/SDK_screenspaceeffect_vs20.fxc
materialsystem/stdshaders/fxctmp9/SDK_Bloom_ps20.inc
materialsystem/stdshaders/fxctmp9/SDK_Bloom_ps20b.inc
materialsystem/stdshaders/fxctmp9/SDK_bloomadd_ps20.inc
materialsystem/stdshaders/fxctmp9/SDK_bloomadd_ps20b.inc
materialsystem/stdshaders/fxctmp9/SDK_screenspaceeffect_vs20.inc
materialsystem/stdshaders/game_shader_dx9_base.vpc
materialsystem/stdshaders/screenspace_general.cpp
materialsystem/stdshaders/stdshader_dx9_20b.txt
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/materialsystem/stdshaders/Bloom.cpp	Tue Jul 30 15:10:15 2013 -0700
     1.3 @@ -0,0 +1,90 @@
     1.4 +//===== Copyright  1996-2005, Valve Corporation, All rights reserved. ======//
     1.5 +//
     1.6 +// Purpose: 
     1.7 +//
     1.8 +// $NoKeywords: $
     1.9 +//===========================================================================//
    1.10 +
    1.11 +#include "BaseVSShader.h"
    1.12 +
    1.13 +#include "SDK_screenspaceeffect_vs20.inc"
    1.14 +#include "SDK_Bloom_ps20.inc"
    1.15 +#include "SDK_Bloom_ps20b.inc"
    1.16 +
    1.17 +BEGIN_VS_SHADER_FLAGS( SDK_Bloom, "Help for Bloom", SHADER_NOT_EDITABLE )
    1.18 +	BEGIN_SHADER_PARAMS
    1.19 +		SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "" )
    1.20 +		SHADER_PARAM( BLURTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" )
    1.21 +	END_SHADER_PARAMS
    1.22 +
    1.23 +	SHADER_INIT
    1.24 +	{
    1.25 +		if( params[FBTEXTURE]->IsDefined() )
    1.26 +		{
    1.27 +			LoadTexture( FBTEXTURE );
    1.28 +		}
    1.29 +		if( params[BLURTEXTURE]->IsDefined() )
    1.30 +		{
    1.31 +			LoadTexture( BLURTEXTURE );
    1.32 +		}
    1.33 +	}
    1.34 +	
    1.35 +	SHADER_FALLBACK
    1.36 +	{
    1.37 +		// Requires DX9 + above
    1.38 +		if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
    1.39 +		{
    1.40 +			Assert( 0 );
    1.41 +			return "Wireframe";
    1.42 +		}
    1.43 +		return 0;
    1.44 +	}
    1.45 +
    1.46 +	SHADER_DRAW
    1.47 +	{
    1.48 +		SHADOW_STATE
    1.49 +		{
    1.50 +			pShaderShadow->EnableDepthWrites( false );
    1.51 +
    1.52 +			pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
    1.53 +			pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
    1.54 +			int fmt = VERTEX_POSITION;
    1.55 +			pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
    1.56 +
    1.57 +			// Pre-cache shaders
    1.58 +			DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
    1.59 +			SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
    1.60 +
    1.61 +			if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
    1.62 +			{
    1.63 +				DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
    1.64 +				SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
    1.65 +			}
    1.66 +			else
    1.67 +			{
    1.68 +				DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
    1.69 +				SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20 );
    1.70 +			}
    1.71 +		}
    1.72 +
    1.73 +		DYNAMIC_STATE
    1.74 +		{
    1.75 +			BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
    1.76 +			BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 );
    1.77 +			DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
    1.78 +			SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
    1.79 +
    1.80 +			if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
    1.81 +			{
    1.82 +				DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
    1.83 +				SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
    1.84 +			}
    1.85 +			else
    1.86 +			{
    1.87 +				DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
    1.88 +				SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20 );
    1.89 +			}
    1.90 +		}
    1.91 +		Draw();
    1.92 +	}
    1.93 +END_SHADER
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/materialsystem/stdshaders/SDK_Bloom_ps2x.fxc	Tue Jul 30 15:10:15 2013 -0700
     2.3 @@ -0,0 +1,21 @@
     2.4 +// STATIC: "CONVERT_TO_SRGB" "0..1"	[ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
     2.5 +// STATIC: "CONVERT_TO_SRGB" "0..0"	[= 0] [XBOX]
     2.6 +
     2.7 +#define HDRTYPE HDR_TYPE_NONE
     2.8 +#include "common_ps_fxc.h"
     2.9 +
    2.10 +sampler FBSampler	: register( s0 );
    2.11 +sampler BlurSampler	: register( s1 );
    2.12 +
    2.13 +struct PS_INPUT
    2.14 +{
    2.15 +	float2 texCoord				: TEXCOORD0;
    2.16 +};
    2.17 +
    2.18 +float4 main( PS_INPUT i ) : COLOR
    2.19 +{
    2.20 +	float4 fbSample = tex2D( FBSampler, i.texCoord );
    2.21 +	float4 blurSample = tex2D( BlurSampler, i.texCoord );
    2.22 +
    2.23 +	return FinalOutput( float4( fbSample + blurSample.rgb * blurSample.a * MAX_HDR_OVERBRIGHT, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
    2.24 +}
    2.25 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/materialsystem/stdshaders/SDK_bloomadd_ps11.fxc	Tue Jul 30 15:10:15 2013 -0700
     3.3 @@ -0,0 +1,18 @@
     3.4 +//======= Copyright  1996-2006, Valve Corporation, All rights reserved. ======
     3.5 +#define CONVERT_TO_SRGB 0
     3.6 +
     3.7 +#include "common_ps_fxc.h"
     3.8 +
     3.9 +sampler TexSampler	: register( s0 );
    3.10 +
    3.11 +struct PS_INPUT
    3.12 +{
    3.13 +	HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate
    3.14 +};
    3.15 +
    3.16 +float4 main( PS_INPUT i ) : COLOR
    3.17 +{
    3.18 +	float4 result = tex2D( TexSampler, i.baseTexCoord );
    3.19 +	result.a = 1.0f;
    3.20 +	return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
    3.21 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/materialsystem/stdshaders/SDK_bloomadd_ps2x.fxc	Tue Jul 30 15:10:15 2013 -0700
     4.3 @@ -0,0 +1,23 @@
     4.4 +//======= Copyright  1996-2006, Valve Corporation, All rights reserved. ======
     4.5 +#define CONVERT_TO_SRGB 0
     4.6 +
     4.7 +#include "common_ps_fxc.h"
     4.8 +
     4.9 +sampler TexSampler	: register( s0 );
    4.10 +
    4.11 +struct PS_INPUT
    4.12 +{
    4.13 +	HALF2 baseTexCoord				: TEXCOORD0;		// Base texture coordinate
    4.14 +	
    4.15 +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches	
    4.16 +	float2 ZeroTexCoord				: TEXCOORD1;
    4.17 +    float2 bloomTexCoord            : TEXCOORD2;
    4.18 +#endif
    4.19 +};
    4.20 +
    4.21 +float4 main( PS_INPUT i ) : COLOR
    4.22 +{
    4.23 +	float4 result = tex2D( TexSampler, i.baseTexCoord );
    4.24 +	result.a = 1.0f;
    4.25 +	return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
    4.26 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/materialsystem/stdshaders/SDK_screenspaceeffect_vs20.fxc	Tue Jul 30 15:10:15 2013 -0700
     5.3 @@ -0,0 +1,47 @@
     5.4 +//========= Copyright  1996-2006, Valve Corporation, All rights reserved. ============//
     5.5 +
     5.6 +// STATIC: "X360APPCHOOSER" "0..1" [= 0]
     5.7 +
     5.8 +#include "common_vs_fxc.h"
     5.9 +
    5.10 +struct VS_INPUT
    5.11 +{
    5.12 +	float3 vPos						: POSITION;
    5.13 +	float2 vBaseTexCoord			: TEXCOORD0;
    5.14 +
    5.15 +	#if X360APPCHOOSER
    5.16 +		float4 vColor				: COLOR0;
    5.17 +	#endif
    5.18 +};
    5.19 +
    5.20 +struct VS_OUTPUT
    5.21 +{
    5.22 +    float4 projPos					: POSITION;	
    5.23 +	float2 baseTexCoord				: TEXCOORD0;
    5.24 +	float2 ZeroTexCoord				: TEXCOORD1;
    5.25 +	float2 bloomTexCoord            : TEXCOORD2;
    5.26 +
    5.27 +	#if X360APPCHOOSER
    5.28 +		float4 vColor				: TEXCOORD3;
    5.29 +	#endif
    5.30 +};
    5.31 +
    5.32 +float4 Texel_Sizes : register (SHADER_SPECIFIC_CONST_0);
    5.33 +
    5.34 +VS_OUTPUT main( const VS_INPUT v )
    5.35 +{
    5.36 +	VS_OUTPUT o = ( VS_OUTPUT )0;
    5.37 +
    5.38 +	o.projPos = float4( v.vPos, 1.0f );
    5.39 +	o.baseTexCoord = v.vBaseTexCoord;
    5.40 +	o.ZeroTexCoord=float2(0,0);
    5.41 +	o.bloomTexCoord.x=v.vBaseTexCoord.x+Texel_Sizes.z;
    5.42 +	o.bloomTexCoord.y=v.vBaseTexCoord.y+Texel_Sizes.w;
    5.43 +
    5.44 +	#if X360APPCHOOSER
    5.45 +		o.vColor.rgba = v.vColor.rgba;
    5.46 +		o.projPos.xyzw = mul( float4( v.vPos.xyz, 1.0f ), cModelViewProj );
    5.47 +	#endif
    5.48 +
    5.49 +	return o;
    5.50 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/materialsystem/stdshaders/fxctmp9/SDK_Bloom_ps20.inc	Tue Jul 30 15:10:15 2013 -0700
     6.3 @@ -0,0 +1,33 @@
     6.4 +#include "shaderlib/cshader.h"
     6.5 +class sdk_bloom_ps20_Static_Index
     6.6 +{
     6.7 +public:
     6.8 +	sdk_bloom_ps20_Static_Index( )
     6.9 +	{
    6.10 +	}
    6.11 +	int GetIndex()
    6.12 +	{
    6.13 +		// Asserts to make sure that we aren't using any skipped combinations.
    6.14 +		// Asserts to make sure that we are setting all of the combination vars.
    6.15 +#ifdef _DEBUG
    6.16 +#endif // _DEBUG
    6.17 +		return 0;
    6.18 +	}
    6.19 +};
    6.20 +#define shaderStaticTest_sdk_bloom_ps20 0
    6.21 +class sdk_bloom_ps20_Dynamic_Index
    6.22 +{
    6.23 +public:
    6.24 +	sdk_bloom_ps20_Dynamic_Index()
    6.25 +	{
    6.26 +	}
    6.27 +	int GetIndex()
    6.28 +	{
    6.29 +		// Asserts to make sure that we aren't using any skipped combinations.
    6.30 +		// Asserts to make sure that we are setting all of the combination vars.
    6.31 +#ifdef _DEBUG
    6.32 +#endif // _DEBUG
    6.33 +		return 0;
    6.34 +	}
    6.35 +};
    6.36 +#define shaderDynamicTest_sdk_bloom_ps20 0
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/materialsystem/stdshaders/fxctmp9/SDK_Bloom_ps20b.inc	Tue Jul 30 15:10:15 2013 -0700
     7.3 @@ -0,0 +1,60 @@
     7.4 +#include "shaderlib/cshader.h"
     7.5 +class sdk_bloom_ps20b_Static_Index
     7.6 +{
     7.7 +private:
     7.8 +	int m_nCONVERT_TO_SRGB;
     7.9 +#ifdef _DEBUG
    7.10 +	bool m_bCONVERT_TO_SRGB;
    7.11 +#endif
    7.12 +public:
    7.13 +	void SetCONVERT_TO_SRGB( int i )
    7.14 +	{
    7.15 +		Assert( i >= 0 && i <= 1 );
    7.16 +		m_nCONVERT_TO_SRGB = i;
    7.17 +#ifdef _DEBUG
    7.18 +		m_bCONVERT_TO_SRGB = true;
    7.19 +#endif
    7.20 +	}
    7.21 +	void SetCONVERT_TO_SRGB( bool i )
    7.22 +	{
    7.23 +		m_nCONVERT_TO_SRGB = i ? 1 : 0;
    7.24 +#ifdef _DEBUG
    7.25 +		m_bCONVERT_TO_SRGB = true;
    7.26 +#endif
    7.27 +	}
    7.28 +public:
    7.29 +	sdk_bloom_ps20b_Static_Index( )
    7.30 +	{
    7.31 +#ifdef _DEBUG
    7.32 +		m_bCONVERT_TO_SRGB = true;
    7.33 +#endif // _DEBUG
    7.34 +		m_nCONVERT_TO_SRGB =  g_pHardwareConfig->NeedsShaderSRGBConversion();
    7.35 +	}
    7.36 +	int GetIndex()
    7.37 +	{
    7.38 +		// Asserts to make sure that we aren't using any skipped combinations.
    7.39 +		// Asserts to make sure that we are setting all of the combination vars.
    7.40 +#ifdef _DEBUG
    7.41 +		bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB;
    7.42 +		Assert( bAllStaticVarsDefined );
    7.43 +#endif // _DEBUG
    7.44 +		return ( 1 * m_nCONVERT_TO_SRGB ) + 0;
    7.45 +	}
    7.46 +};
    7.47 +#define shaderStaticTest_sdk_bloom_ps20b 0
    7.48 +class sdk_bloom_ps20b_Dynamic_Index
    7.49 +{
    7.50 +public:
    7.51 +	sdk_bloom_ps20b_Dynamic_Index()
    7.52 +	{
    7.53 +	}
    7.54 +	int GetIndex()
    7.55 +	{
    7.56 +		// Asserts to make sure that we aren't using any skipped combinations.
    7.57 +		// Asserts to make sure that we are setting all of the combination vars.
    7.58 +#ifdef _DEBUG
    7.59 +#endif // _DEBUG
    7.60 +		return 0;
    7.61 +	}
    7.62 +};
    7.63 +#define shaderDynamicTest_sdk_bloom_ps20b 0
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/materialsystem/stdshaders/fxctmp9/SDK_bloomadd_ps20.inc	Tue Jul 30 15:10:15 2013 -0700
     8.3 @@ -0,0 +1,33 @@
     8.4 +#include "shaderlib/cshader.h"
     8.5 +class sdk_bloomadd_ps20_Static_Index
     8.6 +{
     8.7 +public:
     8.8 +	sdk_bloomadd_ps20_Static_Index( )
     8.9 +	{
    8.10 +	}
    8.11 +	int GetIndex()
    8.12 +	{
    8.13 +		// Asserts to make sure that we aren't using any skipped combinations.
    8.14 +		// Asserts to make sure that we are setting all of the combination vars.
    8.15 +#ifdef _DEBUG
    8.16 +#endif // _DEBUG
    8.17 +		return 0;
    8.18 +	}
    8.19 +};
    8.20 +#define shaderStaticTest_sdk_bloomadd_ps20 0
    8.21 +class sdk_bloomadd_ps20_Dynamic_Index
    8.22 +{
    8.23 +public:
    8.24 +	sdk_bloomadd_ps20_Dynamic_Index()
    8.25 +	{
    8.26 +	}
    8.27 +	int GetIndex()
    8.28 +	{
    8.29 +		// Asserts to make sure that we aren't using any skipped combinations.
    8.30 +		// Asserts to make sure that we are setting all of the combination vars.
    8.31 +#ifdef _DEBUG
    8.32 +#endif // _DEBUG
    8.33 +		return 0;
    8.34 +	}
    8.35 +};
    8.36 +#define shaderDynamicTest_sdk_bloomadd_ps20 0
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/materialsystem/stdshaders/fxctmp9/SDK_bloomadd_ps20b.inc	Tue Jul 30 15:10:15 2013 -0700
     9.3 @@ -0,0 +1,33 @@
     9.4 +#include "shaderlib/cshader.h"
     9.5 +class sdk_bloomadd_ps20b_Static_Index
     9.6 +{
     9.7 +public:
     9.8 +	sdk_bloomadd_ps20b_Static_Index( )
     9.9 +	{
    9.10 +	}
    9.11 +	int GetIndex()
    9.12 +	{
    9.13 +		// Asserts to make sure that we aren't using any skipped combinations.
    9.14 +		// Asserts to make sure that we are setting all of the combination vars.
    9.15 +#ifdef _DEBUG
    9.16 +#endif // _DEBUG
    9.17 +		return 0;
    9.18 +	}
    9.19 +};
    9.20 +#define shaderStaticTest_sdk_bloomadd_ps20b 0
    9.21 +class sdk_bloomadd_ps20b_Dynamic_Index
    9.22 +{
    9.23 +public:
    9.24 +	sdk_bloomadd_ps20b_Dynamic_Index()
    9.25 +	{
    9.26 +	}
    9.27 +	int GetIndex()
    9.28 +	{
    9.29 +		// Asserts to make sure that we aren't using any skipped combinations.
    9.30 +		// Asserts to make sure that we are setting all of the combination vars.
    9.31 +#ifdef _DEBUG
    9.32 +#endif // _DEBUG
    9.33 +		return 0;
    9.34 +	}
    9.35 +};
    9.36 +#define shaderDynamicTest_sdk_bloomadd_ps20b 0
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/materialsystem/stdshaders/fxctmp9/SDK_screenspaceeffect_vs20.inc	Tue Jul 30 15:10:15 2013 -0700
    10.3 @@ -0,0 +1,60 @@
    10.4 +#include "shaderlib/cshader.h"
    10.5 +class sdk_screenspaceeffect_vs20_Static_Index
    10.6 +{
    10.7 +private:
    10.8 +	int m_nX360APPCHOOSER;
    10.9 +#ifdef _DEBUG
   10.10 +	bool m_bX360APPCHOOSER;
   10.11 +#endif
   10.12 +public:
   10.13 +	void SetX360APPCHOOSER( int i )
   10.14 +	{
   10.15 +		Assert( i >= 0 && i <= 1 );
   10.16 +		m_nX360APPCHOOSER = i;
   10.17 +#ifdef _DEBUG
   10.18 +		m_bX360APPCHOOSER = true;
   10.19 +#endif
   10.20 +	}
   10.21 +	void SetX360APPCHOOSER( bool i )
   10.22 +	{
   10.23 +		m_nX360APPCHOOSER = i ? 1 : 0;
   10.24 +#ifdef _DEBUG
   10.25 +		m_bX360APPCHOOSER = true;
   10.26 +#endif
   10.27 +	}
   10.28 +public:
   10.29 +	sdk_screenspaceeffect_vs20_Static_Index( )
   10.30 +	{
   10.31 +#ifdef _DEBUG
   10.32 +		m_bX360APPCHOOSER = true;
   10.33 +#endif // _DEBUG
   10.34 +		m_nX360APPCHOOSER =  0;
   10.35 +	}
   10.36 +	int GetIndex()
   10.37 +	{
   10.38 +		// Asserts to make sure that we aren't using any skipped combinations.
   10.39 +		// Asserts to make sure that we are setting all of the combination vars.
   10.40 +#ifdef _DEBUG
   10.41 +		bool bAllStaticVarsDefined = m_bX360APPCHOOSER;
   10.42 +		Assert( bAllStaticVarsDefined );
   10.43 +#endif // _DEBUG
   10.44 +		return ( 1 * m_nX360APPCHOOSER ) + 0;
   10.45 +	}
   10.46 +};
   10.47 +#define shaderStaticTest_sdk_screenspaceeffect_vs20 0
   10.48 +class sdk_screenspaceeffect_vs20_Dynamic_Index
   10.49 +{
   10.50 +public:
   10.51 +	sdk_screenspaceeffect_vs20_Dynamic_Index()
   10.52 +	{
   10.53 +	}
   10.54 +	int GetIndex()
   10.55 +	{
   10.56 +		// Asserts to make sure that we aren't using any skipped combinations.
   10.57 +		// Asserts to make sure that we are setting all of the combination vars.
   10.58 +#ifdef _DEBUG
   10.59 +#endif // _DEBUG
   10.60 +		return 0;
   10.61 +	}
   10.62 +};
   10.63 +#define shaderDynamicTest_sdk_screenspaceeffect_vs20 0
    11.1 --- a/materialsystem/stdshaders/game_shader_dx9_base.vpc	Thu Jul 18 10:11:37 2013 -0700
    11.2 +++ b/materialsystem/stdshaders/game_shader_dx9_base.vpc	Tue Jul 30 15:10:15 2013 -0700
    11.3 @@ -53,6 +53,9 @@
    11.4  
    11.5  		$File	"example_model_dx9.cpp"
    11.6  		$File	"example_model_dx9_helper.cpp"
    11.7 +
    11.8 +		$File	"Bloom.cpp"
    11.9 +		$File	"screenspace_general.cpp"
   11.10  	}
   11.11  
   11.12  	$Folder	"Header Files"
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/materialsystem/stdshaders/screenspace_general.cpp	Tue Jul 30 15:10:15 2013 -0700
    12.3 @@ -0,0 +1,232 @@
    12.4 +//========= Copyright  1996-2005, Valve Corporation, All rights reserved. ============//
    12.5 +//
    12.6 +// Purpose: 
    12.7 +//
    12.8 +// $NoKeywords: $
    12.9 +//=============================================================================//
   12.10 +
   12.11 +#include "BaseVSShader.h"
   12.12 +
   12.13 +#include "SDK_screenspaceeffect_vs20.inc"
   12.14 +
   12.15 +DEFINE_FALLBACK_SHADER( SDK_screenspace_general, SDK_screenspace_general_dx9 )
   12.16 +BEGIN_VS_SHADER_FLAGS( SDK_screenspace_general_dx9, "Help for screenspace_general", SHADER_NOT_EDITABLE )
   12.17 +	BEGIN_SHADER_PARAMS
   12.18 +		SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.19 +		SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.20 +		SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.21 +		SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.22 +		SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.23 +		SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.24 +		SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.25 +		SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.26 +		SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.27 +		SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.28 +		SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.29 +		SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.30 +		SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.31 +		SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.32 +		SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.33 +		SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.34 +		SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" )
   12.35 +		SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","")
   12.36 +		SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","")
   12.37 +		SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" )
   12.38 +		SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" )
   12.39 +		SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" )
   12.40 +		SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" )
   12.41 +		SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" )
   12.42 +		SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" )
   12.43 +		SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" )
   12.44 +		SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","")
   12.45 +		SHADER_PARAM( X360APPCHOOSER, SHADER_PARAM_TYPE_INTEGER, "0", "Needed for movies in 360 launcher" )
   12.46 +	END_SHADER_PARAMS
   12.47 +
   12.48 +    SHADER_INIT
   12.49 +	{
   12.50 +		if ( params[BASETEXTURE]->IsDefined() )
   12.51 +		{
   12.52 +			LoadTexture( BASETEXTURE );
   12.53 +		}
   12.54 +		if ( params[TEXTURE1]->IsDefined() )
   12.55 +		{
   12.56 +			LoadTexture( TEXTURE1 );
   12.57 +		}
   12.58 +		if ( params[TEXTURE2]->IsDefined() )
   12.59 +		{
   12.60 +			LoadTexture( TEXTURE2 );
   12.61 +		}
   12.62 +		if ( params[TEXTURE3]->IsDefined() )
   12.63 +		{
   12.64 +			LoadTexture( TEXTURE3 );
   12.65 +		}
   12.66 +	}
   12.67 +	
   12.68 +	SHADER_FALLBACK
   12.69 +	{
   12.70 +		if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
   12.71 +		{
   12.72 +			return "screenspace_general_dx8";
   12.73 +		}
   12.74 +
   12.75 +		return 0;
   12.76 +	}
   12.77 +
   12.78 +	SHADER_DRAW
   12.79 +	{
   12.80 +		SHADOW_STATE
   12.81 +		{
   12.82 +			pShaderShadow->EnableDepthWrites( false );
   12.83 +			
   12.84 +			if (params[BASETEXTURE]->IsDefined())
   12.85 +			{
   12.86 +				pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
   12.87 +				ITexture *txtr=params[BASETEXTURE]->GetTextureValue();
   12.88 +				ImageFormat fmt=txtr->GetImageFormat();
   12.89 +				if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
   12.90 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false);
   12.91 +				else
   12.92 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() );
   12.93 +			}				
   12.94 +			if (params[TEXTURE1]->IsDefined())
   12.95 +			{
   12.96 +				pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
   12.97 +				ITexture *txtr=params[TEXTURE1]->GetTextureValue();
   12.98 +				ImageFormat fmt=txtr->GetImageFormat();
   12.99 +				if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  12.100 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false);
  12.101 +				else
  12.102 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() );
  12.103 +			}				
  12.104 +			if (params[TEXTURE2]->IsDefined())
  12.105 +			{
  12.106 +				pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  12.107 +				ITexture *txtr=params[TEXTURE2]->GetTextureValue();
  12.108 +				ImageFormat fmt=txtr->GetImageFormat();
  12.109 +				if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  12.110 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false);
  12.111 +				else
  12.112 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() );
  12.113 +			}				
  12.114 +			if (params[TEXTURE3]->IsDefined())
  12.115 +			{
  12.116 +				pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  12.117 +				ITexture *txtr=params[TEXTURE3]->GetTextureValue();
  12.118 +				ImageFormat fmt=txtr->GetImageFormat();
  12.119 +				if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616))
  12.120 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false);
  12.121 +				else
  12.122 +					pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() );
  12.123 +			}				
  12.124 +			int fmt = VERTEX_POSITION;
  12.125 +
  12.126 +			if ( IS_PARAM_DEFINED( X360APPCHOOSER ) && ( params[X360APPCHOOSER]->GetIntValue() ) )
  12.127 +			{
  12.128 +				fmt |= VERTEX_COLOR;
  12.129 +				EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  12.130 +			}
  12.131 +			pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  12.132 +
  12.133 +			// maybe convert from linear to gamma on write.
  12.134 +			bool srgb_write=true;
  12.135 +			if (params[LINEARWRITE]->GetFloatValue())
  12.136 +				srgb_write=false;
  12.137 +			pShaderShadow->EnableSRGBWrite( srgb_write );
  12.138 +
  12.139 +			// Pre-cache shaders
  12.140 +			DECLARE_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
  12.141 +			SET_STATIC_VERTEX_SHADER_COMBO( X360APPCHOOSER, IS_PARAM_DEFINED( X360APPCHOOSER ) ? params[X360APPCHOOSER]->GetIntValue() : 0 );
  12.142 +			vsh_forgot_to_set_static_X360APPCHOOSER = 0; // This is a dirty workaround to the shortcut [= 0] in the fxc
  12.143 +			SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
  12.144 +
  12.145 +			if (params[DISABLE_COLOR_WRITES]->GetIntValue())
  12.146 +			{
  12.147 +				pShaderShadow->EnableColorWrites(false);
  12.148 +			}
  12.149 +//			if (params[ALPHATESTED]->GetFloatValue())
  12.150 +			{
  12.151 +				pShaderShadow->EnableAlphaTest(true);
  12.152 +				pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0);
  12.153 +			}
  12.154 +			if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  12.155 +			{
  12.156 +				EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  12.157 +			}
  12.158 +
  12.159 +			if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  12.160 +			{
  12.161 +				const char *szPixelShader = params[PIXSHADER]->GetStringValue();
  12.162 +				size_t iLength = Q_strlen( szPixelShader );
  12.163 +
  12.164 +				if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader
  12.165 +				{
  12.166 +					//replace it with the ps20b shader
  12.167 +					char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) );
  12.168 +					memcpy( szNewName, szPixelShader, sizeof( char ) * iLength );
  12.169 +					szNewName[iLength] = 'b';
  12.170 +					szNewName[iLength + 1] = '\0';
  12.171 +					pShaderShadow->SetPixelShader( szNewName, 0 );
  12.172 +				}
  12.173 +				else
  12.174 +				{
  12.175 +					pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  12.176 +				}
  12.177 +			}
  12.178 +			else
  12.179 +			{
  12.180 +				pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 );
  12.181 +			}
  12.182 +		}
  12.183 +
  12.184 +		DYNAMIC_STATE
  12.185 +		{
  12.186 +			if (params[BASETEXTURE]->IsDefined())
  12.187 +			{
  12.188 +				BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 );
  12.189 +			}
  12.190 +			if (params[TEXTURE1]->IsDefined())
  12.191 +			{
  12.192 +				BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 );
  12.193 +			}
  12.194 +			if (params[TEXTURE2]->IsDefined())
  12.195 +			{
  12.196 +				BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 );
  12.197 +			}
  12.198 +			if (params[TEXTURE3]->IsDefined())
  12.199 +			{
  12.200 +				BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 );
  12.201 +			}
  12.202 +			float c0[]={
  12.203 +				params[C0_X]->GetFloatValue(),
  12.204 +				params[C0_Y]->GetFloatValue(),
  12.205 +				params[C0_Z]->GetFloatValue(),
  12.206 +				params[C0_W]->GetFloatValue(),
  12.207 +				params[C1_X]->GetFloatValue(),
  12.208 +				params[C1_Y]->GetFloatValue(),
  12.209 +				params[C1_Z]->GetFloatValue(),
  12.210 +				params[C1_W]->GetFloatValue(),
  12.211 +				params[C2_X]->GetFloatValue(),
  12.212 +				params[C2_Y]->GetFloatValue(),
  12.213 +				params[C2_Z]->GetFloatValue(),
  12.214 +				params[C2_W]->GetFloatValue(),
  12.215 +				params[C3_X]->GetFloatValue(),
  12.216 +				params[C3_Y]->GetFloatValue(),
  12.217 +				params[C3_Z]->GetFloatValue(),
  12.218 +				params[C3_W]->GetFloatValue()
  12.219 +			};
  12.220 +
  12.221 +			pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 );
  12.222 +
  12.223 +			float eyePos[4];
  12.224 +			pShaderAPI->GetWorldSpaceCameraPosition( eyePos );
  12.225 +			pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 );
  12.226 +
  12.227 +			pShaderAPI->SetVertexShaderIndex( 0 );
  12.228 +			pShaderAPI->SetPixelShaderIndex( 0 );
  12.229 +
  12.230 +			DECLARE_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
  12.231 +			SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
  12.232 +		}
  12.233 +		Draw();
  12.234 +	}
  12.235 +END_SHADER
    13.1 --- a/materialsystem/stdshaders/stdshader_dx9_20b.txt	Thu Jul 18 10:11:37 2013 -0700
    13.2 +++ b/materialsystem/stdshaders/stdshader_dx9_20b.txt	Tue Jul 30 15:10:15 2013 -0700
    13.3 @@ -9,3 +9,8 @@
    13.4  
    13.5  example_model_ps20b.fxc
    13.6  example_model_vs20.fxc
    13.7 +
    13.8 +SDK_Bloom_ps2x.fxc
    13.9 +SDK_screenspaceeffect_vs20.fxc
   13.10 +
   13.11 +SDK_bloomadd_ps2x.fxc