Last active
October 3, 2023 12:36
-
-
Save joshcamas/2b67387dae360173f9556608c9f69608 to your computer and use it in GitHub Desktop.
Distant Pixelize Renderer (Using SCPE)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.Rendering.Universal; | |
using System; | |
using UnityEngine; | |
using UnityEngine.Rendering; | |
using SCPE; | |
namespace Ardenfall.Effects | |
{ | |
[Serializable, VolumeComponentMenu("Ardenfall/Distant Pixelize")] | |
public sealed class DistantPixelize : VolumeComponent, IPostProcessComponent | |
{ | |
public ClampedFloatParameter maxSize = new ClampedFloatParameter(0f, 0f, 1f); | |
public ClampedFloatParameter minSize = new ClampedFloatParameter(0f, 0f, 1f); | |
public ClampedFloatParameter maxDistance = new ClampedFloatParameter(0f, 0f, 300f); | |
public bool IsActive() => maxSize.value > 0f && this.active; | |
public bool IsTileCompatible() => false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.Rendering.Universal; | |
using UnityEngine.Rendering; | |
using UnityEngine; | |
using SCPE; | |
namespace Ardenfall.Effects | |
{ | |
public class DistantPixelizeRenderer : ScriptableRendererFeature | |
{ | |
class DistantPixelizeRenderPass : PostEffectRenderer<DistantPixelize> | |
{ | |
public DistantPixelizeRenderPass() | |
{ | |
shaderName = "Ardenfall/Effects/DistantPixelize"; | |
ProfilerTag = this.ToString(); | |
} | |
public void Setup(ScriptableRenderer renderer) | |
{ | |
this.cameraColorTarget = GetCameraTarget(renderer); | |
volumeSettings = VolumeManager.instance.stack.GetComponent<DistantPixelize>(); | |
if(volumeSettings) renderer.EnqueuePass(this); | |
} | |
public override void ConfigurePass(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) | |
{ | |
if (!volumeSettings) return; | |
base.ConfigurePass(cmd, cameraTextureDescriptor); | |
} | |
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) | |
{ | |
if (!volumeSettings) return; | |
if (volumeSettings.IsActive() == false) return; | |
var cmd = CommandBufferPool.Get(ProfilerTag); | |
CopyTargets(cmd, renderingData); | |
Material.SetFloat("_MaxPixelSize", volumeSettings.maxSize.value * 0.1f); | |
Material.SetFloat("_MinPixelSize", volumeSettings.minSize.value * 0.1f); | |
Material.SetFloat("_MaxDistance", volumeSettings.maxDistance.value); | |
FinalBlit(this, context, cmd, mainTexID.id, cameraColorTarget, Material, 0); | |
} | |
} | |
public RenderPassEvent renderPassEvent; | |
private DistantPixelizeRenderPass m_ScriptablePass; | |
public override void Create() | |
{ | |
m_ScriptablePass = new DistantPixelizeRenderPass(); | |
// Configures where the render pass should be injected. | |
m_ScriptablePass.renderPassEvent = renderPassEvent; | |
} | |
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) | |
{ | |
m_ScriptablePass.Setup(renderer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of SCPE was used for this?