diff --git a/bin/resources/bloom_bright.nzsl b/bin/resources/bloom_bright.nzsl index 9ce33a720..4abd3bb24 100644 --- a/bin/resources/bloom_bright.nzsl +++ b/bin/resources/bloom_bright.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; external { diff --git a/bin/resources/bloom_final.nzsl b/bin/resources/bloom_final.nzsl index 5abd7b6f0..d881239da 100644 --- a/bin/resources/bloom_final.nzsl +++ b/bin/resources/bloom_final.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; external { diff --git a/bin/resources/deferred_frag.nzsl b/bin/resources/deferred_frag.nzsl index d69915ce5..6fecfa484 100644 --- a/bin/resources/deferred_frag.nzsl +++ b/bin/resources/deferred_frag.nzsl @@ -1,6 +1,9 @@ [nzsl_version("1.0")] module; +import Engine/InstanceData; +import Engine/ViewerData; + option HasDiffuseTexture: bool = false; option HasAlphaTexture: bool = false; option AlphaTest: bool = false; @@ -12,27 +15,6 @@ struct BasicSettings 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 { [binding(0)] settings: uniform[BasicSettings], diff --git a/bin/resources/deferred_vert.nzsl b/bin/resources/deferred_vert.nzsl index 04543cdbf..1d6a4f7e2 100644 --- a/bin/resources/deferred_vert.nzsl +++ b/bin/resources/deferred_vert.nzsl @@ -1,6 +1,9 @@ [nzsl_version("1.0")] module; +import Engine/InstanceData; +import Engine/ViewerData; + [layout(std140)] struct BasicSettings { @@ -8,27 +11,6 @@ struct BasicSettings 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 { [binding(0)] settings: uniform[BasicSettings], diff --git a/bin/resources/gaussian_blur.nzsl b/bin/resources/gaussian_blur.nzsl index aebfb5ce0..ac69a9ef8 100644 --- a/bin/resources/gaussian_blur.nzsl +++ b/bin/resources/gaussian_blur.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; [layout(std140)] struct BlurData diff --git a/bin/resources/god_rays.nzsl b/bin/resources/god_rays.nzsl index 4f3aef10b..614a02f83 100644 --- a/bin/resources/god_rays.nzsl +++ b/bin/resources/god_rays.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; [layout(std140)] struct Settings diff --git a/bin/resources/lighting.nzsl b/bin/resources/lighting.nzsl index fe65b51c0..72244b0dd 100644 --- a/bin/resources/lighting.nzsl +++ b/bin/resources/lighting.nzsl @@ -1,6 +1,8 @@ [nzsl_version("1.0")] module; +import Engine/ViewerData; + [layout(std140)] struct PointLight { @@ -27,20 +29,6 @@ struct SpotLight 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)] external { diff --git a/bin/resources/skybox.nzsl b/bin/resources/skybox.nzsl index 138921a9e..ca04ecba9 100644 --- a/bin/resources/skybox.nzsl +++ b/bin/resources/skybox.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; external { diff --git a/bin/resources/tone_mapping.nzsl b/bin/resources/tone_mapping.nzsl index b10123e4c..18747ebc7 100644 --- a/bin/resources/tone_mapping.nzsl +++ b/bin/resources/tone_mapping.nzsl @@ -1,19 +1,7 @@ [nzsl_version("1.0")] module; -[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] -} +import Engine/ViewerData; external { diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index 6fc6d8477..8598e76a4 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -77,6 +77,9 @@ int main() Nz::Modules nazara(rendererConfig); + Nz::ShaderWriter::States states; + states.shaderModuleResolver = Nz::Graphics::Instance()->GetShaderModuleResolver(); + Nz::RenderWindow window; Nz::MeshParams meshParams; @@ -150,7 +153,7 @@ int main() skyboxPipelineInfo.faceCulling = true; skyboxPipelineInfo.cullingSide = Nz::FaceSide::Front; 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({ 0, meshPrimitiveParams.vertexDeclaration @@ -381,7 +384,7 @@ int main() 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 bloomBrightShaderBinding; @@ -405,7 +408,7 @@ int main() std::size_t gaussianBlurDataSize = gaussianBlurDataOffsets.AddField(Nz::StructFieldType::Float1); 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 gaussianBlurPipeline = device->InstantiateRenderPipeline(gaussianBlurPipelineInfo); std::vector> gaussianBlurShaderBinding(BloomSubdivisionCount * 2); @@ -435,7 +438,7 @@ int main() std::shared_ptr toneMappingShaderBinding; 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 toneMappingPipeline = device->InstantiateRenderPipeline(fullscreenPipelineInfoViewer); @@ -474,7 +477,7 @@ int main() 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 bloomBlendPipeline = device->InstantiateRenderPipeline(bloomBlendPipelineInfo); @@ -498,7 +501,7 @@ int main() 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 @@ -532,7 +535,7 @@ int main() 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 godraysPipeline = device->InstantiateRenderPipeline(godraysPipelineInfo); @@ -587,7 +590,7 @@ int main() lightingPipelineInfo.stencilBack.depthFail = 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 lightingPipeline = device->InstantiateRenderPipeline(lightingPipelineInfo); @@ -609,7 +612,7 @@ int main() stencilPipelineInfo.stencilBack.compare = Nz::RendererComparison::Always; 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 stencilPipeline = device->InstantiateRenderPipeline(stencilPipelineInfo);