目录调整
This commit is contained in:
parent
d7beb63413
commit
eb31f54866
8
Assets/Scripts/Features.meta
Normal file
8
Assets/Scripts/Features.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9680b5dde4de0b4cbde7385d195a83f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Features/CapsuleShadow.meta
Normal file
8
Assets/Scripts/Features/CapsuleShadow.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd21b59b0005cb1468bcd398f4d50d2a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -77,7 +77,8 @@ namespace X.Rendering.Scene
|
||||
this.sceneEffect = sceneEffect;
|
||||
profiler = new(nameof(CapsuleShadowPass));
|
||||
renderPassEvent = settings.RenderPassEvent;
|
||||
commandBuffer = CommandBufferPool.Get(nameof(CapsuleShadowPass) + sceneEffect.name);
|
||||
commandBuffer = new CommandBuffer();
|
||||
commandBuffer.name = nameof(CapsuleShadowPass) + sceneEffect.name;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
8
Assets/Scripts/Features/OIT.meta
Normal file
8
Assets/Scripts/Features/OIT.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9189c3c3caf6d54fb2353547eb1f1ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Features/OIT/MOIT.meta
Normal file
8
Assets/Scripts/Features/OIT/MOIT.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c13418f95798244409a0dfeee8fb1bb8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Features/OIT/WBOIT.meta
Normal file
8
Assets/Scripts/Features/OIT/WBOIT.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af120a2c8a6e73b4fa4b50452dc87686
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/Features/OIT/WBOIT/WBOITBlend.shader
Normal file
61
Assets/Scripts/Features/OIT/WBOIT/WBOITBlend.shader
Normal file
@ -0,0 +1,61 @@
|
||||
Shader "Hidden/WBOIT/WBOITBlend"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always Cull Back ZWrite Off Fog { Mode Off }
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
sampler2D _AccumTex;
|
||||
sampler2D _RevealageTex;
|
||||
|
||||
v2f vert (uint vertexID: SV_VertexID)
|
||||
{
|
||||
v2f o;
|
||||
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
|
||||
float4 pos = float4(uv * 2.0 - 1.0, UNITY_NEAR_CLIP_VALUE, 1.0);
|
||||
#ifdef UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION
|
||||
pos = ApplyPretransformRotation(pos);
|
||||
#endif
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
uv = float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
|
||||
#endif
|
||||
|
||||
o.vertex = pos;
|
||||
o.uv = uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed4 background = tex2D(_MainTex, i.uv);
|
||||
float4 accum = tex2D(_AccumTex, i.uv);
|
||||
float r = tex2D(_RevealageTex, i.uv).r;
|
||||
|
||||
fixed4 col = float4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);
|
||||
|
||||
return (1.0 - col.a) * col + col.a * background;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Assets/Scripts/Features/OIT/WBOIT/WBOITBlend.shader.meta
Normal file
9
Assets/Scripts/Features/OIT/WBOIT/WBOITBlend.shader.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e995304faaa72846b56efb3c2ab607c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
150
Assets/Scripts/Features/OIT/WBOIT/WBOITFeature.cs
Normal file
150
Assets/Scripts/Features/OIT/WBOIT/WBOITFeature.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Experimental.Rendering.Universal;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
public class WBOITFeature : ScriptableRendererFeature
|
||||
{
|
||||
[Serializable]
|
||||
public class FilterSettings
|
||||
{
|
||||
public RenderQueueType RenderQueueType;
|
||||
public LayerMask LayerMask;
|
||||
|
||||
public FilterSettings()
|
||||
{
|
||||
RenderQueueType = RenderQueueType.Transparent;
|
||||
LayerMask = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class OITSettings
|
||||
{
|
||||
public RenderPassEvent RenderPassEvent = RenderPassEvent.AfterRenderingOpaques;
|
||||
public FilterSettings FilterSettings = new FilterSettings();
|
||||
public Shader BlendShader;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
OITSettings settings;
|
||||
|
||||
OITRenderPass pass;
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
var cam = renderingData.cameraData;
|
||||
if (cam.cameraType != CameraType.Game && cam.cameraType != CameraType.SceneView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
renderer.EnqueuePass(pass);
|
||||
}
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
pass = new OITRenderPass(settings);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
pass.Dispose();
|
||||
}
|
||||
|
||||
class OITRenderPass : ScriptableRenderPass, IDisposable
|
||||
{
|
||||
private ProfilingSampler profiler;
|
||||
private CommandBuffer commandBuffer;
|
||||
private OITSettings settings;
|
||||
private Material blendMaterial;
|
||||
|
||||
static readonly int accumTexID = Shader.PropertyToID("_AccumTex");
|
||||
static readonly int revealageTexID = Shader.PropertyToID("_RevealageTex");
|
||||
static readonly int mainTexID = Shader.PropertyToID("_MainTex");
|
||||
|
||||
RTHandle[] oitRTids = new RTHandle[2];
|
||||
private ShaderTagId shaderTagId = new ShaderTagId("DoOIT");
|
||||
|
||||
public OITRenderPass(OITSettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
profiler = new(nameof(OITRenderPass));
|
||||
commandBuffer = new CommandBuffer();
|
||||
commandBuffer.name = profiler.name;
|
||||
renderPassEvent = settings.RenderPassEvent;
|
||||
blendMaterial = new Material(settings.BlendShader);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
oitRTids[0]?.Release();
|
||||
oitRTids[1]?.Release();
|
||||
commandBuffer.Release();
|
||||
GameObject.DestroyImmediate(blendMaterial);
|
||||
}
|
||||
|
||||
RTHandle destinationRT;
|
||||
|
||||
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
var cmd = commandBuffer;
|
||||
using var scp = new ProfilingScope(cmd, profiler);
|
||||
var rdr = renderingData.cameraData.renderer;
|
||||
var desc = renderingData.cameraData.cameraTargetDescriptor;
|
||||
desc.depthBufferBits = 0;
|
||||
desc.sRGB = false;
|
||||
RenderingUtils.ReAllocateIfNeeded(ref oitRTids[0], desc, filterMode: FilterMode.Bilinear);
|
||||
RenderingUtils.ReAllocateIfNeeded(ref destinationRT, desc, filterMode: FilterMode.Bilinear);
|
||||
|
||||
cmd.SetRenderTarget(oitRTids[0]);
|
||||
cmd.ClearRenderTarget(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
desc.graphicsFormat = SystemInfo.IsFormatSupported(GraphicsFormat.R16_SFloat, FormatUsage.Render) ? GraphicsFormat.R16_SFloat : GraphicsFormat.R32_SFloat;
|
||||
|
||||
RenderingUtils.ReAllocateIfNeeded(ref oitRTids[1], desc, filterMode: FilterMode.Bilinear);
|
||||
|
||||
cmd.SetRenderTarget(oitRTids[1]);
|
||||
cmd.ClearRenderTarget(false, true, new Color(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
RenderQueueRange renderQueueRange = (settings.FilterSettings.RenderQueueType == RenderQueueType.Transparent)
|
||||
? RenderQueueRange.transparent
|
||||
: RenderQueueRange.opaque;
|
||||
|
||||
var filteringSettings = new FilteringSettings(renderQueueRange, settings.FilterSettings.LayerMask);
|
||||
var renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
|
||||
SortingCriteria sortingCriteria = (filteringSettings.renderQueueRange == RenderQueueRange.transparent)
|
||||
? SortingCriteria.CommonTransparent
|
||||
: renderingData.cameraData.defaultOpaqueSortFlags;
|
||||
|
||||
DrawingSettings drawSettings = CreateDrawingSettings(shaderTagId, ref renderingData, sortingCriteria);
|
||||
|
||||
#region Draw Weighted Blended Order-Independent Transparency
|
||||
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings, ref renderStateBlock);
|
||||
#endregion
|
||||
|
||||
#region Blend
|
||||
cmd.SetGlobalTexture(accumTexID, oitRTids[0]);
|
||||
cmd.SetGlobalTexture(revealageTexID, oitRTids[1]);
|
||||
cmd.SetGlobalTexture(mainTexID, rdr.cameraColorTargetHandle);
|
||||
|
||||
cmd.SetRenderTarget(destinationRT, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
|
||||
cmd.DrawProcedural(Matrix4x4.identity, blendMaterial, 0, MeshTopology.Triangles, 3);
|
||||
|
||||
if (SystemInfo.copyTextureSupport != CopyTextureSupport.None)
|
||||
{
|
||||
cmd.CopyTexture(destinationRT, rdr.cameraColorTargetHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
Blit(cmd, destinationRT, rdr.cameraColorTargetHandle);
|
||||
}
|
||||
#endregion
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
cmd.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Features/OIT/WBOIT/WBOITFeature.cs.meta
Normal file
11
Assets/Scripts/Features/OIT/WBOIT/WBOITFeature.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 791db3d002c63d1409813c72e53105ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,74 @@
|
||||
Shader "WBOIT/WBOITSimpleTranspatent"
|
||||
{
|
||||
Properties {
|
||||
_Color ("Color Tint", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Main Tex", 2D) = "white" {}
|
||||
_Alpha("Alpha", Range(0.0, 1.0)) = 0.5
|
||||
}
|
||||
SubShader {
|
||||
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
|
||||
|
||||
|
||||
Pass {
|
||||
Tags { "LightMode" = "DoOIT" }
|
||||
|
||||
ZWrite Off
|
||||
Blend 0 One One
|
||||
Blend 1 Zero OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Lighting.cginc"
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
float _Alpha;
|
||||
|
||||
struct a2v
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float4 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD2;
|
||||
float z : TEXCOORD3;
|
||||
};
|
||||
|
||||
v2f vert(a2v v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
o.z = abs(UnityObjectToViewPos(v.vertex).z);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float w(float z, float alpha)
|
||||
{
|
||||
return alpha * max(1e-2, min(3 * 1e3, 0.03 / (1e-5 + pow(z / 200, 4))));
|
||||
}
|
||||
|
||||
void frag(v2f i, out float4 color : SV_Target0, out float4 alpha : SV_Target1){
|
||||
|
||||
fixed4 albedo = tex2D(_MainTex, i.uv) * _Color;
|
||||
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo.rgb;
|
||||
|
||||
fixed3 C = (albedo.rgb) * _Alpha;
|
||||
|
||||
color = float4(C, _Alpha) * w(i.z, _Alpha);
|
||||
alpha = albedo.aaaa;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5626fadf5ea58ad448d468c2362fadfb
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,35 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: WBOIT_WBOITSimpleTranspatent
|
||||
m_Shader: {fileID: 4800000, guid: 5626fadf5ea58ad448d468c2362fadfb, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _Alpha: 0.5
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 726b6d50ed967394baf2fc73f960aeb8
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Features/Tween.meta
Normal file
8
Assets/Scripts/Features/Tween.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 469ef4e0a428d7649a068442c5c94d22
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,10 +1,10 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.burst": "1.8.19",
|
||||
"com.unity.burst": "1.8.21",
|
||||
"com.unity.cinemachine": "2.10.3",
|
||||
"com.unity.collab-proxy": "2.7.1",
|
||||
"com.unity.formats.fbx": "4.2.1",
|
||||
"com.unity.ide.rider": "3.0.35",
|
||||
"com.unity.ide.rider": "3.0.36",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.inputsystem": "1.14.0",
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.burst": {
|
||||
"version": "1.8.19",
|
||||
"version": "1.8.21",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -68,7 +68,7 @@
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.35",
|
||||
"version": "3.0.36",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -193,7 +193,7 @@
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.settings-manager": {
|
||||
"version": "2.0.1",
|
||||
"version": "2.1.0",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user