Android build settings + metaxr
This commit is contained in:
51
Plugins/MetaXR/Shaders/Highlights.ush
Normal file
51
Plugins/MetaXR/Shaders/Highlights.ush
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
float3 MRUKHighlights(float3 TranslatedWorldPosition, MaterialFloat TotalLights, MaterialFloat3 PixelNormal, inout MaterialFloat TotalLightAlpha)
|
||||
{
|
||||
float3 TotalLight = 0;
|
||||
TotalLightAlpha = 0;
|
||||
|
||||
UNROLL_N(2)
|
||||
for (int i = 0; i < TotalLights; i++)
|
||||
{
|
||||
int groupID = 2 + i * 3;
|
||||
half4 PositionParam = MaterialCollection0.Vectors[groupID];
|
||||
half4 DataParam = MaterialCollection0.Vectors[groupID + 1];
|
||||
half4 ColorParam = MaterialCollection0.Vectors[groupID + 2];
|
||||
|
||||
// LightWorldPosition = float3(PositionParam.xyz);
|
||||
// float LightColor = float3(ColorParam.xyz);
|
||||
// float LightInvRadius = DataParam.x;
|
||||
// float LightIntensity = DataParam.y;
|
||||
// float LightFalloffExponent = DataParam.z;
|
||||
// bool LightInverseSquared = DataParam.w;
|
||||
|
||||
half3 ToLight = PositionParam.xyz - TranslatedWorldPosition;
|
||||
|
||||
half DistanceSqr = dot(ToLight, ToLight);
|
||||
half3 L = ToLight * rsqrt(DistanceSqr);
|
||||
|
||||
float LightMask = 0;
|
||||
|
||||
FLATTEN
|
||||
if (DataParam.w > 0.0)
|
||||
{
|
||||
LightMask = Square(saturate(1 - Square(DistanceSqr * Square(DataParam.x))));
|
||||
DataParam.y *= 0.0001; //fake intensity multiplier, dividing by 0.0001 because Inverse Squared Falloff require really high intensity
|
||||
}
|
||||
else
|
||||
{
|
||||
half3 WorldLightVector = ToLight * DataParam.x;
|
||||
half NormalizeDistanceSquared = dot(WorldLightVector, WorldLightVector);
|
||||
LightMask = pow(1.0f - saturate(NormalizeDistanceSquared), DataParam.z);
|
||||
}
|
||||
|
||||
half angle = saturate(dot(L, PixelNormal));
|
||||
LightMask *= angle;
|
||||
|
||||
TotalLight += LightMask * ColorParam.xyz * DataParam.y;
|
||||
TotalLightAlpha += LightMask;
|
||||
}
|
||||
|
||||
return TotalLight;
|
||||
}
|
||||
32
Plugins/MetaXR/Shaders/JumpFlood.ush
Normal file
32
Plugins/MetaXR/Shaders/JumpFlood.ush
Normal file
@@ -0,0 +1,32 @@
|
||||
float4 MRUKJumpFlood(MaterialFloat2 UV, Texture2D Tex, SamplerState TexSampler , MaterialFloat StepSize)
|
||||
{
|
||||
float BestDistance = 99999;
|
||||
float BestDistance2 = 99999;
|
||||
float2 BestUV = float2(-1,-1);
|
||||
float2 BestUV2 = float2(-1.0, -1.0);
|
||||
|
||||
for (int y = -1; y <= 1; ++y)
|
||||
{
|
||||
for (int x = -1; x <= 1; ++x)
|
||||
{
|
||||
float2 UVOff = UV + float2(x,y) * StepSize;
|
||||
float2 TempVaule = Texture2DSample(Tex, TexSampler, UVOff).xy;
|
||||
float Dist = length(TempVaule - UV);
|
||||
if ((TempVaule.x >= 0) && (TempVaule.y >= 0) && (Dist < BestDistance))
|
||||
{
|
||||
BestDistance = Dist;
|
||||
BestUV = TempVaule;
|
||||
}
|
||||
|
||||
float2 TempVaule2 = Texture2DSample(Tex, TexSampler, UVOff).zw;
|
||||
float Dist2 = length(TempVaule2 - UV);
|
||||
if ((TempVaule2.x >= 0) && (TempVaule2.y >= 0) && (Dist2 < BestDistance2))
|
||||
{
|
||||
BestDistance2 = Dist2;
|
||||
BestUV2 = TempVaule2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return float4(BestUV.x, BestUV.y, BestUV2.x, BestUV2.y);
|
||||
}
|
||||
36
Plugins/MetaXR/Shaders/Private/HardOcclusions.usf
Normal file
36
Plugins/MetaXR/Shaders/Private/HardOcclusions.usf
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "/Engine/Public/Platform.ush"
|
||||
|
||||
#define NUM_VIEWS 2
|
||||
|
||||
// PS Textures Parameters
|
||||
Texture2DArray EnvironmentDepthTexture;
|
||||
SamplerState EnvironmentDepthSampler;
|
||||
float2 DepthFactors;
|
||||
float4x4 ScreenToDepthMatrices[NUM_VIEWS];
|
||||
int DepthViewId;
|
||||
|
||||
void HardOcclusionsPS(
|
||||
noperspective float4 UVAndScreenPos : TEXCOORD0,
|
||||
float4 SvPosition : SV_POSITION,
|
||||
#if INSTANCED_STEREO
|
||||
in uint InstanceId : SV_InstanceID,
|
||||
#elif MOBILE_MULTI_VIEW
|
||||
in uint ViewId : SV_ViewID,
|
||||
#endif
|
||||
out float4 OutColor : SV_Target0,
|
||||
out float OutDepth : SV_DEPTH)
|
||||
{
|
||||
#if INSTANCED_STEREO
|
||||
uint ViewId = InstanceId & 1;
|
||||
#elif !MOBILE_MULTI_VIEW
|
||||
uint ViewId = DepthViewId;
|
||||
#endif
|
||||
float4 TexCoordH = mul(ScreenToDepthMatrices[ViewId], float4(UVAndScreenPos.x, 1.0f - UVAndScreenPos.y, 0.0, 1.0));
|
||||
float3 TexCoord = float3(TexCoordH.x / TexCoordH.w, TexCoordH.y / TexCoordH.w, ViewId);
|
||||
float InputDepthEye = EnvironmentDepthTexture.Sample(EnvironmentDepthSampler, TexCoord).r;
|
||||
float DepthEye = InputDepthEye * DepthFactors.x + DepthFactors.y;
|
||||
OutDepth = DepthEye;
|
||||
OutColor = float4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "/Engine/Private/Common.ush"
|
||||
|
||||
Texture2DArray InTexture;
|
||||
SamplerState InTextureSampler;
|
||||
#if !ENABLE_MULTI_VIEW
|
||||
// Use shader constants on PC Link
|
||||
int ArraySlice;
|
||||
#endif
|
||||
|
||||
void Main(
|
||||
FScreenVertexOutput Input,
|
||||
#if ENABLE_MULTI_VIEW
|
||||
// Use Multi View on Mobile
|
||||
uint ArraySlice : SV_ViewID,
|
||||
#endif
|
||||
out float4 OutColor : SV_Target0
|
||||
)
|
||||
{
|
||||
float3 Dimensions;
|
||||
InTexture.GetDimensions(Dimensions.x, Dimensions.y, Dimensions.z);
|
||||
float2 onePixelOffset = 1.0f / Dimensions.xy;
|
||||
|
||||
const uint NUM_SAMPLES = 4U;
|
||||
const float2 offsets[NUM_SAMPLES] = {
|
||||
float2(-1.0f, 1.0f),
|
||||
float2(1.0f, 1.0f),
|
||||
float2(-1.0f, -1.0f),
|
||||
float2(1.0f, -1.0f)
|
||||
};
|
||||
float4 depths[NUM_SAMPLES];
|
||||
float minDepth = 1.0f;
|
||||
float maxDepth = 0.0f;
|
||||
float depthSum = 0.0f;
|
||||
|
||||
// Find the local min and max, and collect all depth samples in the sampling grid
|
||||
uint i;
|
||||
UNROLL
|
||||
for (i = 0U; i < NUM_SAMPLES; ++i) {
|
||||
float2 uvSample = Input.UV + (offsets[i] + 0.5f) * onePixelOffset;
|
||||
float4 depth4 = InTexture.Gather(InTextureSampler, float3(uvSample, ArraySlice));
|
||||
|
||||
depthSum += dot(depth4, float4(0.25f, 0.25, 0.25, 0.25));
|
||||
|
||||
float localMax = max(max(depth4.x, depth4.y), max(depth4.z, depth4.w));
|
||||
float localMin = min(min(depth4.x, depth4.y), min(depth4.z, depth4.w));
|
||||
|
||||
maxDepth = max(maxDepth, localMax);
|
||||
minDepth = min(minDepth, localMin);
|
||||
|
||||
depths[i] = depth4;
|
||||
}
|
||||
|
||||
float maxSumDepth = 0.0f;
|
||||
float minSumDepth = 0.0f;
|
||||
float maxSumCount = 0.0f;
|
||||
float minSumCount = 0.0f;
|
||||
// Model the entire neighborhood as a bimodal distribution aggregated around the minimum and maximum values.
|
||||
// Each side of the distribution (min and max) accepts values in a multiplicative range with respect to metric depth
|
||||
// This will therefore aggregate all depth values until a maximum slope (depending also on the depth resolution)
|
||||
static const float kMaxMetricDepthThrMultiplier = 0.85f;
|
||||
static const float kMinMetricDepthThrMultiplier = 1.15f;
|
||||
// Compute thresholds in window depth space:
|
||||
// Dmetric = 1 / (1 - Dwin)
|
||||
// Tmetric = kMultiplier * Dmetric
|
||||
// Twin = 1 - 1/Tmetric
|
||||
// Therefore:
|
||||
// Twin = 1 - 1/(kMultiplier * (1 / (1 - Dwin))) = 1 - (1 - Dwin) / kMultiplier = 1 - 1/kMultiplier + Dwin / kMultiplier
|
||||
float depthThrMax = (1.0f - 1.0f / kMaxMetricDepthThrMultiplier) + maxDepth * (1.0f / kMaxMetricDepthThrMultiplier);
|
||||
float depthThrMin = (1.0f - 1.0f / kMinMetricDepthThrMultiplier) + minDepth * (1.0f / kMinMetricDepthThrMultiplier);
|
||||
|
||||
|
||||
float avg = depthSum * (1.0f / float(NUM_SAMPLES));
|
||||
if (depthThrMax < minDepth && depthThrMin > maxDepth) {
|
||||
// Degenerate case: the entire neighborhood is within min-max thresholds for averaging
|
||||
// therefore minAvg == maxAvg == avg.
|
||||
// Directly output the encoded fragColor as:
|
||||
// (1 - minAvg, 1 - maxAvg, avg - minAvg, maxAvg - minAvg)
|
||||
OutColor = float4(1.0f - avg, 1.0f - avg, 0.0f, 0.0f);
|
||||
} else {
|
||||
// Compute average depths around the minimum and maximum values
|
||||
UNROLL
|
||||
for (i = 0U; i < NUM_SAMPLES; ++i) {
|
||||
float4 maxMask = (depths[i] >= float4(depthThrMax, depthThrMax, depthThrMax, depthThrMax));
|
||||
float4 minMask = (depths[i] <= float4(depthThrMin, depthThrMin, depthThrMin, depthThrMin));
|
||||
minSumDepth += dot(minMask, depths[i]);
|
||||
minSumCount += dot(minMask, float4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
maxSumDepth += dot(maxMask, depths[i]);
|
||||
maxSumCount += dot(maxMask, float4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
float minAvg = minSumDepth / minSumCount;
|
||||
float maxAvg = maxSumDepth / maxSumCount;
|
||||
|
||||
// Encoding the depth as a 4-channel RGBA image for improved numerical stability.
|
||||
// minAvg and maxAvg are encoded in inverse range to use more floating point precision in the far field.
|
||||
// The interpolation ratio between min and max is computed as: (avg - minAvg) / (maxAvg - minAvg)
|
||||
// We can perform the differences here at higher precision
|
||||
// We let the division later to the occlusion shader to preserve the bilinear interpolation properties as with minAvg and maxAvg.
|
||||
OutColor = float4(1.0f - minAvg, 1.0f - maxAvg, avg - minAvg, maxAvg - minAvg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "/Engine/Private/Common.ush"
|
||||
|
||||
Texture2DArray InTexture;
|
||||
SamplerState InTextureSampler;
|
||||
int MipLevel;
|
||||
int ArraySlice;
|
||||
|
||||
void MainMipLevel(
|
||||
FScreenVertexOutput Input,
|
||||
out float4 OutColor : SV_Target0
|
||||
)
|
||||
{
|
||||
OutColor = InTexture.SampleLevel(InTextureSampler, float3(Input.UV, ArraySlice), MipLevel);
|
||||
}
|
||||
|
||||
void MainsRGBSourceMipLevel(
|
||||
FScreenVertexOutput Input,
|
||||
out float4 OutColor : SV_Target0
|
||||
)
|
||||
{
|
||||
OutColor = InTexture.SampleLevel(InTextureSampler, float3(Input.UV, ArraySlice), MipLevel);
|
||||
OutColor.rgb = pow( OutColor.rgb, 1.0f / 2.2f );
|
||||
}
|
||||
Reference in New Issue
Block a user