| /** | |
| * MaterialTemplate.usf: | |
| * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved. | |
| */ | |
| /* | |
| Defined by the C++ code: | |
| MATERIALBLENDING_SOLID | |
| MATERIALBLENDING_MASKED | |
| MATERIALBLENDING_TRANSLUCENT | |
| MATERIALBLENDING_ADDITIVE | |
| MATERIALBLENDING_MODULATE | |
| MATERIAL_TWOSIDED | |
| MATERIAL_LIGHTINGMODEL_PHONG | |
| MATERIAL_LIGHTINGMODEL_NONDIRECTIONAL | |
| MATERIAL_LIGHTINGMODEL_UNLIT | |
| MATERIAL_LIGHTINGMODEL_CUSTOM | |
| WORLD_COORDS | |
| WORLD_POS | |
| MATERIAL_USE_GAMMA_CORRECTION | |
| */ | |
| float3x3 LocalToWorldMatrix; | |
| float3x3 WorldToViewMatrix; | |
| /* transform from post-projection to world space */ | |
| float4x4 InvViewProjectionMatrix; | |
| /* world-space camera position */ | |
| float3 CameraWorldPos; | |
| struct FMaterialParameters | |
| { | |
| float2 TexCoords[NUM_MATERIAL_TEXCOORDS]; | |
| float4 VertexColor; | |
| float3 TangentNormal, | |
| TangentReflectionVector, | |
| TangentCameraVector; | |
| half3 TangentLightVector; | |
| float4 ScreenPosition; | |
| float3x3 TangentBasisInverse; | |
| float3 WorldPosition; | |
| float LensFlareIntensity; | |
| float LensFlareOcclusion; | |
| float LensFlareRadialDistance; | |
| float LensFlareSourceDistance; | |
| float LensFlareRayDistance; | |
| }; | |
| // Uniform material expressions. | |
| float4 UniformVector_0; | |
| float4 UniformVector_1; | |
| float4 UniformVector_2; | |
| float4 UniformVector_3; | |
| float UniformScalar_0; | |
| sampler2D Texture2D_0; | |
| sampler2D Texture2D_1; | |
| samplerCUBE TextureCube_0; | |
| samplerCUBE TextureCube_1; | |
| float DepthBiasedAlpha( FMaterialParameters Parameters, float InAlpha, float InBias, float InBiasScale ) | |
| { | |
| float Result; | |
| half SceneDepth = PreviousDepth(Parameters.ScreenPosition); | |
| float DepthBias = (1.0 - InBias) * InBiasScale; | |
| float BlendAmt = saturate((SceneDepth - Parameters.ScreenPosition.w) / max(DepthBias,0.001)); | |
| Result = InAlpha * BlendAmt; | |
| return Result; | |
| } | |
| float3 DepthBiasedBlend( FMaterialParameters Parameters, float3 InColor, float InBias, float InBiasScale ) | |
| { | |
| float3 Result; | |
| float3 SceneColor = PreviousLighting(Parameters.ScreenPosition).rgb; | |
| half SceneDepth = PreviousDepth(Parameters.ScreenPosition); | |
| float DepthBias = (1.0 - InBias) * InBiasScale; | |
| float BlendAmt = saturate((SceneDepth - Parameters.ScreenPosition.w) / max(DepthBias,0.001)); | |
| Result = lerp( SceneColor, InColor * 1.000001, BlendAmt ); | |
| return Result; | |
| } | |
| /** Get the lens flare intensity */ | |
| float GetLensFlareIntensity(FMaterialParameters Parameters) | |
| { | |
| return Parameters.LensFlareIntensity; | |
| return 1.0f; | |
| } | |
| /** Get the lens flare occlusion */ | |
| float GetLensFlareOcclusion(FMaterialParameters Parameters) | |
| { | |
| return Parameters.LensFlareOcclusion; | |
| return 1.0f; | |
| } | |
| /** Get the lens flare radial distance */ | |
| float GetLensFlareRadialDistance(FMaterialParameters Parameters) | |
| { | |
| return Parameters.LensFlareRadialDistance; | |
| return 0.0f; | |
| } | |
| /** Get the lens flare ray distance */ | |
| float GetLensFlareRayDistance(FMaterialParameters Parameters) | |
| { | |
| return Parameters.LensFlareRayDistance; | |
| return 0.0f; | |
| } | |
| /** Get the lens flare source distance */ | |
| float GetLensFlareSourceDistance(FMaterialParameters Parameters) | |
| { | |
| return Parameters.LensFlareSourceDistance; | |
| return 0.0f; | |
| } | |
| half3 GetMaterialNormal(FMaterialParameters Parameters) | |
| { | |
| return float3(0.00000000,0.00000000,1.00000000); | |
| } | |
| half3 GetMaterialEmissive(FMaterialParameters Parameters) | |
| { | |
| return ((((((((1.00000000) - pow(((1.00000000) - max((0.00000000),dot(float3(0.00000000,0.00000000,1.00000000),Parameters.TangentCameraVector))),(3.00000000))) * ((texCUBE(TextureCube_0,Parameters.TangentReflectionVector) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb) + ((texCUBE(TextureCube_1,Parameters.TangentReflectionVector) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb) * ((0.50000000) * ((1.00000000) - ((tex2D(Texture2D_0,(UniformScalar_0 * ((3.00000000) * Parameters.TexCoords[0].xy))) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb))) + (0.75000000)) + (UniformVector_1.rgb * (((tex2D(Texture2D_0,(UniformScalar_0 * ((3.00000000) * Parameters.TexCoords[0].xy))) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb + ((2.00000000) * pow(((tex2D(Texture2D_0,(UniformScalar_0 * ((3.00000000) * Parameters.TexCoords[0].xy))) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb,(2.00000000)))))) + UniformVector_0.rgb); | |
| } | |
| half3 GetMaterialDiffuseColor(FMaterialParameters Parameters) | |
| { | |
| return (float3(0.00000000,0.00000000,0.00000000) * ((1.00000000) - UniformVector_0.rgb)); | |
| } | |
| half GetMaterialDiffusePower(FMaterialParameters Parameters) | |
| { | |
| return (1.00000000); | |
| } | |
| half3 GetMaterialDiffuseColorNormalized(FMaterialParameters Parameters) | |
| { | |
| // Normalizes the diffuse color to reflect the same amount of light regardless of diffuse power. | |
| return GetMaterialDiffuseColor(Parameters) * | |
| ((1 + GetMaterialDiffusePower(Parameters)) / 2); | |
| } | |
| half3 GetMaterialSpecularColor(FMaterialParameters Parameters) | |
| { | |
| return float3(0.00000000,0.00000000,0.00000000); | |
| } | |
| half GetMaterialSpecularPower(FMaterialParameters Parameters) | |
| { | |
| return (15.00000000); | |
| } | |
| half GetMaterialOpacity(FMaterialParameters Parameters) | |
| { | |
| return (UniformVector_1.a * (((tex2D(Texture2D_1,((Parameters.TexCoords[0].xy * UniformVector_3.rg) + UniformVector_2.rg)) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb.g * (((tex2D(Texture2D_0,(UniformScalar_0 * ((3.00000000) * Parameters.TexCoords[0].xy))) * float4(1.00000000,1.00000000,1.00000000,1.00000000)) + float4(0.00000000,0.00000000,0.00000000,0.00000000)).rgb + (0.50000000)))).r; | |
| } | |
| float GetMaterialMask(FMaterialParameters Parameters) | |
| { | |
| return (1.00000000) - 0.33300; | |
| } | |
| float2 GetMaterialDistortion(FMaterialParameters Parameters) | |
| { | |
| return float2(0.00000000,0.00000000); | |
| } | |
| float3 GetMaterialTwoSidedLightingMask(FMaterialParameters Parameters) | |
| { | |
| return ((0.00000000) * float3(1.00000012,1.00000012,1.00000012)); | |
| } | |
| float3 GetMaterialCustomLighting(FMaterialParameters Parameters) | |
| { | |
| return float3(0.00000000,0.00000000,0.00000000); | |
| } | |
| float3 GetMaterialPointLightTransfer(FMaterialParameters Parameters,float3 WorldLightVector,half FalloffExponent) | |
| { | |
| float3 TwoSidedLighting = 0; | |
| float3 TwoSidedLightingMask = 0; | |
| TwoSidedLightingMask = GetMaterialTwoSidedLightingMask(Parameters); | |
| TwoSidedLighting = TwoSidedLightingMask * | |
| GetMaterialDiffuseColorNormalized(Parameters) * | |
| RadialAttenuation(WorldLightVector,FalloffExponent); | |
| float3 Lighting = 0; | |
| Lighting = GetMaterialDiffuseColor(Parameters) * RadialAttenuation(WorldLightVector,FalloffExponent); | |
| Lighting = PointLightPhong( | |
| GetMaterialDiffuseColorNormalized(Parameters), | |
| GetMaterialDiffusePower(Parameters), | |
| GetMaterialSpecularColor(Parameters), | |
| GetMaterialSpecularPower(Parameters), | |
| Parameters.TangentLightVector, | |
| Parameters.TangentCameraVector, | |
| Parameters.TangentNormal, | |
| Parameters.TangentReflectionVector | |
| ) * | |
| RadialAttenuation(WorldLightVector,FalloffExponent); | |
| Lighting = GetMaterialCustomLighting(Parameters) * RadialAttenuation(WorldLightVector,FalloffExponent); | |
| return lerp(Lighting,TwoSidedLighting,TwoSidedLightingMask); | |
| } | |
| float3 GetMaterialHemisphereLightTransferFull(FMaterialParameters Parameters,float3 SkyVector, float3 UpperColor, float3 LowerColor) | |
| { | |
| float3 TwoSidedLighting = 0; | |
| float3 TwoSidedLightingMask = 0; | |
| TwoSidedLightingMask = GetMaterialTwoSidedLightingMask(Parameters); | |
| TwoSidedLighting = TwoSidedLightingMask * GetMaterialDiffuseColor(Parameters); | |
| float3 UpperLighting = 0; | |
| float3 LowerLighting = 0; | |
| UpperLighting = GetMaterialDiffuseColor(Parameters); | |
| LowerLighting = GetMaterialDiffuseColor(Parameters); | |
| //UpperLighting = HemisphereLightPhong(GetMaterialDiffuseColor(Parameters),SkyVector,Parameters.TangentNormal); | |
| //LowerLighting = HemisphereLightPhong(GetMaterialDiffuseColor(Parameters),-SkyVector,Parameters.TangentNormal); | |
| float NormalContribution = dot(SkyVector,Parameters.TangentNormal); | |
| float2 ContributionWeightsSqrt = float2(0.5, 0.5f) + float2(0.5f, -0.5f) * NormalContribution; | |
| float2 ContributionWeights = ContributionWeightsSqrt * ContributionWeightsSqrt; | |
| UpperLighting = GetMaterialDiffuseColor(Parameters) * ContributionWeights[0]; | |
| LowerLighting = GetMaterialDiffuseColor(Parameters) * ContributionWeights[1]; | |
| UpperLighting = 0;//GetMaterialCustomLighting(Parameters); | |
| LowerLighting = 0;//GetMaterialCustomLighting(Parameters); | |
| return lerp(UpperLighting,TwoSidedLighting,TwoSidedLightingMask) * UpperColor + | |
| lerp(LowerLighting,TwoSidedLighting,TwoSidedLightingMask) * LowerColor; | |
| } | |
| void GetMaterialClipping(FMaterialParameters Parameters) { clip(GetMaterialOpacity(Parameters) - 1.0 / 255.0); } | |
| void GetMaterialClipping(FMaterialParameters Parameters) { clip(GetMaterialOpacity(Parameters) - 1.0 / 255.0); } | |
| void GetMaterialClipping(FMaterialParameters Parameters) { clip(GetMaterialOpacity(Parameters) - 1.0 / 255.0); } | |
| #if MATERIALBLENDING_MASKED | |
| void GetMaterialClipping(FMaterialParameters Parameters) { clip(GetMaterialMask(Parameters)); } | |
| #else | |
| void GetMaterialClipping(FMaterialParameters Parameters) { return; } | |
| #endif | |
| #define OPTIONAL_FacingSign | |
| static const float FacingSign = 1.0f; | |
| #define OPTIONAL_FacingSign in float FacingSign : VFACE, | |
| /** vectors needed for user material shaders */ | |
| void CalcMaterialParameters( | |
| in out FMaterialParameters Parameters, | |
| float FacingSign, | |
| float3 CameraVector, | |
| float4 PixelPosition, | |
| half3 LightVector = half3(0,0,1), | |
| uniform bool bAllowTwoSidedFlip = true) | |
| { | |
| Parameters.WorldPosition = PixelPosition.xyz; | |
| Parameters.ScreenPosition = MulMatrix(ViewProjectionMatrix,PixelPosition); | |
| Parameters.ScreenPosition = PixelPosition; | |
| Parameters.TangentCameraVector = normalize(CameraVector); | |
| Parameters.TangentLightVector = normalize((half3)LightVector); | |
| Parameters.TangentNormal = normalize(GetMaterialNormal(Parameters)); | |
| // allow individual shaders to override the flip | |
| if (bAllowTwoSidedFlip) | |
| { | |
| // flip the normal for backfaces being rendered with a two-sided material | |
| Parameters.TangentNormal *= TwoSidedSign; | |
| // D3D requires that VFACE be used by a conditional instruction rather than used as a signed float directly. | |
| float FacingSignFloat = FacingSign >= 0 ? +1 : -1; | |
| #if PS3 || XBOX || SM4_PROFILE || SM2_PROFILE | |
| Parameters.TangentNormal *= FacingSignFloat; | |
| #else | |
| // in SM3 VFACE is actually negative for frontfaces since frontfacing polys in UE3 are CM_CW instead of CM_CCW | |
| Parameters.TangentNormal *= -FacingSignFloat; | |
| #endif | |
| } | |
| Parameters.TangentReflectionVector = -Parameters.TangentCameraVector + Parameters.TangentNormal * dot(Parameters.TangentNormal,Parameters.TangentCameraVector) * 2.0; | |
| } | |
| /** Create the inverse of the tangent basis */ | |
| float3x3 CalcInvTangentBasis( float4 Normal, float3 Tangent ) | |
| { | |
| // determinant of original tangent basis passed down in w component | |
| float Det = (Normal.w - 0.5) * 2; | |
| // scale bias from [0,1] to [-1,1] and normalize normal vector | |
| float3 NormalV = normalize((float3(Normal.xyz) - 0.5) * 2); | |
| // scale bias from [0,1] to [-1,1] and normalize tangent vector | |
| float3 TangentV = normalize((Tangent - 0.5) * 2); | |
| // flip binormal based on determinant of tangent basis | |
| float3 BinormalV = normalize(cross(NormalV,TangentV) * Det); | |
| // 3x3 tangent basis matrix | |
| return transpose(float3x3(TangentV, BinormalV, NormalV)); | |
| } | |
| /** optional gamma correction to be applied to materials. Inverse gamma */ | |
| half MatInverseGamma; | |
| /** | |
| * Apply linear to gamma correction. This is needed when rendering materials to a render target with gamma != 1.0 | |
| * @param Color - color in linear space | |
| * @return color in gamma space | |
| */ | |
| half4 MaterialGammaCorrect( half4 Color ) | |
| { | |
| return float4( pow( Color.xyz, MatInverseGamma ), Color.w ); | |
| } | |
| /** stub when not compiling with gamma correction */ | |
Xet Storage Details
- Size:
- 13.4 kB
- Xet hash:
- 9ed9224427eaf5ab0e06051ae99b9b467010a7c98158d2c3419c4632016e3980
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.