Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RenderGraph #110

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#if EFFEKSEER_URP_SUPPORT

using Effekseer.Internal;
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

#if UNITY_6000_0_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#endif

public class UrpBlitter : IEffekseerBlitter
{
public static readonly int sourceTex = Shader.PropertyToID("_SourceTex");
Expand Down Expand Up @@ -96,6 +101,9 @@ public void Setup(RenderTargetIdentifier cameraColorTarget, RenderTargetIdentifi
}
#endif

#if UNITY_6000_0_OR_NEWER
[Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref UnityEngine.Rendering.Universal.RenderingData renderingData)
{
if (Effekseer.EffekseerSystem.Instance == null) return;
Expand Down Expand Up @@ -145,7 +153,88 @@ public override void Execute(ScriptableRenderContext context, ref UnityEngine.Re
context.ExecuteCommandBuffer(commandBuffer);
}
}

#if UNITY_6000_0_OR_NEWER
class PassData
{
public TextureHandle colorTexture;
public TextureHandle depthTexture;

public Effekseer.Internal.RenderTargetProperty prop = new();
public IEffekseerBlitter blitter = new UrpBlitter();
}

class DummyPassData
{
}

public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
if (Effekseer.EffekseerSystem.Instance == null) return;

string profilerTag = "EffekseerPath";
string profilerDummyTag = "EffekseerDummyPath";

UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();

using (var builder = renderGraph.AddUnsafePass<PassData>(profilerTag, out var passData))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();

passData.blitter = this.blitter;

//passData.prop.colorTargetIdentifier = resourceData.activeColorTexture;
//passData.prop.depthTargetIdentifier = resourceData.activeDepthTexture;
passData.colorTexture = resourceData.activeColorTexture;
passData.depthTexture = resourceData.activeDepthTexture;
passData.prop.colorTargetDescriptor = cameraData.cameraTargetDescriptor;

// Linear and native renderer makes a result white.
passData.prop.colorTargetDescriptor.sRGB = false;

passData.prop.isRequiredToCopyBackground = true;
passData.prop.renderFeature = Effekseer.Internal.RenderFeature.URP;
#if EFFEKSEER_URP_XRRENDERING
passData.prop.xrRendering = cameraData.xrRendering;
#endif
passData.prop.canGrabDepth = cameraData.requiresDepthTexture;

builder.AllowPassCulling(false);
builder.AllowGlobalStateModification(true);

builder.SetRenderFunc((PassData passData, UnsafeGraphContext context) =>
{
using (new ProfilingScope(context.cmd, profilingSampler))
{
var commandBuffer = CommandBufferHelpers.GetNativeCommandBuffer(context.cmd);
passData.prop.colorTargetIdentifier = passData.colorTexture;
passData.prop.depthTargetIdentifier = passData.depthTexture;

Effekseer.EffekseerSystem.Instance.renderer.Render(cameraData.camera, passData.prop, commandBuffer, true, passData.blitter);
}
});
}

// HACK : Dummy pass to ensure that the render graph is executed
using (var builder = renderGraph.AddRasterRenderPass<DummyPassData>(profilerDummyTag, out var passData))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
builder.AllowPassCulling(false);
builder.AllowGlobalStateModification(true);

builder.SetRenderFunc((DummyPassData passData, RasterGraphContext context) =>
{
using (new ProfilingScope(context.cmd, profilingSampler))
{
context.cmd.BeginSample(profilerDummyTag);
context.cmd.EndSample(profilerDummyTag);
}
});
}
}
}
#endif

EffekseerRenderPassURP m_ScriptablePass;

Expand Down
Loading