Skip to content

Commit

Permalink
1.70b
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Dec 27, 2022
1 parent 18555f2 commit 517581c
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Assets/Effekseer/External/URP/Effekseer.URP.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"name": "com.unity.render-pipelines.universal",
"expression": "10.1",
"define": "EFFEKSEER_URP_DEPTHTARGET_FIX"
},
{
"name": "com.unity.render-pipelines.universal",
"expression": "10.10",
"define": "EFFEKSEER_URP_XRRENDERING"
}
],
"noEngineReferences": false
Expand Down
64 changes: 49 additions & 15 deletions Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ public UrpBlitter()
this.blitMaterial = CoreUtils.CreateEngineMaterial("Hidden/Universal Render Pipeline/Blit");
}

public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest)
public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering)
{
CoreUtils.SetRenderTarget(
cmd,
dest,
RenderBufferLoadAction.Load,
RenderBufferStoreAction.Store,
ClearFlag.None,
Color.black);
cmd.SetGlobalTexture(sourceTex, source);
cmd.DrawProcedural(Matrix4x4.identity, blitMaterial, 0, MeshTopology.Quads, 4);
if(xrRendering)
{
CoreUtils.SetRenderTarget(
cmd,
dest,
RenderBufferLoadAction.Load,
RenderBufferStoreAction.Store,
ClearFlag.None,
Color.black);
cmd.SetGlobalTexture(sourceTex, source);
cmd.DrawProcedural(Matrix4x4.identity, blitMaterial, 0, MeshTopology.Quads, 4);
}
else
{
cmd.Blit(source, dest);
}
}
}

Expand All @@ -45,16 +52,37 @@ public EffekseerRenderPassURP(ScriptableRenderer renderer)
this.renderPassEvent = UnityEngine.Rendering.Universal.RenderPassEvent.AfterRenderingTransparents;
}

bool IsValid(RenderTargetIdentifier identifer)
bool IsValidCameraDepthTarget(RenderTargetIdentifier cameraDepthTarget)
{
// HACK
return !identifer.ToString().Contains("NameID -1");
// HACK: When using URP, the depth might be either written to a DepthBuffer attached to
// - cameraColorTarget
// OR
// - cameraDepthTarget
//
// Which one contains the depth is dependent on many variables including but not limited to:
// - Unity Editor version
// - whether camera stacking is used
// - whether MSAA is enabled
// - whether Depth Texture is enabled
//
// Effekseer needs to know where it can access the depth buffer. This hack checks if the depth is
// written to cameraDepthTarget based on the observation, that whenever Unity is writing depth to
// cameraDepthTarget, cameraDepthTarget's RenderTargetIdentifier contains either
// - NameId xxx (where xxx is an integer other than -1)
// OR
// - InstanceID yyy (where yyy is an integer other than 0)
//
// 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.
var identifierString = cameraDepthTarget.ToString();
return !identifierString.Contains("NameID -1") || !identifierString.Contains("InstanceID 0");
}

#if !EFFEKSEER_URP_DEPTHTARGET_FIX
public void Setup(RenderTargetIdentifier cameraColorTarget, RenderTargetIdentifier cameraDepthTarget)
{
bool isValidDepth = IsValid(cameraDepthTarget);
bool isValidDepth = IsValidCameraDepthTarget(cameraDepthTarget);

this.cameraColorTarget = cameraColorTarget;
prop.colorTargetIdentifier = cameraColorTarget;
Expand All @@ -75,7 +103,10 @@ public override void Execute(ScriptableRenderContext context, ref UnityEngine.Re
var renderer = renderingData.cameraData.renderer;
prop.colorTargetIdentifier = renderer.cameraColorTarget;

var isValidDepth = IsValid(renderer.cameraDepthTarget);
// NOTE: We need to know whether the depth in cameraDepthTarget is valid or not since if it is valid,
// we need to pass cameraDepthTarget to SetRenderTarget() later on. If it isn't valid, the depth in
// cameraColorTarget is used instead.
var isValidDepth = IsValidCameraDepthTarget(renderer.cameraDepthTarget);

if (isValidDepth)
{
Expand All @@ -89,6 +120,9 @@ public override void Execute(ScriptableRenderContext context, ref UnityEngine.Re
prop.colorTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;
prop.isRequiredToCopyBackground = true;
prop.renderFeature = Effekseer.Internal.RenderFeature.URP;
#if EFFEKSEER_URP_XRRENDERING
prop.xrRendering = renderingData.cameraData.xrRendering;
#endif
prop.canGrabDepth = renderingData.cameraData.requiresDepthTexture;
Effekseer.EffekseerSystem.Instance.renderer.Render(renderingData.cameraData.camera, prop, null, blitter);
var commandBuffer = Effekseer.EffekseerSystem.Instance.renderer.GetCameraCommandBuffer(renderingData.cameraData.camera);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/Android/libs/x86/libEffekseerUnity.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/x86/EffekseerUnity.dll
Binary file not shown.
Binary file modified Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Assets/Effekseer/Scripts/EffekseerBlitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace Effekseer.Internal
{
public interface IEffekseerBlitter
{
void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest);
void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering);
}

public class StandardBlitter : IEffekseerBlitter
{
public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest)
public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering)
{
cmd.Blit(source, dest);
}
Expand Down
8 changes: 5 additions & 3 deletions Assets/Effekseer/Scripts/EffekseerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public class RenderTargetProperty

Material grabDepthMat;

public bool xrRendering = false;

public RenderTargetProperty()
{
}
Expand Down Expand Up @@ -194,11 +196,11 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture bac
}
else if (isRequiredToCopyBackground)
{
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture);
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, xrRendering);
}
else
{
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture);
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, xrRendering);
}

// restore
Expand Down Expand Up @@ -353,7 +355,7 @@ public BackgroundRenderTexture(int width, int height, int depth, RenderTextureFo
}
else
{
if(QualitySettings.activeColorSpace == ColorSpace.Linear)
if (QualitySettings.activeColorSpace == ColorSpace.Linear)
{
renderTexture = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Linear);
}
Expand Down
12 changes: 9 additions & 3 deletions Assets/Effekseer/Scripts/EffekseerRendererNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void SetupEffekseerRenderCommandBuffer(
{
if (renderTargetProperty.colorBufferID.HasValue)
{
blitter.Blit(cmbBuf, renderTargetProperty.colorBufferID.Value, this.renderTexture.renderTexture);
blitter.Blit(cmbBuf, renderTargetProperty.colorBufferID.Value, this.renderTexture.renderTexture, renderTargetProperty.xrRendering);
cmbBuf.SetRenderTarget(renderTargetProperty.colorBufferID.Value);

if (renderTargetProperty.Viewport.width > 0)
Expand All @@ -137,7 +137,10 @@ private void SetupEffekseerRenderCommandBuffer(
}
else
{
blitter.Blit(cmbBuf, BuiltinRenderTextureType.CameraTarget, this.renderTexture.renderTexture);
// TODO : Fix
bool xrRendering = false;

blitter.Blit(cmbBuf, BuiltinRenderTextureType.CameraTarget, this.renderTexture.renderTexture, xrRendering);
cmbBuf.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);

// to reset shader settings. SetRenderTarget is not applied until drawing
Expand All @@ -164,7 +167,10 @@ private void SetupEffekseerRenderCommandBuffer(
}
else
{
blitter.Blit(cmbBuf, BuiltinRenderTextureType.Depth, this.depthTexture.renderTexture);
// TODO : Fix
bool xrRendering = false;

blitter.Blit(cmbBuf, BuiltinRenderTextureType.Depth, this.depthTexture.renderTexture, xrRendering);
cmbBuf.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);

// to reset shader settings. SetRenderTarget is not applied until drawing
Expand Down
17 changes: 13 additions & 4 deletions Assets/Effekseer/Scripts/EffekseerRendererUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,10 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com
}
else
{
blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.CameraTarget, path.renderTexture.renderTexture);
// TODO : Fix
bool xrRendering = false;

blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.CameraTarget, path.renderTexture.renderTexture, xrRendering);
path.commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, 0, CubemapFace.Unknown, -1);
}
}
Expand All @@ -1217,7 +1220,10 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com
}
else
{
blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.Depth, path.depthTexture.renderTexture);
// TODO : Fix
bool xrRendering = false;

blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.Depth, path.depthTexture.renderTexture, xrRendering);
path.commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, 0, CubemapFace.Unknown, -1);
}
}
Expand Down Expand Up @@ -1248,7 +1254,7 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com
// Add a blit command that copy to the distortion texture
if (renderTargetProperty != null && renderTargetProperty.colorBufferID.HasValue)
{
blitter.Blit(path.commandBuffer, renderTargetProperty.colorBufferID.Value, path.renderTexture.renderTexture);
blitter.Blit(path.commandBuffer, renderTargetProperty.colorBufferID.Value, path.renderTexture.renderTexture, renderTargetProperty.xrRendering);
path.commandBuffer.SetRenderTarget(renderTargetProperty.colorBufferID.Value, 0, CubemapFace.Unknown, -1);

if (renderTargetProperty.Viewport.width > 0)
Expand All @@ -1267,7 +1273,10 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com
}
else
{
blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.CameraTarget, path.renderTexture.renderTexture);
// TODO : Fix
bool xrRendering = false;

blitter.Blit(path.commandBuffer, BuiltinRenderTextureType.CameraTarget, path.renderTexture.renderTexture, xrRendering);
path.commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, 0, CubemapFace.Unknown, -1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Effekseer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "org.effekseer.effekseerforunity",
"description": "",
"version": "1.70.1",
"version": "1.70.2",
"unity": "2019.4",
"displayName": "EffekseerForUnity"
}

0 comments on commit 517581c

Please sign in to comment.