This commit is contained in:
左右看
2023-06-28 00:35:46 +08:00
parent cb5bab5ce9
commit 0d848e4d07
524 changed files with 78452 additions and 12 deletions
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways, ImageEffectAllowedInSceneView]
public class RoughRefraction : MonoBehaviour
{
private readonly Dictionary<Camera, RenderTexture> renderTextureCache = new Dictionary<Camera, RenderTexture>();
private static readonly int CameraOpaqueTexture = Shader.PropertyToID("_CameraOpaqueTexture");
private void OnDisable()
{
if (renderTextureCache != null) {
foreach(var kvp in renderTextureCache)
RenderTexture.ReleaseTemporary(kvp.Value);
}
renderTextureCache?.Clear();
}
private void OnPreRender()
{
SetTexture();
}
private void SetTexture()
{
var current = Camera.current;
if (!renderTextureCache.ContainsKey(current))
{
Shader.SetGlobalTexture(CameraOpaqueTexture, Texture2D.blackTexture);
return;
}
Shader.SetGlobalTexture(CameraOpaqueTexture, renderTextureCache[current]);
}
[ImageEffectOpaque]
private void OnRenderImage(RenderTexture src, RenderTexture dest)
{
var dsc = src.descriptor;
dsc.useMipMap = true;
dsc.autoGenerateMips = false;
dsc.msaaSamples = 1;
dsc.width = Mathf.ClosestPowerOfTwo(dsc.width);
dsc.height = Mathf.ClosestPowerOfTwo(dsc.height);
var current = Camera.current;
if (!renderTextureCache.ContainsKey(current))
renderTextureCache.Add(current, null);
if(renderTextureCache[current])
RenderTexture.ReleaseTemporary(renderTextureCache[current]);
renderTextureCache[current] = RenderTexture.GetTemporary(dsc);
renderTextureCache[current].filterMode = FilterMode.Trilinear;
// temp[current].useMipMap = true;
Graphics.Blit(src, renderTextureCache[current]);
renderTextureCache[current].GenerateMips();
Graphics.Blit(src, dest);
SetTexture();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b5788589ee445e45bf87cdf1ec6ee90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
#if HAVE_URP_12_OR_NEWER || HAVE_URP_10_OR_NEWER
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering.Universal.Internal;
namespace UnityGLTF
{
#if HAVE_URP_12_OR_NEWER
[DisallowMultipleRendererFeature("Opaque Texture (Rough Refractions)")]
#endif
public class RoughRefractionFeature : ScriptableRendererFeature
{
public Downsampling downsampling = Downsampling.None;
class CustomRenderPass : CopyColorPass
{
public Downsampling m_DownsamplingMethod;
public RenderTargetHandle destination;
public CustomRenderPass(RenderPassEvent evt) : base(evt,
CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/Universal Render Pipeline/Sampling")),
CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/Universal Render Pipeline/Blit")))
{ }
public new void Setup(RenderTargetIdentifier source, RenderTargetHandle destination, Downsampling downsampling)
{
base.Setup(source, destination, downsampling);
this.destination = destination;
this.m_DownsamplingMethod = downsampling;
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
var desc = renderingData.cameraData.cameraTargetDescriptor;
desc.useMipMap = true;
desc.autoGenerateMips = true;
renderingData.cameraData.cameraTargetDescriptor = desc;
// base.OnCameraSetup(cmd, ref renderingData);
RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
descriptor.msaaSamples = 1;
descriptor.depthBufferBits = 0;
if (m_DownsamplingMethod == Downsampling._2xBilinear)
{
descriptor.width /= 2;
descriptor.height /= 2;
}
else if (m_DownsamplingMethod == Downsampling._4xBox || m_DownsamplingMethod == Downsampling._4xBilinear)
{
descriptor.width /= 4;
descriptor.height /= 4;
}
cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Trilinear);
}
}
CustomRenderPass m_ScriptablePass;
RenderTargetHandle m_OpaqueColor;
/// <inheritdoc/>
public override void Create()
{
m_OpaqueColor.Init("_CameraOpaqueTexture");
}
// Here you can inject one or multiple render passes in the renderer.
// This method is called when setting up the renderer once per-camera.
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (m_ScriptablePass == null)
{
m_ScriptablePass = new CustomRenderPass(RenderPassEvent.AfterRenderingSkybox);
}
m_ScriptablePass.Setup(renderer.cameraColorTarget, m_OpaqueColor, downsampling);
renderer.EnqueuePass(m_ScriptablePass);
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9aa176c7981ee2a469e664fd93f010b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
{
"name": "UnityGltf.RenderPipelines",
"references": [
"GUID:15fc0a57446b3144c949da3e2b9737a9",
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
"GUID:2bafac87e7f4b9b418d9448d219b01ab"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [
"UNITY_2020_3_OR_NEWER"
],
"versionDefines": [
{
"name": "com.unity.render-pipelines.universal",
"expression": "12",
"define": "HAVE_URP_12_OR_NEWER"
},
{
"name": "com.unity.render-pipelines.universal",
"expression": "10",
"define": "HAVE_URP_10_OR_NEWER"
}
],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fe848190f1a690142846fa6384b74e17
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: