RealtimeStyleTransferRuntime/Plugins/StyleTransfer/Shaders/Private/ShadowMaskToInputTensor.usf

29 lines
1.0 KiB
Plaintext
Raw Normal View History

// Copyright 2022 Manuel Wagner - All rights reserved
Texture2D InputTexture;
SamplerState InputTextureSampler;
RWBuffer<float> OutputUAV;
uint2 OutputDimensions; // X = InputTensor.GetSize(1), Y = InputTensor.GetSize(2) -> this does not correspond to input texture XY
float2 HalfPixelUV;
[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)]
void ShadowMaskToInputTensorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID)
{
const uint2 OutputUAVTexelCoordinate = DispatchThreadID.xy;
if(any(OutputUAVTexelCoordinate >= OutputDimensions))
{
return;
}
const uint GlobalIndex = OutputUAVTexelCoordinate.x * OutputDimensions.y + OutputUAVTexelCoordinate.y;
// note that the OutputUAV has shape (1, Y, X, C)
// which is why we need to flip the indexing
const float2 UV = float2(OutputUAVTexelCoordinate.yx) / float2(OutputDimensions.yx) + HalfPixelUV;
const float4 TextureValue = InputTexture.SampleLevel(InputTextureSampler, UV, 0);
OutputUAV[GlobalIndex + 0] = TextureValue.r;
}
#include "/Engine/Public/Platform.ush"