Skip to content

Commit

Permalink
全体へのコードクリーンナップの適用
Browse files Browse the repository at this point in the history
  • Loading branch information
CA-Tatami committed Aug 7, 2024
1 parent 475dd2c commit abcda80
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 230 deletions.
32 changes: 13 additions & 19 deletions Assets/Nova/Runtime/Core/Scripts/ApplyDistortionPass.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------
// Copyright 2021 CyberAgent, Inc.
// Copyright 2024 CyberAgent, Inc.
// --------------------------------------------------------------

using UnityEngine;
Expand All @@ -16,7 +16,7 @@ public sealed class ApplyDistortionPass : ScriptableRenderPass
private readonly int _mainTexPropertyId = Shader.PropertyToID("_MainTex");
private readonly Material _material;
private readonly ProfilingSampler _renderPassProfilingSampler;

private RenderTargetIdentifier _distortedUvBufferIdentifier;

public ApplyDistortionPass(bool applyToSceneView, Shader shader)
Expand All @@ -35,32 +35,26 @@ public void Setup(RenderTargetIdentifier distortedUvBufferIdentifier)
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (_material == null)
{
return;
}
{ return; }

if (!_applyToSceneView && renderingData.cameraData.cameraType == CameraType.SceneView)
{
return;
}

#if UNITY_2022_1_OR_NEWER
{ return; }

#if UNITY_2022_1_OR_NEWER
var source = renderingData.cameraData.renderer.cameraColorTargetHandle.nameID;
#else
#else
var source = renderingData.cameraData.renderer.cameraColorTarget;
#endif
#endif

var cmd = CommandBufferPool.Get();
cmd.Clear();
using (new ProfilingScope(cmd, _renderPassProfilingSampler))
{
cmd.SetGlobalTexture(_mainTexPropertyId, source);
cmd.SetGlobalTexture(_distortionBufferPropertyId, _distortedUvBufferIdentifier);
Blit(cmd, ref renderingData, _material);
}

{ cmd.SetGlobalTexture(_mainTexPropertyId, source);
cmd.SetGlobalTexture(_distortionBufferPropertyId, _distortedUvBufferIdentifier);
Blit(cmd, ref renderingData, _material); }

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
}
44 changes: 22 additions & 22 deletions Assets/Nova/Runtime/Core/Scripts/DistortedUvBufferPass.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------
// Copyright 2021 CyberAgent, Inc.
// Copyright 2024 CyberAgent, Inc.
// --------------------------------------------------------------

using UnityEngine;
Expand All @@ -11,16 +11,16 @@ namespace Nova.Runtime.Core.Scripts
public sealed class DistortedUvBufferPass : ScriptableRenderPass
{
private const string ProfilerTag = nameof(DistortedUvBufferPass);
private readonly ProfilingSampler _profilingSampler = new ProfilingSampler(ProfilerTag);
private readonly ProfilingSampler _profilingSampler = new(ProfilerTag);
private readonly RenderQueueRange _renderQueueRange = RenderQueueRange.all;
private readonly ShaderTagId _shaderTagId;
private FilteringSettings _filteringSettings;

#if UNITY_2022_1_OR_NEWER
#if UNITY_2022_1_OR_NEWER
private RTHandle _renderTargetRTHandle;
#else
#else
private RenderTargetIdentifier _renderTargetIdentifier;
#endif
#endif

public DistortedUvBufferPass(string lightMode)
{
Expand All @@ -29,26 +29,26 @@ public DistortedUvBufferPass(string lightMode)
_shaderTagId = new ShaderTagId(lightMode);
}

#if UNITY_2022_1_OR_NEWER
#if UNITY_2022_1_OR_NEWER
public void Setup(RTHandle renderTargetRTHandle)
{
_renderTargetRTHandle = renderTargetRTHandle;
}
#else
#else
public void Setup(RenderTargetIdentifier renderTargetIdentifier)
{
_renderTargetIdentifier = renderTargetIdentifier;
}
#endif
#endif

public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
var renderer = renderingData.cameraData.renderer;
#if UNITY_2022_1_OR_NEWER
#if UNITY_2022_1_OR_NEWER
ConfigureTarget(_renderTargetRTHandle, renderer.cameraDepthTargetHandle);
#else
#else
ConfigureTarget(_renderTargetIdentifier, renderer.cameraDepthTarget);
#endif
#endif
ConfigureClear(ClearFlag.Color, Color.gray);
}

Expand All @@ -58,23 +58,23 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
cmd.Clear();

using (new ProfilingScope(cmd, _profilingSampler))
{
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
{ context.ExecuteCommandBuffer(cmd);
cmd.Clear();

var drawingSettings =
CreateDrawingSettings(_shaderTagId, ref renderingData, SortingCriteria.CommonTransparent);
#if UNITY_2023_1_OR_NEWER
var drawingSettings =
CreateDrawingSettings(_shaderTagId, ref renderingData, SortingCriteria.CommonTransparent);

#if UNITY_2023_1_OR_NEWER
var param = new RendererListParams(renderingData.cullResults, drawingSettings, _filteringSettings);
var renderList = context.CreateRendererList(ref param);
cmd.DrawRendererList(renderList);
#else
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref _filteringSettings);
#endif
#else
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref _filteringSettings);
#endif
}

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
}
29 changes: 15 additions & 14 deletions Assets/Nova/Runtime/Core/Scripts/ScreenSpaceDistortion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------
// Copyright 2023 CyberAgent, Inc.
// Copyright 2024 CyberAgent, Inc.
// --------------------------------------------------------------

using System;
Expand All @@ -19,52 +19,53 @@ public sealed class ScreenSpaceDistortion : ScriptableRendererFeature
private ApplyDistortionPass _applyDistortionPass;

private DistortedUvBufferPass _distortedUvBufferPass;
#if UNITY_2022_1_OR_NEWER

#if UNITY_2022_1_OR_NEWER
private RTHandle _distortedUvBufferRTHandle;
#endif
#endif

public override void Create()
{
_applyDistortionShader = Shader.Find("Hidden/Nova/Particles/ApplyDistortion");
if (_applyDistortionShader == null) return;
if (_applyDistortionShader == null)
{ return; }

_distortedUvBufferPass = new DistortedUvBufferPass(DistortionLightMode);
_applyDistortionPass = new ApplyDistortionPass(_applyToSceneView, _applyDistortionShader);
}

public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (_applyDistortionShader == null
if (_applyDistortionShader == null
|| renderingData.cameraData.cameraType == CameraType.Reflection
|| renderingData.cameraData.cameraType == CameraType.Preview)
return;
{ return; }

var distortedUvBufferFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGHalf)
? RenderTextureFormat.RGHalf
: RenderTextureFormat.DefaultHDR;
#if UNITY_2022_1_OR_NEWER

#if UNITY_2022_1_OR_NEWER
var desc = renderingData.cameraData.cameraTargetDescriptor;
desc.depthBufferBits = 0;
desc.colorFormat = distortedUvBufferFormat;
RenderingUtils.ReAllocateIfNeeded(ref _distortedUvBufferRTHandle, desc);
_distortedUvBufferPass.Setup(_distortedUvBufferRTHandle);
_applyDistortionPass.Setup(_distortedUvBufferRTHandle);
#else
#else
var cameraTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;
var distortedUvBuffer = RenderTexture.GetTemporary(cameraTargetDescriptor.width,
cameraTargetDescriptor.height, 0, distortedUvBufferFormat, RenderTextureReadWrite.Default,
cameraTargetDescriptor.msaaSamples);
var distortedUvBufferIdentifier = new RenderTargetIdentifier(distortedUvBuffer);
_distortedUvBufferPass.Setup(distortedUvBufferIdentifier);
_applyDistortionPass.Setup(distortedUvBufferIdentifier);
#endif
#endif
renderer.EnqueuePass(_distortedUvBufferPass);
renderer.EnqueuePass(_applyDistortionPass);
#if !UNITY_2022_1_OR_NEWER
#if !UNITY_2022_1_OR_NEWER
RenderTexture.ReleaseTemporary(distortedUvBuffer);
#endif
#endif
}
}
}
}
22 changes: 11 additions & 11 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesApplyDistortion.shader
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ Shader "Hidden/Nova/Particles/ApplyDistortion"
"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"
}
ZTest Always ZWrite Off Cull Off

Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#if UNITY_VERSION >= 202200
#if UNITY_VERSION >= 202200
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#endif
#endif

TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D(_ScreenSpaceUvTexture);
SAMPLER(sampler_ScreenSpaceUvTexture);
half4 _TintColor;

#if UNITY_VERSION < 202200
#if UNITY_VERSION < 202200
struct Attributes
{
float4 positionOS : POSITION;
Expand All @@ -46,16 +46,16 @@ Shader "Hidden/Nova/Particles/ApplyDistortion"
OUT.uv = IN.uv;
return OUT;
}
#endif
#endif

half4 frag(Varyings IN) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#if UNITY_VERSION >= 202200
#if UNITY_VERSION >= 202200
const float2 uv = IN.texcoord;
#else
#else
const float2 uv = IN.uv;
#endif
#endif
half2 dist = SAMPLE_TEXTURE2D(_ScreenSpaceUvTexture, sampler_ScreenSpaceUvTexture, uv).xy;
dist = dist.xy * 2.0 - 1.0;
half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + dist);
Expand All @@ -64,4 +64,4 @@ Shader "Hidden/Nova/Particles/ApplyDistortion"
ENDHLSL
}
}
}
}
56 changes: 28 additions & 28 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesDistortion.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,40 @@ TEXTURE2D(_AlphaTransitionMap);
SAMPLER(sampler_AlphaTransitionMap);

CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
DECLARE_CUSTOM_COORD(_BaseMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_BaseMapOffsetYCoord);
half _BaseMapChannelsX;
half _BaseMapChannelsY;
float4 _BaseMap_ST;
DECLARE_CUSTOM_COORD(_BaseMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_BaseMapOffsetYCoord);
half _BaseMapChannelsX;
half _BaseMapChannelsY;

float _BaseMapRotation;
DECLARE_CUSTOM_COORD(_BaseMapRotationCoord);
float4 _BaseMapRotationOffsets;
float _DistortionIntensity;
float _DistortionIntensityCoord;
float _BaseMapRotation;
DECLARE_CUSTOM_COORD(_BaseMapRotationCoord);
float4 _BaseMapRotationOffsets;
float _DistortionIntensity;
float _DistortionIntensityCoord;

float4 _FlowMap_ST;
DECLARE_CUSTOM_COORD(_FlowMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_FlowMapOffsetYCoord);
half _FlowMapChannelsX;
half _FlowMapChannelsY;
float4 _FlowMap_ST;
DECLARE_CUSTOM_COORD(_FlowMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_FlowMapOffsetYCoord);
half _FlowMapChannelsX;
half _FlowMapChannelsY;

float _FlowIntensity;
DECLARE_CUSTOM_COORD(_FlowIntensityCoord);
float _FlowIntensity;
DECLARE_CUSTOM_COORD(_FlowIntensityCoord);

float4 _AlphaTransitionMap_ST;
DECLARE_CUSTOM_COORD(_AlphaTransitionMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_AlphaTransitionMapOffsetYCoord);
half _AlphaTransitionMapChannelsX;
float4 _AlphaTransitionMap_ST;
DECLARE_CUSTOM_COORD(_AlphaTransitionMapOffsetXCoord);
DECLARE_CUSTOM_COORD(_AlphaTransitionMapOffsetYCoord);
half _AlphaTransitionMapChannelsX;

float _AlphaTransitionProgress;
DECLARE_CUSTOM_COORD(_AlphaTransitionProgressCoord);
float _DissolveSharpness;
float _AlphaTransitionProgress;
DECLARE_CUSTOM_COORD(_AlphaTransitionProgressCoord);
float _DissolveSharpness;

float _SoftParticlesIntensity;
float _DepthFadeNear;
float _DepthFadeFar;
float _DepthFadeWidth;
float _SoftParticlesIntensity;
float _DepthFadeNear;
float _DepthFadeFar;
float _DepthFadeWidth;
CBUFFER_END

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ Shader "Nova/Particles/Distortion"
}

CustomEditor "Nova.Editor.Core.Scripts.ParticlesDistortionGUI"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ half4 frag(Varyings input) : SV_Target
#else
baseMapSamplerState = sampler_BaseMap;
#endif
half4 distortionSrc = SAMPLE_TEXTURE2D(_BaseMap, baseMapSamplerState, input.baseUv.xy);
half4 distortionSrc = SAMPLE_TEXTURE2D(_BaseMap, baseMapSamplerState, input.baseUv.xy);
half2 distortion;
distortion.x = distortionSrc[(uint)_BaseMapChannelsX];
distortion.y = distortionSrc[(uint)_BaseMapChannelsY];
Expand Down
Loading

0 comments on commit abcda80

Please sign in to comment.