diff --git a/examples/GraphicsTest/main.cpp b/examples/GraphicsTest/main.cpp index 09c98bbf6..40f19f228 100644 --- a/examples/GraphicsTest/main.cpp +++ b/examples/GraphicsTest/main.cpp @@ -62,11 +62,13 @@ int main() texParams.renderDevice = device; texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB; - std::shared_ptr material = std::make_shared(Nz::BasicMaterial::GetSettings()); - material->EnableDepthBuffer(true); - material->EnableFaceCulling(true); + std::shared_ptr material; - Nz::BasicMaterial basicMat(*material); + std::shared_ptr materialPass = std::make_shared(Nz::BasicMaterial::GetSettings()); + materialPass->EnableDepthBuffer(true); + materialPass->EnableFaceCulling(true); + + Nz::BasicMaterial basicMat(*materialPass); basicMat.EnableAlphaTest(false); basicMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams)); basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams)); diff --git a/examples/PhysicsDemo/main.cpp b/examples/PhysicsDemo/main.cpp index c6f0d2146..1473147d4 100644 --- a/examples/PhysicsDemo/main.cpp +++ b/examples/PhysicsDemo/main.cpp @@ -75,15 +75,30 @@ int main() texParams.renderDevice = device; texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB; - std::shared_ptr material = std::make_shared(Nz::BasicMaterial::GetSettings()); - material->EnableDepthBuffer(true); - material->EnableDepthClamp(true); - material->EnableFaceCulling(true); + std::shared_ptr material = std::make_shared(); + + auto customSettings = Nz::BasicMaterial::GetSettings()->GetBuilderData(); + customSettings.shaders.clear(); + customSettings.shaders.emplace_back(std::make_shared(Nz::ShaderStageType::Vertex, Nz::ShaderLang::Parse(resourceDir / "depth_vert.nzsl"))); + + auto depthSettings = std::make_shared(std::move(customSettings)); + + std::shared_ptr depthPass = std::make_shared(depthSettings); + depthPass->EnableDepthBuffer(true); + depthPass->EnableFaceCulling(true); + + std::shared_ptr materialPass = std::make_shared(Nz::BasicMaterial::GetSettings()); + materialPass->EnableDepthBuffer(true); + materialPass->EnableDepthClamp(true); + materialPass->EnableFaceCulling(true); + + material->AddPass("DepthPass", depthPass); + material->AddPass("ForwardPass", materialPass); Nz::TextureSamplerInfo samplerInfo; samplerInfo.anisotropyLevel = 8; - Nz::BasicMaterial basicMat(*material); + Nz::BasicMaterial basicMat(*materialPass); basicMat.EnableAlphaTest(false); basicMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams)); basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams)); @@ -111,11 +126,15 @@ int main() auto shipCollider = std::make_shared(vertices, vertexMapper.GetVertexCount(), 0.01f); - std::shared_ptr colliderMat = std::make_shared(Nz::BasicMaterial::GetSettings()); - colliderMat->EnableDepthBuffer(true); - colliderMat->SetPrimitiveMode(Nz::PrimitiveMode::LineList); + std::shared_ptr colliderMat = std::make_shared(); - Nz::BasicMaterial colliderBasicMat(*colliderMat); + std::shared_ptr colliderMatPass = std::make_shared(Nz::BasicMaterial::GetSettings()); + colliderMatPass->EnableDepthBuffer(true); + colliderMatPass->SetPrimitiveMode(Nz::PrimitiveMode::LineList); + + colliderMat->AddPass("ForwardPass", colliderMatPass); + + Nz::BasicMaterial colliderBasicMat(*colliderMatPass); colliderBasicMat.SetDiffuseColor(Nz::Color::Green); std::shared_ptr colliderModel;