📄 vertexlit_and_unlit_generic_ps20.fxc
字号:
// STATIC: "BASETEXTURE" "0..1"
// STATIC: "DETAILTEXTURE" "0..1"
// STATIC: "BUMPMAP" "0..1"
// STATIC: "CUBEMAP" "0..1"
// STATIC: "DIFFUSELIGHTING" "0..1"
// STATIC: "ENVMAPMASK" "0..1"
// STATIC: "BASEALPHAENVMAPMASK" "0..1"
// STATIC: "SELFILLUM" "0..1"
// STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "VERTEXALPHA" "0..1"
// SKIP: $DETAILTEXTURE && $BUMPMAP
// SKIP: $ENVMAPMASK && $BUMPMAP
// SKIP: $NORMALMAPALPHAENVMAPMASK && $BASEALPHAENVMAPMASK
// SKIP: $NORMALMAPALPHAENVMAPMASK && $ENVMAPMASK
// SKIP: $BASEALPHAENVMAPMASK && $ENVMAPMASK
// SKIP: $BASEALPHAENVMAPMASK && $SELFILLUM
#include "common_ps_fxc.h"
const HALF4 g_EnvmapTint : register( c0 );
const HALF4 g_DiffuseModulation : register( c1 );
const HALF3 g_EnvmapContrast : register( c2 );
const HALF3 g_EnvmapSaturation : register( c3 );
const HALF4 g_OverbrightFactor : register( c4 );
const HALF4 g_SelfIllumTint : register( c5 );
sampler BaseTextureSampler : register( s0 );
sampler EnvmapSampler : register( s1 );
sampler DetailSampler : register( s2 );
sampler BumpmapSampler : register( s3 );
sampler EnvmapMaskSampler : register( s4 );
struct PS_INPUT
{
HALF2 baseTexCoord : TEXCOORD0;
// detail textures and bumpmaps are mutually exclusive so that we have enough texcoords.
HALF2 detailOrBumpTexCoord : TEXCOORD1;
// bump mapping and a separate envmap mask texture are mutually exclusive.
HALF2 envmapMaskTexCoord : TEXCOORD2;
HALF3 worldVertToEyeVector : TEXCOORD3;
HALF3x3 tangentSpaceTranspose : TEXCOORD4;
HALF4 color1 : COLOR0;
HALF3 color2 : COLOR1;
HALF3 color3 : TEXCOORD7;
};
HALF4 main( PS_INPUT i ) : COLOR
{
bool bBaseTexture = BASETEXTURE ? true : false;
bool bDetailTexture = DETAILTEXTURE ? true : false;
bool bBumpmap = BUMPMAP ? true : false;
bool bCubemap = CUBEMAP ? true : false;
bool bDiffuseLighting = DIFFUSELIGHTING ? true : false;
bool bEnvmapMask = ENVMAPMASK ? true : false;
bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false;
bool bSelfIllum = SELFILLUM ? true : false;
bool bNormalMapAlphaEnvmapMask = NORMALMAPALPHAENVMAPMASK ? true : false;
bool bVertexColor = VERTEXCOLOR ? true : false;
bool bVertexAlpha = VERTEXALPHA ? true : false;
// hack hack hack
// I need to fix this and all vmts that use it since it's screwed up in lightmappedgeneric_dx8.
if( bCubemap && bBumpmap )
{
bNormalMapAlphaEnvmapMask = true;
}
HALF4 baseColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f );
if( bBaseTexture )
{
baseColor = tex2D( BaseTextureSampler, i.baseTexCoord );
}
HALF3 detailColor = HALF3( 1.0f, 1.0f, 1.0f );
if( bDetailTexture )
{
detailColor = 2.0 * tex2D( DetailSampler, i.detailOrBumpTexCoord );
}
HALF3 specularFactor = 1.0f;
HALF3 tangentSpaceNormal = HALF3( 0.0f, 0.0f, 1.0f );
HALF4 normalTexel = 1.0f;
if( bBumpmap )
{
normalTexel = tex2D( BumpmapSampler, i.detailOrBumpTexCoord );
if( bNormalMapAlphaEnvmapMask )
{
specularFactor *= normalTexel.a;
}
tangentSpaceNormal = 2.0 * normalTexel - 1.0;
}
HALF4 envmapMaskTexel;
if( bEnvmapMask )
{
envmapMaskTexel = tex2D( EnvmapMaskSampler, i.envmapMaskTexCoord );
specularFactor *= envmapMaskTexel.xyz;
}
if( bBaseAlphaEnvmapMask )
{
specularFactor *= 1.0 - baseColor.a; // this blows!
}
HALF3 diffuseLighting = HALF3( 1.0f, 1.0f, 1.0f );
if( bDiffuseLighting )
{
if( bBumpmap )
{
diffuseLighting = saturate( dot( tangentSpaceNormal, bumpBasis[0] ) ) * i.color1.rgb +
saturate( dot( tangentSpaceNormal, bumpBasis[1] ) ) * i.color2.rgb +
saturate( dot( tangentSpaceNormal, bumpBasis[2] ) ) * i.color3.rgb;
}
else
{
diffuseLighting = i.color1.rgb;
}
}
HALF3 albedo = HALF3( 1.0f, 1.0f, 1.0f );
HALF alpha = 1.0f;
if( bBaseTexture )
{
albedo *= baseColor;
if( !bBaseAlphaEnvmapMask && !bSelfIllum )
{
alpha *= baseColor.a;
}
}
// If we only have specularity, assume that we want a black diffuse component, and
// get alpha from the envmapmask
if( !bBaseTexture && bCubemap )
{
diffuseLighting = HALF3( 0.0f, 0.0f, 0.0f );
if( bEnvmapMask )
{
alpha *= envmapMaskTexel.a;
}
}
// FIXME: This could be done per vertex!
diffuseLighting *= g_DiffuseModulation.rgb;
alpha *= g_DiffuseModulation.a;
if( bVertexColor )
{
albedo *= i.color1.rgb;
}
if( bVertexAlpha )
{
alpha *= i.color1.a;
}
if( bDetailTexture )
{
albedo *= detailColor;
}
HALF3 diffuseComponent = albedo * diffuseLighting;
if ( bDiffuseLighting )
{
diffuseComponent *= g_OverbrightFactor;
}
if( bSelfIllum )
{
HALF3 selfIllumComponent = g_SelfIllumTint * albedo;
diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a );
}
HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f );
if( bCubemap )
{
#ifdef NV3X
HALF3 worldSpaceNormal;
if ( bBumpmap )
{
worldSpaceNormal = mul(tangentSpaceNormal, i.tangentSpaceTranspose );
}
else
{
worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal );
}
#else
float3 worldSpaceNormal = mul( tangentSpaceNormal, i.tangentSpaceTranspose );
#endif
HALF3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, i.worldVertToEyeVector );
specularLighting = texCUBE( EnvmapSampler, reflectVect );
specularLighting *= specularFactor;
specularLighting *= g_EnvmapTint;
HALF3 specularLightingSquared = specularLighting * specularLighting;
specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast );
HALF3 greyScale = dot( specularLighting, HALF3( 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f ) );
specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation );
}
HALF3 result = diffuseComponent + specularLighting;
return HALF4( result, alpha );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -