From 663244cde05fc3eb73a6abc98d3b69d3432a06e0 Mon Sep 17 00:00:00 2001 From: durswd Date: Fri, 14 Jul 2023 19:42:11 +0900 Subject: [PATCH 1/3] wip fix fix fix fix fix fix wip --- Dev/Cpp/CMakeLists.txt | 16 - .../EffekseerMaterialEditor/CMakeLists.txt | 18 +- .../Graphics/efkMat.Graphics.cpp | 686 ++++++++---------- .../Graphics/efkMat.Graphics.h | 224 ++---- .../effekseerMaterialEditor.cpp | 110 ++- .../EffekseerMaterialEditor/efkMat.Editor.cpp | 99 +-- Dev/Cpp/EffekseerRendererGL/CMakeLists.txt | 6 + .../EffekseerRendererGL.MaterialLoader.h | 8 + 8 files changed, 439 insertions(+), 728 deletions(-) diff --git a/Dev/Cpp/CMakeLists.txt b/Dev/Cpp/CMakeLists.txt index 66079f4c63..e2af5c6954 100644 --- a/Dev/Cpp/CMakeLists.txt +++ b/Dev/Cpp/CMakeLists.txt @@ -190,22 +190,6 @@ if(BUILD_VIEWER) set(BUILD_TEST_TEMP ${BUILD_TEST}) set(BUILD_TEST OFF) - add_subdirectory("3rdParty/AltseedRHI") - set_target_properties (AltseedRHI PROPERTIES FOLDER Thirdparty) - set(BUILD_TEST ${BUILD_TEST_TEMP}) - - if(APPLE) - add_dependencies(AltseedRHI ExternalProject_zlib ExternalProject_libpng) - else() - add_dependencies(AltseedRHI ExternalProject_glew) - endif() - - target_include_directories( - AltseedRHI - PRIVATE - ${EFK_THIRDPARTY_INCLUDES} - ) - add_subdirectory("EffekseerMaterial") set_property(TARGET EffekseerMaterial PROPERTY FOLDER Libraries) add_subdirectory("EffekseerMaterialEditor") diff --git a/Dev/Cpp/EffekseerMaterialEditor/CMakeLists.txt b/Dev/Cpp/EffekseerMaterialEditor/CMakeLists.txt index c0061ebcdf..8583a6636c 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/CMakeLists.txt +++ b/Dev/Cpp/EffekseerMaterialEditor/CMakeLists.txt @@ -45,12 +45,13 @@ if(WIN32) add_dependencies(EffekseerMaterialEditor ExternalProject_glew ExternalProject_glfw) endif() +target_compile_definitions(EffekseerMaterialEditor PRIVATE NOMINMAX) + target_include_directories( EffekseerMaterialEditor PRIVATE ${EFK_THIRDPARTY_INCLUDES} ../include/ - ${PROJECT_SOURCE_DIR}/../3rdParty/AltseedRHI/include/ ../EffekseerMaterial/ ThirdParty/picojson/) @@ -63,15 +64,17 @@ target_link_directories( target_link_libraries( EffekseerMaterialEditor PRIVATE + Effekseer + EffekseerRendererGL EffekseerMaterial EditorCommon - AltseedRHI Boxer nfd imgui imgui_platform imgui-node-editor ImGradientHDR + IPC ) if(USE_LIBPNG_LOADER) @@ -97,9 +100,6 @@ if (WIN32) target_link_libraries( EffekseerMaterialEditor PRIVATE - Effekseer # to use shader loader - EffekseerRendererGL # to use shader loader - IPC debug libglew32d optimized libglew32) @@ -118,9 +118,6 @@ find_library(CORE_VIDEO_FRAMEWORK CoreVideo) target_link_libraries( EffekseerMaterialEditor PRIVATE - Effekseer # to use shader loader - EffekseerRendererGL # to use shader loader - IPC ${CMAKE_THREAD_LIBS_INIT} ${COCOA_FRAMEWORK} ${OPENGL_LIBRARIES} @@ -147,9 +144,6 @@ include_directories( target_link_libraries( EffekseerMaterialEditor PRIVATE - Effekseer # to use shader loader - EffekseerRendererGL # to use shader loader - IPC dl stdc++fs ${CMAKE_THREAD_LIBS_INIT} @@ -160,7 +154,7 @@ endif() set_target_properties(EffekseerMaterialEditor PROPERTIES LINKER_LANGUAGE CXX) -set(files ${hs} ${srcs} ${srcs_third_imgui_platform}) +set(files ${hs} ${srcs}) set(files ${srcs} ${hs}) diff --git a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp index 235a772ddc..6e02fc041b 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp +++ b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp @@ -1,6 +1,4 @@ -#include "efkMat.Graphics.h" - #ifdef __APPLE__ #include #elif defined(_WIN32) @@ -10,13 +8,20 @@ #include #endif +#include "efkMat.Graphics.h" + #include #include +#include #include #include #include +#include "../EffekseerMaterialCompiler/OpenGL/EffekseerMaterialCompilerGL.h" #include "../EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h" +#include "../EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.MaterialLoader.h" +#include "../EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.Shader.h" +#include "../EffekseerRendererGL/EffekseerRendererGL.h" #define TINYOBJLOADER_IMPLEMENTATION #include "../ThirdParty/tiny_obj_loader.h" @@ -24,6 +29,44 @@ namespace EffekseerMaterial { +void StoreData(Effekseer::Backend::GraphicsDeviceRef gd, Effekseer::Backend::UniformBufferRef vertexUniformBuffer, Effekseer::Backend::UniformBufferRef pixelUniformBuffer, const Effekseer::Backend::UniformLayoutElement& elm, std::array data) +{ + if (elm.Stage == Effekseer::Backend::ShaderStageType::Vertex) + { + if (elm.Type == Effekseer::Backend::UniformBufferLayoutElementType::Vector4) + { + gd->UpdateUniformBuffer(vertexUniformBuffer, sizeof(float) * 4, elm.Offset, data.data()); + } + } + + if (elm.Stage == Effekseer::Backend::ShaderStageType::Pixel) + { + if (elm.Type == Effekseer::Backend::UniformBufferLayoutElementType::Vector4) + { + gd->UpdateUniformBuffer(pixelUniformBuffer, sizeof(float) * 4, elm.Offset, data.data()); + } + } +}; + +void StoreData(Effekseer::Backend::GraphicsDeviceRef gd, Effekseer::Backend::UniformBufferRef vertexUniformBuffer, Effekseer::Backend::UniformBufferRef pixelUniformBuffer, const Effekseer::Backend::UniformLayoutElement& elm, Effekseer::Matrix44 data) +{ + if (elm.Stage == Effekseer::Backend::ShaderStageType::Vertex) + { + if (elm.Type == Effekseer::Backend::UniformBufferLayoutElementType::Matrix44) + { + gd->UpdateUniformBuffer(vertexUniformBuffer, sizeof(float) * 16, elm.Offset, &data.Values); + } + } + + if (elm.Stage == Effekseer::Backend::ShaderStageType::Pixel) + { + if (elm.Type == Effekseer::Backend::UniformBufferLayoutElementType::Matrix44) + { + gd->UpdateUniformBuffer(pixelUniformBuffer, sizeof(float) * 16, elm.Offset, &data.Values); + } + } +}; + Effekseer::Gradient ToEffekseerGradient(const Gradient& gradient) { Effekseer::Gradient ret; @@ -47,42 +90,15 @@ Effekseer::Gradient ToEffekseerGradient(const Gradient& gradient) bool Graphics::Initialize(int32_t width, int32_t height) { - manager = ar::Manager::Create(ar::GraphicsDeviceType::OpenGL); - - ar::ManagerInitializationParameter param; - param.WindowWidth = width; - param.WindowHeight = height; - - if (manager->Initialize(param) != ar::ErrorCode::OK) + graphicsDevice_ = EffekseerRendererGL::CreateGraphicsDevice(EffekseerRendererGL::OpenGLDeviceType::OpenGL3, true); + if (graphicsDevice_ == nullptr) { - ar::SafeDelete(manager); return false; } - compiler = ar::Compiler::Create(manager); - return true; } -Graphics::Graphics() -{ -} - -Graphics::~Graphics() -{ - ar::SafeDelete(compiler); - ar::SafeDelete(manager); -} - -Texture::Texture() -{ -} - -Texture::~Texture() -{ - ar::SafeDelete(texture_); -} - bool Texture::Validate() { if (path_ == "") @@ -98,34 +114,29 @@ bool Texture::Validate() return false; } - texture_ = ar::Texture2D::Create(graphics_->GetManager()); - if (texture_ == nullptr) - { - return false; - } - - if (!texture_->Initialize(graphics_->GetManager(), file->GetData(), file->GetSize(), false, false)) + auto textureLoader = EffekseerRenderer::CreateTextureLoader(graphics_->GetGraphicsDevice()); + auto texture = textureLoader->Load(file->GetData(), file->GetSize(), Effekseer::TextureType::Color, false); + if (texture != nullptr) { - Invalidate(); - return false; + texture_ = texture->GetBackend(); } - - return true; + return texture_ != nullptr; } void Texture::Invalidate() { if (path_ == "") return; - - ar::SafeDelete(texture_); + texture_.Reset(); } uint64_t Texture::GetInternal() { if (texture_ == nullptr) return 0; - auto ret = texture_->GetInternalObjects()[0]; + + auto prop = EffekseerRendererGL::GetTextureProperty(texture_); + auto ret = prop.Buffer; // Temp glBindTexture(GL_TEXTURE_2D, ret); @@ -157,13 +168,21 @@ std::shared_ptr Texture::Load(std::shared_ptr graphics, Vecto { auto obj = std::make_shared(); - obj->texture_ = ar::Texture2D::Create(graphics->GetManager()); - if (obj->texture_ == nullptr) + Effekseer::Backend::TextureParameter texParam; + texParam.Size[0] = size.X; + texParam.Size[1] = size.Y; + + Effekseer::CustomVector data; + data.resize(size.X * size.Y * 4); + + if (initialData != nullptr) { - return nullptr; + memcpy(data.data(), initialData, data.size()); } - if (!obj->texture_->Initialize(graphics->GetManager(), size.X, size.Y, ar::TextureFormat::R8G8B8A8_UNORM, (void*)initialData, false)) + obj->texture_ = graphics->GetGraphicsDevice()->CreateTexture(texParam, data); + + if (obj->texture_ == nullptr) { return nullptr; } @@ -201,16 +220,6 @@ void TextureCache::NotifyFileChanged(const char* path) } } -Mesh::Mesh() -{ -} - -Mesh ::~Mesh() -{ - ar::SafeDelete(vb); - ar::SafeDelete(ib); -} - std::shared_ptr Mesh::Load(std::shared_ptr graphics, const char* path) { tinyobj::attrib_t attrib; @@ -267,12 +276,10 @@ std::shared_ptr Mesh::Load(std::shared_ptr graphics, const char* normal.X = attrib.normals[3 * idx.normal_index + 0]; normal.Y = attrib.normals[3 * idx.normal_index + 1]; normal.Z = attrib.normals[3 * idx.normal_index + 2]; - vertexes[index_offset + v].Normal = Vertex::CreatePacked(normal); + vertexes[index_offset + v].Normal = normal; vertexes[index_offset + v].UV1.X = attrib.texcoords[2 * idx.texcoord_index + 0]; vertexes[index_offset + v].UV1.Y = 1.0f - attrib.texcoords[2 * idx.texcoord_index + 1]; - vertexes[index_offset + v].UV2.X = attrib.texcoords[2 * idx.texcoord_index + 0]; - vertexes[index_offset + v].UV2.Y = 1.0f - attrib.texcoords[2 * idx.texcoord_index + 1]; vertexes[index_offset + v].Color[0] = attrib.colors[3 * idx.vertex_index + 0] * 255; vertexes[index_offset + v].Color[1] = attrib.colors[3 * idx.vertex_index + 1] * 255; vertexes[index_offset + v].Color[2] = attrib.colors[3 * idx.vertex_index + 2] * 255; @@ -314,31 +321,20 @@ std::shared_ptr Mesh::Load(std::shared_ptr graphics, const char* } tangentsum = tangentsum / static_cast(kv.second.size()); + tangentsum.Normalize(); for (auto i : kv.second) { - vertexes[i].Tangent = Vertex::CreatePacked(tangentsum); + vertexes[i].Tangent = tangentsum; + vertexes[i].Binormal = Vector3::Cross(vertexes[i].Normal, vertexes[i].Tangent); + vertexes[i].Binormal.Normalize(); } } - auto vb = ar::VertexBuffer::Create(graphics->GetManager()); - vb->Initialize(graphics->GetManager(), sizeof(Vertex), vertexes.size(), false); - - auto ib = ar::IndexBuffer::Create(graphics->GetManager()); - ib->Initialize(graphics->GetManager(), indexes.size(), false); - - if (!vb->Write(vertexes.data(), vertexes.size() * sizeof(Vertex))) - { - assert(0); - } - - if (!ib->Write(indexes.data(), indexes.size() * sizeof(int16_t))) - { - assert(0); - } + auto vb = graphics->GetGraphicsDevice()->CreateVertexBuffer(sizeof(Vertex) * vertexes.size(), vertexes.data(), false); + auto ib = graphics->GetGraphicsDevice()->CreateIndexBuffer(indexes.size(), indexes.data(), Effekseer::Backend::IndexBufferStrideType::Stride2); auto mesh = std::make_shared(); - mesh->vb = vb; mesh->ib = ib; mesh->indexCount = indexes.size(); @@ -346,94 +342,62 @@ std::shared_ptr Mesh::Load(std::shared_ptr graphics, const char* return mesh; } -Preview::Preview() +bool Preview::Initialize(std::shared_ptr graphics) { -} + std::array vb; + std::array ib; + + vb[0].Pos.X = -1.0; + vb[0].Pos.Y = +1.0; + vb[0].Pos.Z = 0.0; + vb[1].Pos.X = +1.0; + vb[1].Pos.Y = +1.0; + vb[1].Pos.Z = 0.0; + vb[2].Pos.X = +1.0; + vb[2].Pos.Y = -1.0; + vb[2].Pos.Z = 0.0; + vb[3].Pos.X = -1.0; + vb[3].Pos.Y = -1.0; + vb[3].Pos.Z = 0.0; + + vb[0].UV1.X = 0.0; + vb[0].UV1.Y = 0.0; + vb[1].UV1.X = 1.0; + vb[1].UV1.Y = 0.0; + vb[2].UV1.X = 1.0; + vb[2].UV1.Y = 1.0; + vb[3].UV1.X = 0.0; + vb[3].UV1.Y = 1.0; + + for (auto& v : vb) + { + v.Color.fill(255); + v.Normal = Vector3(0, 0, 1); + v.Tangent = Vector3(0, 1, 0); + v.Binormal = Vector3(1, 0, 0); + } -Preview::~Preview() -{ - ar::SafeDelete(vb); - ar::SafeDelete(ib); - ar::SafeDelete(shader); - ar::SafeDelete(renderTarget_); - ar::SafeDelete(depthTarget_); - ar::SafeDelete(context); - ar::SafeDelete(constantBuffer); -} + ib[0] = 0; + ib[1] = 1; + ib[2] = 2; + ib[3] = 0; + ib[4] = 2; + ib[5] = 3; -bool Preview::Initialize(std::shared_ptr graphics) -{ graphics_ = graphics; - vb = ar::VertexBuffer::Create(graphics->GetManager()); - vb->Initialize(graphics->GetManager(), sizeof(Vertex), 4, false); - - ib = ar::IndexBuffer::Create(graphics->GetManager()); - ib->Initialize(graphics->GetManager(), 6, false); - - Vertex vb_[4]; - uint16_t ib_[6]; - - vb_[0].Pos.X = -1.0; - vb_[0].Pos.Y = +1.0; - vb_[0].Pos.Z = 0.5; - vb_[1].Pos.X = +1.0; - vb_[1].Pos.Y = +1.0; - vb_[1].Pos.Z = 0.5; - vb_[2].Pos.X = +1.0; - vb_[2].Pos.Y = -1.0; - vb_[2].Pos.Z = 0.5; - vb_[3].Pos.X = -1.0; - vb_[3].Pos.Y = -1.0; - vb_[3].Pos.Z = 0.5; - - vb_[0].UV1.X = 0.0; - vb_[0].UV1.Y = 0.0; - vb_[1].UV1.X = 1.0; - vb_[1].UV1.Y = 0.0; - vb_[2].UV1.X = 1.0; - vb_[2].UV1.Y = 1.0; - vb_[3].UV1.X = 0.0; - vb_[3].UV1.Y = 1.0; - - vb_[0].Color[0] = 255; - vb_[0].Color[1] = 255; - vb_[0].Color[2] = 255; - vb_[0].Color[3] = 255; - - vb_[1].Color[0] = 255; - vb_[1].Color[1] = 255; - vb_[1].Color[2] = 255; - vb_[1].Color[3] = 255; - - vb_[2].Color[0] = 255; - vb_[2].Color[1] = 255; - vb_[2].Color[2] = 255; - vb_[2].Color[3] = 255; - - vb_[3].Color[0] = 255; - vb_[3].Color[1] = 255; - vb_[3].Color[2] = 255; - vb_[3].Color[3] = 255; - - vb->Write(vb_, sizeof(Vertex) * 4); - - ib_[0] = 0; - ib_[1] = 1; - ib_[2] = 2; - ib_[3] = 0; - ib_[4] = 2; - ib_[5] = 3; - - ib->Write(ib_, sizeof(uint16_t) * 6); - - renderTarget_ = ar::RenderTexture2D::Create(graphics->GetManager()); - renderTarget_->Initialize(graphics->GetManager(), TextureSize, TextureSize, ar::TextureFormat::R8G8B8A8_UNORM); - - depthTarget_ = ar::DepthTexture::Create(graphics->GetManager()); - depthTarget_->Initialize(graphics->GetManager(), TextureSize, TextureSize); - - context = ar::Context::Create(graphics_->GetManager()); - context->Initialize(graphics_->GetManager()); + + screenVB_ = graphics->GetGraphicsDevice()->CreateVertexBuffer(sizeof(Vertex) * vb.size(), vb.data(), false); + screenIB_ = graphics->GetGraphicsDevice()->CreateIndexBuffer(ib.size(), ib.data(), Effekseer::Backend::IndexBufferStrideType::Stride2); + + Effekseer::Backend::RenderTextureParameter renderTexParam; + renderTexParam.Size[0] = TextureSize; + renderTexParam.Size[1] = TextureSize; + renderTarget_ = graphics_->GetGraphicsDevice()->CreateRenderTexture(renderTexParam); + + Effekseer::Backend::DepthTextureParameter depthTexParam; + depthTexParam.Size[0] = TextureSize; + depthTexParam.Size[1] = TextureSize; + depthTarget_ = graphics_->GetGraphicsDevice()->CreateDepthTexture(depthTexParam); mesh_ = Mesh::Load(graphics_, "resources/meshes/sphere.obj"); @@ -446,107 +410,89 @@ bool Preview::Initialize(std::shared_ptr graphics) black_ = Texture::Load(graphics_, {1, 1}, blackPixels.data()); white_ = Texture::Load(graphics_, {1, 1}, whitePixels.data()); + Effekseer::FixedSizeVector renderTargets; + renderTargets.resize(1); + renderTargets.at(0) = renderTarget_; + renderPass_ = graphics->GetGraphicsDevice()->CreateRenderPass(renderTargets, depthTarget_); return true; } -static const char g_header_vs_gl3_src[] = "" - "#define lowp\n" - "#define mediump\n" - "#define highp\n" - "#define IN in\n" - "#define CENTROID centroid\n" - "#define TEX2D textureLod\n" - "#define OUT out\n" - "uniform vec4 customData1;\n" // HACK - "uniform vec4 customData2;\n"; // HACK - -static const char g_header_fs_gl3_src[] = "" - "#define lowp\n" - "#define mediump\n" - "#define highp\n" - "#define IN in\n" - "#define CENTROID centroid\n" - "#define TEX2D texture\n" - "layout (location = 0) out vec4 FRAGCOLOR;\n" - "uniform vec4 customData1;\n" // HACK - "uniform vec4 customData2;\n"; // HACK - -bool Preview::CompileShader(std::string& vs, - std::string& ps, - std::vector> textures, - std::vector>& uniforms, - std::vector>& gradients, - std::vector>& fixedGradients) +bool Preview::UpdateShader(const CompileResult& compileResult) { - VS = vs; - PS = ps; + auto gd = graphics_->GetGraphicsDevice().DownCast(); + auto vl = EffekseerRenderer::GetMaterialModelVertexLayout(graphics_->GetGraphicsDevice()).DownCast(); + + auto compiler = Effekseer::MaterialCompilerGL(); + auto binary = compiler.Compile(compileResult.materialFile.get()); - ar::SafeDelete(shader); - ar::SafeDelete(constantBuffer); + auto parameterGenerator = EffekseerRenderer::MaterialShaderParameterGenerator(*compileResult.materialFile, true, 0, 1); + Effekseer::CustomVector uniformLayoutElements; + EffekseerRendererGL::StoreModelVertexUniform(*compileResult.materialFile, parameterGenerator, uniformLayoutElements, false); + EffekseerRendererGL::StorePixelUniform(*compileResult.materialFile, parameterGenerator, uniformLayoutElements, 0); + uniformLayout_ = Effekseer::MakeRefPtr(EffekseerRendererGL::StoreTextureLocations(*compileResult.materialFile), uniformLayoutElements); - ar::ShaderCompilerParameter param; - param.VertexShaderTexts.push_back(g_header_vs_gl3_src); - param.VertexShaderTexts.push_back(VS); - param.PixelShaderTexts.push_back(g_header_fs_gl3_src); - param.PixelShaderTexts.push_back(PS); - param.OpenGLVersion = ar::OpenGLVersionType::OpenGL33; - ar::ShaderCompilerResult result; + VS = reinterpret_cast(binary->GetVertexShaderData(Effekseer::MaterialShaderType::Model)); + PS = reinterpret_cast(binary->GetPixelShaderData(Effekseer::MaterialShaderType::Model)); - if (!graphics_->GetCompiler()->Compile(result, param)) + shader_ = gd->CreateShaderFromCodes( + {{EffekseerRendererGL::GetVertexShaderHeader(gd->GetDeviceType())}, VS.c_str()}, + {{EffekseerRendererGL::GetFragmentShaderHeader(gd->GetDeviceType())}, PS.c_str()}, + uniformLayout_) + .DownCast(); + + Effekseer::SafeRelease(binary); + + if (shader_ == nullptr) { - std::cout << "Compile Error : " << std::endl; - std::cout << result.ErrorMessage << std::endl; return false; } - shader = ar::Shader::Create(graphics_->GetManager()); - std::vector layout; - layout.resize(6); - layout[0].Name = "atPosition"; - layout[0].LayoutFormat = ar::VertexLayoutFormat::R32G32B32_FLOAT; - layout[1].Name = "atTexCoord"; - layout[1].LayoutFormat = ar::VertexLayoutFormat::R32G32_FLOAT; - layout[2].Name = "atTexCoord2"; - layout[2].LayoutFormat = ar::VertexLayoutFormat::R32G32_FLOAT; - layout[3].Name = "atNormal"; - layout[3].LayoutFormat = ar::VertexLayoutFormat::R8G8B8A8_UNORM; - layout[4].Name = "atTangent"; - layout[4].LayoutFormat = ar::VertexLayoutFormat::R8G8B8A8_UNORM; - layout[5].Name = "atColor"; - layout[5].LayoutFormat = ar::VertexLayoutFormat::R8G8B8A8_UNORM; - - shader->Initialize(graphics_->GetManager(), result, layout, false); - - constantBuffer = ar::ConstantBuffer::Create(graphics_->GetManager()); - constantBuffer->Initialize(graphics_->GetManager(), shader->GetPixelConstantBufferSize()); - - for (auto layout : shader->GetPixelConstantLayouts()) + vertexUniformBuffer_ = gd->CreateUniformBuffer(parameterGenerator.VertexShaderUniformBufferSize, nullptr); + pixelUniformBuffer_ = gd->CreateUniformBuffer(parameterGenerator.PixelShaderUniformBufferSize, nullptr); + + Effekseer::Backend::PipelineStateParameter pipParam; + + // OpenGL doesn't require it + pipParam.FrameBufferPtr = nullptr; + pipParam.VertexLayoutPtr = vl; + pipParam.ShaderPtr = shader_; + pipParam.IsDepthTestEnabled = false; + pipParam.IsDepthWriteEnabled = false; + + pipParam.IsBlendEnabled = true; + pipParam.BlendSrcFunc = Effekseer::Backend::BlendFuncType::SrcAlpha; + pipParam.BlendDstFunc = Effekseer::Backend::BlendFuncType::OneMinusSrcAlpha; + pipParam.BlendSrcFuncAlpha = Effekseer::Backend::BlendFuncType::SrcAlpha; + pipParam.BlendDstFuncAlpha = Effekseer::Backend::BlendFuncType::OneMinusSrcAlpha; + pipParam.BlendEquationRGB = Effekseer::Backend::BlendEquationType::Add; + pipParam.BlendEquationAlpha = Effekseer::Backend::BlendEquationType::Add; + pipelineState_ = graphics_->GetGraphicsDevice()->CreatePipelineState(pipParam); + + for (const auto& elm : uniformLayout_->GetElements()) { - for (auto uni : uniforms) + for (const auto& uni : compileResult.uniforms) { - if (uni->UniformName == layout.first) + if (uni->UniformName == elm.Name.c_str()) { - constantBuffer->SetData(uni->DefaultConstants.data(), layout.second.GetSize(), layout.second.Offset); - break; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, uni->DefaultConstants); } } - for (const auto grad : gradients) + for (const auto grad : compileResult.gradients) { auto data = EffekseerRenderer::ToUniform(ToEffekseerGradient(grad->Defaults)); for (size_t i = 0; i < data.size(); i++) { - if (grad->UniformName + "_" + std::to_string(i) == layout.first) + if (grad->UniformName + "_" + std::to_string(i) == elm.Name.c_str()) { - constantBuffer->SetData(data[i].data(), layout.second.GetSize(), layout.second.Offset); - break; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, data[i]); } } } } - textures_ = textures; + textures_ = compileResult.textures; return true; } @@ -557,17 +503,20 @@ bool Preview::UpdateUniforms(std::vector> te { std::cout << "Update Uniforms" << std::endl; - if (shader == nullptr) + if (shader_ == nullptr) + { return false; + } - for (auto layout : shader->GetPixelConstantLayouts()) + // TODO remove copy and paste + auto gd = graphics_->GetGraphicsDevice().DownCast(); + for (const auto& elm : uniformLayout_->GetElements()) { - for (auto uni : uniforms) + for (const auto& uni : uniforms) { - if (uni->UniformName == layout.first) + if (uni->UniformName == elm.Name.c_str()) { - constantBuffer->SetData(uni->DefaultConstants.data(), layout.second.GetSize(), layout.second.Offset); - break; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, uni->DefaultConstants); } } @@ -577,10 +526,9 @@ bool Preview::UpdateUniforms(std::vector> te for (size_t i = 0; i < data.size(); i++) { - if (grad->UniformName + "_" + std::to_string(i) == layout.first) + if (grad->UniformName + "_" + std::to_string(i) == elm.Name.c_str()) { - constantBuffer->SetData(data[i].data(), layout.second.GetSize(), layout.second.Offset); - break; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, data[i]); } } } @@ -593,10 +541,12 @@ bool Preview::UpdateUniforms(std::vector> te bool Preview::UpdateConstantValues(float time, std::array customData1, std::array customData2) { - if (shader == nullptr) + if (shader_ == nullptr) + { return false; + } - Matrix44 matProj; + Effekseer::Matrix44 matProj; if (ModelType == PreviewModelType::Screen) { @@ -604,131 +554,121 @@ bool Preview::UpdateConstantValues(float time, std::array customData1, } else { - matProj.SetPerspectiveFovRH_OpenGL(30.0f / 180.0f * 3.14f, 1.0, 0.1f, 10.0f); + matProj.PerspectiveFovRH_OpenGL(30.0f / 180.0f * 3.14f, 1.0, 0.1f, 10.0f); } - for (auto layout : shader->GetPixelConstantLayouts()) + Effekseer::Matrix44 matCamera; + matCamera.LookAtRH(Effekseer::Vector3D(0, 0, 2), Effekseer::Vector3D(0, 0, 0), Effekseer::Vector3D(0, 1, 0)); + + Effekseer::Matrix44 matCameraProj; + + Effekseer::Matrix44::Mul(matCameraProj, matCamera, matProj); + + auto gd = graphics_->GetGraphicsDevice().DownCast(); + + for (const auto& elm : uniformLayout_->GetElements()) { - if (layout.first == "uMatProjection") + if (elm.Name == "ProjectionMatrix") { - constantBuffer->SetData(matProj.Values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, matCameraProj); } - - if (layout.first == "uMatCamera") + else if (elm.Name == "ModelMatrix") { - Matrix44 mat; - mat.SetLookAtRH(Vector3(0, 0, 2), Vector3(0, 0, 0), Vector3(0, 1, 0)); - - constantBuffer->SetData(mat.Values, layout.second.GetSize(), layout.second.Offset); + Effekseer::Matrix44 matModel; + matModel.Indentity(); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, matModel); } - - if (layout.first == "mUVInversed") + else if (elm.Name == "ModelColor") + { + std::array values; + values.fill(1.0f); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); + } + else if (elm.Name == "mUVInversed") { - float values[4]; + std::array values; values[0] = 1.0f; values[1] = -1.0f; values[2] = 1.0f; values[3] = -1.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "mUVInversedBack") + else if (elm.Name == "mUVInversedBack") { - float values[4]; + std::array values; values[0] = 1.0f; values[1] = -1.0f; values[2] = 1.0f; values[3] = -1.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "cameraPosition") + else if (elm.Name == "cameraPosition") { - float values[4]; + std::array values; values[0] = 0.0f; values[1] = 0.0f; values[2] = 2.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "reconstructionParam1") + else if (elm.Name == "reconstructionParam1") { - float values[4]; + std::array values; values[0] = 0.0f; values[1] = 1.0f; values[2] = 0.0f; values[3] = 1.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "reconstructionParam2") + else if (elm.Name == "reconstructionParam2") { - float values[4]; + std::array values; values[0] = matProj.Values[2][2]; values[1] = matProj.Values[3][2]; values[2] = matProj.Values[2][3]; values[3] = matProj.Values[3][3]; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "lightDirection") + else if (elm.Name == "lightDirection") { - float values[4]; + std::array values; values[0] = 1.0f / sqrt(3.0f); values[1] = 1.0f / sqrt(3.0f); values[2] = 1.0f / sqrt(3.0f); - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + values[3] = 1.0f; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "lightColor") + else if (elm.Name == "lightColor") { - float values[4]; - values[0] = 1.0f; - values[1] = 1.0f; - values[2] = 1.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + std::array values; + values.fill(1); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "lightAmbientColor") + else if (elm.Name == "lightAmbientColor") { - float values[4]; - values[0] = 0.0f; - values[1] = 0.0f; - values[2] = 0.0f; - - constantBuffer->SetData(values, layout.second.GetSize(), layout.second.Offset); + std::array values; + values.fill(0); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - } - - for (auto layout : shader->GetPixelConstantLayouts()) - { - if (layout.first == "predefined_uniform") + else if (elm.Name == "predefined_uniform") { std::array values; values[0] = time; values[1] = 1.0f; values[2] = 0.0f; values[3] = time; - constantBuffer->SetData(values.data(), layout.second.GetSize(), layout.second.Offset); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "customData1") + else if (elm.Name == "customData1") { - float values[4]; - constantBuffer->SetData(customData1.data(), layout.second.GetSize(), layout.second.Offset); + std::array values; + values.fill(0); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - - if (layout.first == "customData2") + else if (elm.Name == "customData2") { - float values[4]; - constantBuffer->SetData(customData2.data(), layout.second.GetSize(), layout.second.Offset); + std::array values; + values.fill(0); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } } @@ -737,111 +677,71 @@ bool Preview::UpdateConstantValues(float time, std::array customData1, void Preview::Render() { - ar::SceneParameter sceneParam; - sceneParam.RenderTargets[0] = renderTarget_; - sceneParam.DepthTarget = depthTarget_; - - graphics_->GetManager()->BeginScene(sceneParam); - graphics_->GetManager()->BeginRendering(); - - ar::Color color; - color.R = 0; - color.G = 0; - color.B = 0; - color.A = 0; - graphics_->GetManager()->Clear(true, true, color); + auto gd = graphics_->GetGraphicsDevice(); - context->Begin(); + gd->BeginRenderPass(renderPass_, true, true, Effekseer::Color(0, 0, 0, 0)); - if (shader != nullptr) + if (shader_ != nullptr) { + Effekseer::Backend::DrawParameter drawParam; + if (mesh_ != nullptr && ModelType != PreviewModelType::Screen) { - ar::DrawParameter drawParam; - drawParam.AlphaBlend = ar::AlphaBlendMode::Blend; - drawParam.Culling = ar::CullingType::Double; drawParam.VertexBufferPtr = mesh_->GetVertexBuffer(); drawParam.IndexBufferPtr = mesh_->GetIndexBuffer(); - drawParam.IndexCount = mesh_->GetIndexCount(); drawParam.IndexOffset = 0; - drawParam.ShaderPtr = shader; - drawParam.IsDepthTest = false; - drawParam.IsDepthWrite = false; - drawParam.VertexConstantBufferPtr = this->constantBuffer; - drawParam.PixelConstantBufferPtr = this->constantBuffer; - - auto pixelLayouts = shader->GetPixelTextureLayouts(); - - for (int i = 0; i < textures_.size(); i++) - { - if (pixelLayouts.count(textures_[i]->Name) > 0) - { - auto ind = pixelLayouts[textures_[i]->Name].Index; - - drawParam.PixelShaderTextures[ind] = - (textures_[i]->TexturePtr != nullptr) ? textures_[i]->TexturePtr->GetTexture() : nullptr; - drawParam.PixelShaderTextureWraps[ind] = - textures_[i]->SamplerType == TextureSamplerType::Repeat ? ar::TextureWrapType::Repeat : ar::TextureWrapType::Clamp; - } - } - - if (pixelLayouts.count("efk_depth") > 0) - { - drawParam.PixelShaderTextures[pixelLayouts["efk_depth"].Index] = white_->GetTexture(); - } - - context->Draw(drawParam); + drawParam.InstanceCount = 1; + drawParam.PrimitiveCount = mesh_->GetIndexCount() / 3; + drawParam.PipelineStatePtr = pipelineState_; + drawParam.VertexUniformBufferPtr = vertexUniformBuffer_; + drawParam.PixelUniformBufferPtr = pixelUniformBuffer_; } else { - ar::DrawParameter drawParam; - drawParam.AlphaBlend = ar::AlphaBlendMode::Blend; - drawParam.Culling = ar::CullingType::Double; - drawParam.VertexBufferPtr = vb; - drawParam.IndexBufferPtr = ib; - drawParam.IndexCount = 6; + drawParam.VertexBufferPtr = screenVB_; + drawParam.IndexBufferPtr = screenIB_; drawParam.IndexOffset = 0; - drawParam.ShaderPtr = shader; - drawParam.IsDepthTest = false; - drawParam.IsDepthWrite = false; - drawParam.VertexConstantBufferPtr = this->constantBuffer; - drawParam.PixelConstantBufferPtr = this->constantBuffer; - - auto pixelLayouts = shader->GetPixelTextureLayouts(); + drawParam.InstanceCount = 1; + drawParam.PrimitiveCount = 2; + drawParam.PipelineStatePtr = pipelineState_; + drawParam.VertexUniformBufferPtr = vertexUniformBuffer_; + drawParam.PixelUniformBufferPtr = pixelUniformBuffer_; + } - for (int i = 0; i < textures_.size(); i++) + for (int i = 0; i < textures_.size(); i++) + { + for (size_t j = 0; j < uniformLayout_->GetTextures().size(); j++) { - if (pixelLayouts.count(textures_[i]->Name) > 0) + if (textures_[i]->Name == uniformLayout_->GetTextures()[j].c_str()) { - auto ind = pixelLayouts[textures_[i]->Name].Index; - - drawParam.PixelShaderTextures[ind] = - (textures_[i]->TexturePtr != nullptr) ? textures_[i]->TexturePtr->GetTexture() : nullptr; - drawParam.PixelShaderTextureWraps[ind] = - textures_[i]->SamplerType == TextureSamplerType::Repeat ? ar::TextureWrapType::Repeat : ar::TextureWrapType::Clamp; + drawParam.TexturePtrs[j] = textures_[i]->TexturePtr->GetTexture(); + drawParam.TextureWrapTypes[j] = textures_[i]->SamplerType == TextureSamplerType::Repeat ? Effekseer::Backend::TextureWrapType::Repeat : Effekseer::Backend::TextureWrapType::Clamp; } } + } - if (pixelLayouts.count("efk_depth") > 0) + for (size_t j = 0; j < uniformLayout_->GetTextures().size(); j++) + { + if (uniformLayout_->GetTextures()[j] == "efk_depth") { - drawParam.PixelShaderTextures[pixelLayouts["efk_depth"].Index] = white_->GetTexture(); + drawParam.TexturePtrs[j] = white_->GetTexture(); + drawParam.TextureWrapTypes[j] = Effekseer::Backend::TextureWrapType::Clamp; } - - context->Draw(drawParam); } - } - context->End(); + gd->Draw(drawParam); + } - graphics_->GetManager()->EndRendering(); - graphics_->GetManager()->EndScene(); + gd->EndRenderPass(); } uint64_t Preview::GetInternal() { if (renderTarget_ == nullptr) return 0; - auto ret = renderTarget_->GetInternalObjects()[0]; + + auto prop = EffekseerRendererGL::GetTextureProperty(renderTarget_); + auto ret = prop.Buffer; // Temp glBindTexture(GL_TEXTURE_2D, ret); diff --git a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.h b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.h index 73e2285a66..3a6c54497c 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.h +++ b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.h @@ -1,14 +1,20 @@ #pragma once -#include +#include +#include #include #include #include +#include + namespace EffekseerMaterial { +class Texture; +class TextureWithSampler; + enum class PreviewModelType { Screen, @@ -125,151 +131,25 @@ struct Vector3 } }; -struct Matrix44 +struct CompileResult { -private: -public: - Matrix44() = default; - - float Values[4][4]; - - Matrix44& OrthographicRH(float width, float height, float zn, float zf) - { - Values[0][0] = 2 / width; - Values[0][1] = 0; - Values[0][2] = 0; - Values[0][3] = 0; - - Values[1][0] = 0; - Values[1][1] = 2 / height; - Values[1][2] = 0; - Values[1][3] = 0; - - Values[2][0] = 0; - Values[2][1] = 0; - Values[2][2] = 1 / (zn - zf); - Values[2][3] = 0; - - Values[3][0] = 0; - Values[3][1] = 0; - Values[3][2] = zn / (zn - zf); - Values[3][3] = 1; - return *this; - } - - Matrix44& SetPerspectiveFovRH(float ovY, float aspect, float zn, float zf) - { - float yScale = 1 / tanf(ovY / 2); - float xScale = yScale / aspect; - - Values[0][0] = xScale; - Values[1][0] = 0; - Values[2][0] = 0; - Values[3][0] = 0; - - Values[0][1] = 0; - Values[1][1] = yScale; - Values[2][1] = 0; - Values[3][1] = 0; - - Values[0][2] = 0; - Values[1][2] = 0; - Values[2][2] = zf / (zn - zf); - Values[3][2] = -1; - - Values[0][3] = 0; - Values[1][3] = 0; - Values[2][3] = zn * zf / (zn - zf); - Values[3][3] = 0; - return *this; - } - - Matrix44& SetPerspectiveFovRH_OpenGL(float ovY, float aspect, float zn, float zf) - { - float yScale = 1 / tanf(ovY / 2); - float xScale = yScale / aspect; - float dz = zf - zn; - - Values[0][0] = xScale; - Values[1][0] = 0; - Values[2][0] = 0; - Values[3][0] = 0; - - Values[0][1] = 0; - Values[1][1] = yScale; - Values[2][1] = 0; - Values[3][1] = 0; - - Values[0][2] = 0; - Values[1][2] = 0; - Values[2][2] = -(zf + zn) / dz; - Values[3][2] = -1.0f; - - Values[0][3] = 0; - Values[1][3] = 0; - Values[2][3] = -2.0f * zn * zf / dz; - Values[3][3] = 0.0f; - - return *this; - } - - Matrix44& SetLookAtRH(const Vector3& eye, const Vector3& at, const Vector3& up) - { - std::memset(Values, 0, sizeof(float) * 16); - - Vector3 F = Vector3::Subtract(eye, at).GetNormal(); - Vector3 R = Vector3::Cross(up, F).GetNormal(); - Vector3 U = Vector3::Cross(F, R).GetNormal(); - - Values[0][0] = R.X; - Values[0][1] = R.Y; - Values[0][2] = R.Z; - Values[0][3] = 0.0f; - - Values[1][0] = U.X; - Values[1][1] = U.Y; - Values[1][2] = U.Z; - Values[1][3] = 0.0f; - - Values[2][0] = F.X; - Values[2][1] = F.Y; - Values[2][2] = F.Z; - Values[2][3] = 0.0f; - - Values[0][3] = -Vector3::Dot(R, eye); - Values[1][3] = -Vector3::Dot(U, eye); - Values[2][3] = -Vector3::Dot(F, eye); - Values[3][3] = 1.0f; - return *this; - } + std::shared_ptr materialFile; + std::vector> textures; + std::vector> uniforms; + std::vector> gradients; + std::vector> fixedGradients; + int customData1Count; + int customData2Count; }; struct Vertex { Vector3 Pos; + Vector3 Normal; + Vector3 Binormal; + Vector3 Tangent; Vector2 UV1; - Vector2 UV2; - std::array Normal; - std::array Tangent; - uint8_t Color[4]; - - static std::array CreatePacked(const Vector3& v) - { - std::array ret; - ret[0] = static_cast((v.X + 1.0f) / 2.0f * 255); - ret[1] = static_cast((v.Y + 1.0f) / 2.0f * 255); - ret[2] = static_cast((v.Z + 1.0f) / 2.0f * 255); - return ret; - } - - static Vector3 CreateUnpacked(const std::array& v) - { - Vector3 ret; - ret.X = v[0] / 255.0f * 2.0f - 1.0f; - ret.Y = v[1] / 255.0f * 2.0f - 1.0f; - ret.Z = v[2] / 255.0f * 2.0f - 1.0f; - return ret; - } + std::array Color; }; static void CalcTangentSpace(const Vertex& v1, const Vertex& v2, const Vertex& v3, Vector3& binormal, Vector3& tangent) @@ -320,21 +200,14 @@ static void CalcTangentSpace(const Vertex& v1, const Vertex& v2, const Vertex& v class Graphics { private: - ar::Manager* manager = nullptr; - ar::Compiler* compiler = nullptr; + Effekseer::Backend::GraphicsDeviceRef graphicsDevice_; public: bool Initialize(int32_t width, int32_t height); - Graphics(); - virtual ~Graphics(); - ar::Manager* GetManager() + Effekseer::Backend::GraphicsDeviceRef GetGraphicsDevice() { - return manager; - } - ar::Compiler* GetCompiler() - { - return compiler; + return graphicsDevice_; } }; @@ -343,12 +216,9 @@ class Texture private: std::string path_; std::shared_ptr graphics_; - ar::Texture2D* texture_ = nullptr; + Effekseer::Backend::TextureRef texture_ = nullptr; public: - Texture(); - virtual ~Texture(); - bool Validate(); void Invalidate(); @@ -359,10 +229,11 @@ class Texture return path_; } - ar::Texture2D* GetTexture() + Effekseer::Backend::TextureRef GetTexture() { return texture_; } + static std::shared_ptr Load(std::shared_ptr graphics, const char* path); static std::shared_ptr Load(std::shared_ptr graphics, Vector2 size, const void* initialData); @@ -391,20 +262,17 @@ class TextureCache class Mesh { private: - ar::VertexBuffer* vb = nullptr; - ar::IndexBuffer* ib = nullptr; + Effekseer::Backend::VertexBufferRef vb = nullptr; + Effekseer::Backend::IndexBufferRef ib = nullptr; int32_t indexCount = 0; public: - Mesh(); - virtual ~Mesh(); - - ar::VertexBuffer* GetVertexBuffer() + Effekseer::Backend::VertexBufferRef GetVertexBuffer() { return vb; } - ar::IndexBuffer* GetIndexBuffer() + Effekseer::Backend::IndexBufferRef GetIndexBuffer() { return ib; } @@ -421,41 +289,39 @@ class Preview { private: std::shared_ptr graphics_; - ar::RenderTexture2D* renderTarget_ = nullptr; - ar::DepthTexture* depthTarget_ = nullptr; - ar::Shader* shader = nullptr; - ar::VertexBuffer* vb = nullptr; - ar::IndexBuffer* ib = nullptr; - ar::ConstantBuffer* constantBuffer = nullptr; - ar::Context* context = nullptr; + + Effekseer::Backend::TextureRef renderTarget_ = nullptr; + Effekseer::Backend::TextureRef depthTarget_ = nullptr; + Effekseer::Backend::ShaderRef shader_ = nullptr; + Effekseer::Backend::VertexBufferRef screenVB_ = nullptr; + Effekseer::Backend::IndexBufferRef screenIB_ = nullptr; + Effekseer::Backend::RenderPassRef renderPass_ = nullptr; + Effekseer::Backend::PipelineStateRef pipelineState_ = nullptr; + Effekseer::Backend::UniformBufferRef vertexUniformBuffer_ = nullptr; + Effekseer::Backend::UniformBufferRef pixelUniformBuffer_ = nullptr; + Effekseer::Backend::UniformLayoutRef uniformLayout_ = nullptr; + std::vector> textures_; std::shared_ptr mesh_; std::shared_ptr black_; std::shared_ptr white_; public: - Preview(); - virtual ~Preview(); bool Initialize(std::shared_ptr graphics); - bool CompileShader(std::string& vs, - std::string& ps, - std::vector> textures, - std::vector>& uniforms, - std::vector>& gradients, - std::vector>& fixedGradients); + bool UpdateShader(const CompileResult& compileResult); bool UpdateUniforms(std::vector> textures, std::vector>& uniforms, std::vector>& gradients); bool UpdateConstantValues(float time, std::array customData1, std::array customData2); void Render(); - std::string VS; - std::string PS; - PreviewModelType ModelType = PreviewModelType::Screen; uint64_t GetInternal(); + std::string VS; + std::string PS; + static const int32_t TextureSize = 128; }; diff --git a/Dev/Cpp/EffekseerMaterialEditor/effekseerMaterialEditor.cpp b/Dev/Cpp/EffekseerMaterialEditor/effekseerMaterialEditor.cpp index b7ef250cdc..acf8ceb731 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/effekseerMaterialEditor.cpp +++ b/Dev/Cpp/EffekseerMaterialEditor/effekseerMaterialEditor.cpp @@ -10,7 +10,6 @@ #include "../IPC/IPC.h" -#include #include #include #include @@ -56,11 +55,7 @@ namespace ed = ax::NodeEditor; GLFWwindow* glfwMainWindow = nullptr; -ar::Manager* arManager = nullptr; -ar::Context* context = nullptr; - -std::shared_ptr graphics; -std::shared_ptr editor; +std::shared_ptr g_editor; std::shared_ptr g_selectedNode; bool g_showDebugWindow = false; @@ -127,17 +122,17 @@ void GLFLW_CloseCallback(GLFWwindow* w) { bool isChanged = false; - for (size_t i = 0; i < editor->GetContents().size(); i++) + for (size_t i = 0; i < g_editor->GetContents().size(); i++) { - if (editor->GetContents()[i]->GetIsChanged()) + if (g_editor->GetContents()[i]->GetIsChanged()) { auto closeIfCan = [w]() -> void { bool isChanged = false; - for (size_t i = 0; i < editor->GetContents().size(); i++) + for (size_t i = 0; i < g_editor->GetContents().size(); i++) { - if (editor->GetContents()[i]->GetIsChanged()) + if (g_editor->GetContents()[i]->GetIsChanged()) { isChanged = true; } @@ -150,7 +145,7 @@ void GLFLW_CloseCallback(GLFWwindow* w) }; auto closeDialog = - std::make_shared(editor->GetContents()[i], [closeIfCan]() + std::make_shared(g_editor->GetContents()[i], [closeIfCan]() { closeIfCan(); }); newDialogs.push_back(closeDialog); isChanged = true; @@ -306,10 +301,8 @@ int mainLoop(int argc, char* argv[]) glfwMakeContextCurrent(glfwMainWindow); glfwSwapInterval(1); - graphics = std::make_shared(); + auto graphics = std::make_shared(); graphics->Initialize(config->WindowWidth, config->WindowHeight); - context = ar::Context::Create(graphics->GetManager()); - auto arManager = graphics->GetManager(); #if __APPLE__ // GL 3.2 + GLSL 150 @@ -338,7 +331,7 @@ int mainLoop(int argc, char* argv[]) } ChangeLanguage(config->Language); - editor = std::make_shared(graphics); + g_editor = std::make_shared(graphics); keyStatePre.fill(false); keyState.fill(false); @@ -410,24 +403,24 @@ int mainLoop(int argc, char* argv[]) else if (commandDataTOMaterialEditor.Type == IPC::CommandType::OpenMaterial) { spdlog::trace("ICP - Receive - OpenMaterial : {}", (const char*)(commandDataTOMaterialEditor.str.data())); - editor->LoadOrSelect(commandDataTOMaterialEditor.str.data()); + g_editor->LoadOrSelect(commandDataTOMaterialEditor.str.data()); } else if (commandDataTOMaterialEditor.Type == IPC::CommandType::OpenOrCreateMaterial) { spdlog::trace("ICP - Receive - OpenOrCreateMaterial : {}", (const char*)(commandDataTOMaterialEditor.str.data())); - if (editor->LoadOrSelect(commandDataTOMaterialEditor.str.data()) == EffekseerMaterial::ErrorCode::NotFound) + if (g_editor->LoadOrSelect(commandDataTOMaterialEditor.str.data()) == EffekseerMaterial::ErrorCode::NotFound) { - editor->New(); - editor->SaveAs(commandDataTOMaterialEditor.str.data()); + g_editor->New(); + g_editor->SaveAs(commandDataTOMaterialEditor.str.data()); } } } } - auto material = editor->GetSelectedMaterial(); + auto material = g_editor->GetSelectedMaterial(); if (material != nullptr && material->GetCommandManager()->GetHistoryID() != previousHistoryID) { - auto content = editor->GetContents()[editor->GetSelectedContentIndex()]; + auto content = g_editor->GetContents()[g_editor->GetSelectedContentIndex()]; spdlog::trace("ICP - Send - NotifyUpdate : {}", material->GetPath()); content->UpdateBinary(); @@ -474,34 +467,34 @@ int mainLoop(int argc, char* argv[]) { if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("New").c_str())) { - editor->New(); + g_editor->New(); } if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("Load").c_str())) { - editor->Load(); + g_editor->Load(); } } #ifdef __APPLE__ if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("Save").c_str(), "Command+S")) { - editor->Save(); + g_editor->Save(); } if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("SaveAs").c_str(), "Command+S")) { - editor->SaveAs(); + g_editor->SaveAs(); } #else if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("Save").c_str(), "Ctrl+S")) { - editor->Save(); + g_editor->Save(); } if (ImGui::MenuItem(EffekseerMaterial::StringContainer::GetValue("SaveAs").c_str(), "Ctrl+S")) { - editor->SaveAs(); + g_editor->SaveAs(); } #endif @@ -562,16 +555,16 @@ int mainLoop(int argc, char* argv[]) { if (ImGui::BeginTabBar("###MainTab")) { - bool isSelectedNow = editor->GetIsSelectedDirty(); + bool isSelectedNow = g_editor->GetIsSelectedDirty(); - editor->ClearDirtiedSelectedFlags(); + g_editor->ClearDirtiedSelectedFlags(); - for (size_t i = 0; i < editor->GetContents().size(); i++) + for (size_t i = 0; i < g_editor->GetContents().size(); i++) { - std::string tabName = editor->GetContents()[i]->GetName(); + std::string tabName = g_editor->GetContents()[i]->GetName(); tabName += "###tab" + std::to_string(i); - bool isSelected = editor->GetSelectedContentIndex() == i; + bool isSelected = g_editor->GetSelectedContentIndex() == i; ImGuiTabItemFlags tabItemFlags = 0; if (isSelected && isSelectedNow) @@ -585,15 +578,15 @@ int mainLoop(int argc, char* argv[]) // avoid to select when selected contents is changed if (!isSelectedNow) { - editor->SelectContent(i); + g_editor->SelectContent(i); } - if (i == editor->GetSelectedContentIndex()) + if (i == g_editor->GetSelectedContentIndex()) { ImGui::Columns(2); - if (editor->GetContents()[i]->IsLoading) + if (g_editor->GetContents()[i]->IsLoading) { ImGui::SetColumnWidth(0, leftWidth); } @@ -604,13 +597,13 @@ int mainLoop(int argc, char* argv[]) ImGui::BeginChild("###Left"); - editor->UpdatePreview(); + g_editor->UpdatePreview(); ImGui::Separator(); if (g_selectedNode != nullptr) { - editor->UpdateParameterEditor(g_selectedNode); + g_editor->UpdateParameterEditor(g_selectedNode); } ImGui::EndChild(); @@ -623,14 +616,14 @@ int mainLoop(int argc, char* argv[]) if (!ImGui::IsAnyItemActive()) { - editor->GetContents()[i]->GetMaterial()->GetCommandManager()->MakeMergeDisabled(); + g_editor->GetContents()[i]->GetMaterial()->GetCommandManager()->MakeMergeDisabled(); } - ed::SetCurrentEditor(editor->GetContents()[i]->GetEditorContext()); + ed::SetCurrentEditor(g_editor->GetContents()[i]->GetEditorContext()); ed::Begin("###MainEditor", ImVec2(0.0, 0.0f)); // ed::Suspend(); - editor->Update(); + g_editor->Update(); ed::End(); @@ -639,7 +632,7 @@ int mainLoop(int argc, char* argv[]) g_selectedNode = nullptr; if (ed::GetSelectedNodes(nodeIDs, 2) > 0) { - for (auto node : editor->GetContents()[i]->GetMaterial()->GetNodes()) + for (auto node : g_editor->GetContents()[i]->GetMaterial()->GetNodes()) { if (node->GUID == nodeIDs[0].Get()) { @@ -661,16 +654,16 @@ int mainLoop(int argc, char* argv[]) if (!isOpen) { // close item - if (editor->GetContents()[i]->GetIsChanged()) + if (g_editor->GetContents()[i]->GetIsChanged()) { auto closeDialog = - std::make_shared(editor->GetContents()[i], []() {}); + std::make_shared(g_editor->GetContents()[i], []() {}); // ImGui::OpenPopup(closeDialog->GetID()); newDialogs.push_back(closeDialog); } else { - editor->GetContents()[i]->IsClosing = true; + g_editor->GetContents()[i]->IsClosing = true; } } } @@ -686,7 +679,7 @@ int mainLoop(int argc, char* argv[]) { if (!ipcMode) { - auto creatDialog = std::make_shared(editor); + auto creatDialog = std::make_shared(g_editor); // ImGui::OpenPopup(creatDialog->GetID()); newDialogs.push_back(creatDialog); } @@ -755,28 +748,10 @@ int mainLoop(int argc, char* argv[]) } } - editor->preview_->Render(); + g_editor->preview_->Render(); } - editor->CloseContents(); - - arManager->BeginRendering(); - - ar::SceneParameter sparam; - - arManager->BeginScene(sparam); - - ar::Color clearColor; - clearColor.R = 100; - clearColor.G = 50; - clearColor.B = 50; - clearColor.A = 0; - - arManager->Clear(true, true, clearColor); - - arManager->EndScene(); - - arManager->EndRendering(); + g_editor->CloseContents(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); @@ -787,14 +762,13 @@ int mainLoop(int argc, char* argv[]) } } - editor.reset(); + g_editor.reset(); + g_selectedNode.reset(); ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - ar::SafeDelete(context); - if (glfwMainWindow != nullptr) { mainWindowState = mainWindow->GetState(); diff --git a/Dev/Cpp/EffekseerMaterialEditor/efkMat.Editor.cpp b/Dev/Cpp/EffekseerMaterialEditor/efkMat.Editor.cpp index 89ea40c032..c1bc44ffe7 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/efkMat.Editor.cpp +++ b/Dev/Cpp/EffekseerMaterialEditor/efkMat.Editor.cpp @@ -82,47 +82,43 @@ static std::tuple GetSelectedNodeBounds(float margin) return std::tuple{}; } -void Compile(std::shared_ptr graphics, - std::shared_ptr material, - std::shared_ptr node, - std::vector>& outputTextures, - std::vector>& outputUniforms, - std::vector>& gradients, - std::vector>& fixedGradients, - std::string& vs, - std::string& ps) +CompileResult Compile(std::shared_ptr graphics, + std::shared_ptr material, + std::shared_ptr node) { + CompileResult compileResult; + compileResult.materialFile = std::make_shared(); + + std::vector> outputTextures; + EffekseerMaterial::TextExporter exporter; auto result = (&exporter)->Export(material, node); - auto efkMaterial = Effekseer::MaterialFile(); - efkMaterial.SetGenericCode(result.Code.c_str()); - efkMaterial.SetIsSimpleVertex(false); - efkMaterial.SetHasRefraction(result.HasRefraction); - efkMaterial.SetShadingModel(static_cast(result.ShadingModel)); - - // HACK (adhoc support in the editor) - // efkMaterial.SetCustomData1Count(result.CustomData1); - // efkMaterial.SetCustomData2Count(result.CustomData2); + compileResult.materialFile->SetGenericCode(result.Code.c_str()); + compileResult.materialFile->SetIsSimpleVertex(false); + compileResult.materialFile->SetHasRefraction(result.HasRefraction); + compileResult.materialFile->SetShadingModel(static_cast(result.ShadingModel)); + compileResult.materialFile->SetCustomData1Count(result.CustomData1); + compileResult.materialFile->SetCustomData2Count(result.CustomData2); - efkMaterial.SetTextureCount(result.Textures.size()); - efkMaterial.SetUniformCount(result.Uniforms.size()); + compileResult.materialFile->SetTextureCount(result.Textures.size()); + compileResult.materialFile->SetUniformCount(result.Uniforms.size()); for (const auto& type : result.RequiredPredefinedMethodTypes) { - efkMaterial.RequiredMethods.emplace_back(static_cast(type)); + compileResult.materialFile->RequiredMethods.emplace_back(static_cast(type)); } for (size_t i = 0; i < result.Textures.size(); i++) { - efkMaterial.SetTextureIndex(i, i); - efkMaterial.SetTextureName(i, result.Textures[i]->UniformName.c_str()); + compileResult.materialFile->SetTextureIndex(i, i); + compileResult.materialFile->SetTextureName(i, result.Textures[i]->UniformName.c_str()); } for (size_t i = 0; i < result.Uniforms.size(); i++) { - efkMaterial.SetUniformIndex(i, (int)result.Uniforms[i]->Type); - efkMaterial.SetUniformName(i, result.Uniforms[i]->UniformName.c_str()); + compileResult.materialFile->SetUniformIndex(i, (int)result.Uniforms[i]->Type); + compileResult.materialFile->SetUniformName(i, result.Uniforms[i]->UniformName.c_str()); } const auto copyGradient = [&](std::vector& dst, const std::vector>& src) @@ -149,15 +145,9 @@ void Compile(std::shared_ptr graphics, } }; - copyGradient(efkMaterial.Gradients, result.Gradients); - - copyGradient(efkMaterial.FixedGradients, result.FixedGradients); - - auto compiler = ::Effekseer::CreateUniqueReference(new Effekseer::MaterialCompilerGL()); - auto binary = ::Effekseer::CreateUniqueReference(compiler->Compile(&efkMaterial, 1024, 1024)); + copyGradient(compileResult.materialFile->Gradients, result.Gradients); - vs = reinterpret_cast(binary->GetVertexShaderData(Effekseer::MaterialShaderType::Standard)); - ps = reinterpret_cast(binary->GetPixelShaderData(Effekseer::MaterialShaderType::Standard)); + copyGradient(compileResult.materialFile->FixedGradients, result.FixedGradients); auto textures = result.Textures; auto removed_it = std::remove_if(textures.begin(), @@ -186,11 +176,14 @@ void Compile(std::shared_ptr graphics, outputTextures.push_back(ts); } - outputUniforms = result.Uniforms; - - fixedGradients = result.FixedGradients; + compileResult.textures = outputTextures; + compileResult.uniforms = result.Uniforms; + compileResult.fixedGradients = result.FixedGradients; + compileResult.gradients = result.Gradients; + compileResult.customData1Count = result.CustomData1; + compileResult.customData2Count = result.CustomData2; - gradients = result.Gradients; + return compileResult; } void ExtractUniforms(std::shared_ptr graphics, @@ -803,14 +796,7 @@ void Editor::UpdateNodes() if (!node->GetIsDirtied() && !isSelectedDirty_) continue; - std::vector> uniforms; - std::vector> textures; - std::vector> gradients; - std::vector> fixedGradients; - - std::string vs; - std::string ps; - Compile(graphics_, material, node, textures, uniforms, gradients, fixedGradients, vs, ps); + auto compileResult = Compile(graphics_, material, node); // update pin state for (auto behavior : node->Parameter->BehaviorComponents) @@ -825,10 +811,10 @@ void Editor::UpdateNodes() } } - preview_->CompileShader(vs, ps, textures, uniforms, gradients, fixedGradients); - previewTextureCount_ = textures.size(); - previewUniformCount_ = uniforms.size(); - previewGradientCount_ = gradients.size(); + preview_->UpdateShader(compileResult); + previewTextureCount_ = compileResult.textures.size(); + previewUniformCount_ = compileResult.uniforms.size(); + previewGradientCount_ = compileResult.gradients.size(); } for (auto node : material->GetNodes()) @@ -885,14 +871,7 @@ void Editor::UpdateNodes() preview->ModelType = PreviewModelType::Sphere; } - std::vector> uniforms; - std::vector> textures; - std::vector> gradients; - std::vector> fixedGradients; - - std::string vs; - std::string ps; - Compile(graphics_, material, node, textures, uniforms, gradients, fixedGradients, vs, ps); + auto compileResult = Compile(graphics_, material, node); // update pin state for (auto behavior : node->Parameter->BehaviorComponents) @@ -907,7 +886,7 @@ void Editor::UpdateNodes() } } - preview->CompileShader(vs, ps, textures, uniforms, gradients, fixedGradients); + preview->UpdateShader(compileResult); material->ClearDirty(node); material->ClearContentDirty(node); @@ -1461,12 +1440,12 @@ void Editor::UpdateParameterEditor(std::shared_ptr node) if (texture != nullptr && texture->GetTexture() != nullptr) { - ImGui::Image((void*)texture->GetTexture()->GetInternalObjects()[0], size, ImVec2(0.0, 1.0), ImVec2(1.0, 0.0)); + ImGui::Image((void*)texture->GetInternal(), size, ImVec2(0.0, 1.0), ImVec2(1.0, 0.0)); showPath(); // adhoc - glBindTexture(GL_TEXTURE_2D, (GLuint)texture->GetTexture()->GetInternalObjects()[0]); + glBindTexture(GL_TEXTURE_2D, (GLuint)texture->GetInternal()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } diff --git a/Dev/Cpp/EffekseerRendererGL/CMakeLists.txt b/Dev/Cpp/EffekseerRendererGL/CMakeLists.txt index 3eb4ac3c87..433822a7ab 100644 --- a/Dev/Cpp/EffekseerRendererGL/CMakeLists.txt +++ b/Dev/Cpp/EffekseerRendererGL/CMakeLists.txt @@ -30,6 +30,11 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/../Effe set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${PublicHeader}") target_link_libraries(${PROJECT_NAME} PUBLIC Effekseer EffekseerRendererCommon) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + if(CLANG_FORMAT_ENABLED) clang_format(${PROJECT_NAME}) endif() @@ -37,6 +42,7 @@ endif() #-------------------- # Install + foreach (file ${PublicHeaders}) get_filename_component(dir ${file} DIRECTORY) install(FILES ${file} DESTINATION include/EffekseerRendererGL/${dir}) diff --git a/Dev/Cpp/EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.MaterialLoader.h b/Dev/Cpp/EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.MaterialLoader.h index 9c52e7eeb8..45865334b6 100644 --- a/Dev/Cpp/EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.MaterialLoader.h +++ b/Dev/Cpp/EffekseerRendererGL/EffekseerRenderer/EffekseerRendererGL.MaterialLoader.h @@ -13,6 +13,14 @@ class CompiledMaterialBinary; namespace EffekseerRendererGL { +void StoreVertexUniform(const ::Effekseer::MaterialFile& materialFile, const EffekseerRenderer::MaterialShaderParameterGenerator& generator, Effekseer::CustomVector& uniformLayout); + +void StoreModelVertexUniform(const ::Effekseer::MaterialFile& materialFile, const EffekseerRenderer::MaterialShaderParameterGenerator& generator, Effekseer::CustomVector& uniformLayout, bool instancing); + +void StorePixelUniform(const ::Effekseer::MaterialFile& materialFile, const EffekseerRenderer::MaterialShaderParameterGenerator& generator, Effekseer::CustomVector& uniformLayout, int shaderType); + +Effekseer::CustomVector> StoreTextureLocations(const ::Effekseer::MaterialFile& materialFile); + class MaterialLoader : public ::Effekseer::MaterialLoader { private: From e89d2991b508a9cfd47632f01b26cbc6292a920d Mon Sep 17 00:00:00 2001 From: durswd Date: Thu, 20 Jul 2023 12:31:26 +0900 Subject: [PATCH 2/3] wip --- .../Graphics/efkMat.Graphics.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp index 6e02fc041b..e243716aba 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp +++ b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp @@ -425,9 +425,9 @@ bool Preview::UpdateShader(const CompileResult& compileResult) auto compiler = Effekseer::MaterialCompilerGL(); auto binary = compiler.Compile(compileResult.materialFile.get()); - auto parameterGenerator = EffekseerRenderer::MaterialShaderParameterGenerator(*compileResult.materialFile, true, 0, 1); + auto parameterGenerator = EffekseerRenderer::MaterialShaderParameterGenerator(*compileResult.materialFile, true, 0, 10); Effekseer::CustomVector uniformLayoutElements; - EffekseerRendererGL::StoreModelVertexUniform(*compileResult.materialFile, parameterGenerator, uniformLayoutElements, false); + EffekseerRendererGL::StoreModelVertexUniform(*compileResult.materialFile, parameterGenerator, uniformLayoutElements, true); EffekseerRendererGL::StorePixelUniform(*compileResult.materialFile, parameterGenerator, uniformLayoutElements, 0); uniformLayout_ = Effekseer::MakeRefPtr(EffekseerRendererGL::StoreTextureLocations(*compileResult.materialFile), uniformLayoutElements); @@ -584,6 +584,15 @@ bool Preview::UpdateConstantValues(float time, std::array customData1, values.fill(1.0f); StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } + else if (elm.Name == "UVOffset") + { + std::array values; + values[0] = 0.0f; + values[1] = 0.0f; + values[2] = 1.0f; + values[3] = 1.0f; + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); + } else if (elm.Name == "mUVInversed") { std::array values; @@ -658,17 +667,13 @@ bool Preview::UpdateConstantValues(float time, std::array customData1, values[3] = time; StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); } - else if (elm.Name == "customData1") + else if (elm.Name == "customData1s") { - std::array values; - values.fill(0); - StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, customData1); } - else if (elm.Name == "customData2") + else if (elm.Name == "customData2s") { - std::array values; - values.fill(0); - StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, values); + StoreData(gd, vertexUniformBuffer_, pixelUniformBuffer_, elm, customData2); } } From f8393f6052cd41c49342d6938b8c63eec38ddb56 Mon Sep 17 00:00:00 2001 From: durswd Date: Thu, 20 Jul 2023 19:37:10 +0900 Subject: [PATCH 3/3] fix --- Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp index e243716aba..455e32e68c 100644 --- a/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp +++ b/Dev/Cpp/EffekseerMaterialEditor/Graphics/efkMat.Graphics.cpp @@ -422,8 +422,8 @@ bool Preview::UpdateShader(const CompileResult& compileResult) auto gd = graphics_->GetGraphicsDevice().DownCast(); auto vl = EffekseerRenderer::GetMaterialModelVertexLayout(graphics_->GetGraphicsDevice()).DownCast(); - auto compiler = Effekseer::MaterialCompilerGL(); - auto binary = compiler.Compile(compileResult.materialFile.get()); + auto compiler = Effekseer::MakeRefPtr(); + auto binary = compiler->Compile(compileResult.materialFile.get()); auto parameterGenerator = EffekseerRenderer::MaterialShaderParameterGenerator(*compileResult.materialFile, true, 0, 10); Effekseer::CustomVector uniformLayoutElements;