utkutuzcu/tst / Engine /Shaders /CompilingShader-BasePassPixelShader.usf
utkutuzcu's picture
download
raw
8.92 kB
/*=============================================================================
BasePassPixelShader.usf: Base pass pixel shader
Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
=============================================================================*/
#define NEEDS_LIGHTMAP_COORDINATE (TEXTURE_LIGHTMAP || SIMPLE_TEXTURE_LIGHTMAP)
/* If simple lighting is enabled then the base pass shader will just be Diffuse * LightMap + Emissive */
#define SIMPLE_LIGHTING ((SIMPLE_VERTEX_LIGHTMAP || SIMPLE_TEXTURE_LIGHTMAP) && !MATERIAL_LIGHTINGMODEL_CUSTOM)
#define NEEDS_BASEPASS_FOGGING (MATERIALBLENDING_TRANSLUCENT || MATERIALBLENDING_ADDITIVE)
#include "Common.usf"
#include "Material.usf"
#include "VertexFactory.usf"
half3 UpperSkyColor;
half3 LowerSkyColor;
// SkyFactor and AmbientColor are constants if we assume SHOW_Lighting to be always set. We make the assumption that on console
// performance is more important than being able to toggle this flag and therefore use special shortcut.
#if XBOX || PS3
static const half3 AmbientColor = 0;
static const half SkyFactor = 1;
#else
half4 AmbientColorAndSkyFactor;
static const half3 AmbientColor = AmbientColorAndSkyFactor.rgb;
static const half SkyFactor = AmbientColorAndSkyFactor.a;
#endif
#if TEXTURE_LIGHTMAP || SIMPLE_TEXTURE_LIGHTMAP
//Directional lightmaps use 3 samplers here so the most a material can use is 13
//This is enforced by the material compiler through MAX_ME_PIXELSHADER_SAMPLERS
sampler2D LightMapTextures[NUM_LIGHTMAP_COEFFICIENTS];
// The light-map scale array is a set of float4s so it can be set as a contiguous chunk regardless of platform shader constant alignment.
float4 LightMapScale[NUM_LIGHTMAP_COEFFICIENTS];
//NV-begin
float4 LightMapResolution[NUM_LIGHTMAP_COEFFICIENTS];
sampler2D BSplineTexture;
float3 tex2DBicubic(sampler2D tex, float4 Res, float2 uv)
{
float x = uv.x * Res.x;
float y = uv.y * Res.y;
// Assuming d3d9.
x -= 0.5f;
y -= 0.5f;
float px = floor(x);
float py = floor(y);
float fx = x - px;
float fy = y - py;
float4 vX = tex2D( BSplineTexture, float2(fx, 0.0f) );
float4 vY = tex2D( BSplineTexture, float2(fy, 0.0f) );
float2 hX = vX.xy;
float2 gX = vX.zw;
float2 hY = vY.xy;
float2 gY = vY.zw;
float2 InvRes = Res.zw;
float3 r = gY.x * ( gX.x * tex2D(tex, float2(px + hX.x, py + hY.x) * InvRes) +
gX.y * tex2D(tex, float2(px + hX.y, py + hY.x) * InvRes) ) +
gY.y * ( gX.x * tex2D(tex, float2(px + hX.x, py + hY.y) * InvRes) +
gX.y * tex2D(tex, float2(px + hX.y, py + hY.y) * InvRes) );
return r;
}
#endif
//NV-end
void Main(
FVertexFactoryInterpolants Interpolants,
#if VERTEX_LIGHTMAP
//for vertex-lightmapped translucency we are out of interpolators to pass in the vertex fog
//so it must be packed in the w of other interpolators
float4 LightMapA_FogR : TEXCOORD2,
float4 LightMapB_FogG : TEXCOORD3,
float4 LightMapC_FogB : TEXCOORD4,
#else
#if SIMPLE_VERTEX_LIGHTMAP
float3 LightMapA : TEXCOORD2,
#endif
//for texture-lightmapped translucency we can pass the vertex fog in its own interpolator
#if NEEDS_BASEPASS_FOGGING
float4 VertexFog : TEXCOORD4,
#endif
#endif
float4 PixelPosition : TEXCOORD5,
float4 CameraVector_FogA: TEXCOORD6,
#if !MATERIAL_LIGHTINGMODEL_UNLIT
float3 SkyVector : TEXCOORD7,
#endif
OPTIONAL_FacingSign
out float4 OutColor : COLOR0
)
{
FMaterialParameters MaterialParameters = GetMaterialParameters(Interpolants);
//Don't flip the normal for backfaces of two-sided materials used with this shader.
//As a result, the backfaces will have the same lighting as the frontfaces, instead of being mostly black.
CalcMaterialParameters(MaterialParameters,FacingSign,CameraVector_FogA.xyz,PixelPosition,half3(0,0,1),false);
#if MATERIALBLENDING_MASKED
//Clip if the blend mode requires it.
GetMaterialClipping(MaterialParameters);
#endif
half3 Color = GetMaterialEmissive(MaterialParameters);
#if !MATERIAL_LIGHTINGMODEL_UNLIT
#if !SIMPLE_LIGHTING
static const half3x3 LightMapBasis = half3x3(
half3( 0.0f, -1.0f / sqrt(2.0f), +1.0f / sqrt(2.0f)),
half3( sqrt(6.0f) / 3.0f, -1.0f / sqrt(6.0f), -1.0f / sqrt(6.0f)),
half3( 1.0f / sqrt(3.0f), 1.0f / sqrt(3.0f), 1.0f / sqrt(3.0f))
);
half3 LightMapNormal = mul(MaterialParameters.TangentNormal,LightMapBasis);
half3 LightMapReflectionVector = mul(MaterialParameters.TangentReflectionVector,LightMapBasis);
half3 TwoSidedLightingMask = GetMaterialTwoSidedLightingMask(MaterialParameters);
#if MATERIAL_LIGHTINGMODEL_NONDIRECTIONAL
TwoSidedLightingMask = 1;
#endif
#if !MATERIAL_LIGHTINGMODEL_CUSTOM
half3 DiffuseTransferCoefficients =
pow(
saturate(LightMapNormal) * saturate(LightMapNormal),
GetMaterialDiffusePower(MaterialParameters)
) * (1 - TwoSidedLightingMask) + TwoSidedLightingMask;
half3 SpecularTransferCoefficients =
pow(
saturate(LightMapReflectionVector),
GetMaterialSpecularPower(MaterialParameters) + 1
) * (1 - TwoSidedLightingMask);
#endif
#endif //#if SIMPLE_LIGHTING
#if VERTEX_LIGHTMAP
half3 VertexLightMap[3] = { LightMapA_FogR.xyz, LightMapB_FogG.xyz, LightMapC_FogB.xyz };
#elif SIMPLE_VERTEX_LIGHTMAP
half3 VertexLightMap[1] = { LightMapA };
#endif
half3 LightTransfer = 0;
UNROLL
for(int CoefficientIndex = 0;CoefficientIndex < NUM_LIGHTMAP_COEFFICIENTS;CoefficientIndex++)
{
#if TEXTURE_LIGHTMAP || SIMPLE_TEXTURE_LIGHTMAP
// Dice-begin: Henrik - doing better sRGB here for lightmaps than the xenon hardware (removed the hardware sRGB lookup on lightmaps)
// note that this is beeing done AFTER hardware interpolation, since the conversion is a power, doing this here is not equivalent (but probably visually OK)
#if XBOX
half3 LightMap = tex2D(LightMapTextures[CoefficientIndex],GetLightMapCoordinate(Interpolants)).rgb;
LightMap = pow((LightMap+0.055)/(1.055),2.4);
LightMap = LightMap * LightMapScale[CoefficientIndex].rgb;
#else
//NV-begin
#if USE_BICUBIC_FILTERING
half3 LightMap = tex2DBicubic(LightMapTextures[CoefficientIndex], LightMapResolution[CoefficientIndex], GetLightMapCoordinate(Interpolants)).rgb * LightMapScale[CoefficientIndex].rgb;
#else
half3 LightMap = tex2D(LightMapTextures[CoefficientIndex],GetLightMapCoordinate(Interpolants)).rgb * LightMapScale[CoefficientIndex].rgb;
#endif
//NV-end
#endif
// Dice-end
#elif VERTEX_LIGHTMAP || SIMPLE_VERTEX_LIGHTMAP
half3 LightMap = VertexLightMap[CoefficientIndex];
#else
half3 LightMap = 0;
#endif
#if MATERIAL_LIGHTINGMODEL_CUSTOM
MaterialParameters.TangentLightVector = LightMapBasis[CoefficientIndex];
LightTransfer += LightMap * GetMaterialCustomLighting(MaterialParameters);
#elif SIMPLE_LIGHTING
LightTransfer += pow(LightMap,GetMaterialDiffusePower(MaterialParameters)) *
GetMaterialDiffuseColorNormalized(MaterialParameters);
#else
LightTransfer += LightMap * DiffuseTransferCoefficients[CoefficientIndex] * GetMaterialDiffuseColorNormalized(MaterialParameters);
#ifndef DISABLE_LIGHTMAP_SPECULAR
LightTransfer += LightMap * SpecularTransferCoefficients[CoefficientIndex] * GetMaterialSpecularColor(MaterialParameters);
#endif
#endif
}
Color += LightTransfer;
#if ENABLE_SKY_LIGHT
Color += GetMaterialHemisphereLightTransferFull(MaterialParameters,normalize(SkyVector),UpperSkyColor,LowerSkyColor) * SkyFactor;
#endif
#if !SIMPLE_LIGHTING
Color += GetMaterialDiffuseColor(MaterialParameters) * AmbientColor;
#endif
#endif
#if NEEDS_BASEPASS_FOGGING
half4 Fog;
#if VERTEX_LIGHTMAP
//fog was stored in the .w of each interpolator
Fog = half4(LightMapA_FogR.w, LightMapB_FogG.w, LightMapC_FogB.w, CameraVector_FogA.w);
#else
Fog = VertexFog;
#endif
#endif
half Opacity = GetMaterialOpacity(MaterialParameters);
#if MATERIALBLENDING_TRANSLUCENT
OutColor = MaterialGammaCorrect(half4(Color * Fog.a + Fog.rgb, Opacity));
OutColor = RETURN_COLOR(OutColor);
#elif MATERIALBLENDING_ADDITIVE
OutColor = MaterialGammaCorrect(half4(Color * Fog.a * Opacity, 0.0f));
OutColor = RETURN_COLOR(AccumulateSceneColor(OutColor));
#elif MATERIALBLENDING_MODULATE
// RETURN_COLOR not needed with modulative blending
OutColor = MaterialGammaCorrect(half4(Color, Opacity));
#else
// Output clip space w in scene color alpha
OutColor = RETURN_COLOR(MaterialGammaCorrect(float4(Color,MaterialParameters.ScreenPosition.w)));
#endif
}

Xet Storage Details

Size:
8.92 kB
·
Xet hash:
9ec1875d89ff7c8b3c75cb705666003a5b3691f8815d6266624ac625634b934a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.