Add fullscreen vertex shader module

This commit is contained in:
SirLynix
2022-06-16 19:26:57 +02:00
parent ddd1e3027c
commit 6f18a02999
14 changed files with 67 additions and 363 deletions

View File

@@ -366,7 +366,6 @@ namespace Nz
builder.SetScissor(renderRegion);
builder.SetViewport(renderRegion);
builder.BindPipeline(*graphics->GetBlitPipeline(false));
builder.BindVertexBuffer(0, *graphics->GetFullscreenVertexBuffer());
builder.BindShaderBinding(0, *data.blitShaderBinding);
builder.Draw(3);
@@ -539,7 +538,6 @@ namespace Nz
Graphics* graphics = Graphics::Instance();
builder.BindPipeline(*graphics->GetBlitPipeline(false));
builder.BindVertexBuffer(0, *graphics->GetFullscreenVertexBuffer());
bool first = true;

View File

@@ -29,6 +29,10 @@ namespace Nz
#include <Nazara/Graphics/Resources/Shaders/DepthMaterial.nzslb.h>
};
const UInt8 r_fullscreenVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/FullscreenVertex.nzslb.h>
};
const UInt8 r_phongMaterialShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongMaterial.nzslb.h>
};
@@ -90,7 +94,6 @@ namespace Nz
m_samplerCache.emplace(m_renderDevice);
BuildDefaultTextures();
BuildFullscreenVertexBuffer();
RegisterShaderModules();
BuildBlitPipeline();
RegisterMaterialPasses();
@@ -131,8 +134,6 @@ namespace Nz
MaterialPipeline::Uninitialize();
m_renderPassCache.reset();
m_samplerCache.reset();
m_fullscreenVertexBuffer.reset();
m_fullscreenVertexDeclaration.reset();
m_blitPipeline.reset();
m_blitPipelineLayout.reset();
m_defaultTextures.whiteTextures.fill(nullptr);
@@ -166,12 +167,6 @@ namespace Nz
pipelineInfo.pipelineLayout = m_blitPipelineLayout;
pipelineInfo.shaderModules.push_back(std::move(blitShader));
pipelineInfo.vertexBuffers.assign({
{
0,
m_fullscreenVertexDeclaration
}
});
m_blitPipeline = m_renderDevice->InstantiateRenderPipeline(pipelineInfo);
@@ -207,29 +202,6 @@ namespace Nz
}
}
void Graphics::BuildFullscreenVertexBuffer()
{
m_fullscreenVertexDeclaration = VertexDeclaration::Get(VertexLayout::XY_UV);
std::array<Nz::VertexStruct_XY_UV, 3> vertexData = {
{
{
Nz::Vector2f(-1.f, 1.f),
Nz::Vector2f(0.0f, 1.0f),
},
{
Nz::Vector2f(-1.f, -3.f),
Nz::Vector2f(0.0f, -1.0f),
},
{
Nz::Vector2f(3.f, 1.f),
Nz::Vector2f(2.0f, 1.0f),
}
}
};
m_fullscreenVertexBuffer = m_renderDevice->InstantiateBuffer(BufferType::Vertex, m_fullscreenVertexDeclaration->GetStride() * vertexData.size(), BufferUsage::DeviceLocal | BufferUsage::Write, vertexData.data());
}
void Graphics::RegisterMaterialPasses()
{
m_materialPassRegistry.RegisterPass("ForwardPass");
@@ -241,6 +213,7 @@ namespace Nz
m_shaderModuleResolver = std::make_shared<nzsl::FilesystemModuleResolver>();
RegisterEmbedShaderModule(r_basicMaterialShader);
RegisterEmbedShaderModule(r_depthMaterialShader);
RegisterEmbedShaderModule(r_fullscreenVertexShader);
RegisterEmbedShaderModule(r_phongMaterialShader);
RegisterEmbedShaderModule(r_textureBlitShader);
RegisterEmbedShaderModule(r_instanceDataModule);

View File

@@ -0,0 +1,33 @@
[nzsl_version("1.0")]
module Engine.FullscreenVertex;
[export]
struct VertIn
{
[builtin(vertex_index)] vert_index: i32
}
[export]
struct VertOut
{
[builtin(position)] position: vec4[f32],
[location(0)] uv: vec2[f32]
}
const vertPos = array[vec2[f32]](
vec2[f32](-1.0, 1.0),
vec2[f32](-1.0, -3.0),
vec2[f32]( 3.0, 1.0)
);
[export, entry(vert)]
fn VertexShader(input: VertIn) -> VertOut
{
let position = vertPos[input.vert_index];
let output: VertOut;
output.position = vec4[f32](position, 0.0, 1.0);
output.uv = position * 0.5 + vec2[f32](0.5, 0.5);
return output;
}

View File

@@ -1,33 +1,13 @@
[nzsl_version("1.0")]
module TextureBlit;
import VertOut, VertexShader from Engine.FullscreenVertex;
external
{
[binding(0)] texture: sampler2D[f32]
}
struct VertIn
{
[location(0)] position: vec2[f32],
[location(1)] uv: vec2[f32]
}
struct VertOut
{
[builtin(position)] position: vec4[f32],
[location(0)] uv: vec2[f32]
}
[entry(vert)]
fn main(vertIn: VertIn) -> VertOut
{
let output: VertOut;
output.position = vec4[f32](vertIn.position, 0.0, 1.0);
output.uv = vertIn.uv;
return output;
}
struct FragOut
{
[location(0)] color: vec4[f32]