Skip to content

Commit

Permalink
Support the latest effekseer on UnityRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Nov 17, 2024
1 parent 36cf4a1 commit 8e51dfb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
45 changes: 7 additions & 38 deletions Dev/Cpp/renderer/EffekseerRendererImplemented.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void ModelRenderer::EndRendering(const efkModelNodeParam& parameter, void* userD
}
else
{
shader = m_renderer->GetShader(collector_.ShaderType);
shader = static_cast<Shader*>(m_renderer->GetImpl()->GetShader(collector_.ShaderType));
}

::EffekseerRenderer::RenderStateBase::State& state = m_renderer->GetRenderState()->Push();
Expand Down Expand Up @@ -407,13 +407,13 @@ bool RendererImplemented::Initialize(int32_t squareMaxCount)
}
}

unlitShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::Unlit));
backDistortedShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::BackDistortion));
litShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::Lit));
GetImpl()->ShaderUnlit = std::unique_ptr<EffekseerRenderer::ShaderBase>(new Shader(EffekseerRenderer::RendererShaderType::Unlit));
GetImpl()->ShaderDistortion = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::BackDistortion));
GetImpl()->ShaderLit = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::Lit));

adUnlitShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedUnlit));
adBackDistortedShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedBackDistortion));
adLitShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedLit));
GetImpl()->ShaderAdUnlit = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedUnlit));
GetImpl()->ShaderAdDistortion = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedBackDistortion));
GetImpl()->ShaderAdLit = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::AdvancedLit));

m_standardRenderer = new EffekseerRenderer::StandardRenderer<RendererImplemented, Shader>(this);
GetImpl()->isSoftParticleEnabled = true;
Expand Down Expand Up @@ -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) {}
Expand Down
9 changes: 0 additions & 9 deletions Dev/Cpp/renderer/EffekseerRendererImplemented.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek
Effekseer::Backend::GraphicsDeviceRef graphicsDevice_ = nullptr;
Effekseer::Backend::VertexBufferRef vertexBuffer_ = nullptr;

std::unique_ptr<Shader> unlitShader_;
std::unique_ptr<Shader> backDistortedShader_;
std::unique_ptr<Shader> litShader_;
std::unique_ptr<Shader> adUnlitShader_;
std::unique_ptr<Shader> adBackDistortedShader_;
std::unique_ptr<Shader> adLitShader_;

Shader* m_currentShader = nullptr;
RenderState* m_renderState = nullptr;

Expand Down Expand Up @@ -425,8 +418,6 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek
std::vector<std::array<float, 4>>& customData1,
std::vector<std::array<float, 4>>& customData2);

Shader* GetShader(::EffekseerRenderer::RendererShaderType materialType) const;

void BeginShader(Shader* shader);
void EndShader(Shader* shader);

Expand Down
11 changes: 7 additions & 4 deletions Dev/Cpp/renderer/EffekseerRendererShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace EffekseerRendererUnity
{

class Shader final
class Shader : public EffekseerRenderer::ShaderBase
{
private:
EffekseerRenderer::MaterialShaderParameterGenerator parameterGenerator_;
Expand All @@ -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 <typename T> T* GetVertexConstantBuffer() { return reinterpret_cast<T*>(vertexConstantBuffer.data()); }

template <typename T> T* GettPixelConstantBuffer() { return reinterpret_cast<T*>(pixelConstantBuffer.data()); }

void SetConstantBuffer() {}
void SetConstantBuffer() override {}

EffekseerRenderer::RendererShaderType GetType() const;

Expand Down

0 comments on commit 8e51dfb

Please sign in to comment.