2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2018-12-03 22:25:23 -05:00
|
|
|
|
|
|
|
|
/*=============================================================================
|
|
|
|
|
DummyRenderResources.cpp: Implementations of frequently used render resources.
|
|
|
|
|
=============================================================================*/
|
|
|
|
|
|
|
|
|
|
#include "CommonRenderResources.h"
|
|
|
|
|
#include "Containers/DynamicRHIResourceArray.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TGlobalResource<FFilterVertexDeclaration> GFilterVertexDeclaration;
|
|
|
|
|
TGlobalResource<FEmptyVertexDeclaration> GEmptyVertexDeclaration;
|
|
|
|
|
|
|
|
|
|
TGlobalResource<FScreenRectangleVertexBuffer> GScreenRectangleVertexBuffer;
|
|
|
|
|
TGlobalResource<FScreenRectangleIndexBuffer> GScreenRectangleIndexBuffer;
|
|
|
|
|
|
2019-06-11 18:27:07 -04:00
|
|
|
IMPLEMENT_GLOBAL_SHADER(FScreenVertexShaderVS, "/Engine/Private/Tools/FullscreenVertexShader.usf", "MainVS", SF_Vertex);
|
2019-05-24 19:15:38 -04:00
|
|
|
IMPLEMENT_GLOBAL_SHADER(FCopyRectPS, "/Engine/Private/ScreenPass.usf", "CopyRectPS", SF_Pixel);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void FScreenRectangleVertexBuffer::InitRHI()
|
|
|
|
|
{
|
|
|
|
|
TResourceArray<FFilterVertex, VERTEXBUFFER_ALIGNMENT> Vertices;
|
|
|
|
|
Vertices.SetNumUninitialized(6);
|
|
|
|
|
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[0].Position = FVector4f(1, 1, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[0].UV = FVector2f(1, 1);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[1].Position = FVector4f(0, 1, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[1].UV = FVector2f(0, 1);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[2].Position = FVector4f(1, 0, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[2].UV = FVector2f(1, 0);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[3].Position = FVector4f(0, 0, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[3].UV = FVector2f(0, 0);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
|
|
|
|
//The final two vertices are used for the triangle optimization (a single triangle spans the entire viewport )
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[4].Position = FVector4f(-1, 1, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[4].UV = FVector2f(-1, 1);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
2021-09-22 10:01:48 -04:00
|
|
|
Vertices[5].Position = FVector4f(1, -1, 0, 1);
|
2021-11-18 14:37:34 -05:00
|
|
|
Vertices[5].UV = FVector2f(1, -1);
|
2018-12-03 22:25:23 -05:00
|
|
|
|
|
|
|
|
// Create vertex buffer. Fill buffer with initial data upon creation
|
2021-02-16 08:37:39 -04:00
|
|
|
FRHIResourceCreateInfo CreateInfo(TEXT("FScreenRectangleVertexBuffer"), &Vertices);
|
2018-12-03 22:25:23 -05:00
|
|
|
VertexBufferRHI = RHICreateVertexBuffer(Vertices.GetResourceDataSize(), BUF_Static, CreateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FScreenRectangleIndexBuffer::InitRHI()
|
|
|
|
|
{
|
2020-07-06 18:58:26 -04:00
|
|
|
const uint16 Indices[] =
|
|
|
|
|
{
|
|
|
|
|
0, 1, 2, 2, 1, 3, // [0 .. 5] Full screen quad with 2 triangles
|
|
|
|
|
0, 4, 5, // [6 .. 8] Full screen triangle
|
|
|
|
|
3, 2, 1 // [9 .. 11] Full screen rect defined with TL, TR, BL corners
|
|
|
|
|
};
|
2018-12-03 22:25:23 -05:00
|
|
|
|
|
|
|
|
TResourceArray<uint16, INDEXBUFFER_ALIGNMENT> IndexBuffer;
|
2019-09-28 08:19:35 -04:00
|
|
|
uint32 NumIndices = UE_ARRAY_COUNT(Indices);
|
2018-12-03 22:25:23 -05:00
|
|
|
IndexBuffer.AddUninitialized(NumIndices);
|
|
|
|
|
FMemory::Memcpy(IndexBuffer.GetData(), Indices, NumIndices * sizeof(uint16));
|
|
|
|
|
|
|
|
|
|
// Create index buffer. Fill buffer with initial data upon creation
|
2021-02-16 08:37:39 -04:00
|
|
|
FRHIResourceCreateInfo CreateInfo(TEXT("FScreenRectangleIndexBuffer"), &IndexBuffer);
|
2018-12-03 22:25:23 -05:00
|
|
|
IndexBufferRHI = RHICreateIndexBuffer(sizeof(uint16), IndexBuffer.GetResourceDataSize(), BUF_Static, CreateInfo);
|
|
|
|
|
}
|