You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
94 lines
4.4 KiB
Plaintext
94 lines
4.4 KiB
Plaintext
/************************************************************************************
|
|
|
|
Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
|
|
|
|
Licensed under the Oculus VR SDK License Version 2.0 (the "License");
|
|
you may not use the Oculus VR SDK except in compliance with the License,
|
|
which is provided at the time of installation or download, or which
|
|
otherwise accompanies this software in either electronic or hard copy form.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.oculusvr.com/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
*************************************************************************************/
|
|
/*=============================================================================
|
|
PostProcessHMD.usf: PostProcessing shader to distort and chromaab correction
|
|
for HMD devices
|
|
=============================================================================*/
|
|
|
|
#include "Common.usf"
|
|
#include "PostProcessCommon.usf"
|
|
|
|
float2 EyeToSrcUVScale;
|
|
float2 EyeToSrcUVOffset;
|
|
|
|
#if USE_TIMEWARP
|
|
float4x4 EyeRotationStart;
|
|
float4x4 EyeRotationEnd;
|
|
|
|
float2 TimewarpTexCoord(float2 TexCoord, float4x4 rotMat)
|
|
{
|
|
// Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic
|
|
// aberration and distortion). These are now "real world" vectors in direction (x,y,1)
|
|
// relative to the eye of the HMD. Apply the 3x3 timewarp rotation to these vectors.
|
|
float3 transformed = float3( mul ( rotMat, float4(TexCoord.xy, 1, 1) ).xyz);
|
|
// Project them back onto the Z=1 plane of the rendered images.
|
|
float2 flattened = (transformed.xy / transformed.z);
|
|
// Scale them into ([0,0.5],[0,1]) or ([0.5,0],[0,1]) UV lookup space (depending on eye)
|
|
return(EyeToSrcUVScale * flattened + EyeToSrcUVOffset);
|
|
}
|
|
|
|
void MainVS(in float2 Position : ATTRIBUTE0, in float2 TexCoord0 : ATTRIBUTE1, in float2 TexCoord1 : ATTRIBUTE2,
|
|
in float2 TexCoord2 : ATTRIBUTE3, in float VignetteFactor : ATTRIBUTE4, in float TimewarpFactor : ATTRIBUTE5,
|
|
|
|
out float4 OutPosition : POSITION, out float4 OutVignetteColor : COLOR0,
|
|
out float2 OutTexCoord0 : TEXCOORD0, out float2 OutTexCoord1 : TEXCOORD1, out float2 OutTexCoord2 : TEXCOORD2)
|
|
{
|
|
float4x4 lerpedEyeRot = lerp(EyeRotationStart, EyeRotationEnd, TimewarpFactor);
|
|
OutTexCoord0 = TimewarpTexCoord(TexCoord0, lerpedEyeRot);
|
|
OutTexCoord1 = TimewarpTexCoord(TexCoord1, lerpedEyeRot);
|
|
OutTexCoord2 = TimewarpTexCoord(TexCoord2, lerpedEyeRot);
|
|
OutPosition = float4(Position.xy, 0.5, 1.0);
|
|
OutVignetteColor = VignetteFactor;
|
|
}
|
|
#else
|
|
|
|
void MainVS(in float2 Position : ATTRIBUTE0, in float2 TexCoord0 : ATTRIBUTE1, in float2 TexCoord1 : ATTRIBUTE2,
|
|
in float2 TexCoord2 : ATTRIBUTE3, in float VignetteFactor : ATTRIBUTE4, in float TimewarpFactor : ATTRIBUTE5,
|
|
|
|
out float4 OutPosition : SV_Position, out float4 OutVignetteColor : COLOR0,
|
|
out float2 OutTexCoord0 : TEXCOORD0, out float2 OutTexCoord1 : TEXCOORD1, out float2 OutTexCoord2 : TEXCOORD2)
|
|
{
|
|
OutPosition.xy = Position.xy;
|
|
OutPosition.z = 0.5;
|
|
OutPosition.w = 1.0;
|
|
|
|
// Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
|
|
// Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
|
|
OutTexCoord0 = TexCoord0 * EyeToSrcUVScale + EyeToSrcUVOffset;
|
|
OutTexCoord1 = TexCoord1 * EyeToSrcUVScale + EyeToSrcUVOffset;
|
|
OutTexCoord2 = TexCoord2 * EyeToSrcUVScale + EyeToSrcUVOffset;
|
|
OutVignetteColor = VignetteFactor; // Used for vignette fade.
|
|
}
|
|
#endif
|
|
|
|
void MainPS(in float4 Position : SV_Position, in float4 Color : COLOR0,
|
|
in float2 TexCoord0 : TEXCOORD0, in float2 TexCoord1 : TEXCOORD1, in float2 TexCoord2 : TEXCOORD2,
|
|
|
|
out float4 OutColor : SV_Target0)
|
|
{
|
|
float ResultR = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, TexCoord0).r;
|
|
float ResultG = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, TexCoord1).g;
|
|
float ResultB = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, TexCoord2).b;
|
|
OutColor = float4(ResultR * Color.r, ResultG * Color.g, ResultB * Color.b, 1.0);
|
|
}
|
|
|
|
|