diff --git a/Cat/PostProcessing/CatAA/CatAA.cs b/Cat/PostProcessing/CatAA/CatAA.cs index 65d7f93..7a16dd9 100644 --- a/Cat/PostProcessing/CatAA/CatAA.cs +++ b/Cat/PostProcessing/CatAA/CatAA.cs @@ -137,18 +137,26 @@ override protected void UpdateCameraMatricesPerFrame(Camera camera, VectorInt2 c TMSAACounter = (TMSAACounter + 1) % 4 ; } - var newP = jitterVectors[TMSAACounter] * Settings.jitterStrength; + var newP = jitterVectors[TMSAACounter]; + + if (settings.jitterMatrix == JitterMatrixType.HaltonSequence) { + newP = newP - new Vector2(0.5f, 0.5f); + } + + newP *= Settings.jitterStrength; newP.x /= (float)cameraSize.x; newP.y /= (float)cameraSize.y; + + camera.nonJitteredProjectionMatrix = camera.projectionMatrix; if (camera.orthographic) { camera.projectionMatrix = GetOrthographicProjectionMatrix(newP, camera); } else { camera.projectionMatrix = GetPerspectiveProjectionMatrix(newP, camera); } + Shader.SetGlobalVector(PropertyIDs.TAAJitterVelocity_v, isSceneView ? Vector2.zero : newP); - } override protected void UpdateMaterialPerFrame(Material material, Camera camera, VectorInt2 cameraSize) { @@ -174,7 +182,7 @@ private void OnPostRender() { //[ImageEffectTransformsToLDR] internal override void RenderImage(RenderTexture source, RenderTexture destination) { var isSceneView = postProcessingManager.isSceneView; - if (isSceneView && disableTAAInSceneView) { + if (false || isSceneView && disableTAAInSceneView) { Blit(source, destination); return; } diff --git a/Cat/PostProcessing/CatAA/Resources/CatAA.shader b/Cat/PostProcessing/CatAA/Resources/CatAA.shader index e3a065a..ec92a12 100644 --- a/Cat/PostProcessing/CatAA/Resources/CatAA.shader +++ b/Cat/PostProcessing/CatAA/Resources/CatAA.shader @@ -200,11 +200,31 @@ Shader "Hidden/CatAA" { if (0) { float3 result = 0; + float2 pureVelocity = Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy; + float2 jitterVelocity = _TAAJitterVelocity*2; - velocity = !_IsVelocityPredictionEnabled ? 0 : Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy; - result.xy = abs(velocity.xy) * 1.0*pow(10, 2.2); + float2 divisor = max(abs(pureVelocity), abs(pureVelocity)); + result.rgb = float3(divisor == 0 ? 0 : abs(pureVelocity - jitterVelocity) / divisor, any(divisor == 00)); + result.rg /= (1 + result.rg); + //result.rg = abs(pureVelocity) * 100000; + return float4(result, 1); + } + + if (0) { + float3 result = 0; + //velocity = !_IsVelocityPredictionEnabled ? 0 : Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy; + velocity = Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy; + velocity -= _TAAJitterVelocity * 1.5; + //result.xy = abs(velocity.xy-0) * 100;//1.0*pow(10, 2.3); + result = pow(saturate(result), 2.2); + + float2 uvPrev = uv - velocity.xy; + float4 history = tex2D(historyTex, uvPrev); + float confidence = any(history)*0.98750011; + float4 mainTex = tex2D(currentTex, uv); + result = lerp(mainTex, history, confidence).rgb; return float4(result, 1); } diff --git a/Cat/PostProcessing/CatAmbientOcclusion/CatAO.cs b/Cat/PostProcessing/CatAmbientOcclusion/CatAO.cs index 458d9cc..a1e2206 100644 --- a/Cat/PostProcessing/CatAmbientOcclusion/CatAO.cs +++ b/Cat/PostProcessing/CatAmbientOcclusion/CatAO.cs @@ -51,10 +51,12 @@ public Settings settings { OnValidate(); } } - private Settings lastSettings; - private CameraEvent GetAppropriateCameraEvent(bool isDebugModeOn) { - return isDebugModeOn ? CameraEvent.BeforeImageEffectsOpaque : CameraEvent.BeforeReflections; + private RenderingPath m_currentRenderingPath; + private CameraEvent GetAppropriateCameraEvent(bool isDebugModeOn, RenderingPath renderingPath) { + return isDebugModeOn || renderingPath != RenderingPath.DeferredShading + ? CameraEvent.BeforeImageEffectsOpaque + : CameraEvent.BeforeReflections; } private CameraEvent m_CameraEvent = CameraEvent.BeforeReflections; override protected CameraEvent cameraEvent { @@ -88,6 +90,7 @@ override protected void UpdateRenderTextures(Camera camera, VectorInt2 cameraSiz } override protected void UpdateMaterialPerFrame(Material material, Camera camera, VectorInt2 cameraSize) { + m_currentRenderingPath = camera.actualRenderingPath; setMaterialDirty(); } @@ -125,9 +128,11 @@ override protected void PopulateCommandBuffer(CommandBuffer buffer, Material mat // ReleaseTemporaryRT(buffer, PropertyIDs.OcclusionNormals3_t); ReleaseTemporaryRT(buffer, PropertyIDs.OcclusionNormals2_t); ReleaseTemporaryRT(buffer, PropertyIDs.OcclusionNormals1_t); - Blit(buffer, BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.GBuffer0, material, (int)SSRPass.MultiplyAlpha); + if (m_currentRenderingPath == RenderingPath.DeferredShading) { + Blit(buffer, BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.GBuffer0, material, (int)SSRPass.MultiplyAlpha); + } - var appropriateCameraEvent = GetAppropriateCameraEvent(settings.debugOn); + var appropriateCameraEvent = GetAppropriateCameraEvent(settings.debugOn, m_currentRenderingPath); if (appropriateCameraEvent != m_CameraEvent) { postProcessingManager.RemoveCommandBuffer(this, cameraEvent, buffer); m_CameraEvent = appropriateCameraEvent; @@ -137,7 +142,6 @@ override protected void PopulateCommandBuffer(CommandBuffer buffer, Material mat public void OnValidate () { setMaterialDirty(); - lastSettings = m_Settings; } } diff --git a/Cat/PostProcessing/CatColorGrading/CatColorGrading.cs b/Cat/PostProcessing/CatColorGrading/CatColorGrading.cs index 0cc4663..598f06b 100644 --- a/Cat/PostProcessing/CatColorGrading/CatColorGrading.cs +++ b/Cat/PostProcessing/CatColorGrading/CatColorGrading.cs @@ -133,8 +133,6 @@ override protected void UpdateMaterial(Material material, Camera camera, VectorI var exposure = Mathf.Pow(2, settings.exposure); var contrast = Mathf.Max(EPSILON, settings.contrast + Mathf.Max(0, settings.contrast) * Mathf.Max(0, settings.contrast) + 1); var saturation = (settings.saturation + Mathf.Max(0, settings.saturation) * Mathf.Max(0, settings.saturation) + 1) / contrast; - var temperature = settings.temperature; - var tint = settings.tint; var blackPoint = 0 + settings.blackPoint * 0.25f; var whitePoint = 1 +settings. whitePoint * 0.25f; @@ -142,8 +140,6 @@ override protected void UpdateMaterial(Material material, Camera camera, VectorI material.SetFloat(PropertyIDs.Contrast_f, contrast); material.SetFloat(PropertyIDs.Saturation_f, saturation); - //material.SetFloat(PropertyIDs.Temperature_f, settings.temperature); - //material.SetFloat(PropertyIDs.Tint_f, settings.tint); material.SetVector(PropertyIDs.ColorBalance_v, CalculateColorBalance(settings.temperature, settings.tint)); material.SetFloat(PropertyIDs.BlackPoint_f, blackPoint); material.SetFloat(PropertyIDs.WhitePoint_f, whitePoint); diff --git a/Cat/PostProcessing/CatDepthOfField/CatDepthOfField.cs b/Cat/PostProcessing/CatDepthOfField/CatDepthOfField.cs index d21858c..3e567b5 100644 --- a/Cat/PostProcessing/CatDepthOfField/CatDepthOfField.cs +++ b/Cat/PostProcessing/CatDepthOfField/CatDepthOfField.cs @@ -121,8 +121,6 @@ private enum DOFPass { } internal override void RenderImage(RenderTexture source, RenderTexture destination) { - const int maxMipLvl = 7; - //var mipLevelFloat = Mathf.Clamp(Mathf.Log(Mathf.Max(source.width, source.height) / 32.0f + 1, 2), maxUpsample, maxMipLvl); material.SetFloat(PropertyIDs.MipLevel_f, 0); diff --git a/Cat/PostProcessing/CatDepthOfField/Editor.meta b/Cat/PostProcessing/CatDepthOfField/Editor.meta new file mode 100644 index 0000000..b298814 --- /dev/null +++ b/Cat/PostProcessing/CatDepthOfField/Editor.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cb5da131da449a747b5b9539ec6e82ae +folderAsset: yes +timeCreated: 1501160245 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Cat/PostProcessing/CatSSR/CatSSR.cs b/Cat/PostProcessing/CatSSR/CatSSR.cs index 310b070..9205b96 100644 --- a/Cat/PostProcessing/CatSSR/CatSSR.cs +++ b/Cat/PostProcessing/CatSSR/CatSSR.cs @@ -414,8 +414,6 @@ override protected void PopulateCommandBuffer(CommandBuffer buffer, Material mat new VectorInt2(reflRTSize.x / 64, reflRTSize.y / 128), }; - var reflectionSource_t = settings.useTemporalSampling ? new RenderTargetIdentifier(lastFrame) : BuiltinRenderTextureType.CameraTarget; - // #region Depth // GetTemporaryRT(buffer, PropertyIDs.Depth_t, HitTextureSize, RenderTextureFormat.RHalf, FilterMode.Point, RenderTextureReadWrite.Linear); // Blit(buffer, PropertyIDs.Depth_t, material, (int)SSRPass.Depth); diff --git a/Cat/PostProcessing/Includes/PostProcessingCommon.cginc b/Cat/PostProcessing/Includes/PostProcessingCommon.cginc index 78774fb..d70bbce 100644 --- a/Cat/PostProcessing/Includes/PostProcessingCommon.cginc +++ b/Cat/PostProcessing/Includes/PostProcessingCommon.cginc @@ -201,6 +201,6 @@ VertexOutput vert(VertexInput v) { return o; } */ -float2 GetVelocity(float2 uv) { return !_IsVelocityPredictionEnabled ? 0 : Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy - _TAAJitterVelocity; } +float2 GetVelocity(float2 uv) { return !_IsVelocityPredictionEnabled ? 0 : Tex2Dlod(_CameraMotionVectorsTexture, uv, 0).xy; } // - _TAAJitterVelocity * 0; } // Does not seem to be neccessary in Unity2017.2f3 #endif // POST_PROCESSING_COMMON_INCLUDED diff --git a/Cat/PostProcessing/PostProcessingManager.cs b/Cat/PostProcessing/PostProcessingManager.cs index 5e266a2..ad6af4e 100644 --- a/Cat/PostProcessing/PostProcessingManager.cs +++ b/Cat/PostProcessing/PostProcessingManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using Cat.Common; @@ -63,7 +62,7 @@ protected void OnDestroy() { if (m_DepthTexture != null) { m_DepthTexture.Release(); } - camera.RemoveCommandBuffer(CameraEvent.AfterDepthTexture, depthCommandBuffer); + camera.RemoveCommandBuffer(m_DepthCommandBufferCameraEvent, depthCommandBuffer); } @@ -170,6 +169,7 @@ where effect is PostProcessingBaseImageEffect // select makePostRenderDelegate(effect); } + private bool m_requiresDepthTexture = false; internal void UpdateCameraDepthTextureMode() { var depthTextureMode = DepthTextureMode.None; var effects = GetEffects(camera); @@ -183,11 +183,8 @@ internal void UpdateCameraDepthTextureMode() { } camera.depthTextureMode = depthTextureMode; - camera.RemoveCommandBuffer(CameraEvent.BeforeLighting, depthCommandBuffer); - if ((depthTextureMode & DepthTextureMode.Depth) == DepthTextureMode.Depth) { - camera.AddCommandBuffer(CameraEvent.BeforeLighting, depthCommandBuffer); - } + m_requiresDepthTexture = (depthTextureMode & DepthTextureMode.Depth) == DepthTextureMode.Depth; } internal void UpdateCameraCommandBuffers() { @@ -283,6 +280,7 @@ private void OnPreCull(){ UpdateDepthTexture(); m_lastCameraSize = cameraSize; } + UpdateCameraDepthBufferCameraEvent(cam.actualRenderingPath); foreach (var preCullFunc in m_preCullChain) { preCullFunc(cam, size); @@ -342,6 +340,40 @@ private RenderTexture depthTexture { } } + private Material m_DepthMaterial = null; + protected Material depthMaterial { + get { + const string shaderName = "Hidden/Cat Depth Shader"; + if (m_DepthMaterial == null) { + var shader = Shader.Find(shaderName); + if (shader == null) { + this.enabled = false; + throw new ArgumentException(String.Format("Shader not found: '{0}'", shaderName)); + } + m_DepthMaterial = new Material(shader); + m_DepthMaterial.hideFlags = HideFlags.DontSave; + } + return m_DepthMaterial; + } + } + + private CameraEvent GetAppropriateDepthBufferCameraEvent(RenderingPath renderingPath) { + return renderingPath != RenderingPath.DeferredShading + ? CameraEvent.AfterForwardOpaque + : CameraEvent.BeforeLighting; + } + + internal void UpdateCameraDepthBufferCameraEvent(RenderingPath renderingPath) { + camera.RemoveCommandBuffer(m_DepthCommandBufferCameraEvent, depthCommandBuffer); + + if (m_requiresDepthTexture ) { + m_DepthCommandBufferCameraEvent = GetAppropriateDepthBufferCameraEvent(renderingPath); + camera.AddCommandBuffer(m_DepthCommandBufferCameraEvent, depthCommandBuffer); + } + } + + + private CameraEvent m_DepthCommandBufferCameraEvent; private CommandBuffer m_DepthCommandBuffer; private CommandBuffer depthCommandBuffer { get { @@ -375,7 +407,8 @@ void UpdateDepthCommandBuffer() { var cb = depthCommandBuffer; cb.Clear(); - cb.Blit(BuiltinRenderTextureType.ResolvedDepth, depthTexture); + //cb.Blit(BuiltinRenderTextureType.Depth, depthTexture); + cb.Blit(BuiltinRenderTextureType.None, depthTexture, depthMaterial, 0); cb.SetGlobalTexture(PropertyIDs.Depth_t, depthTexture); } diff --git a/Cat/PostProcessing/Resources.meta b/Cat/PostProcessing/Resources.meta new file mode 100644 index 0000000..b2d446a --- /dev/null +++ b/Cat/PostProcessing/Resources.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: bc10b9e622f05fe4e9fb3b818beec4a9 +folderAsset: yes +timeCreated: 1504263707 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Cat/PostProcessing/Resources/CatDepthShader.shader b/Cat/PostProcessing/Resources/CatDepthShader.shader new file mode 100644 index 0000000..eec9e48 --- /dev/null +++ b/Cat/PostProcessing/Resources/CatDepthShader.shader @@ -0,0 +1,80 @@ +//The MIT License(MIT) + +//Copyright(c) 2017 Joachim Coenen + +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files (the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions: + +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. + +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. + +Shader "Hidden/Cat Depth Shader" { + Properties { + _MainTex ("Base (RGB)", 2D) = "black" {} + } + + CGINCLUDE + #include "UnityCG.cginc" + #include "../../Includes/CatCommon.cginc" + + + uniform UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); uniform float4 _CameraDepthTexture_TexelSize; + static const bool _IsDebugOn = false; + + + struct VertexInput { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD; + }; + + struct VertexOutput { + float4 pos : POSITION; + float2 uv : TEXCOORD0; + }; + + VertexOutput vert(VertexInput v) { + VertexOutput o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = v.texcoord.xy; + + return o; + } + + + half4 frag(VertexOutput i) : SV_Target { + return float4(sampleDepthLod(_CameraDepthTexture, i.uv.xy, 0), 0, 0, 1); + + } + + ENDCG + + Subshader { + ZTest Always Cull Off ZWrite Off + Fog { Mode off } + + //Pass 0 ChromaticAberration + Pass { + + CGPROGRAM + #pragma target 3.0 + + #pragma fragmentoption ARB_precision_hint_fastest + #pragma vertex vert + #pragma fragment frag + ENDCG + } + } + Fallback "Diffuse" +} diff --git a/Cat/PostProcessing/Resources/CatDepthShader.shader.meta b/Cat/PostProcessing/Resources/CatDepthShader.shader.meta new file mode 100644 index 0000000..6ff4c45 --- /dev/null +++ b/Cat/PostProcessing/Resources/CatDepthShader.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 31c4fdccc641fa14d84dbd1d680c6c62 +timeCreated: 1504263711 +licenseType: Free +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Cat/Scripts/Editor/Graph.cs b/Cat/Scripts/Editor/Graph.cs index 9991832..742131c 100644 --- a/Cat/Scripts/Editor/Graph.cs +++ b/Cat/Scripts/Editor/Graph.cs @@ -25,8 +25,6 @@ public Graph(Rect viewPort, Rect range) { // Transform a point into the graph rect Vector2 PointToScreen(Vector2 p) { - var x01 = (p.x - m_Range.xMin) / m_Range.width; - var xvb = x01 * m_ViewPort.width + m_ViewPort.xMin; return Vector2.Scale(p, m_ParamA) + m_ParamB; }