Make work with astra

This commit is contained in:
Andras Schmelczer 2026-09-14 08:01:49 +01:00
commit c8ee5045e2
801 changed files with 6338 additions and 4613 deletions

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 479a3739c785a11469f3ee1f463994f7
timeCreated: 1507217626
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 479a3739c785a11469f3ee1f463994f7
timeCreated: 1507217626
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: fa5e8bc9da963d949955cf16217de64f
timeCreated: 1500302146
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: fa5e8bc9da963d949955cf16217de64f
timeCreated: 1500302146
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: bd3a79df710fe68418617efeba366df4
timeCreated: 1510244436
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: bd3a79df710fe68418617efeba366df4
timeCreated: 1510244436
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,65 +0,0 @@
Shader "Hidden/Post FX/Monitors/Waveform Render"
{
SubShader
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGINCLUDE
#pragma fragmentoption ARB_precision_hint_fastest
#pragma target 5.0
#include "UnityCG.cginc"
StructuredBuffer<uint4> _Waveform;
float2 _Size;
float4 _Channels;
float _Exposure;
float3 Tonemap(float3 x, float exposure)
{
const float a = 6.2;
const float b = 0.5;
const float c = 1.7;
const float d = 0.06;
x *= exposure;
x = max((0.0).xxx, x - (0.004).xxx);
x = (x * (a * x + b)) / (x * (a * x + c) + d);
return x * x;
}
float4 FragWaveform(v2f_img i) : SV_Target
{
const float3 red = float3(1.4, 0.03, 0.02);
const float3 green = float3(0.02, 1.1, 0.05);
const float3 blue = float3(0.0, 0.25, 1.5);
float3 color = float3(0.0, 0.0, 0.0);
uint2 uvI = i.pos.xy;
float4 w = _Waveform[uvI.y + uvI.x * _Size.y]; // Waveform data is stored in columns instead of rows
color += red * w.r * _Channels.r;
color += green * w.g * _Channels.g;
color += blue * w.b * _Channels.b;
color += w.aaa * _Channels.a * 1.5;
color = Tonemap(color, _Exposure);
color += (0.1).xxx;
return float4(saturate(color), 1.0);
}
ENDCG
// (0)
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment FragWaveform
ENDCG
}
}
FallBack off
}

View file

@ -1,118 +0,0 @@
Shader "Hidden/Post FX/UI/Trackball"
{
CGINCLUDE
#include "UnityCG.cginc"
#define PI 3.14159265359
#define PI2 6.28318530718
float _Offset;
float _DisabledState;
float2 _Resolution; // x: size, y: size / 2
float3 HsvToRgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
float4 CreateWheel(v2f_img i, float crossColor, float offsetColor)
{
const float kHueOuterRadius = 0.45;
const float kHueInnerRadius = 0.38;
const float kLumOuterRadius = 0.495;
const float kLumInnerRadius = 0.48;
float4 color = (0.0).xxxx;
float2 uvc = i.uv - (0.5).xx;
float dist = sqrt(dot(uvc, uvc));
float delta = fwidth(dist);
float angle = atan2(uvc.x, uvc.y);
// Cross
{
float radius = (0.5 - kHueInnerRadius) * _Resolution.x + 1.0;
float2 pixel = (_Resolution.xx - 1.0) * i.uv + 1.0;
float vline = step(floor(fmod(pixel.x, _Resolution.y)), 0.0);
vline *= step(radius, pixel.y) * step(pixel.y, _Resolution.x - radius);
float hline = step(floor(fmod(pixel.y, _Resolution.y)), 0.0);
hline *= step(radius, pixel.x) * step(pixel.x, _Resolution.x - radius);
color += hline.xxxx * (1.0).xxxx;
color += vline.xxxx * (1.0).xxxx;
color = saturate(color);
color *= half4((crossColor).xxx, 0.05);
}
// Hue
{
float alphaOut = smoothstep(kHueOuterRadius - delta, kHueOuterRadius + delta, dist);
float alphaIn = smoothstep(kHueInnerRadius - delta, kHueInnerRadius + delta, dist);
float hue = angle;
hue = 1.0 - ((hue > 0.0) ? hue : PI2 + hue) / PI2;
float4 c = float4(HsvToRgb(float3(hue, 1.0, 1.0)), 1.0);
color += lerp((0.0).xxxx, c, alphaIn - alphaOut);
}
// Offset
{
float alphaOut = smoothstep(kLumOuterRadius - delta, kLumOuterRadius + delta, dist);
float alphaIn = smoothstep(kLumInnerRadius - delta, kLumInnerRadius + delta / 2, dist);
float4 c = float4((offsetColor).xxx, 1.0);
float a = PI * _Offset;
if (_Offset >= 0 && angle < a && angle > 0.0)
c = float4((1.0).xxx, 0.5);
else if (angle > a && angle < 0.0)
c = float4((1.0).xxx, 0.5);
color += lerp((0.0).xxxx, c, alphaIn - alphaOut);
}
return color * _DisabledState;
}
float4 FragTrackballDark(v2f_img i) : SV_Target
{
return CreateWheel(i, 1.0, 0.15);
}
float4 FragTrackballLight(v2f_img i) : SV_Target
{
return CreateWheel(i, 0.0, 0.3);
}
ENDCG
SubShader
{
Cull Off ZWrite Off ZTest Always
// (0) Dark skin
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment FragTrackballDark
ENDCG
}
// (1) Light skin
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment FragTrackballLight
ENDCG
}
}
}

View file

@ -1,106 +0,0 @@
using UnityEngine.PostProcessing;
namespace UnityEditor.PostProcessing
{
using Mode = BuiltinDebugViewsModel.Mode;
using Settings = BuiltinDebugViewsModel.Settings;
[PostProcessingModelEditor(typeof(BuiltinDebugViewsModel), alwaysEnabled: true)]
public class BuiltinDebugViewsEditor : PostProcessingModelEditor
{
struct DepthSettings
{
public SerializedProperty scale;
}
struct MotionVectorsSettings
{
public SerializedProperty sourceOpacity;
public SerializedProperty motionImageOpacity;
public SerializedProperty motionImageAmplitude;
public SerializedProperty motionVectorsOpacity;
public SerializedProperty motionVectorsResolution;
public SerializedProperty motionVectorsAmplitude;
}
SerializedProperty m_Mode;
DepthSettings m_Depth;
MotionVectorsSettings m_MotionVectors;
public override void OnEnable()
{
m_Mode = FindSetting((Settings x) => x.mode);
m_Depth = new DepthSettings
{
scale = FindSetting((Settings x) => x.depth.scale)
};
m_MotionVectors = new MotionVectorsSettings
{
sourceOpacity = FindSetting((Settings x) => x.motionVectors.sourceOpacity),
motionImageOpacity = FindSetting((Settings x) => x.motionVectors.motionImageOpacity),
motionImageAmplitude = FindSetting((Settings x) => x.motionVectors.motionImageAmplitude),
motionVectorsOpacity = FindSetting((Settings x) => x.motionVectors.motionVectorsOpacity),
motionVectorsResolution = FindSetting((Settings x) => x.motionVectors.motionVectorsResolution),
motionVectorsAmplitude = FindSetting((Settings x) => x.motionVectors.motionVectorsAmplitude),
};
}
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(m_Mode);
int mode = m_Mode.intValue;
if (mode == (int)Mode.Depth)
{
EditorGUILayout.PropertyField(m_Depth.scale);
}
else if (mode == (int)Mode.MotionVectors)
{
EditorGUILayout.HelpBox("Switch to play mode to see motion vectors.", MessageType.Info);
EditorGUILayout.LabelField("Source Image", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_MotionVectors.sourceOpacity, EditorGUIHelper.GetContent("Opacity"));
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Motion Vectors (overlay)", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
if (m_MotionVectors.motionImageOpacity.floatValue > 0f)
EditorGUILayout.HelpBox("Please keep opacity to 0 if you're subject to motion sickness.", MessageType.Warning);
EditorGUILayout.PropertyField(m_MotionVectors.motionImageOpacity, EditorGUIHelper.GetContent("Opacity"));
EditorGUILayout.PropertyField(m_MotionVectors.motionImageAmplitude, EditorGUIHelper.GetContent("Amplitude"));
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Motion Vectors (arrows)", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsOpacity, EditorGUIHelper.GetContent("Opacity"));
EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsResolution, EditorGUIHelper.GetContent("Resolution"));
EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsAmplitude, EditorGUIHelper.GetContent("Amplitude"));
EditorGUI.indentLevel--;
}
else
{
CheckActiveEffect(mode == (int)Mode.AmbientOcclusion && !profile.ambientOcclusion.enabled, "Ambient Occlusion");
CheckActiveEffect(mode == (int)Mode.FocusPlane && !profile.depthOfField.enabled, "Depth Of Field");
CheckActiveEffect(mode == (int)Mode.EyeAdaptation && !profile.eyeAdaptation.enabled, "Eye Adaptation");
CheckActiveEffect((mode == (int)Mode.LogLut || mode == (int)Mode.PreGradingLog) && !profile.colorGrading.enabled, "Color Grading");
CheckActiveEffect(mode == (int)Mode.UserLut && !profile.userLut.enabled, "User Lut");
}
}
void CheckActiveEffect(bool expr, string name)
{
if (expr)
EditorGUILayout.HelpBox(string.Format("{0} isn't enabled, the debug view won't work.", name), MessageType.Warning);
}
}
}

View file

@ -1,58 +0,0 @@
using UnityEngine;
namespace UnityEditor.PostProcessing
{
using UnityObject = Object;
static class EditorResources
{
static string m_EditorResourcesPath = string.Empty;
internal static string editorResourcesPath
{
get
{
if (string.IsNullOrEmpty(m_EditorResourcesPath))
{
string path;
if (SearchForEditorResourcesPath(out path))
m_EditorResourcesPath = path;
else
Debug.LogError("Unable to locate editor resources. Make sure the PostProcessing package has been installed correctly.");
}
return m_EditorResourcesPath;
}
}
internal static T Load<T>(string name)
where T : UnityObject
{
return AssetDatabase.LoadAssetAtPath<T>(editorResourcesPath + name);
}
static bool SearchForEditorResourcesPath(out string path)
{
path = string.Empty;
string searchStr = "/PostProcessing/Editor Resources/";
string str = null;
foreach (var assetPath in AssetDatabase.GetAllAssetPaths())
{
if (assetPath.Contains(searchStr))
{
str = assetPath;
break;
}
}
if (str == null)
return false;
path = str.Substring(0, str.LastIndexOf(searchStr) + searchStr.Length);
return true;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

View file

@ -1,243 +0,0 @@
#ifndef __DEPTH_OF_FIELD__
#define __DEPTH_OF_FIELD__
#if SHADER_TARGET >= 50
// Use separate texture/sampler objects on Shader Model 5.0
#define SEPARATE_TEXTURE_SAMPLER
#define DOF_DECL_TEX2D(tex) Texture2D tex; SamplerState sampler##tex
#define DOF_TEX2D(tex, coord) tex.Sample(sampler##tex, coord)
#else
#define DOF_DECL_TEX2D(tex) sampler2D tex
#define DOF_TEX2D(tex, coord) tex2D(tex, coord)
#endif
#include "Common.cginc"
#include "DiskKernels.cginc"
DOF_DECL_TEX2D(_CameraDepthTexture);
DOF_DECL_TEX2D(_CameraMotionVectorsTexture);
DOF_DECL_TEX2D(_CoCTex);
// Camera parameters
float _Distance;
float _LensCoeff; // f^2 / (N * (S1 - f) * film_width * 2)
float _MaxCoC;
float _RcpMaxCoC;
float _RcpAspect;
half3 _TaaParams; // Jitter.x, Jitter.y, Blending
struct VaryingsDOF
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half2 uvAlt : TEXCOORD1;
};
// Common vertex shader with single pass stereo rendering support
VaryingsDOF VertDOF(AttributesDefault v)
{
half2 uvAlt = v.texcoord;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0.0) uvAlt.y = 1.0 - uvAlt.y;
#endif
VaryingsDOF o;
o.pos = UnityObjectToClipPos(v.vertex);
#if defined(UNITY_SINGLE_PASS_STEREO)
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST);
o.uvAlt = UnityStereoScreenSpaceUVAdjust(uvAlt, _MainTex_ST);
#else
o.uv = v.texcoord;
o.uvAlt = uvAlt;
#endif
return o;
}
// CoC calculation
half4 FragCoC(VaryingsDOF i) : SV_Target
{
float depth = LinearEyeDepth(DOF_TEX2D(_CameraDepthTexture, i.uv));
half coc = (depth - _Distance) * _LensCoeff / max(depth, 1e-5);
return saturate(coc * 0.5 * _RcpMaxCoC + 0.5);
}
// Temporal filter
half4 FragTempFilter(VaryingsDOF i) : SV_Target
{
float3 uvOffs = _MainTex_TexelSize.xyy * float3(1, 1, 0);
#if defined(SEPARATE_TEXTURE_SAMPLER)
half4 cocTL = _CoCTex.GatherRed(sampler_CoCTex, i.uv - uvOffs.xy * 0.5); // top-left
half4 cocBR = _CoCTex.GatherRed(sampler_CoCTex, i.uv + uvOffs.xy * 0.5); // bottom-right
half coc1 = cocTL.x; // top
half coc2 = cocTL.z; // left
half coc3 = cocBR.x; // bottom
half coc4 = cocBR.z; // right
#else
half coc1 = DOF_TEX2D(_CoCTex, i.uv - uvOffs.xz).r; // top
half coc2 = DOF_TEX2D(_CoCTex, i.uv - uvOffs.zy).r; // left
half coc3 = DOF_TEX2D(_CoCTex, i.uv + uvOffs.zy).r; // bottom
half coc4 = DOF_TEX2D(_CoCTex, i.uv + uvOffs.xz).r; // right
#endif
// Dejittered center sample.
half coc0 = DOF_TEX2D(_CoCTex, i.uv - _TaaParams.xy).r;
// CoC dilation: determine the closest point in the four neighbors.
float3 closest = float3(0, 0, coc0);
closest = coc1 < closest.z ? float3(-uvOffs.xz, coc1) : closest;
closest = coc2 < closest.z ? float3(-uvOffs.zy, coc2) : closest;
closest = coc3 < closest.z ? float3(+uvOffs.zy, coc3) : closest;
closest = coc4 < closest.z ? float3(+uvOffs.xz, coc4) : closest;
// Sample the history buffer with the motion vector at the closest point.
float2 motion = DOF_TEX2D(_CameraMotionVectorsTexture, i.uv + closest.xy).xy;
half cocHis = DOF_TEX2D(_MainTex, i.uv - motion).r;
// Neighborhood clamping.
half cocMin = closest.z;
half cocMax = max(max(max(max(coc0, coc1), coc2), coc3), coc4);
cocHis = clamp(cocHis, cocMin, cocMax);
// Blend with the history.
return lerp(coc0, cocHis, _TaaParams.z);
}
// Prefilter: downsampling and premultiplying.
half4 FragPrefilter(VaryingsDOF i) : SV_Target
{
#if defined(SEPARATE_TEXTURE_SAMPLER)
// Sample source colors.
half4 c_r = _MainTex.GatherRed (sampler_MainTex, i.uv);
half4 c_g = _MainTex.GatherGreen(sampler_MainTex, i.uv);
half4 c_b = _MainTex.GatherBlue (sampler_MainTex, i.uv);
half3 c0 = half3(c_r.x, c_g.x, c_b.x);
half3 c1 = half3(c_r.y, c_g.y, c_b.y);
half3 c2 = half3(c_r.z, c_g.z, c_b.z);
half3 c3 = half3(c_r.w, c_g.w, c_b.w);
// Sample CoCs.
half4 cocs = _CoCTex.Gather(sampler_CoCTex, i.uvAlt) * 2.0 - 1.0;
half coc0 = cocs.x;
half coc1 = cocs.y;
half coc2 = cocs.z;
half coc3 = cocs.w;
#else
float3 duv = _MainTex_TexelSize.xyx * float3(0.5, 0.5, -0.5);
// Sample source colors.
half3 c0 = DOF_TEX2D(_MainTex, i.uv - duv.xy).rgb;
half3 c1 = DOF_TEX2D(_MainTex, i.uv - duv.zy).rgb;
half3 c2 = DOF_TEX2D(_MainTex, i.uv + duv.zy).rgb;
half3 c3 = DOF_TEX2D(_MainTex, i.uv + duv.xy).rgb;
// Sample CoCs.
half coc0 = DOF_TEX2D(_CoCTex, i.uvAlt - duv.xy).r * 2.0 - 1.0;
half coc1 = DOF_TEX2D(_CoCTex, i.uvAlt - duv.zy).r * 2.0 - 1.0;
half coc2 = DOF_TEX2D(_CoCTex, i.uvAlt + duv.zy).r * 2.0 - 1.0;
half coc3 = DOF_TEX2D(_CoCTex, i.uvAlt + duv.xy).r * 2.0 - 1.0;
#endif
// Apply CoC and luma weights to reduce bleeding and flickering.
float w0 = abs(coc0) / (Max3(c0) + 1.0);
float w1 = abs(coc1) / (Max3(c1) + 1.0);
float w2 = abs(coc2) / (Max3(c2) + 1.0);
float w3 = abs(coc3) / (Max3(c3) + 1.0);
// Weighted average of the color samples
half3 avg = c0 * w0 + c1 * w1 + c2 * w2 + c3 * w3;
avg /= max(w0 + w1 + w2 + w3, 1e-5);
// Select the largest CoC value.
half coc_min = Min4(coc0, coc1, coc2, coc3);
half coc_max = Max4(coc0, coc1, coc2, coc3);
half coc = (-coc_min > coc_max ? coc_min : coc_max) * _MaxCoC;
// Premultiply CoC again.
avg *= smoothstep(0, _MainTex_TexelSize.y * 2, abs(coc));
#if defined(UNITY_COLORSPACE_GAMMA)
avg = GammaToLinearSpace(avg);
#endif
return half4(avg, coc);
}
// Bokeh filter with disk-shaped kernels
half4 FragBlur(VaryingsDOF i) : SV_Target
{
half4 samp0 = DOF_TEX2D(_MainTex, i.uv);
half4 bgAcc = 0.0; // Background: far field bokeh
half4 fgAcc = 0.0; // Foreground: near field bokeh
UNITY_LOOP for (int si = 0; si < kSampleCount; si++)
{
float2 disp = kDiskKernel[si] * _MaxCoC;
float dist = length(disp);
float2 duv = float2(disp.x * _RcpAspect, disp.y);
half4 samp = DOF_TEX2D(_MainTex, i.uv + duv);
// BG: Compare CoC of the current sample and the center sample
// and select smaller one.
half bgCoC = max(min(samp0.a, samp.a), 0.0);
// Compare the CoC to the sample distance.
// Add a small margin to smooth out.
const half margin = _MainTex_TexelSize.y * 2;
half bgWeight = saturate((bgCoC - dist + margin) / margin);
half fgWeight = saturate((-samp.a - dist + margin) / margin);
// Cut influence from focused areas because they're darkened by CoC
// premultiplying. This is only needed for near field.
fgWeight *= step(_MainTex_TexelSize.y, -samp.a);
// Accumulation
bgAcc += half4(samp.rgb, 1.0) * bgWeight;
fgAcc += half4(samp.rgb, 1.0) * fgWeight;
}
// Get the weighted average.
bgAcc.rgb /= bgAcc.a + (bgAcc.a == 0.0); // zero-div guard
fgAcc.rgb /= fgAcc.a + (fgAcc.a == 0.0);
// BG: Calculate the alpha value only based on the center CoC.
// This is a rather aggressive approximation but provides stable results.
bgAcc.a = smoothstep(_MainTex_TexelSize.y, _MainTex_TexelSize.y * 2.0, samp0.a);
// FG: Normalize the total of the weights.
fgAcc.a *= UNITY_PI / kSampleCount;
// Alpha premultiplying
half alpha = saturate(fgAcc.a);
half3 rgb = lerp(bgAcc.rgb, fgAcc.rgb, alpha);
return half4(rgb, alpha);
}
// Postfilter blur
half4 FragPostBlur(VaryingsDOF i) : SV_Target
{
// 9 tap tent filter with 4 bilinear samples
const float4 duv = _MainTex_TexelSize.xyxy * float4(0.5, 0.5, -0.5, 0);
half4 acc;
acc = DOF_TEX2D(_MainTex, i.uv - duv.xy);
acc += DOF_TEX2D(_MainTex, i.uv - duv.zy);
acc += DOF_TEX2D(_MainTex, i.uv + duv.zy);
acc += DOF_TEX2D(_MainTex, i.uv + duv.xy);
return acc / 4.0;
}
#endif // __DEPTH_OF_FIELD__

View file

@ -1,12 +0,0 @@
namespace UnityEngine.PostProcessing
{
public sealed class MinAttribute : PropertyAttribute
{
public readonly float min;
public MinAttribute(float min)
{
this.min = min;
}
}
}

View file

@ -1,258 +0,0 @@
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.PostProcessing
{
using Mode = BuiltinDebugViewsModel.Mode;
public sealed class BuiltinDebugViewsComponent : PostProcessingComponentCommandBuffer<BuiltinDebugViewsModel>
{
static class Uniforms
{
internal static readonly int _DepthScale = Shader.PropertyToID("_DepthScale");
internal static readonly int _TempRT = Shader.PropertyToID("_TempRT");
internal static readonly int _Opacity = Shader.PropertyToID("_Opacity");
internal static readonly int _MainTex = Shader.PropertyToID("_MainTex");
internal static readonly int _TempRT2 = Shader.PropertyToID("_TempRT2");
internal static readonly int _Amplitude = Shader.PropertyToID("_Amplitude");
internal static readonly int _Scale = Shader.PropertyToID("_Scale");
}
const string k_ShaderString = "Hidden/Post FX/Builtin Debug Views";
enum Pass
{
Depth,
Normals,
MovecOpacity,
MovecImaging,
MovecArrows
}
ArrowArray m_Arrows;
class ArrowArray
{
public Mesh mesh { get; private set; }
public int columnCount { get; private set; }
public int rowCount { get; private set; }
public void BuildMesh(int columns, int rows)
{
// Base shape
var arrow = new Vector3[6]
{
new Vector3(0f, 0f, 0f),
new Vector3(0f, 1f, 0f),
new Vector3(0f, 1f, 0f),
new Vector3(-1f, 1f, 0f),
new Vector3(0f, 1f, 0f),
new Vector3(1f, 1f, 0f)
};
// make the vertex array
int vcount = 6 * columns * rows;
var vertices = new List<Vector3>(vcount);
var uvs = new List<Vector2>(vcount);
for (int iy = 0; iy < rows; iy++)
{
for (int ix = 0; ix < columns; ix++)
{
var uv = new Vector2(
(0.5f + ix) / columns,
(0.5f + iy) / rows
);
for (int i = 0; i < 6; i++)
{
vertices.Add(arrow[i]);
uvs.Add(uv);
}
}
}
// make the index array
var indices = new int[vcount];
for (int i = 0; i < vcount; i++)
indices[i] = i;
// initialize the mesh object
mesh = new Mesh { hideFlags = HideFlags.DontSave };
mesh.SetVertices(vertices);
mesh.SetUVs(0, uvs);
mesh.SetIndices(indices, MeshTopology.Lines, 0);
mesh.UploadMeshData(true);
// update the properties
columnCount = columns;
rowCount = rows;
}
public void Release()
{
GraphicsUtils.Destroy(mesh);
mesh = null;
}
}
public override bool active
{
get
{
return model.IsModeActive(Mode.Depth)
|| model.IsModeActive(Mode.Normals)
|| model.IsModeActive(Mode.MotionVectors);
}
}
public override DepthTextureMode GetCameraFlags()
{
var mode = model.settings.mode;
var flags = DepthTextureMode.None;
switch (mode)
{
case Mode.Normals:
flags |= DepthTextureMode.DepthNormals;
break;
case Mode.MotionVectors:
flags |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
break;
case Mode.Depth:
flags |= DepthTextureMode.Depth;
break;
}
return flags;
}
public override CameraEvent GetCameraEvent()
{
return model.settings.mode == Mode.MotionVectors
? CameraEvent.BeforeImageEffects
: CameraEvent.BeforeImageEffectsOpaque;
}
public override string GetName()
{
return "Builtin Debug Views";
}
public override void PopulateCommandBuffer(CommandBuffer cb)
{
var settings = model.settings;
var material = context.materialFactory.Get(k_ShaderString);
material.shaderKeywords = null;
if (context.isGBufferAvailable)
material.EnableKeyword("SOURCE_GBUFFER");
switch (settings.mode)
{
case Mode.Depth:
DepthPass(cb);
break;
case Mode.Normals:
DepthNormalsPass(cb);
break;
case Mode.MotionVectors:
MotionVectorsPass(cb);
break;
}
context.Interrupt();
}
void DepthPass(CommandBuffer cb)
{
var material = context.materialFactory.Get(k_ShaderString);
var settings = model.settings.depth;
cb.SetGlobalFloat(Uniforms._DepthScale, 1f / settings.scale);
cb.Blit((Texture)null, BuiltinRenderTextureType.CameraTarget, material, (int)Pass.Depth);
}
void DepthNormalsPass(CommandBuffer cb)
{
var material = context.materialFactory.Get(k_ShaderString);
cb.Blit((Texture)null, BuiltinRenderTextureType.CameraTarget, material, (int)Pass.Normals);
}
void MotionVectorsPass(CommandBuffer cb)
{
#if UNITY_EDITOR
// Don't render motion vectors preview when the editor is not playing as it can in some
// cases results in ugly artifacts (i.e. when resizing the game view).
if (!Application.isPlaying)
return;
#endif
var material = context.materialFactory.Get(k_ShaderString);
var settings = model.settings.motionVectors;
// Blit the original source image
int tempRT = Uniforms._TempRT;
cb.GetTemporaryRT(tempRT, context.width, context.height, 0, FilterMode.Bilinear);
cb.SetGlobalFloat(Uniforms._Opacity, settings.sourceOpacity);
cb.SetGlobalTexture(Uniforms._MainTex, BuiltinRenderTextureType.CameraTarget);
cb.Blit(BuiltinRenderTextureType.CameraTarget, tempRT, material, (int)Pass.MovecOpacity);
// Motion vectors (imaging)
if (settings.motionImageOpacity > 0f && settings.motionImageAmplitude > 0f)
{
int tempRT2 = Uniforms._TempRT2;
cb.GetTemporaryRT(tempRT2, context.width, context.height, 0, FilterMode.Bilinear);
cb.SetGlobalFloat(Uniforms._Opacity, settings.motionImageOpacity);
cb.SetGlobalFloat(Uniforms._Amplitude, settings.motionImageAmplitude);
cb.SetGlobalTexture(Uniforms._MainTex, tempRT);
cb.Blit(tempRT, tempRT2, material, (int)Pass.MovecImaging);
cb.ReleaseTemporaryRT(tempRT);
tempRT = tempRT2;
}
// Motion vectors (arrows)
if (settings.motionVectorsOpacity > 0f && settings.motionVectorsAmplitude > 0f)
{
PrepareArrows();
float sy = 1f / settings.motionVectorsResolution;
float sx = sy * context.height / context.width;
cb.SetGlobalVector(Uniforms._Scale, new Vector2(sx, sy));
cb.SetGlobalFloat(Uniforms._Opacity, settings.motionVectorsOpacity);
cb.SetGlobalFloat(Uniforms._Amplitude, settings.motionVectorsAmplitude);
cb.DrawMesh(m_Arrows.mesh, Matrix4x4.identity, material, 0, (int)Pass.MovecArrows);
}
cb.SetGlobalTexture(Uniforms._MainTex, tempRT);
cb.Blit(tempRT, BuiltinRenderTextureType.CameraTarget);
cb.ReleaseTemporaryRT(tempRT);
}
void PrepareArrows()
{
int row = model.settings.motionVectors.motionVectorsResolution;
int col = row * Screen.width / Screen.height;
if (m_Arrows == null)
m_Arrows = new ArrowArray();
if (m_Arrows.columnCount != col || m_Arrows.rowCount != row)
{
m_Arrows.Release();
m_Arrows.BuildMesh(col, row);
}
}
public override void OnDisable()
{
if (m_Arrows != null)
m_Arrows.Release();
m_Arrows = null;
}
}
}

View file

@ -1,165 +0,0 @@
using UnityEngine.Rendering;
namespace UnityEngine.PostProcessing
{
using DebugMode = BuiltinDebugViewsModel.Mode;
public sealed class DepthOfFieldComponent : PostProcessingComponentRenderTexture<DepthOfFieldModel>
{
static class Uniforms
{
internal static readonly int _DepthOfFieldTex = Shader.PropertyToID("_DepthOfFieldTex");
internal static readonly int _DepthOfFieldCoCTex = Shader.PropertyToID("_DepthOfFieldCoCTex");
internal static readonly int _Distance = Shader.PropertyToID("_Distance");
internal static readonly int _LensCoeff = Shader.PropertyToID("_LensCoeff");
internal static readonly int _MaxCoC = Shader.PropertyToID("_MaxCoC");
internal static readonly int _RcpMaxCoC = Shader.PropertyToID("_RcpMaxCoC");
internal static readonly int _RcpAspect = Shader.PropertyToID("_RcpAspect");
internal static readonly int _MainTex = Shader.PropertyToID("_MainTex");
internal static readonly int _CoCTex = Shader.PropertyToID("_CoCTex");
internal static readonly int _TaaParams = Shader.PropertyToID("_TaaParams");
internal static readonly int _DepthOfFieldParams = Shader.PropertyToID("_DepthOfFieldParams");
}
const string k_ShaderString = "Hidden/Post FX/Depth Of Field";
public override bool active
{
get
{
return model.enabled
&& !context.interrupted;
}
}
public override DepthTextureMode GetCameraFlags()
{
return DepthTextureMode.Depth;
}
RenderTexture m_CoCHistory;
// Height of the 35mm full-frame format (36mm x 24mm)
const float k_FilmHeight = 0.024f;
float CalculateFocalLength()
{
var settings = model.settings;
if (!settings.useCameraFov)
return settings.focalLength / 1000f;
float fov = context.camera.fieldOfView * Mathf.Deg2Rad;
return 0.5f * k_FilmHeight / Mathf.Tan(0.5f * fov);
}
float CalculateMaxCoCRadius(int screenHeight)
{
// Estimate the allowable maximum radius of CoC from the kernel
// size (the equation below was empirically derived).
float radiusInPixels = (float)model.settings.kernelSize * 4f + 6f;
// Applying a 5% limit to the CoC radius to keep the size of
// TileMax/NeighborMax small enough.
return Mathf.Min(0.05f, radiusInPixels / screenHeight);
}
bool CheckHistory(int width, int height)
{
return m_CoCHistory != null && m_CoCHistory.IsCreated() &&
m_CoCHistory.width == width && m_CoCHistory.height == height;
}
RenderTextureFormat SelectFormat(RenderTextureFormat primary, RenderTextureFormat secondary)
{
if (SystemInfo.SupportsRenderTextureFormat(primary)) return primary;
if (SystemInfo.SupportsRenderTextureFormat(secondary)) return secondary;
return RenderTextureFormat.Default;
}
public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC, Vector2 taaJitter, float taaBlending)
{
var settings = model.settings;
var colorFormat = RenderTextureFormat.DefaultHDR;
var cocFormat = SelectFormat(RenderTextureFormat.R8, RenderTextureFormat.RHalf);
// Avoid using R8 on OSX with Metal. #896121, https://goo.gl/MgKqu6
#if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX) && !UNITY_2017_1_OR_NEWER
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal)
cocFormat = SelectFormat(RenderTextureFormat.RHalf, RenderTextureFormat.Default);
#endif
// Material setup
var f = CalculateFocalLength();
var s1 = Mathf.Max(settings.focusDistance, f);
var aspect = (float)source.width / source.height;
var coeff = f * f / (settings.aperture * (s1 - f) * k_FilmHeight * 2);
var maxCoC = CalculateMaxCoCRadius(source.height);
var material = context.materialFactory.Get(k_ShaderString);
material.SetFloat(Uniforms._Distance, s1);
material.SetFloat(Uniforms._LensCoeff, coeff);
material.SetFloat(Uniforms._MaxCoC, maxCoC);
material.SetFloat(Uniforms._RcpMaxCoC, 1f / maxCoC);
material.SetFloat(Uniforms._RcpAspect, 1f / aspect);
// CoC calculation pass
var rtCoC = context.renderTextureFactory.Get(context.width, context.height, 0, cocFormat, RenderTextureReadWrite.Linear);
Graphics.Blit(null, rtCoC, material, 0);
if (antialiasCoC)
{
// CoC temporal filter pass
material.SetTexture(Uniforms._CoCTex, rtCoC);
var blend = CheckHistory(context.width, context.height) ? taaBlending : 0f;
material.SetVector(Uniforms._TaaParams, new Vector3(taaJitter.x, taaJitter.y, blend));
var rtFiltered = RenderTexture.GetTemporary(context.width, context.height, 0, cocFormat);
Graphics.Blit(m_CoCHistory, rtFiltered, material, 1);
context.renderTextureFactory.Release(rtCoC);
if (m_CoCHistory != null) RenderTexture.ReleaseTemporary(m_CoCHistory);
m_CoCHistory = rtCoC = rtFiltered;
}
// Downsampling and prefiltering pass
var rt1 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, colorFormat);
material.SetTexture(Uniforms._CoCTex, rtCoC);
Graphics.Blit(source, rt1, material, 2);
// Bokeh simulation pass
var rt2 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, colorFormat);
Graphics.Blit(rt1, rt2, material, 3 + (int)settings.kernelSize);
// Postfilter pass
Graphics.Blit(rt2, rt1, material, 7);
// Give the results to the uber shader.
uberMaterial.SetVector(Uniforms._DepthOfFieldParams, new Vector3(s1, coeff, maxCoC));
if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane))
{
uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
context.Interrupt();
}
else
{
uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1);
uberMaterial.SetTexture(Uniforms._DepthOfFieldCoCTex, rtCoC);
uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
}
context.renderTextureFactory.Release(rt2);
}
public override void OnDisable()
{
if (m_CoCHistory != null)
RenderTexture.ReleaseTemporary(m_CoCHistory);
m_CoCHistory = null;
}
}
}

Some files were not shown because too many files have changed in this diff Show more