| /*============================================================================= | |
| Common.hlsl: Common shader code. | |
| Copyright 1998-2008 Epic Games, Inc. All Rights Reserved. | |
| =============================================================================*/ | |
| // Tangent space bias | |
| // Register keyword in CG. Note no pixel constant registers on PS3! | |
| // On PS3, remap Tangent and Binormal to slot 5 and 6, so they don't overlap texcoord 6 and 7 | |
| // Input semantic for pixel shaders to get the screenspace pixel position (window position) | |
| // The PS3 reads our FColor values as ARGB; GBAR swizzles the components into the right order. | |
| // Tangent space bias | |
| // Register keyword in HLSL 4.0 | |
| // D3D10 vertex declarations read our FColor values as BGRA, so they need to be reversed. | |
| // Tangent space bias | |
| // Register keyword in HLSL | |
| // When multiplying with a matrix that is passed in externally through a matrix parameter, you MUST use MulMatrix. | |
| // When multiplying by a generated matrix (float3x3(VecA, VecB, VecC)), you MUST use mul | |
| // Note that MulMatrix also works for multiplying vector by matrix (transforming by transposed matrix), e.g. MulMatrix( Vect, Mtx ). | |
| // Clamp the base, so it's never <= 0.0f on PS3 (INF/NaN). | |
| // Clamp the base, so it's never <= 0.0f (INF/NaN). | |
| float ClampedPow(float X,float Y) | |
| { | |
| return pow(max(abs(X),0.0001f),Y); | |
| } | |
| float2 ClampedPow(float2 X,float2 Y) | |
| { | |
| return pow(max(abs(X),float2(0.0001f,0.0001f)),Y); | |
| } | |
| float3 ClampedPow(float3 X,float3 Y) | |
| { | |
| return pow(max(abs(X),float3(0.0001f,0.0001f,0.0001f)),Y); | |
| } | |
| float4 ClampedPow(float4 X,float4 Y) | |
| { | |
| return pow(max(abs(X),float4(0.0001f,0.0001f,0.0001f,0.0001f)),Y); | |
| } | |
| // It's necessary to use these whenever you're reading a depth value from a depth texture | |
| // SM4 is the only platform that natively supports uints in shaders; we just use floats on other platforms. | |
| // Pixel and vertex shader constant registers that are reserved by the Engine. | |
| // ---------------------------------------------------------------------------------------- | |
| // These #defines must match the enums EPixelShaderRegisters and EVertexShaderRegister | |
| // as they are defined in RHI.h. | |
| cbuffer VSOffsetConstants : register(b1) | |
| { | |
| float4x4 ViewProjectionMatrix VERTEXREGISTER(VSR_ViewProjMatrix); | |
| float4 CameraPosition VERTEXREGISTER(VSR_ViewOrigin); | |
| }; | |
| cbuffer PSOffsetConstants : register(b2) | |
| { | |
| // Converts projection-space XY coordinates to texture-space UV coordinates | |
| float4 ScreenPositionScaleBias PIXELREGISTER(PSR_ScreenPositionScaleBias); | |
| float4 MinZ_MaxZRatio PIXELREGISTER(PSR_MinZ_MaxZ_Ratio); | |
| }; | |
| float4x4 ViewProjectionMatrix VERTEXREGISTER(VSR_ViewProjMatrix); | |
| float4 CameraPosition VERTEXREGISTER(VSR_ViewOrigin); | |
| // Converts projection-space XY coordinates to texture-space UV coordinates | |
| float4 ScreenPositionScaleBias PIXELREGISTER(PSR_ScreenPositionScaleBias); | |
| float4 MinZ_MaxZRatio PIXELREGISTER(PSR_MinZ_MaxZ_Ratio); | |
| // The x component is set to 1 when rendering to an LDR buffer, otherwise 2^SCENE_COLOR_BIAS_FACTOR_EXP (See XeD3DRenderTarget.cpp) | |
| float4 SCENE_COLOR_BIAS_FACTOR PIXELREGISTER(PSR_ColorBiasFactor); | |
| // For two sided surfaces, this is the sign that should be applied to the normal. | |
| // In SM2, the surfaces are drawn twice with opposite signs. | |
| // In all other profiles, the surfaces are only drawn once without backface culling, and VFACE | |
| // is used to determine which side is being drawn. TwoSidedSign still contains useful information | |
| // about whether the model is flipped in that case. | |
| half TwoSidedSign; | |
| sampler2D SceneDepthTexture; | |
| sampler2D SceneColorTexture; | |
| sampler2D LightAttenuationTexture; | |
| // dice-begin: Henrik adding downsampled texture for rain | |
| sampler SceneDownsampled8; | |
| // dice-end | |
| // ---------------------------------------------------------------------------------------- | |
| float4 BiasColor( float4 Color ) | |
| { | |
| return float4( Color.rgb * SCENE_COLOR_BIAS_FACTOR.x, Color.a ); | |
| } | |
| // RETURN_COLOR should only be used when rendering to the SceneColor surface | |
| // We don't use an inline function so we can avoid type promotion/ coercion. | |
| //the largest value any color component is allowed to have, scene color is clamped to this in DOFAndBloomGatherPixelShader.usf | |
| //also used to pack color into the fixed point filter buffer, which requires a range of [0-1] | |
| float Square(float A) | |
| { | |
| return A * A; | |
| } | |
| float4 ExpandRGBE( float4 RGBE ) | |
| { | |
| return float4( ldexp( RGBE.xyz, 255.0 * RGBE.w - 128.0 ), 1.0 ); | |
| } | |
| float4 ExpandCompressedRGBE( float4 RGBE ) | |
| { | |
| return float4( ldexp( RGBE.xyz, 255.0 / 16.0 * RGBE.w - 8.0 ), 1.0 ); | |
| } | |
| half3 PointLightPhong(half3 DiffuseColor,half DiffusePower,half3 SpecularColor,half SpecularPower, half3 L, float3 E, half3 N, float3 R) | |
| { | |
| half3 DiffuseLighting = pow(saturate(dot(N,L)),DiffusePower), | |
| SpecularLighting = pow(saturate(dot(R,L)),max(SpecularPower,0.0001)); | |
| return DiffuseColor * DiffuseLighting + SpecularLighting * SpecularColor; | |
| } | |
| float4 PreviousLighting(float4 ScreenPosition) | |
| { | |
| return tex2D(SceneColorTexture,ScreenPosition.xy / ScreenPosition.w * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz); | |
| } | |
| float RadialAttenuation(float3 WorldLightVector,half FalloffExponent) | |
| { | |
| return pow( | |
| saturate(1.0f - dot(WorldLightVector,WorldLightVector)), | |
| FalloffExponent | |
| ); | |
| } | |
| half3 GetLightAttenuation(float4 ScreenPosition) | |
| { | |
| return tex2D(LightAttenuationTexture, ScreenPosition.xy / ScreenPosition.w * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz).rgb; | |
| } | |
| /** return the scene lighting texture */ | |
| half3 CalcSceneColor(float2 ScreenUV) | |
| { | |
| return tex2D(SceneColorTexture,ScreenUV).rgb; | |
| } | |
| /** return all channels of the scene lighting texture */ | |
| half4 CalcFullSceneColor(float2 ScreenUV) | |
| { | |
| return tex2D(SceneColorTexture,ScreenUV); | |
| } | |
| half ConvertToClipSpaceW( half DeviceZ ) | |
| { | |
| //return MinZ_MaxZRatio[0] / (1.0 - (DeviceZ / MinZ_MaxZRatio[1])); | |
| return 1.f / (DeviceZ * MinZ_MaxZRatio[2] - MinZ_MaxZRatio[3]); | |
| } | |
| /** return the depth value stored in the depth buffer - but convert it to w first */ | |
| half CalcSceneDepth( float2 ScreenUV ) | |
| { | |
| // get depth buffer z value | |
| half DeviceZ = texDepth2D(SceneDepthTexture,ScreenUV).r; | |
| // convert it to clip space w | |
| return ConvertToClipSpaceW(DeviceZ); | |
| } | |
| /** | |
| * Returns scene color in rgb, depth in a | |
| */ | |
| half4 CalcSceneColorAndDepth( float2 ScreenUV ) | |
| { | |
| return half4(CalcSceneColor(ScreenUV), CalcSceneDepth(ScreenUV)); | |
| } | |
| /** | |
| * Return the depth value stored in the scene color scratch target's alpha, which is bound as SceneDepthTexture | |
| */ | |
| half CalcSceneDepth( float2 ScreenUV ) | |
| { | |
| return tex2D(SceneDepthTexture,ScreenUV).a; | |
| } | |
| /** | |
| * Returns scene color in rgb, depth in a | |
| */ | |
| half4 CalcSceneColorAndDepth( float2 ScreenUV ) | |
| { | |
| return half4(CalcSceneColor(ScreenUV), CalcSceneDepth(ScreenUV)); | |
| } | |
| /** return the depth value stored in lighting target's alpha */ | |
| half CalcSceneDepth( float2 ScreenUV ) | |
| { | |
| // depth stored in alpha | |
| return tex2D(SceneColorTexture,ScreenUV).a; | |
| } | |
| /** | |
| * Returns scene color in rgb, depth in a | |
| */ | |
| half4 CalcSceneColorAndDepth( float2 ScreenUV ) | |
| { | |
| return tex2D(SceneColorTexture,ScreenUV); | |
| } | |
| /** | |
| * Used to output a scale value based on scene color luminance when additively blending. | |
| */ | |
| half4 AccumulateSceneColor(half4 InSceneColor) | |
| { | |
| // Tweakable luminance scale | |
| const half SceneColorAccumulationFactor = 0.1f; | |
| const half MaxLuminanceScale = 0.1f; | |
| const half3 LuminanceWeights = half3(.3f, .59f, .11f) * SceneColorAccumulationFactor; | |
| half ScaledLuminance = clamp(dot(InSceneColor.rgb, LuminanceWeights), 0.0f, MaxLuminanceScale); | |
| return half4(InSceneColor.rgb, ScaledLuminance * ScaledLuminance); | |
| } | |
| half4 AccumulateSceneColor(half4 InSceneColor) | |
| { | |
| return InSceneColor; | |
| } | |
| half PreviousDepth(float4 ScreenPosition) | |
| { | |
| return CalcSceneDepth(ScreenPosition.xy / ScreenPosition.w * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz); | |
| } | |
| /** | |
| * aligns the clip space position so that it can be used as a texture coordinate | |
| * to properly align in screen space | |
| */ | |
| float4 ScreenAlignedPosition( float4 ScreenPosition ) | |
| { | |
| return float4(ScreenPosition.xy / ScreenPosition.w * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz, ScreenPosition.z/ScreenPosition.w,1); | |
| } | |
| /** | |
| * Aligns the [0,1] UV to match the view within the backbuffer | |
| */ | |
| half2 ScreenAlignedUV( half2 UV ) | |
| { | |
| return (UV*half2(2,-2) + half2(-1,1))*ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz; | |
| } | |
Xet Storage Details
- Size:
- 11.1 kB
- Xet hash:
- 39cf5146f7d2417da187e4a71b4edcc036d8871902b1a0c78677d2a55f6a0f09
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.