Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 24 additions & 14 deletions Dev/Plugin/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,28 @@ bool TryPrepareRender(RTHandle colorBuffer, RTHandle depthBuffer, HDCamera hdCam
prop.depthTargetRenderTexture = depthBuffer;
prop.renderFeature = Effekseer.Internal.RenderFeature.HDRP;

// TODO : It needs to support VR and override
prop.ActualScreenSize = new Vector2Int(hdCamera.actualWidth, hdCamera.actualHeight);
prop.SourceViewport = hdCamera.camera.pixelRect;
#if UNITY_6000_0_OR_NEWER
// HDRP keeps the full-resolution RT allocated and shrinks the active viewport when
// dynamic resolution is enabled, so keep the render viewport and the source
// sampling viewport separate.
prop.Viewport = new Rect(0, 0, hdCamera.actualWidth, hdCamera.actualHeight);
#else
prop.Viewport = new Rect(0, 0, hdCamera.camera.pixelRect.width, hdCamera.camera.pixelRect.height);
#endif

prop.colorTargetDescriptor = new UnityEngine.RenderTextureDescriptor(colorRT.width, colorRT.height, colorRT.format, 0, colorRT.mipmapCount);
// HDRP-WA-DRS-001 (English): HDRP 14-17 keep camera RTHandles at their maximum allocation
// while Dynamic Resolution changes only the active viewport. camera.pixelRect is the
// unscaled GameView rectangle and copying that area also samples unused RTHandle pixels.
// Use the camera color RTHandle's current viewport for target binding and source sampling.
// Remove this only when HDRP exposes a camera color descriptor whose size is the active
// viewport rather than the backing allocation.
// HDRP-WA-DRS-001 (日本語): HDRP 14-17 は Camera RTHandle を最大サイズのまま確保し、
// Dynamic Resolution では有効 Viewport のみを変更します。camera.pixelRect は縮小前の
// GameView 領域なので、そのままコピーすると RTHandle の未使用領域まで参照します。
// Target の設定とコピー元の Sampling には Camera Color RTHandle の現在の Viewport を
// 使用します。HDRP が確保サイズではなく有効 Viewport サイズの Camera Color Descriptor を
// 提供するようになった場合のみ削除してください。
var activeViewportSize = colorBuffer.GetScaledSize(colorBuffer.rtHandleProperties.currentViewportSize);
activeViewportSize.x = Mathf.Clamp(activeViewportSize.x, 1, colorRT.width);
activeViewportSize.y = Mathf.Clamp(activeViewportSize.y, 1, colorRT.height);
prop.ActualScreenSize = activeViewportSize;
prop.SourceViewport = new Rect(0, 0, activeViewportSize.x, activeViewportSize.y);
prop.Viewport = new Rect(0, 0, activeViewportSize.x, activeViewportSize.y);

prop.colorTargetDescriptor = EffekseerRenderTargetDescriptorUtils.CreateTemporaryColorDescriptor(
colorRT, hdCamera.camera);
prop.colorTargetDescriptor.depthBufferBits = 0;
prop.colorTargetDescriptor.msaaSamples = hdCamera.msaaSamples == MSAASamples.None ? 1 : 2;
prop.isRequiredToChangeViewport = true;
return true;
Expand All @@ -81,7 +90,8 @@ void Execute(RTHandle colorBuffer, RTHandle depthBuffer, CommandBuffer cmd, HDCa
return;
}

EffekseerSystem.Instance.renderer.Render(hdCamera.camera, LayerMask.value, prop, cmd, true, blitter);
EffekseerRenderCoordinator.Render(EffekseerSystem.Instance.renderer,
new EffekseerRenderFrameInput(hdCamera.camera, LayerMask.value, prop, cmd, true, blitter));
}

protected override void Execute(CustomPassContext ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ public override void Render(PostProcessRenderContext context)

context.command.Blit(context.source, depthIdentifer, grabDepthMat);

prop.colorTargetDescriptor = new RenderTextureDescriptor(context.width, context.height, context.sourceFormat);
prop.xrRendering = Effekseer.Internal.EffekseerRenderTargetDescriptorUtils.CanUseXREyeTextureDescriptor(context.camera);
prop.colorTargetDescriptor = Effekseer.Internal.EffekseerRenderTargetDescriptorUtils.CreatePostProcessingDescriptor(
context.camera, context.width, context.height, context.sourceFormat);
prop.colorTargetIdentifier = context.destination;
prop.depthTargetIdentifier = depthIdentifer;
prop.renderFeature = Effekseer.Internal.RenderFeature.PostProcess;
prop.canGrabDepth = true;
context.command.SetRenderTarget(context.destination, depthIdentifer);

Effekseer.EffekseerSystem.Instance.renderer.Render(context.camera, int.MaxValue, prop, context.command, false, standardBlitter);
Effekseer.Internal.EffekseerRenderCoordinator.Render(Effekseer.EffekseerSystem.Instance.renderer,
new Effekseer.Internal.EffekseerRenderFrameInput(context.camera, int.MaxValue, prop, context.command, false, standardBlitter));

context.command.ReleaseTemporaryRT(propertyId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#if EFFEKSEER_URP_SUPPORT && UNITY_6000_0_OR_NEWER

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

internal sealed class EffekseerURPRasterCommandBuffer : IEffekseerCommandBuffer
{
readonly RasterCommandBuffer _commandBuffer;

public EffekseerURPRasterCommandBuffer(RasterCommandBuffer commandBuffer)
{
_commandBuffer = commandBuffer;
}

public void SetViewport(Rect viewport)
{
_commandBuffer.SetViewport(viewport);
}

public void SetGlobalBuffer(string name, ComputeBuffer buffer)
{
_commandBuffer.SetGlobalBuffer(name, buffer);
}

public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology,
int vertexCount, int instanceCount, MaterialPropertyBlock properties)
{
_commandBuffer.DrawProcedural(matrix, material, shaderPass, topology, vertexCount, instanceCount, properties);
}

public void IssuePluginEvent(IntPtr callback, int eventId)
{
_commandBuffer.IssuePluginEvent(callback, eventId);
}
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,46 @@ public class UrpBlitter : IEffekseerBlitter
{
public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering)
{
// XR-WA-003 (English): CommandBuffer.Blit is unsafe for XR and RenderGraph, so those
// paths use the SRP Blitter. Unity 2022.3-2023.2 non-XR keeps CommandBuffer.Blit because
// URP 16 SceneView can otherwise interpret editor target color channels incorrectly.
// Remove the legacy branch after all supported pre-Unity-6 SceneView formats are verified.
// XR-WA-003 (日本語): CommandBuffer.Blit はXR・RenderGraphでは安全でないためSRP Blitterを
// 使用します。一方Unity 2022.3-2023.2の非XRでは、URP 16 SceneViewのEditor Target形式で
// Color Channelの解釈が変わる場合があるためCommandBuffer.Blitを維持します。Unity 6未満の
// 全SceneView形式でSRP Blitterを検証できた場合のみLegacy分岐を削除してください。
#if UNITY_6000_0_OR_NEWER
CoreUtils.SetRenderTarget(cmd, dest);
Blitter.BlitTexture(cmd, source, Vector2.one, Blitter.GetBlitMaterial(xrRendering ? TextureXR.dimension : TextureDimension.Tex2D), 0);
#else
if (xrRendering)
{
CoreUtils.SetRenderTarget(cmd, dest);
// FIXME: Scaling is ignored.
// The interface should take RTHandle instead of RenderTargetIdentifier and use Blitter.BlitCameraTexture.
// However, this will cause issues in terms of compatibility with Built-in RP support.
Blitter.BlitTexture(cmd, source, Vector2.one, Blitter.GetBlitMaterial(TextureXR.dimension), 0);
}
else
{
cmd.Blit(source, dest);
}
#endif
}

public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material, bool xrRendering)
{
cmd.Blit(source, dest, material);
#if UNITY_6000_0_OR_NEWER
CoreUtils.SetRenderTarget(cmd, dest);
Blitter.BlitTexture(cmd, source, Vector2.one, material, 0);
#else
if (xrRendering)
{
CoreUtils.SetRenderTarget(cmd, dest);
Blitter.BlitTexture(cmd, source, Vector2.one, material, 0);
}
else
{
cmd.Blit(source, dest, material);
}
#endif
}

public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, bool xrRendering)
Expand Down Expand Up @@ -68,7 +91,7 @@ public void SetLayerMask(UnityEngine.LayerMask layerMask)

bool IsValidCameraDepthTarget(RenderTargetIdentifier cameraDepthTarget)
{
// HACK: When using URP, the depth might be either written to a DepthBuffer attached to
// XR-WA-007 (English): When using URP, the depth might be either written to a DepthBuffer attached to
// - cameraColorTarget
// OR
// - cameraDepthTarget
Expand All @@ -89,11 +112,17 @@ bool IsValidCameraDepthTarget(RenderTargetIdentifier cameraDepthTarget)
// A RenderTargetIdentifier might point to a valid RenderTexture in many different ways
// (including NameID or InstanceID), whether NameID or InstanceID is used to identify a valid
// RenderTexture depends on the Unity Editor / URP package version.
// Remove this when every supported URP version provides an authoritative valid-depth-target API.
// XR-WA-007 (日本語): URP の有効な Depth は Camera Color 側または Camera Depth 側にあり、
// Unity・URP・Camera Stack・MSAA・Depth Texture 設定により変わります。そのため Identifier の
// NameID / InstanceID から有効性を判定します。対応する全 URP 版で正式な有効 Depth Target API が
// 提供された場合のみ削除してください。
var identifierString = cameraDepthTarget.ToString();
return !identifierString.Contains("NameID -1") || !identifierString.Contains("InstanceID 0");
}

void PrepareRenderTargetProperty(RenderTargetProperty renderTargetProperty, RenderTextureDescriptor colorTargetDescriptor, bool requiresDepthTexture, bool xrRendering)
void PrepareRenderTargetProperty(RenderTargetProperty renderTargetProperty, RenderTextureDescriptor colorTargetDescriptor,
bool requiresDepthTexture, bool xrRendering)
{
renderTargetProperty.colorBufferID = null;
renderTargetProperty.depthTargetIdentifier = null;
Expand All @@ -113,14 +142,20 @@ void PrepareRenderTargetProperty(RenderTargetProperty renderTargetProperty, Rend
renderTargetProperty.xrRendering = xrRendering;
}

// Unity 6000.5 / URP 17.5 removed ScriptableRenderPass.Execute. Unity 6000.0-6000.4
// still exposes it as an obsolete compatibility path, so keep it only for those versions.
// Unity 6000.5 / URP 17.5 では ScriptableRenderPass.Execute が削除されました。
// Unity 6000.0-6000.4 では旧互換経路として残っているため、それらのバージョンまで定義します。
#if !UNITY_6000_5_OR_NEWER
#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;
var xrRendering = renderingData.cameraData.xrRendering;
PrepareRenderTargetProperty(prop, renderingData.cameraData.cameraTargetDescriptor, renderingData.cameraData.requiresDepthTexture, xrRendering);
PrepareRenderTargetProperty(prop, renderingData.cameraData.cameraTargetDescriptor,
renderingData.cameraData.requiresDepthTexture, xrRendering);
var renderer = renderingData.cameraData.renderer;
prop.colorTargetIdentifier = renderer.cameraColorTargetHandle;

Expand All @@ -140,10 +175,12 @@ public override void Execute(ScriptableRenderContext context, ref UnityEngine.Re
}

var cmd = CommandBufferPool.Get(RenderPassName);
Effekseer.EffekseerSystem.Instance.renderer.Render(renderingData.cameraData.camera, layerMask.value, prop, cmd, true, blitter);
EffekseerRenderCoordinator.Render(Effekseer.EffekseerSystem.Instance.renderer,
new EffekseerRenderFrameInput(renderingData.cameraData.camera, layerMask.value, prop, cmd, true, blitter));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
#endif

#if UNITY_6000_0_OR_NEWER
class PassData
Expand All @@ -168,7 +205,8 @@ static void ExecuteRenderGraphPass(PassData passData, UnsafeGraphContext context
var commandBuffer = CommandBufferHelpers.GetNativeCommandBuffer(context.cmd);
passData.prop.colorTargetIdentifier = (RenderTargetIdentifier)passData.colorTexture;
passData.prop.depthTargetIdentifier = passData.depthTexture.IsValid() ? (RenderTargetIdentifier)passData.depthTexture : (RenderTargetIdentifier?)null;
system.renderer.Render(passData.camera, passData.layerMask, passData.prop, commandBuffer, true, passData.blitter);
EffekseerRenderCoordinator.Render(system.renderer,
new EffekseerRenderFrameInput(passData.camera, passData.layerMask, passData.prop, commandBuffer, true, passData.blitter));
}

static void ExecuteRasterRenderGraphPass(PassData passData, RasterGraphContext context)
Expand All @@ -179,10 +217,10 @@ static void ExecuteRasterRenderGraphPass(PassData passData, RasterGraphContext c
return;
}

var commandBuffer = CommandBufferHelpers.GetNativeCommandBuffer(context.cmd);
passData.prop.colorTargetIdentifier = (RenderTargetIdentifier)passData.colorTexture;
passData.prop.depthTargetIdentifier = passData.depthTexture.IsValid() ? (RenderTargetIdentifier)passData.depthTexture : (RenderTargetIdentifier?)null;
system.renderer.Render(passData.camera, passData.layerMask, passData.prop, commandBuffer, true, passData.blitter, false);
EffekseerRenderCoordinator.RenderExternal(system.renderer,
new EffekseerRenderFrameInput(passData.camera, passData.layerMask, passData.prop, null, true, passData.blitter,
usesExternalCommands: true),
new EffekseerURPRasterCommandBuffer(context.cmd));
}

bool CanUseRasterPass(UniversalCameraData cameraData)
Expand Down Expand Up @@ -217,7 +255,8 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
passData.blitter = this.blitter;
passData.colorTexture = colorTexture;
passData.depthTexture = resourceData.activeDepthTexture;
PrepareRenderTargetProperty(passData.prop, cameraData.cameraTargetDescriptor, cameraData.requiresDepthTexture, xrRendering);
PrepareRenderTargetProperty(passData.prop, cameraData.cameraTargetDescriptor,
cameraData.requiresDepthTexture, xrRendering);

builder.SetRenderAttachment(passData.colorTexture, 0, AccessFlags.ReadWrite);
if (passData.depthTexture.IsValid())
Expand All @@ -244,7 +283,8 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
{
builder.UseTexture(passData.depthTexture, AccessFlags.ReadWrite);
}
PrepareRenderTargetProperty(passData.prop, cameraData.cameraTargetDescriptor, cameraData.requiresDepthTexture, xrRendering);
PrepareRenderTargetProperty(passData.prop, cameraData.cameraTargetDescriptor,
cameraData.requiresDepthTexture, xrRendering);

builder.AllowPassCulling(false);
builder.AllowGlobalStateModification(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ Texture2D _blendUVDistortionTex : register(t6);
SamplerState sampler_blendUVDistortionTex : register(s6);

#ifndef DISABLED_SOFT_PARTICLE
// XR-WA-002 (English): SPI/Multiview depth is a texture array and must use the current eye slice.
// XR-WA-002 (日本語): SPI/Multiview の深度は Texture Array のため現在の Eye Slice を参照します。
// Remove only when Unity transparently binds and samples one texture type for every XR mode.
// Unity が全 XR モードで単一の Texture 型を透過的に Bind/Sample する場合のみ削除してください。
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
Texture2DArray _depthTex : register(t7);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, float3(uv, unity_StereoEyeIndex))
#else
Texture2D _depthTex : register(t7);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, uv)
#endif
SamplerState sampler_depthTex : register(s7);
#endif

Expand Down Expand Up @@ -132,7 +142,7 @@ float4 frag(const PS_Input Input)

if (softParticleParam.w != 0.0f)
{
float backgroundZ = _depthTex.Sample(sampler_depthTex, screenUV).x;
float backgroundZ = EFK_SAMPLE_DEPTH(screenUV).x;
Output.a *= SoftParticle(
backgroundZ,
screenPos.z,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ Texture2D _blendUVDistortionTex : register(t6);
SamplerState sampler_blendUVDistortionTex : register(s6);

#ifndef DISABLED_SOFT_PARTICLE
// XR-WA-002 (English): SPI/Multiview depth is a texture array and must use the current eye slice.
// XR-WA-002 (日本語): SPI/Multiview の深度は Texture Array のため現在の Eye Slice を参照します。
// Remove only when Unity transparently binds and samples one texture type for every XR mode.
// Unity が全 XR モードで単一の Texture 型を透過的に Bind/Sample する場合のみ削除してください。
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
Texture2DArray _depthTex : register(t7);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, float3(uv, unity_StereoEyeIndex))
#else
Texture2D _depthTex : register(t7);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, uv)
#endif
SamplerState sampler_depthTex : register(s7);
#endif

Expand All @@ -75,7 +85,13 @@ Texture2D _blendUVDistortionTex : register(t5);
SamplerState sampler_blendUVDistortionTex : register(s5);

#ifndef DISABLED_SOFT_PARTICLE
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
Texture2DArray _depthTex : register(t6);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, float3(uv, unity_StereoEyeIndex))
#else
Texture2D _depthTex : register(t6);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, uv)
#endif
SamplerState sampler_depthTex : register(s6);
#endif

Expand Down Expand Up @@ -103,6 +119,7 @@ struct PS_Input
#ifndef DISABLED_SOFT_PARTICLE
float4 PosP : TEXCOORD7;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};

#include "EffekseerShaderAdCommonPS.cginc"
Expand All @@ -112,6 +129,7 @@ struct PS_Input
float4 frag(const PS_Input Input)
: SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(Input);
bool convColorSpace = convertColorSpace != 0.0f;

float4 fCameraFrontDirection = -float4(UNITY_MATRIX_V[2].xyz, 1.0);
Expand Down Expand Up @@ -193,7 +211,7 @@ float4 frag(const PS_Input Input)

if (softParticleParam.w != 0.0f)
{
float backgroundZ = _depthTex.Sample(sampler_depthTex, screenUV).x;
float backgroundZ = EFK_SAMPLE_DEPTH(screenUV).x;
Output.a *= SoftParticle(
backgroundZ,
screenPos.z,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ SamplerState sampler_colorTex : register(s0);
UNITY_DECLARE_SCREENSPACE_TEXTURE(_backTex);

#ifndef DISABLED_SOFT_PARTICLE
// XR-WA-002 (English): SPI/Multiview depth is a texture array and must use the current eye slice.
// XR-WA-002 (日本語): SPI/Multiview の深度は Texture Array のため現在の Eye Slice を参照します。
// Remove only when Unity transparently binds and samples one texture type for every XR mode.
// Unity が全 XR モードで単一の Texture 型を透過的に Bind/Sample する場合のみ削除してください。
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
Texture2DArray _depthTex : register(t2);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, float3(uv, unity_StereoEyeIndex))
#else
Texture2D _depthTex : register(t2);
#define EFK_SAMPLE_DEPTH(uv) _depthTex.Sample(sampler_depthTex, uv)
#endif
SamplerState sampler_depthTex : register(s2);
#endif

Expand Down Expand Up @@ -78,7 +88,7 @@ float4 frag(const PS_Input Input)

if (softParticleParam.w != 0.0f)
{
float backgroundZ = _depthTex.Sample(sampler_depthTex, screenUV).x;
float backgroundZ = EFK_SAMPLE_DEPTH(screenUV).x;
Output.a *= SoftParticle(
backgroundZ,
screenPos.z,
Expand Down
Loading
Loading