Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

231 lines
11 KiB

//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $Header: $
// $NoKeywords: $
//===========================================================================//
#include "BaseVSShader.h"
#include "vertexlitgeneric_dx9_helper.h"
#include "shaderapifast.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
BEGIN_VS_SHADER( UnlitGeneric, "Help for UnlitGeneric" )
BEGIN_SHADER_PARAMS
SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
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( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "envmap frame number" )
SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
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( 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( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" )
SHADER_PARAM( VERTEXALPHATEST, SHADER_PARAM_TYPE_INTEGER, "0", "" )
SHADER_PARAM( HDRCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "hdr color scale" )
SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" )
SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" )
SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" )
SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "2D map for warping specular" )
SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" )
SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" )
SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" )
SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" )
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( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" )
SHADER_PARAM( DECALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Decal texture" )
SHADER_PARAM( DECALBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining decal texture with base. 0=normal(decal*srca + base*(1-srca), 1= mod, 2=mod2x, 3=additive" )
SHADER_PARAM( DISTANCEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use distance-coded alpha generated from hi-res texture by vtex.")
SHADER_PARAM( DISTANCEALPHAFROMDETAIL, SHADER_PARAM_TYPE_BOOL, "0", "Take the distance-coded alpha mask from the detail texture.")
SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
SHADER_PARAM( SCALEEDGESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft edges based upon resolution. 1024x768 = nominal.")
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( GLOW, SHADER_PARAM_TYPE_BOOL, "0", "Enable glow/shadow for distance coded textures.")
SHADER_PARAM( GLOWCOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outter glow for distance coded line art." )
SHADER_PARAM( GLOWALPHA, SHADER_PARAM_TYPE_FLOAT, "1", "Base glow alpha amount for glows/shadows with distance alpha." )
SHADER_PARAM( GLOWSTART, SHADER_PARAM_TYPE_FLOAT, "0.7", "start value for glow/shadow")
SHADER_PARAM( GLOWEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "end value for glow/shadow")
SHADER_PARAM( GLOWX, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset x for glow mask.")
SHADER_PARAM( GLOWY, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset y for glow mask.")
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( SCALEOUTLINESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft part of the outline based upon resolution. 1024x768 = nominal.")
SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" )
SHADER_PARAM( GAMMACOLORREAD, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of color texture read." )
SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." )
SHADER_PARAM( RECEIVEFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Forces this material to receive flashlights." )
SHADER_PARAM( SINGLEPASSFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Flags this material as possibly being run through single pass flashlight code" )
SHADER_PARAM( DISPLACEMENTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Displacement map" )
SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
SHADER_PARAM( TINTMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Separate tint mask texture (as opposed to using basetexture alpha)" )
END_SHADER_PARAMS
void SetupVars( VertexLitGeneric_DX9_Vars_t& info )
{
info.m_nBaseTexture = BASETEXTURE;
info.m_nBaseTextureFrame = FRAME;
info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
info.m_nAlbedo = ALBEDO;
info.m_nSelfIllumTint = -1;
info.m_nDetail = DETAIL;
info.m_nDetailFrame = DETAILFRAME;
info.m_nDetailScale = DETAILSCALE;
info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM;
info.m_nDecalTexture = DECALTEXTURE;
info.m_nDecalTextureCombineMode = DECALBLENDMODE;
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 = -1;
info.m_nBumpFrame = -1;
info.m_nBumpTransform = -1;
info.m_nEnvmapContrast = ENVMAPCONTRAST;
info.m_nEnvmapSaturation = ENVMAPSATURATION;
info.m_nAlphaTestReference = ALPHATESTREFERENCE;
info.m_nVertexAlphaTest = VERTEXALPHATEST;
info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
info.m_nHDRColorScale = HDRCOLORSCALE;
info.m_nPhongExponent = -1;
info.m_nPhongExponentTexture = -1;
info.m_nDiffuseWarpTexture = -1;
info.m_nPhongWarpTexture = -1;
info.m_nPhongBoost = -1;
info.m_nPhongFresnelRanges = -1;
info.m_nPhong = -1;
info.m_nForcePhong = -1;
info.m_nPhongTint = -1;
info.m_nPhongAlbedoTint = -1;
info.m_nSelfIllumEnvMapMask_Alpha = -1;
info.m_nAmbientOnly = -1;
info.m_nBaseMapAlphaPhongMask = -1;
info.m_nEnvmapFresnel = -1;
info.m_nSelfIllumMask = -1;
info.m_nAmbientOcclusion = -1;
info.m_nBaseMapLuminancePhongMask = -1;
info.m_nDistanceAlpha = DISTANCEALPHA;
info.m_nDistanceAlphaFromDetail = DISTANCEALPHAFROMDETAIL;
info.m_nSoftEdges = SOFTEDGES;
info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART;
info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND;
info.m_nScaleEdgeSoftnessBasedOnScreenRes = SCALEEDGESOFTNESSBASEDONSCREENRES;
info.m_nGlow = GLOW;
info.m_nGlowColor = GLOWCOLOR;
info.m_nGlowAlpha = GLOWALPHA;
info.m_nGlowStart = GLOWSTART;
info.m_nGlowEnd = GLOWEND;
info.m_nGlowX = GLOWX;
info.m_nGlowY = GLOWY;
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_nScaleOutlineSoftnessBasedOnScreenRes = SCALEOUTLINESOFTNESSBASEDONSCREENRES;
info.m_nSeparateDetailUVs = SEPARATEDETAILUVS;
info.m_nLinearWrite = LINEARWRITE;
info.m_nGammaColorRead = GAMMACOLORREAD;
info.m_nReceiveFlashlight = RECEIVEFLASHLIGHT;
info.m_nSinglePassFlashlight = SINGLEPASSFLASHLIGHT;
info.m_nShaderSrgbRead360 = SHADERSRGBREAD360;
info.m_nDisplacementMap = DISPLACEMENTMAP;
info.m_nTintMaskTexture = TINTMASKTEXTURE;
}
SHADER_INIT_PARAMS()
{
VertexLitGeneric_DX9_Vars_t vars;
SetupVars( vars );
InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, false, vars );
}
SHADER_FALLBACK
{
return 0;
}
SHADER_INIT
{
VertexLitGeneric_DX9_Vars_t vars;
SetupVars( vars );
InitVertexLitGeneric_DX9( this, params, false, vars );
}
SHADER_DRAW
{
VertexLitGeneric_DX9_Vars_t vars;
SetupVars( vars );
if ( ( pShaderShadow == NULL ) && ( pShaderAPI != NULL ) && (params[RECEIVEFLASHLIGHT]->GetIntValue() == 0) && ShaderApiFast( pShaderAPI )->InFlashlightMode() && !( IsX360() || IsPS3() ) ) // Not snapshotting && flashlight pass
{
// Don't go in here on the 360/PS3 with single-pass flashlight, because there is no 2nd draw call for this material.
// FIXME: Is the !IsX360/PS3() test too broad?
Draw( false );
}
else
{
DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, false, vars, vertexCompression, pContextDataPtr );
}
}
void ExecuteFastPath( int *dynVSIdx, int *dynPSIdx, IMaterialVar** params, IShaderDynamicAPI * pShaderAPI,
VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, BOOL bCSMEnabled )
{
*dynVSIdx = -1;
*dynPSIdx = -1;
VertexLitGeneric_DX9_Vars_t vars;
SetupVars( vars );
// Only draw standard pass for now
DrawVertexLitGeneric_DX9_ExecuteFastPath( dynVSIdx, dynPSIdx, this, params, pShaderAPI, vars, vertexCompression,
pContextDataPtr, bCSMEnabled, false );
}
END_SHADER