From 8e51dfba4d7f6e68591e9c77f5547d5511925bf5 Mon Sep 17 00:00:00 2001 From: durswd Date: Mon, 18 Nov 2024 02:28:43 +0900 Subject: [PATCH] Support the latest effekseer on UnityRenderer --- .../renderer/EffekseerRendererImplemented.cpp | 45 +++---------------- .../renderer/EffekseerRendererImplemented.h | 9 ---- Dev/Cpp/renderer/EffekseerRendererShader.h | 11 +++-- 3 files changed, 14 insertions(+), 51 deletions(-) diff --git a/Dev/Cpp/renderer/EffekseerRendererImplemented.cpp b/Dev/Cpp/renderer/EffekseerRendererImplemented.cpp index ea5274c8..cdb6adbd 100644 --- a/Dev/Cpp/renderer/EffekseerRendererImplemented.cpp +++ b/Dev/Cpp/renderer/EffekseerRendererImplemented.cpp @@ -242,7 +242,7 @@ void ModelRenderer::EndRendering(const efkModelNodeParam& parameter, void* userD } else { - shader = m_renderer->GetShader(collector_.ShaderType); + shader = static_cast(m_renderer->GetImpl()->GetShader(collector_.ShaderType)); } ::EffekseerRenderer::RenderStateBase::State& state = m_renderer->GetRenderState()->Push(); @@ -407,13 +407,13 @@ bool RendererImplemented::Initialize(int32_t squareMaxCount) } } - unlitShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::Unlit)); - backDistortedShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::BackDistortion)); - litShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::Lit)); + GetImpl()->ShaderUnlit = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::Unlit)); + GetImpl()->ShaderDistortion = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::BackDistortion)); + GetImpl()->ShaderLit = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::Lit)); - adUnlitShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedUnlit)); - adBackDistortedShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedBackDistortion)); - adLitShader_ = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedLit)); + GetImpl()->ShaderAdUnlit = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedUnlit)); + GetImpl()->ShaderAdDistortion = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedBackDistortion)); + GetImpl()->ShaderAdLit = std::unique_ptr(new Shader(EffekseerRenderer::RendererShaderType::AdvancedLit)); m_standardRenderer = new EffekseerRenderer::StandardRenderer(this); GetImpl()->isSoftParticleEnabled = true; @@ -1030,37 +1030,6 @@ void RendererImplemented::DrawModel(Effekseer::ModelRef model, renderParameters.push_back(rp); } -Shader* RendererImplemented::GetShader(::EffekseerRenderer::RendererShaderType materialType) const -{ - if (materialType == ::EffekseerRenderer::RendererShaderType::BackDistortion) - { - return backDistortedShader_.get(); - } - else if (materialType == ::EffekseerRenderer::RendererShaderType::Lit) - { - return litShader_.get(); - } - else if (materialType == ::EffekseerRenderer::RendererShaderType::Unlit) - { - return unlitShader_.get(); - } - if (materialType == ::EffekseerRenderer::RendererShaderType::AdvancedBackDistortion) - { - return adBackDistortedShader_.get(); - } - else if (materialType == ::EffekseerRenderer::RendererShaderType::AdvancedLit) - { - return adLitShader_.get(); - } - else if (materialType == ::EffekseerRenderer::RendererShaderType::AdvancedUnlit) - { - return adUnlitShader_.get(); - } - - // retuan as a default shader - return unlitShader_.get(); -} - void RendererImplemented::BeginShader(Shader* shader) { m_currentShader = shader; } void RendererImplemented::RendererImplemented::EndShader(Shader* shader) {} diff --git a/Dev/Cpp/renderer/EffekseerRendererImplemented.h b/Dev/Cpp/renderer/EffekseerRendererImplemented.h index b51206d7..72cab3c1 100644 --- a/Dev/Cpp/renderer/EffekseerRendererImplemented.h +++ b/Dev/Cpp/renderer/EffekseerRendererImplemented.h @@ -234,13 +234,6 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek Effekseer::Backend::GraphicsDeviceRef graphicsDevice_ = nullptr; Effekseer::Backend::VertexBufferRef vertexBuffer_ = nullptr; - std::unique_ptr unlitShader_; - std::unique_ptr backDistortedShader_; - std::unique_ptr litShader_; - std::unique_ptr adUnlitShader_; - std::unique_ptr adBackDistortedShader_; - std::unique_ptr adLitShader_; - Shader* m_currentShader = nullptr; RenderState* m_renderState = nullptr; @@ -425,8 +418,6 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek std::vector>& customData1, std::vector>& customData2); - Shader* GetShader(::EffekseerRenderer::RendererShaderType materialType) const; - void BeginShader(Shader* shader); void EndShader(Shader* shader); diff --git a/Dev/Cpp/renderer/EffekseerRendererShader.h b/Dev/Cpp/renderer/EffekseerRendererShader.h index 44df99ed..f8bd7fb2 100644 --- a/Dev/Cpp/renderer/EffekseerRendererShader.h +++ b/Dev/Cpp/renderer/EffekseerRendererShader.h @@ -7,7 +7,7 @@ namespace EffekseerRendererUnity { -class Shader final +class Shader : public EffekseerRenderer::ShaderBase { private: EffekseerRenderer::MaterialShaderParameterGenerator parameterGenerator_; @@ -28,15 +28,18 @@ class Shader final ~Shader(); - void* GetVertexConstantBuffer() { return vertexConstantBuffer.data(); } + virtual void SetVertexConstantBufferSize(int32_t size) override {} + virtual void SetPixelConstantBufferSize(int32_t size) override {} - void* GetPixelConstantBuffer() { return pixelConstantBuffer.data(); } + void* GetVertexConstantBuffer() override { return vertexConstantBuffer.data(); } + + void* GetPixelConstantBuffer() override { return pixelConstantBuffer.data(); } template T* GetVertexConstantBuffer() { return reinterpret_cast(vertexConstantBuffer.data()); } template T* GettPixelConstantBuffer() { return reinterpret_cast(pixelConstantBuffer.data()); } - void SetConstantBuffer() {} + void SetConstantBuffer() override {} EffekseerRenderer::RendererShaderType GetType() const;