aboutsummaryrefslogtreecommitdiff
path: root/mp/src/materialsystem/stdshaders/cable_dx8.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-12-23 14:58:45 -0800
committerJoe Ludwig <[email protected]>2013-12-23 15:00:03 -0800
commit7309a5f13f63fdcc7b1e090f6c176113a9d95061 (patch)
treead65c7fbe46a3c70bdc0a1426e88247ce1b0d7f5 /mp/src/materialsystem/stdshaders/cable_dx8.cpp
parentMerge pull request #182 from ardneran/master (diff)
downloadsource-sdk-2013-7309a5f13f63fdcc7b1e090f6c176113a9d95061.tar.xz
source-sdk-2013-7309a5f13f63fdcc7b1e090f6c176113a9d95061.zip
Added many shader source files
This should include the latest version of every shader that was in the 2007 SDK. It also includes a smattering of debug shaders, both VR distortion shaders, and other assorted shaders that will hopefully be useful. None of these new files are included in the game shader DLL project. If you need to modify one of these shaders for use in your mod you will need to rename it so that you don't collide with the version of that shader that lives in stdshader_dx9.dll.
Diffstat (limited to 'mp/src/materialsystem/stdshaders/cable_dx8.cpp')
-rw-r--r--mp/src/materialsystem/stdshaders/cable_dx8.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/mp/src/materialsystem/stdshaders/cable_dx8.cpp b/mp/src/materialsystem/stdshaders/cable_dx8.cpp
new file mode 100644
index 00000000..9e3c98dd
--- /dev/null
+++ b/mp/src/materialsystem/stdshaders/cable_dx8.cpp
@@ -0,0 +1,132 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: A wet version of base * lightmap
+//
+// $Header: $
+// $NoKeywords: $
+//===========================================================================//
+
+#include "BaseVSShader.h"
+
+#include "cable.inc"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+DEFINE_FALLBACK_SHADER( Cable, Cable_DX8 )
+
+BEGIN_VS_SHADER( Cable_DX8,
+ "Help for Cable shader" )
+ BEGIN_SHADER_PARAMS
+ SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "cable/cablenormalmap", "bumpmap texture" )
+ SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.1", "Minimum amount of light (0-1 value)" )
+ SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.3", "Maximum amount of light" )
+ END_SHADER_PARAMS
+
+ SHADER_FALLBACK
+ {
+ if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders())
+ {
+ return "UnlitGeneric_DX6";
+ }
+ return 0;
+ }
+
+ SHADER_INIT
+ {
+ LoadBumpMap( BUMPMAP );
+ LoadTexture( BASETEXTURE );
+ }
+
+ SHADER_DRAW
+ {
+ SHADOW_STATE
+ {
+ // Enable blending?
+ if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) )
+ {
+ pShaderShadow->EnableDepthWrites( false );
+ pShaderShadow->EnableBlending( true );
+ pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
+ }
+
+ pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) );
+
+ pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
+ pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
+ if ( g_pHardwareConfig->GetDXSupportLevel() >= 90)
+ {
+ pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
+ }
+
+ int tCoordDimensions[] = {2,2};
+ pShaderShadow->VertexShaderVertexFormat(
+ VERTEX_POSITION | VERTEX_COLOR | VERTEX_TANGENT_S | VERTEX_TANGENT_T,
+ 2, tCoordDimensions, 0 );
+
+ cable_Static_Index vshIndex;
+ pShaderShadow->SetVertexShader( "Cable", vshIndex.GetIndex() );
+
+ pShaderShadow->SetPixelShader( "Cable" );
+
+ // we are writing linear values from this shader.
+ // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
+ // The COLOR really decides if we are gamma or linear.
+ if ( g_pHardwareConfig->GetDXSupportLevel() >= 90)
+ {
+ pShaderShadow->EnableSRGBWrite( true );
+ }
+
+ FogToFogColor();
+ }
+ DYNAMIC_STATE
+ {
+ BindTexture( SHADER_SAMPLER0, BUMPMAP );
+ BindTexture( SHADER_SAMPLER1, BASETEXTURE );
+
+
+ // The dot product with the light is remapped from the range
+ // [-1,1] to [MinLight, MaxLight].
+
+ // Given:
+ // -A + B = MinLight
+ // A + B = MaxLight
+ // then A = (MaxLight - MinLight) / 2
+ // and B = (MaxLight + MinLight) / 2
+
+ // So here, we multiply the light direction by A to scale the dot product.
+ // Then in the pixel shader we add by B.
+ float flMinLight = params[MINLIGHT]->GetFloatValue();
+ float flMaxLight = params[MAXLIGHT]->GetFloatValue();
+
+ float A = (flMaxLight - flMinLight) * 0.5f;
+ float B = (flMaxLight + flMinLight) * 0.5f;
+
+ float b4[4] = {B,B,B,B};
+ if( g_pHardwareConfig->GetDXSupportLevel() >= 90)
+ {
+ SetPixelShaderConstantGammaToLinear( 0, b4 );
+ }
+ else
+ {
+ pShaderAPI->SetPixelShaderConstant( 0, b4 );
+ }
+
+ // This is the light direction [0,1,0,0] * A * 0.5
+ float lightDir[4] = {0, A*0.5, 0, 0};
+ if( g_pHardwareConfig->GetDXSupportLevel() >= 90)
+ {
+ SetVertexShaderConstantGammaToLinear( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lightDir );
+ }
+ else
+ {
+ pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lightDir );
+ }
+
+ cable_Dynamic_Index vshIndex;
+ vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
+ pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
+ }
+ Draw();
+ }
+END_SHADER