Wraiyth tutorial is quite outdated at some places. I don't remember if
it worked with post_sepia_vs20.inc or SDK_screenspaceeffect_vs20.inc.
I had some problems with it so I can paste here my code:
post_sepia.cpp:
/*#include "BaseVSShader.h"
#include "post_sepia_ps20.inc"
#include "post_sepia_vs20.inc"
//#include "SDK_screenspaceeffect_vs20.inc"
BEGIN_VS_SHADER( Post_Sepia, "Help for Post_Sepia" )
BEGIN_SHADER_PARAMS
SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB",
"" )
END_SHADER_PARAMS
// Set up anything that is necessary to make decisions in
SHADER_FALLBACK.
SHADER_INIT_PARAMS()
{
}
SHADER_FALLBACK
{
return 0;
}
SHADER_INIT
{
if( params[FBTEXTURE]->IsDefined() )
{
LoadTexture( FBTEXTURE );
}
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true);
int fmt = VERTEX_POSITION | VERTEX_FORMAT_VERTEX_SHADER;
int texCoordDimensions [] = { 2 };
pShaderShadow->VertexShaderVertexFormat( fmt, 1,
texCoordDimensions, 0 );
DECLARE_STATIC_PIXEL_SHADER( post_sepia_ps20 );
SET_STATIC_PIXEL_SHADER( post_sepia_ps20 );
DECLARE_STATIC_VERTEX_SHADER( post_sepia_vs20 );
SET_STATIC_VERTEX_SHADER( post_sepia_vs20 );
}
DYNAMIC_STATE
{
if (params[FBTEXTURE]->IsDefined ())
BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
DECLARE_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
SET_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
DECLARE_DYNAMIC_VERTEX_SHADER( post_sepia_vs20 );
SET_DYNAMIC_VERTEX_SHADER( post_sepia_vs20 );
}
Draw();
}
END_SHADER
*/
#include "BaseVSShader.h"
#include "SDK_screenspaceeffect_vs20.inc"
#include "post_sepia_ps20.inc"
BEGIN_VS_SHADER_FLAGS( Post_Sepia, "Help for Sepia", SHADER_NOT_EDITABLE )
BEGIN_SHADER_PARAMS
SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE,
"_rt_FullFrameFB", "" )
//SHADER_PARAM( BLURTEXTURE, SHADER_PARAM_TYPE_TEXTURE,
"_rt_SmallHDR0", "" )
END_SHADER_PARAMS
SHADER_INIT
{
if( params[FBTEXTURE]->IsDefined() )
{
LoadTexture( FBTEXTURE );
}
// if( params[BLURTEXTURE]->IsDefined() )
//{
//LoadTexture( BLURTEXTURE );
//}
}
SHADER_FALLBACK
{
// Requires DX9 + above
if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
{
Assert( 0 );
return "Wireframe";
}
return 0;
}
SHADER_DRAW
{
SHADOW_STATE
{
pShaderShadow->EnableDepthWrites( false );
pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
//pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
int fmt = VERTEX_POSITION;
pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
// Pre-cache shaders
DECLARE_STATIC_VERTEX_SHADER(
sdk_screenspaceeffect_vs20 );
SET_STATIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
//if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
//{
//DECLARE_STATIC_PIXEL_SHADER( sdk_bloom_ps20b
);
//SET_STATIC_PIXEL_SHADER( sdk_bloom_ps20b );
//}
//else
//{
DECLARE_STATIC_PIXEL_SHADER( post_sepia_ps20 );
SET_STATIC_PIXEL_SHADER( post_sepia_ps20 );
//}
}
DYNAMIC_STATE
{
BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 );
//BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 );
DECLARE_DYNAMIC_VERTEX_SHADER(
sdk_screenspaceeffect_vs20 );
SET_DYNAMIC_VERTEX_SHADER( sdk_screenspaceeffect_vs20 );
//if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
//{
//DECLARE_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b
);
//SET_DYNAMIC_PIXEL_SHADER( sdk_bloom_ps20b );
//}
//else
//{
DECLARE_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
SET_DYNAMIC_PIXEL_SHADER( post_sepia_ps20 );
//}
}
Draw();
}
END_SHADER
post_sepia_ps20.fxc:
#include "common_ps_fxc.h"
sampler BaseTextureSampler : register( s0 );
HALF4 main(float2 iTexCoord : TEXCOORD0) : COLOR
{
float4 vWeightsBW=float4(0.3,0.59,0.11,0);
float4 vWeightsSepia=float4(0.9,0.7,0.3,1);
float4 cColor=tex2D(BaseTextureSampler,iTexCoord);
float4 cTempColor=dot(cColor,vWeightsBW);
return dot(cTempColor,vWeightsSepia);
}
post_sepia_vs20.fxc:
#include "common_vs_fxc.h"
struct VS_INPUT
{
float3 position : POSITION;
float2 texCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 position : POSITION;
float2 texCoord : TEXCOORD0;
};
VS_OUTPUT main(const VS_INPUT v)
{
VS_OUTPUT o = (VS_OUTPUT) 0;
o.position = float4(v.position,1.0);
o.texCoord = v.texCoord;
return o;
}
materials/shaders/post_sepia:
"Post_Sepia"
{
"$fbtexture" "_rt_FullFrameFB"
}
ScreenSpaceEffects.cpp:
ADD_SCREENSPACE_EFFECT( CExampleEffect, exampleeffect );
//------------------------------------------------------------------------------
// CExampleEffect constructor
//------------------------------------------------------------------------------
CExampleEffect::CExampleEffect( )
{
m_bEnable = false;
}
//------------------------------------------------------------------------------
// CExampleEffect destructor
//------------------------------------------------------------------------------
CExampleEffect::~CExampleEffect( )
{
}
//------------------------------------------------------------------------------
// CExampleEffect init
//------------------------------------------------------------------------------
void CExampleEffect::Init( )
{
// This is just example code, init your effect material here
//m_Material.Init( "engine/exampleeffect", TEXTURE_GROUP_OTHER );
m_Material.Init( "shaders/post_sepia", TEXTURE_GROUP_CLIENT_EFFECTS );
VertexFormat_t fmt = m_Material->GetVertexFormat ();
m_bEnable = false;
}
//------------------------------------------------------------------------------
// CExampleEffect shutdown
//------------------------------------------------------------------------------
void CExampleEffect::Shutdown( )
{
m_Material.Shutdown();
}
//------------------------------------------------------------------------------
// CExampleEffect enable
//------------------------------------------------------------------------------
void CExampleEffect::Enable( bool bEnable )
{
// This is just example code, don't enable it
m_bEnable = bEnable;
}
bool CExampleEffect::IsEnabled( )
{
return m_bEnable;
}
//------------------------------------------------------------------------------
// CExampleEffect SetParameters
//------------------------------------------------------------------------------
void CExampleEffect::SetParameters( KeyValues *params )
{
}
//------------------------------------------------------------------------------
// CExampleEffect render
//------------------------------------------------------------------------------
void CExampleEffect::Render( int x, int y, int w, int h )
{
if ( !IsEnabled() )
return;
// Render Effect
Rect_t actualRect;
UpdateScreenEffectTexture( 0, x, y, w, h, false, &actualRect );
ITexture *pTexture = GetFullFrameFrameBufferTexture( 0 );
CMatRenderContextPtr pRenderContext( materials );
bool found = false;
IMaterialVar *fbtexturevar = m_Material->FindVar ("$fbtexture", &found);
if (fbtexturevar && pTexture)
fbtexturevar->SetTextureValue (pTexture);
pRenderContext->DrawScreenSpaceRectangle( m_Material, x, y, w, h,
actualRect.x, actualRect.y,
actualRect.x+actualRect.width-1, actualRect.y+actualRect.height-1,
pTexture->GetActualWidth(), pTexture->GetActualHeight() );
}
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders