Skip to content

Commit

Permalink
texture optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeroluna committed Nov 4, 2024
1 parent cd7a439 commit 3cb0834
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Vivify/HeckImplementation/CustomDataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ internal class CreateCameraData : ICustomEventCustomData
internal CreateCameraData(CustomData customData, Dictionary<string, Track> tracks)
{
Name = customData.GetRequired<string>(ID_FIELD);
Texture = customData.GetRequired<string>(TEXTURE);
Texture = customData.Get<string>(TEXTURE);
DepthTexture = customData.Get<string?>(DEPTH_TEXTURE);
CustomData? propertyData = customData.Get<CustomData?>(PROPERTIES);
if (propertyData != null)
Expand All @@ -265,7 +265,7 @@ internal CreateCameraData(CustomData customData, Dictionary<string, Track> track

internal string Name { get; }

internal string Texture { get; }
internal string? Texture { get; }

internal string? DepthTexture { get; }

Expand Down
100 changes: 53 additions & 47 deletions Vivify/PostProcessing/CullingTextureController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class CullingTextureController : CullingCameraController

internal override int DefaultCullingMask => _postProcessingController.DefaultCullingMask;

internal int Key { get; private set; }
internal int? Key { get; private set; }

internal int? DepthKey { get; private set; }

Expand All @@ -38,7 +38,11 @@ internal class CullingTextureController : CullingCameraController
internal void Init(CreateCameraData cameraData)
{
_cameraPropertyController.Id = cameraData.Name;
Key = Shader.PropertyToID(cameraData.Texture);
if (cameraData.Texture != null)
{
Key = Shader.PropertyToID(cameraData.Texture);
}

if (cameraData.DepthTexture != null)
{
DepthKey = Shader.PropertyToID(cameraData.DepthTexture);
Expand Down Expand Up @@ -120,62 +124,64 @@ private void OnRenderImage(RenderTexture src, RenderTexture dst)
Camera.MonoOrStereoscopicEye stereoActiveEye = Camera.stereoActiveEye;
RenderTextureDescriptor descriptor = src.descriptor;

if (!RenderTextures.TryGetValue(stereoActiveEye, out RenderTexture colorTexture) ||
!RTEquals(colorTexture, src))
{
colorTexture?.Release();
colorTexture = new RenderTexture(descriptor);
RenderTextures[stereoActiveEye] = colorTexture;
}

if (MainEffect)
if (Key != null)
{
(_mainEffectRenderer ??=
new MainEffectRenderer(gameObject.transform.parent.GetComponent<MainEffectController>())).Render(
src,
colorTexture);
}
else
{
Graphics.Blit(src, colorTexture);
}

if (DepthKey == null)
{
return;
}
if (!RenderTextures.TryGetValue(stereoActiveEye, out RenderTexture colorTexture) ||
!RTEquals(colorTexture, src))
{
colorTexture?.Release();
colorTexture = new RenderTexture(descriptor);
RenderTextures[stereoActiveEye] = colorTexture;
}

if (!RenderTexturesDepth.TryGetValue(stereoActiveEye, out RenderTexture depthTexture) ||
!RTEquals(depthTexture, src))
{
depthTexture?.Release();
descriptor.colorFormat = RenderTextureFormat.R8;
depthTexture = new RenderTexture(descriptor);
RenderTexturesDepth[stereoActiveEye] = depthTexture;
if (MainEffect)
{
(_mainEffectRenderer ??=
new MainEffectRenderer(gameObject.transform.parent.GetComponent<MainEffectController>())).Render(
src,
colorTexture);
}
else
{
Graphics.Blit(src, colorTexture);
}
}

if (depthTexture.dimension == TextureDimension.Tex2DArray)
// ReSharper disable once InvertIf
if (DepthKey != null)
{
Material? sliceMaterial = _depthShaderManager.DepthArrayMaterial;
if (sliceMaterial == null)
if (!RenderTexturesDepth.TryGetValue(stereoActiveEye, out RenderTexture depthTexture) ||
!RTEquals(depthTexture, src))
{
return;
depthTexture?.Release();
descriptor.colorFormat = RenderTextureFormat.R8;
depthTexture = new RenderTexture(descriptor);
RenderTexturesDepth[stereoActiveEye] = depthTexture;
}

sliceMaterial.SetFloat(_arraySliceIndex, 0);
Graphics.Blit(null, depthTexture, sliceMaterial, -1, 0);
sliceMaterial.SetFloat(_arraySliceIndex, 1);
Graphics.Blit(null, depthTexture, sliceMaterial, -1, 1);
}
else
{
Material? depthMaterial = _depthShaderManager.DepthMaterial;
if (depthMaterial == null)
if (depthTexture.dimension == TextureDimension.Tex2DArray)
{
return;
Material? sliceMaterial = _depthShaderManager.DepthArrayMaterial;
if (sliceMaterial == null)
{
return;
}

sliceMaterial.SetFloat(_arraySliceIndex, 0);
Graphics.Blit(null, depthTexture, sliceMaterial, -1, 0);
sliceMaterial.SetFloat(_arraySliceIndex, 1);
Graphics.Blit(null, depthTexture, sliceMaterial, -1, 1);
}
else
{
Material? depthMaterial = _depthShaderManager.DepthMaterial;
if (depthMaterial == null)
{
return;
}

Graphics.Blit(null, depthTexture, depthMaterial);
Graphics.Blit(null, depthTexture, depthMaterial);
}
}
}
}
5 changes: 3 additions & 2 deletions Vivify/PostProcessing/PostProcessingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,12 @@ private void OnPreRender()
camera.Render();
}

if (cullingTextureController.RenderTextures.TryGetValue(
if (cullingTextureController.Key != null &&
cullingTextureController.RenderTextures.TryGetValue(
stereoActiveEye,
out RenderTexture colorTexture))
{
Shader.SetGlobalTexture(cullingTextureController.Key, colorTexture);
Shader.SetGlobalTexture(cullingTextureController.Key.Value, colorTexture);
}

if (cullingTextureController.DepthKey != null &&
Expand Down

0 comments on commit 3cb0834

Please sign in to comment.