1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
|