Examples/DeferredShading: Use modules
This commit is contained in:
parent
33554cf5a0
commit
b595a5d4ec
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
import Engine/InstanceData;
|
||||||
|
import Engine/ViewerData;
|
||||||
|
|
||||||
option HasDiffuseTexture: bool = false;
|
option HasDiffuseTexture: bool = false;
|
||||||
option HasAlphaTexture: bool = false;
|
option HasAlphaTexture: bool = false;
|
||||||
option AlphaTest: bool = false;
|
option AlphaTest: bool = false;
|
||||||
|
|
@ -12,27 +15,6 @@ struct BasicSettings
|
||||||
DiffuseColor: vec4[f32]
|
DiffuseColor: vec4[f32]
|
||||||
}
|
}
|
||||||
|
|
||||||
[layout(std140)]
|
|
||||||
struct InstanceData
|
|
||||||
{
|
|
||||||
worldMatrix: mat4[f32],
|
|
||||||
invWorldMatrix: mat4[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
[layout(std140)]
|
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
[binding(0)] settings: uniform[BasicSettings],
|
[binding(0)] settings: uniform[BasicSettings],
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
import Engine/InstanceData;
|
||||||
|
import Engine/ViewerData;
|
||||||
|
|
||||||
[layout(std140)]
|
[layout(std140)]
|
||||||
struct BasicSettings
|
struct BasicSettings
|
||||||
{
|
{
|
||||||
|
|
@ -8,27 +11,6 @@ struct BasicSettings
|
||||||
DiffuseColor: vec4[f32]
|
DiffuseColor: vec4[f32]
|
||||||
}
|
}
|
||||||
|
|
||||||
[layout(std140)]
|
|
||||||
struct InstanceData
|
|
||||||
{
|
|
||||||
worldMatrix: mat4[f32],
|
|
||||||
invWorldMatrix: mat4[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
[layout(std140)]
|
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
[binding(0)] settings: uniform[BasicSettings],
|
[binding(0)] settings: uniform[BasicSettings],
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
[layout(std140)]
|
[layout(std140)]
|
||||||
struct BlurData
|
struct BlurData
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
[layout(std140)]
|
[layout(std140)]
|
||||||
struct Settings
|
struct Settings
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
import Engine/ViewerData;
|
||||||
|
|
||||||
[layout(std140)]
|
[layout(std140)]
|
||||||
struct PointLight
|
struct PointLight
|
||||||
{
|
{
|
||||||
|
|
@ -27,20 +29,6 @@ struct SpotLight
|
||||||
outerAngle: f32
|
outerAngle: f32
|
||||||
}
|
}
|
||||||
|
|
||||||
[layout(std140)]
|
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
[set(0)]
|
[set(0)]
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
[nzsl_version("1.0")]
|
[nzsl_version("1.0")]
|
||||||
module;
|
module;
|
||||||
|
|
||||||
[layout(std140)]
|
import Engine/ViewerData;
|
||||||
struct ViewerData
|
|
||||||
{
|
|
||||||
projectionMatrix: mat4[f32],
|
|
||||||
invProjectionMatrix: mat4[f32],
|
|
||||||
viewMatrix: mat4[f32],
|
|
||||||
invViewMatrix: mat4[f32],
|
|
||||||
viewProjMatrix: mat4[f32],
|
|
||||||
invViewProjMatrix: mat4[f32],
|
|
||||||
renderTargetSize: vec2[f32],
|
|
||||||
invRenderTargetSize: vec2[f32],
|
|
||||||
eyePosition: vec3[f32]
|
|
||||||
}
|
|
||||||
|
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,9 @@ int main()
|
||||||
|
|
||||||
Nz::Modules<Nz::Graphics> nazara(rendererConfig);
|
Nz::Modules<Nz::Graphics> nazara(rendererConfig);
|
||||||
|
|
||||||
|
Nz::ShaderWriter::States states;
|
||||||
|
states.shaderModuleResolver = Nz::Graphics::Instance()->GetShaderModuleResolver();
|
||||||
|
|
||||||
Nz::RenderWindow window;
|
Nz::RenderWindow window;
|
||||||
|
|
||||||
Nz::MeshParams meshParams;
|
Nz::MeshParams meshParams;
|
||||||
|
|
@ -150,7 +153,7 @@ int main()
|
||||||
skyboxPipelineInfo.faceCulling = true;
|
skyboxPipelineInfo.faceCulling = true;
|
||||||
skyboxPipelineInfo.cullingSide = Nz::FaceSide::Front;
|
skyboxPipelineInfo.cullingSide = Nz::FaceSide::Front;
|
||||||
skyboxPipelineInfo.pipelineLayout = skyboxPipelineLayout;
|
skyboxPipelineInfo.pipelineLayout = skyboxPipelineLayout;
|
||||||
skyboxPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "skybox.nzsl", {}));
|
skyboxPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "skybox.nzsl", states));
|
||||||
skyboxPipelineInfo.vertexBuffers.push_back({
|
skyboxPipelineInfo.vertexBuffers.push_back({
|
||||||
0,
|
0,
|
||||||
meshPrimitiveParams.vertexDeclaration
|
meshPrimitiveParams.vertexDeclaration
|
||||||
|
|
@ -381,7 +384,7 @@ int main()
|
||||||
fullscreenVertexDeclaration
|
fullscreenVertexDeclaration
|
||||||
});
|
});
|
||||||
|
|
||||||
fullscreenPipelineInfoViewer.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "bloom_bright.nzsl", {}));
|
fullscreenPipelineInfoViewer.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "bloom_bright.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::ShaderBinding> bloomBrightShaderBinding;
|
std::shared_ptr<Nz::ShaderBinding> bloomBrightShaderBinding;
|
||||||
|
|
||||||
|
|
@ -405,7 +408,7 @@ int main()
|
||||||
std::size_t gaussianBlurDataSize = gaussianBlurDataOffsets.AddField(Nz::StructFieldType::Float1);
|
std::size_t gaussianBlurDataSize = gaussianBlurDataOffsets.AddField(Nz::StructFieldType::Float1);
|
||||||
|
|
||||||
gaussianBlurPipelineInfo.shaderModules.clear();
|
gaussianBlurPipelineInfo.shaderModules.clear();
|
||||||
gaussianBlurPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "gaussian_blur.nzsl", {}));
|
gaussianBlurPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "gaussian_blur.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> gaussianBlurPipeline = device->InstantiateRenderPipeline(gaussianBlurPipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> gaussianBlurPipeline = device->InstantiateRenderPipeline(gaussianBlurPipelineInfo);
|
||||||
std::vector<std::shared_ptr<Nz::ShaderBinding>> gaussianBlurShaderBinding(BloomSubdivisionCount * 2);
|
std::vector<std::shared_ptr<Nz::ShaderBinding>> gaussianBlurShaderBinding(BloomSubdivisionCount * 2);
|
||||||
|
|
@ -435,7 +438,7 @@ int main()
|
||||||
std::shared_ptr<Nz::ShaderBinding> toneMappingShaderBinding;
|
std::shared_ptr<Nz::ShaderBinding> toneMappingShaderBinding;
|
||||||
|
|
||||||
fullscreenPipelineInfoViewer.shaderModules.clear();
|
fullscreenPipelineInfoViewer.shaderModules.clear();
|
||||||
fullscreenPipelineInfoViewer.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "tone_mapping.nzsl", {}));
|
fullscreenPipelineInfoViewer.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "tone_mapping.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> toneMappingPipeline = device->InstantiateRenderPipeline(fullscreenPipelineInfoViewer);
|
std::shared_ptr<Nz::RenderPipeline> toneMappingPipeline = device->InstantiateRenderPipeline(fullscreenPipelineInfoViewer);
|
||||||
|
|
||||||
|
|
@ -474,7 +477,7 @@ int main()
|
||||||
fullscreenVertexDeclaration
|
fullscreenVertexDeclaration
|
||||||
});
|
});
|
||||||
|
|
||||||
bloomBlendPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "bloom_final.nzsl", {}));
|
bloomBlendPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "bloom_final.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> bloomBlendPipeline = device->InstantiateRenderPipeline(bloomBlendPipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> bloomBlendPipeline = device->InstantiateRenderPipeline(bloomBlendPipelineInfo);
|
||||||
|
|
||||||
|
|
@ -498,7 +501,7 @@ int main()
|
||||||
fullscreenVertexDeclaration
|
fullscreenVertexDeclaration
|
||||||
});
|
});
|
||||||
|
|
||||||
fullscreenPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "gamma.nzsl", {}));
|
fullscreenPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "gamma.nzsl", states));
|
||||||
|
|
||||||
// God rays
|
// God rays
|
||||||
|
|
||||||
|
|
@ -532,7 +535,7 @@ int main()
|
||||||
fullscreenVertexDeclaration
|
fullscreenVertexDeclaration
|
||||||
});
|
});
|
||||||
|
|
||||||
godraysPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "god_rays.nzsl", {}));
|
godraysPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "god_rays.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> godraysPipeline = device->InstantiateRenderPipeline(godraysPipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> godraysPipeline = device->InstantiateRenderPipeline(godraysPipelineInfo);
|
||||||
|
|
||||||
|
|
@ -587,7 +590,7 @@ int main()
|
||||||
lightingPipelineInfo.stencilBack.depthFail = Nz::StencilOperation::Zero;
|
lightingPipelineInfo.stencilBack.depthFail = Nz::StencilOperation::Zero;
|
||||||
lightingPipelineInfo.stencilBack.pass = Nz::StencilOperation::Zero;
|
lightingPipelineInfo.stencilBack.pass = Nz::StencilOperation::Zero;
|
||||||
|
|
||||||
lightingPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "lighting.nzsl", {}));
|
lightingPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "lighting.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> lightingPipeline = device->InstantiateRenderPipeline(lightingPipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> lightingPipeline = device->InstantiateRenderPipeline(lightingPipelineInfo);
|
||||||
|
|
||||||
|
|
@ -609,7 +612,7 @@ int main()
|
||||||
stencilPipelineInfo.stencilBack.compare = Nz::RendererComparison::Always;
|
stencilPipelineInfo.stencilBack.compare = Nz::RendererComparison::Always;
|
||||||
stencilPipelineInfo.stencilBack.depthFail = Nz::StencilOperation::Invert;
|
stencilPipelineInfo.stencilBack.depthFail = Nz::StencilOperation::Invert;
|
||||||
|
|
||||||
stencilPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "lighting.nzsl", {}));
|
stencilPipelineInfo.shaderModules.push_back(device->InstantiateShaderModule(Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraShader, resourceDir / "lighting.nzsl", states));
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> stencilPipeline = device->InstantiateRenderPipeline(stencilPipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> stencilPipeline = device->InstantiateRenderPipeline(stencilPipelineInfo);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue