-
Notifications
You must be signed in to change notification settings - Fork 24
/
lightmappedgeneric_dx9.cpp
216 lines (183 loc) · 10.5 KB
/
lightmappedgeneric_dx9.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Lightmap only shader
//
// $Header: $
// $NoKeywords: $
//=============================================================================//
#include "BaseVSShader.h"
#include "convar.h"
#include "lightmappedgeneric_dx9_helper.h"
#include "lightmappedpaint_dx9_helper.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
ConVar r_twopasspaint( "r_twopasspaint", "1", 0, "HAZARD: Only change this outside a map. Enable two-pass paint method. You will need to reload all materials when changing this convar" );
static LightmappedGeneric_DX9_Vars_t s_info;
BEGIN_VS_SHADER( LightmappedGeneric,
"Help for LightmappedGeneric" )
BEGIN_SHADER_PARAMS
SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
SHADER_PARAM( ALPHA2, SHADER_PARAM_TYPE_FLOAT, "1", "" )
// detail (multi-) texturing
SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" )
SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" )
SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" )
SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
SHADER_PARAM( BUMPMASK, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture" )
SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" )
SHADER_PARAM( BASETEXTURENOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" )
SHADER_PARAM( BASETEXTURE2NOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" )
SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0",
"If this is 1, then when detail alpha=0, no base texture is blended and when "
"detail alpha=1, you get detail*base*lightmap" )
SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "light munging lookup texture" )
SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" )
SHADER_PARAM( MASKEDBLENDING, SHADER_PARAM_TYPE_INTEGER, "0", "blend using texture with no vertex alpha. For using texture blending on non-displacements" )
SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" )
SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha.");
SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha.");
SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.")
SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." )
SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline")
SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline")
SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline")
SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline")
SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline")
SHADER_PARAM( PARALLAXMAP, SHADER_PARAM_TYPE_INTEGER, "0", "1=treat alpha of bumpmap as height" )
SHADER_PARAM( HEIGHT_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.1", "height map scale for parallax mapping" )
SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
SHADER_PARAM( ENVMAPLIGHTSCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much the lightmap effects environment map reflection, 0.0 is off, 1.0 will allow complete blackness of the environment map if the lightmap is black" )
SHADER_PARAM( FOW, SHADER_PARAM_TYPE_TEXTURE, "", "FoW Render Target" )
SHADER_PARAM( PAINTSPLATNORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "paint/splatnormal_default", "The paint splat normal map to use when paint is enabled on the surface" )
SHADER_PARAM( PAINTSPLATENVMAP, SHADER_PARAM_TYPE_TEXTURE, "env_cubemap", "The envmap to use on the paint pass. You're getting one whether you like it or not" )
END_SHADER_PARAMS
void SetupVars( LightmappedGeneric_DX9_Vars_t& info )
{
info.m_nBaseTexture = BASETEXTURE;
info.m_nBaseTextureFrame = FRAME;
info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
info.m_nAlbedo = ALBEDO;
info.m_nSelfIllumTint = SELFILLUMTINT;
info.m_nAlpha2 = ALPHA2;
info.m_nDetail = DETAIL;
info.m_nDetailFrame = DETAILFRAME;
info.m_nDetailScale = DETAILSCALE;
info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
info.m_nDetailTint = DETAILTINT;
info.m_nEnvmap = ENVMAP;
info.m_nEnvmapFrame = ENVMAPFRAME;
info.m_nEnvmapMask = ENVMAPMASK;
info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
info.m_nEnvmapTint = ENVMAPTINT;
info.m_nBumpmap = BUMPMAP;
info.m_nBumpFrame = BUMPFRAME;
info.m_nBumpTransform = BUMPTRANSFORM;
info.m_nEnvmapContrast = ENVMAPCONTRAST;
info.m_nEnvmapSaturation = ENVMAPSATURATION;
info.m_nFresnelReflection = FRESNELREFLECTION;
info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING;
info.m_nBumpmap2 = BUMPMAP2;
info.m_nBumpFrame2 = BUMPFRAME2;
info.m_nBumpTransform2 = BUMPTRANSFORM2;
info.m_nBumpMask = BUMPMASK;
info.m_nBaseTexture2 = BASETEXTURE2;
info.m_nBaseTexture2Frame = FRAME2;
info.m_nBaseTextureNoEnvmap = BASETEXTURENOENVMAP;
info.m_nBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP;
info.m_nDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE;
info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
info.m_nLightWarpTexture = LIGHTWARPTEXTURE;
info.m_nBlendModulateTexture = BLENDMODULATETEXTURE;
info.m_nMaskedBlending = MASKEDBLENDING;
info.m_nBlendMaskTransform = BLENDMASKTRANSFORM;
info.m_nSelfShadowedBumpFlag = SSBUMP;
info.m_nSeamlessMappingScale = SEAMLESS_SCALE;
info.m_nAlphaTestReference = ALPHATESTREFERENCE;
info.m_nSoftEdges = SOFTEDGES;
info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART;
info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND;
info.m_nOutline = OUTLINE;
info.m_nOutlineColor = OUTLINECOLOR;
info.m_nOutlineAlpha = OUTLINEALPHA;
info.m_nOutlineStart0 = OUTLINESTART0;
info.m_nOutlineStart1 = OUTLINESTART1;
info.m_nOutlineEnd0 = OUTLINEEND0;
info.m_nOutlineEnd1 = OUTLINEEND1;
info.m_nParallaxMap = PARALLAXMAP;
info.m_nHeightScale = HEIGHT_SCALE;
info.m_nShaderSrgbRead360 = SHADERSRGBREAD360;
info.m_nEnvMapLightScale = ENVMAPLIGHTSCALE;
info.m_nFoW = FOW;
info.m_nPaintSplatNormal = PAINTSPLATNORMALMAP;
info.m_nPaintSplatEnvMap = PAINTSPLATENVMAP;
}
SHADER_FALLBACK
{
return 0;
}
// Set up anything that is necessary to make decisions in SHADER_FALLBACK.
SHADER_INIT_PARAMS()
{
SetupVars( s_info );
InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info );
}
SHADER_INIT
{
SetupVars( s_info );
InitLightmappedGeneric_DX9( this, params, s_info );
}
SHADER_DRAW
{
DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
// If the game/mod can potentially support the paint feature, then we need to always record snapshots
// as though there may be a 2nd pass. When in a map containing paint, you need to also draw the 2nd pass.
if ( g_pConfig->m_bPaintInGame )
{
// If recording snapshots OR in a map with paint...
if ( ( pShaderShadow || g_pConfig->m_bPaintInMap ) && r_twopasspaint.GetBool() )
{
#ifdef _X360
// Do not render paint during the auto Z pass on Xbox 360
if ( pShaderAPI )
pShaderAPI->EnablePredication( false, true );
#endif // _X360
DrawLightmappedPaint_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
#ifdef _X360
if ( pShaderAPI )
pShaderAPI->DisablePredication();
#endif // _X360
}
else
{
Draw( false );
}
}
}
END_SHADER