-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from lukakldiashvili/version/0.3
Version 0.3
- Loading branch information
Showing
31 changed files
with
369 additions
and
318 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Unified.UniversalBlur.Editor", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:179652d7da581408b8baeed6637275e9", | ||
"GUID:3eae0364be2026648bf74846acb8a731", | ||
"GUID:15fc0a57446b3144c949da3e2b9737a9" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
5 changes: 2 additions & 3 deletions
5
...rsalBlur/Materials/KawaseBlurMat.mat.meta → .../Unified.UniversalBlur.Editor.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Unified.UniversalBlur.Runtime | ||
{ | ||
internal struct BlurPassData : IDisposable | ||
{ | ||
internal Material EffectMaterial; | ||
internal int PassIndex; | ||
|
||
public float Downsample; | ||
public float Intensity; | ||
public float Scale; | ||
public int Iterations; | ||
|
||
public RenderTextureDescriptor Descriptor; | ||
|
||
public | ||
// #if UNITY_2022_1_OR_NEWER | ||
// RTHandle | ||
// #else | ||
RenderTexture | ||
// #endif | ||
RT1, RT2; | ||
|
||
public void Dispose() | ||
{ | ||
if (RT1 != null) | ||
RT1.Release(); | ||
|
||
if (RT2 != null) | ||
RT2.Release(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using UnityEngine; | ||
using UnityEngine.Experimental.Rendering; | ||
using UnityEngine.Rendering; | ||
|
||
namespace Unified.UniversalBlur.Runtime | ||
{ | ||
public static class Helpers | ||
{ | ||
// Derived from RenderingUtils.RTHandleNeedsReAlloc | ||
public static bool HasDescriptorChanged(RenderTextureDescriptor descriptorA, RenderTextureDescriptor descriptorB, bool scaled) | ||
{ | ||
if (descriptorA.useDynamicScale != scaled) | ||
return true; | ||
if (!scaled && (descriptorA.width != descriptorB.width || descriptorA.height != descriptorB.height)) | ||
return true; | ||
return | ||
descriptorA.depthBufferBits != descriptorB.depthBufferBits || | ||
(descriptorA.depthBufferBits == (int)DepthBits.None && | ||
descriptorA.graphicsFormat != (GraphicsFormat)descriptorB.colorFormat) || | ||
descriptorA.dimension != descriptorB.dimension || | ||
descriptorA.enableRandomWrite != descriptorB.enableRandomWrite || | ||
descriptorA.useMipMap != descriptorB.useMipMap || | ||
descriptorA.autoGenerateMips != descriptorB.autoGenerateMips || | ||
descriptorA.msaaSamples != descriptorB.msaaSamples || | ||
descriptorA.bindMS != descriptorB.bindMS || | ||
descriptorA.useDynamicScale != descriptorB.useDynamicScale || | ||
descriptorA.memoryless != descriptorB.memoryless; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Unified.UniversalBlur.Runtime | ||
{ | ||
public enum ScaleBlurWith | ||
{ | ||
Disabled, | ||
ScreenHeight, | ||
ScreenWidth, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using UnityEngine; | ||
using UnityEngine.Rendering; | ||
using UnityEngine.Rendering.Universal; | ||
|
||
namespace Unified.UniversalBlur.Runtime | ||
{ | ||
public class UniversalBlurFeature : ScriptableRendererFeature | ||
{ | ||
private enum InjectionPoint | ||
{ | ||
BeforeRenderingTransparents = RenderPassEvent.BeforeRenderingTransparents, | ||
BeforeRenderingPostProcessing = RenderPassEvent.BeforeRenderingPostProcessing, | ||
AfterRenderingPostProcessing = RenderPassEvent.AfterRenderingPostProcessing | ||
} | ||
|
||
[field: SerializeField, HideInInspector] public int PassIndex { get; set; } = 0; | ||
|
||
[field: Header("Blur Settings")] | ||
[field: SerializeField] private InjectionPoint injectionPoint = InjectionPoint.AfterRenderingPostProcessing; | ||
|
||
[field: Space] | ||
[field: Range(0f, 1f)] [field: SerializeField] public float Intensity { get; set; } = 1.0f; | ||
|
||
[Range(1f, 10f)] [SerializeField] private float downsample = 2.0f; | ||
[Range(1, 20)] [SerializeField] private int iterations = 6; | ||
[Range(0f, 5f)] [SerializeField] private float scale = .5f; | ||
[SerializeField] private ScaleBlurWith scaleBlurWith; | ||
[SerializeField] private float scaleReferenceSize = 1080f; | ||
|
||
[SerializeField] | ||
[HideInInspector] | ||
[Reload("Shaders/KawaseBlur.shader")] | ||
private Shader shader; | ||
|
||
private readonly ScriptableRenderPassInput _requirements = ScriptableRenderPassInput.Color; | ||
|
||
public Material PassMaterial => _material; | ||
|
||
// Hidden by scope because of incorrect behaviour in the editor | ||
private bool disableInSceneView = true; | ||
|
||
private Material _material; | ||
private UniversalBlurPass _fullScreenPass; | ||
private bool _injectedBeforeTransparents; | ||
|
||
/// <inheritdoc/> | ||
public override void Create() | ||
{ | ||
_fullScreenPass = new UniversalBlurPass(); | ||
_fullScreenPass.renderPassEvent = (RenderPassEvent)injectionPoint; | ||
|
||
ScriptableRenderPassInput modifiedRequirements = _requirements; | ||
|
||
var requiresColor = (_requirements & ScriptableRenderPassInput.Color) != 0; | ||
_injectedBeforeTransparents = injectionPoint <= InjectionPoint.BeforeRenderingTransparents; | ||
|
||
if (requiresColor && !_injectedBeforeTransparents) | ||
{ | ||
modifiedRequirements ^= ScriptableRenderPassInput.Color; | ||
} | ||
|
||
_fullScreenPass.ConfigureInput(modifiedRequirements); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) | ||
{ | ||
if (!TrySetShadersAndMaterials()) | ||
{ | ||
Debug.LogErrorFormat("{0}.AddRenderPasses(): Missing material. {1} render pass will not be added.", GetType().Name, name); | ||
return; | ||
} | ||
|
||
var passData = GetBlurPassData(); | ||
|
||
_fullScreenPass.Setup(passData, renderingData); | ||
|
||
renderer.EnqueuePass(_fullScreenPass); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void Dispose(bool disposing) | ||
{ | ||
_fullScreenPass?.Dispose(); | ||
CoreUtils.Destroy(_material); | ||
} | ||
|
||
private bool TrySetShadersAndMaterials() | ||
{ | ||
if (shader == null) | ||
{ | ||
shader = Shader.Find("Unified/KawaseBlur"); | ||
} | ||
|
||
if (_material == null && shader != null) | ||
_material = CoreUtils.CreateEngineMaterial(shader); | ||
return _material != null; | ||
} | ||
|
||
private float CalculateScale() => scaleBlurWith switch | ||
{ | ||
ScaleBlurWith.ScreenHeight => scale * (Screen.height / scaleReferenceSize), | ||
ScaleBlurWith.ScreenWidth => scale * (Screen.width / scaleReferenceSize), | ||
_ => scale | ||
}; | ||
|
||
private BlurPassData GetBlurPassData() | ||
{ | ||
return new BlurPassData() | ||
{ | ||
EffectMaterial = _material, | ||
Downsample = downsample, | ||
Intensity = Intensity, | ||
PassIndex = PassIndex, | ||
Scale = CalculateScale(), | ||
Iterations = iterations, | ||
}; | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.