// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include namespace Nz { namespace { const UInt8 r_depthMaterialShader[] = { #include }; } std::vector> DepthMaterial::BuildShaders() { ShaderAst::ModulePtr shaderModule; #ifdef NAZARA_DEBUG std::filesystem::path shaderPath = "../../src/Nazara/Graphics/Resources/Shaders/depth_material.nzsl"; if (std::filesystem::exists(shaderPath)) { try { shaderModule = ShaderLang::ParseFromFile(shaderPath); } catch (const std::exception& e) { NazaraError(std::string("failed to load shader from engine folder: ") + e.what()); } } #endif if (!shaderModule) shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast(r_depthMaterialShader), sizeof(r_depthMaterialShader))); auto shader = std::make_shared(ShaderStageType::Fragment | ShaderStageType::Vertex, std::move(shaderModule)); return { std::move(shader) }; } bool DepthMaterial::Initialize() { BasicUniformOffsets offsets; std::tie(offsets, std::ignore) = BuildUniformOffsets(); BasicBuildOptions options; options.defaultValues.resize(offsets.totalSize); options.shaders = BuildShaders(); options.basicOffsets = s_basicUniformOffsets; options.basicOptionIndexes = &s_basicOptionIndexes; options.basicTextureIndexes = &s_basicTextureIndexes; s_depthMaterialSettings = std::make_shared(Build(options)); return true; } void DepthMaterial::Uninitialize() { s_depthMaterialSettings.reset(); } std::shared_ptr DepthMaterial::s_depthMaterialSettings; }