Add fullscreen vertex shader module
This commit is contained in:
parent
ddd1e3027c
commit
6f18a02999
|
|
@ -1,6 +1,7 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
external
|
||||
|
|
@ -9,30 +10,13 @@ external
|
|||
[set(0), binding(1)] colorTexture: sampler2D[f32],
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[builtin(position)] position: vec4[f32],
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
/*let BrightLuminance = 0.8;
|
||||
let BrightMiddleGrey = 0.5;
|
||||
|
|
@ -56,13 +40,3 @@ fn main(input: FragIn) -> FragOut
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
external
|
||||
|
|
@ -10,43 +11,16 @@ external
|
|||
[set(0), binding(2)] bloomTexture: sampler2D[f32],
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32],
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[location(0)] uv: vec2[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let output: FragOut;
|
||||
output.color = /*colorTexture.Sample(fragcoord) + */bloomTexture.Sample(input.uv);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,20 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
|
||||
external
|
||||
{
|
||||
[binding(0)] colorTexture: sampler2D[f32]
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[location(0)] vertUV: vec2[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let gamma = 2.2;
|
||||
|
||||
|
|
@ -38,12 +23,3 @@ fn main(input: FragIn) -> FragOut
|
|||
//output.color = pow(colorTexture.Sample(input.uv), vec4[f32](1.0 / gamma, 1.0 / gamma, 1.0 / gamma, 1.0));
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.vertUV = input.uv;
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
[layout(std140)]
|
||||
|
|
@ -17,30 +18,13 @@ external
|
|||
[set(0), binding(2)] blurData: uniform[BlurData]
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32],
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[location(0)] uv: vec2[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let invTargetSize = viewerData.invRenderTargetSize * blurData.sizeFactor;
|
||||
|
||||
|
|
@ -57,13 +41,3 @@ fn main(input: FragIn) -> FragOut
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
[layout(std140)]
|
||||
|
|
@ -22,30 +23,13 @@ external
|
|||
[set(0), binding(2)] occluderTexture: sampler2D[f32]
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[builtin(position)] position: vec4[f32],
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let deltaUV = input.uv - settings.lightPosition;
|
||||
deltaUV *= 1.0 / f32(SampleCount) * settings.density;
|
||||
|
|
@ -71,13 +55,3 @@ fn main(input: FragIn) -> FragOut
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import VertOut, VertexShader from Engine.FullscreenVertex;
|
||||
import ViewerData from Engine.ViewerData;
|
||||
|
||||
external
|
||||
|
|
@ -9,30 +10,13 @@ external
|
|||
[set(0), binding(1)] inputTexture: sampler2D[f32]
|
||||
}
|
||||
|
||||
struct FragIn
|
||||
{
|
||||
[location(0)] uv: vec2[f32],
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec2[f32],
|
||||
[location(1)] uv: vec2[f32],
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[location(0)] uv: vec2[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
fn main(input: FragIn) -> FragOut
|
||||
fn main(input: VertOut) -> FragOut
|
||||
{
|
||||
let exposure = 0.8;
|
||||
|
||||
|
|
@ -46,13 +30,3 @@ fn main(input: FragIn) -> FragOut
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let output: VertOut;
|
||||
output.position = vec4[f32](input.pos, 0.0, 1.0);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -359,10 +359,6 @@ int main()
|
|||
light.radius = radiusDis(randomEngine);
|
||||
}
|
||||
|
||||
|
||||
const std::shared_ptr<const Nz::VertexDeclaration>& fullscreenVertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XY_UV);
|
||||
|
||||
|
||||
unsigned int offscreenWidth = windowSize.x;
|
||||
unsigned int offscreenHeight = windowSize.y;
|
||||
|
||||
|
|
@ -384,10 +380,6 @@ int main()
|
|||
Nz::RenderPipelineInfo fullscreenPipelineInfoViewer;
|
||||
fullscreenPipelineInfoViewer.primitiveMode = Nz::PrimitiveMode::TriangleList;
|
||||
fullscreenPipelineInfoViewer.pipelineLayout = device->InstantiateRenderPipelineLayout(fullscreenPipelineLayoutInfoViewer);
|
||||
fullscreenPipelineInfoViewer.vertexBuffers.push_back({
|
||||
0,
|
||||
fullscreenVertexDeclaration
|
||||
});
|
||||
|
||||
fullscreenPipelineInfoViewer.shaderModules.push_back(device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, shaderDir / "bloom_bright.nzsl", states));
|
||||
|
||||
|
|
@ -477,10 +469,6 @@ int main()
|
|||
bloomBlendPipelineInfo.blend.srcColor = Nz::BlendFunc::One;
|
||||
bloomBlendPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleList;
|
||||
bloomBlendPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(bloomBlendPipelineLayoutInfo);
|
||||
bloomBlendPipelineInfo.vertexBuffers.push_back({
|
||||
0,
|
||||
fullscreenVertexDeclaration
|
||||
});
|
||||
|
||||
bloomBlendPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, shaderDir / "bloom_final.nzsl", states));
|
||||
|
||||
|
|
@ -501,10 +489,6 @@ int main()
|
|||
Nz::RenderPipelineInfo fullscreenPipelineInfo;
|
||||
fullscreenPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleList;
|
||||
fullscreenPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(fullscreenPipelineLayoutInfo);
|
||||
fullscreenPipelineInfo.vertexBuffers.push_back({
|
||||
0,
|
||||
fullscreenVertexDeclaration
|
||||
});
|
||||
|
||||
fullscreenPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, shaderDir / "gamma.nzsl", states));
|
||||
|
||||
|
|
@ -535,10 +519,6 @@ int main()
|
|||
Nz::RenderPipelineInfo godraysPipelineInfo;
|
||||
godraysPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleList;
|
||||
godraysPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(godraysPipelineLayoutInfo);
|
||||
godraysPipelineInfo.vertexBuffers.push_back({
|
||||
0,
|
||||
fullscreenVertexDeclaration
|
||||
});
|
||||
|
||||
godraysPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, shaderDir / "god_rays.nzsl", states));
|
||||
|
||||
|
|
@ -622,46 +602,6 @@ int main()
|
|||
|
||||
std::vector<std::shared_ptr<Nz::ShaderBinding>> lightingShaderBindings;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*std::array<Nz::VertexStruct_XYZ_UV, 4> vertexData = {
|
||||
{
|
||||
{
|
||||
Nz::Vector3f(-1.f, -1.f, 0.0f),
|
||||
Nz::Vector2f(0.0f, 0.0f),
|
||||
},
|
||||
{
|
||||
Nz::Vector3f(1.f, -1.f, 0.0f),
|
||||
Nz::Vector2f(1.0f, 0.0f),
|
||||
},
|
||||
{
|
||||
Nz::Vector3f(-1.f, 1.f, 0.0f),
|
||||
Nz::Vector2f(0.0f, 1.0f),
|
||||
},
|
||||
{
|
||||
Nz::Vector3f(1.f, 1.f, 0.0f),
|
||||
Nz::Vector2f(1.0f, 1.0f),
|
||||
},
|
||||
}
|
||||
};*/
|
||||
|
||||
std::shared_ptr<Nz::RenderBuffer> fullscreenVertexBuffer = device->InstantiateBuffer(Nz::BufferType::Vertex, fullscreenVertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Write, vertexData.data());
|
||||
|
||||
std::shared_ptr<Nz::ShaderBinding> bloomSkipBlit;
|
||||
std::shared_ptr<Nz::ShaderBinding> finalBlitBinding;
|
||||
|
||||
|
|
@ -973,7 +913,6 @@ int main()
|
|||
builder.BindShaderBinding(0, *godRaysShaderBinding);
|
||||
|
||||
builder.BindPipeline(*godraysPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
});
|
||||
|
|
@ -990,7 +929,6 @@ int main()
|
|||
builder.BindShaderBinding(0, *bloomBrightShaderBinding);
|
||||
|
||||
builder.BindPipeline(*bloomBrightPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
});
|
||||
|
|
@ -1013,7 +951,6 @@ int main()
|
|||
|
||||
builder.BindShaderBinding(0, *gaussianBlurShaderBinding[i * 2 + 0]);
|
||||
builder.BindPipeline(*gaussianBlurPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
});
|
||||
|
|
@ -1034,7 +971,6 @@ int main()
|
|||
|
||||
builder.BindShaderBinding(0, *gaussianBlurShaderBinding[i * 2 + 1]);
|
||||
builder.BindPipeline(*gaussianBlurPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
});
|
||||
|
|
@ -1053,7 +989,6 @@ int main()
|
|||
{
|
||||
builder.SetScissor(env.renderRect);
|
||||
builder.SetViewport(env.renderRect);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
// Blend bloom
|
||||
builder.BindPipeline(*bloomBlendPipeline);
|
||||
|
|
@ -1092,7 +1027,6 @@ int main()
|
|||
|
||||
builder.BindShaderBinding(0, *toneMappingShaderBinding);
|
||||
builder.BindPipeline(*toneMappingPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
});
|
||||
|
|
@ -1592,7 +1526,7 @@ int main()
|
|||
|
||||
builder.BindShaderBinding(0, *finalBlitBinding);
|
||||
builder.BindPipeline(*fullscreenPipeline);
|
||||
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
|
||||
|
||||
builder.Draw(3);
|
||||
}
|
||||
builder.EndDebugRegion();
|
||||
|
|
|
|||
|
|
@ -12,51 +12,24 @@
|
|||
|
||||
NAZARA_REQUEST_DEDICATED_GPU()
|
||||
|
||||
const char barModuleSource[] = R"(
|
||||
const char shaderSource[] = R"(
|
||||
[nzsl_version("1.0")]
|
||||
module Test.Bar;
|
||||
module;
|
||||
|
||||
fn dummy() {}
|
||||
option red: bool = false;
|
||||
|
||||
[export]
|
||||
[layout(std140)]
|
||||
struct Bar
|
||||
{
|
||||
}
|
||||
)";
|
||||
|
||||
const char dataModuleSource[] = R"(
|
||||
[nzsl_version("1.0")]
|
||||
module Test.Data;
|
||||
|
||||
import Test.Bar;
|
||||
|
||||
struct Foo {}
|
||||
|
||||
[export]
|
||||
[layout(std140)]
|
||||
struct Data
|
||||
{
|
||||
projectionMatrix: mat4[f32],
|
||||
worldMatrix: mat4[f32],
|
||||
viewMatrix: mat4[f32],
|
||||
pilier: Bar
|
||||
viewMatrix: mat4[f32]
|
||||
}
|
||||
)";
|
||||
|
||||
const char shaderSource[] = R"(
|
||||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
import Test.Data;
|
||||
import Test.Bar;
|
||||
|
||||
option red: bool = false;
|
||||
|
||||
[set(0)]
|
||||
external
|
||||
{
|
||||
[binding(0)] viewerData: uniform[Data]
|
||||
[binding(0)] data: uniform[Data]
|
||||
}
|
||||
|
||||
[set(1)]
|
||||
|
|
@ -100,7 +73,7 @@ fn main(fragIn: VertOut) -> FragOut
|
|||
fn main(vertIn: VertIn) -> VertOut
|
||||
{
|
||||
let vertOut: VertOut;
|
||||
vertOut.position = viewerData.projectionMatrix * viewerData.viewMatrix * viewerData.worldMatrix * vec4[f32](vertIn.position, 1.0);
|
||||
vertOut.position = data.projectionMatrix * data.viewMatrix * data.worldMatrix * vec4[f32](vertIn.position, 1.0);
|
||||
vertOut.normal = vertIn.normal;
|
||||
vertOut.uv = vertIn.uv;
|
||||
|
||||
|
|
@ -110,9 +83,9 @@ fn main(vertIn: VertIn) -> VertOut
|
|||
|
||||
int main()
|
||||
{
|
||||
std::filesystem::path resourceDir = "resources";
|
||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
|
||||
resourceDir = ".." / resourceDir;
|
||||
std::filesystem::path resourceDir = "assets/examples";
|
||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||
resourceDir = "../.." / resourceDir;
|
||||
|
||||
Nz::Renderer::Config rendererConfig;
|
||||
std::cout << "Run using Vulkan? (y/n)" << std::endl;
|
||||
|
|
@ -141,26 +114,8 @@ int main()
|
|||
return __LINE__;
|
||||
}
|
||||
|
||||
auto directoryModuleResolver = std::make_shared<nzsl::FilesystemModuleResolver>();
|
||||
directoryModuleResolver->RegisterModule(std::string_view(barModuleSource));
|
||||
directoryModuleResolver->RegisterModule(std::string_view(dataModuleSource));
|
||||
|
||||
nzsl::Ast::SanitizeVisitor::Options sanitizeOpt;
|
||||
sanitizeOpt.moduleResolver = directoryModuleResolver;
|
||||
|
||||
shaderModule = nzsl::Ast::Sanitize(*shaderModule, sanitizeOpt);
|
||||
if (!shaderModule)
|
||||
{
|
||||
std::cout << "Failed to compile shader module" << std::endl;
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
nzsl::LangWriter langWriter;
|
||||
std::string output = langWriter.Generate(*shaderModule);
|
||||
std::cout << output << std::endl;
|
||||
assert(nzsl::Ast::Sanitize(*nzsl::Parse(output)));
|
||||
|
||||
nzsl::ShaderWriter::States states;
|
||||
states.optionValues[Nz::CRC32("red")] = false; //< Try enabling this!
|
||||
states.optimize = true;
|
||||
|
||||
auto fragVertShader = device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, *shaderModule, states);
|
||||
|
|
@ -176,14 +131,14 @@ int main()
|
|||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
||||
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);
|
||||
|
||||
std::shared_ptr<Nz::Mesh> drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
|
||||
if (!drfreak)
|
||||
std::shared_ptr<Nz::Mesh> spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
|
||||
if (!spaceship)
|
||||
{
|
||||
NazaraError("Failed to load model");
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
std::shared_ptr<Nz::StaticMesh> spaceshipMesh = std::static_pointer_cast<Nz::StaticMesh>(drfreak->GetSubMesh(0));
|
||||
std::shared_ptr<Nz::StaticMesh> spaceshipMesh = std::static_pointer_cast<Nz::StaticMesh>(spaceship->GetSubMesh(0));
|
||||
|
||||
const std::shared_ptr<Nz::VertexBuffer>& meshVB = spaceshipMesh->GetVertexBuffer();
|
||||
const std::shared_ptr<const Nz::IndexBuffer>& meshIB = spaceshipMesh->GetIndexBuffer();
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ namespace Nz
|
|||
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline(bool transparent) const;
|
||||
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
|
||||
inline const DefaultTextures& GetDefaultTextures() const;
|
||||
inline const std::shared_ptr<RenderBuffer>& GetFullscreenVertexBuffer() const;
|
||||
inline const std::shared_ptr<VertexDeclaration>& GetFullscreenVertexDeclaration() const;
|
||||
inline MaterialPassRegistry& GetMaterialPassRegistry();
|
||||
inline const MaterialPassRegistry& GetMaterialPassRegistry() const;
|
||||
inline PixelFormat GetPreferredDepthStencilFormat() const;
|
||||
|
|
@ -62,7 +60,6 @@ namespace Nz
|
|||
private:
|
||||
void BuildBlitPipeline();
|
||||
void BuildDefaultTextures();
|
||||
void BuildFullscreenVertexBuffer();
|
||||
void RegisterMaterialPasses();
|
||||
void RegisterShaderModules();
|
||||
template<std::size_t N> void RegisterEmbedShaderModule(const UInt8(&content)[N]);
|
||||
|
|
@ -71,12 +68,10 @@ namespace Nz
|
|||
std::optional<RenderPassCache> m_renderPassCache;
|
||||
std::optional<TextureSamplerCache> m_samplerCache;
|
||||
std::shared_ptr<nzsl::FilesystemModuleResolver> m_shaderModuleResolver;
|
||||
std::shared_ptr<RenderBuffer> m_fullscreenVertexBuffer;
|
||||
std::shared_ptr<RenderDevice> m_renderDevice;
|
||||
std::shared_ptr<RenderPipeline> m_blitPipeline;
|
||||
std::shared_ptr<RenderPipeline> m_blitPipelineTransparent;
|
||||
std::shared_ptr<RenderPipelineLayout> m_blitPipelineLayout;
|
||||
std::shared_ptr<VertexDeclaration> m_fullscreenVertexDeclaration;
|
||||
DefaultTextures m_defaultTextures;
|
||||
MaterialPassRegistry m_materialPassRegistry;
|
||||
PixelFormat m_preferredDepthStencilFormat;
|
||||
|
|
|
|||
|
|
@ -22,16 +22,6 @@ namespace Nz
|
|||
return m_defaultTextures;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<RenderBuffer>& Graphics::GetFullscreenVertexBuffer() const
|
||||
{
|
||||
return m_fullscreenVertexBuffer;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<VertexDeclaration>& Graphics::GetFullscreenVertexDeclaration() const
|
||||
{
|
||||
return m_fullscreenVertexDeclaration;
|
||||
}
|
||||
|
||||
inline MaterialPassRegistry& Graphics::GetMaterialPassRegistry()
|
||||
{
|
||||
return m_materialPassRegistry;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue