From 3dc83774af4e12725bb56125a163ac1a58ce432e Mon Sep 17 00:00:00 2001 From: Jean Lamarre Date: Fri, 28 Oct 2022 14:41:09 -0400 Subject: [PATCH 1/4] wip visual #learningstuff --- Assets/Material/Retroed.mat | 131 ++++++++++++++++ .../Retroed.mat.meta} | 4 +- Assets/Readme.asset | 34 ---- Assets/Scripts/Visual.meta | 3 + Assets/Scripts/Visual/RetroPostProcess.cs | 35 +++++ .../Scripts/Visual/RetroPostProcess.cs.meta | 11 ++ .../Settings/URP-HighFidelity-Renderer.asset | 42 ++++- Assets/Settings/URP-HighFidelity.asset | 5 + Assets/Shaders.meta | 8 + Assets/Shaders/Retroed.shader | 62 ++++++++ Assets/Shaders/Retroed.shader.meta | 10 ++ Assets/Sprites/transparence.png | Bin 0 -> 4390 bytes Assets/Sprites/transparence.png.meta | 147 ++++++++++++++++++ ProjectSettings/TagManager.asset | 2 +- 14 files changed, 456 insertions(+), 38 deletions(-) create mode 100644 Assets/Material/Retroed.mat rename Assets/{Readme.asset.meta => Material/Retroed.mat.meta} (64%) delete mode 100644 Assets/Readme.asset create mode 100644 Assets/Scripts/Visual.meta create mode 100644 Assets/Scripts/Visual/RetroPostProcess.cs create mode 100644 Assets/Scripts/Visual/RetroPostProcess.cs.meta create mode 100644 Assets/Shaders.meta create mode 100644 Assets/Shaders/Retroed.shader create mode 100644 Assets/Shaders/Retroed.shader.meta create mode 100644 Assets/Sprites/transparence.png create mode 100644 Assets/Sprites/transparence.png.meta diff --git a/Assets/Material/Retroed.mat b/Assets/Material/Retroed.mat new file mode 100644 index 0000000..698b0fe --- /dev/null +++ b/Assets/Material/Retroed.mat @@ -0,0 +1,131 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-4790970344126815099 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 5 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Retroed + m_Shader: {fileID: 4800000, guid: c4d7011496fb8f34ead8b47276ae3f0a, type: 3} + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 4.49, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaClip: 0 + - _Blend: 0 + - _BlendOp: 0 + - _BumpScale: 1 + - _CellSizeX: 4 + - _CellSizeY: 4 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _SampleGI: 0 + - _ScreenHeight: 240 + - _ScreenWidth: 320 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Readme.asset.meta b/Assets/Material/Retroed.mat.meta similarity index 64% rename from Assets/Readme.asset.meta rename to Assets/Material/Retroed.mat.meta index ab3ad45..86b1fe0 100644 --- a/Assets/Readme.asset.meta +++ b/Assets/Material/Retroed.mat.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: 8105016687592461f977c054a80ce2f2 +guid: bc45e5f0151133446b26221ec8ea680c NativeFormatImporter: externalObjects: {} - mainObjectFileID: 0 + mainObjectFileID: 2100000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Readme.asset b/Assets/Readme.asset deleted file mode 100644 index 77c2f83..0000000 --- a/Assets/Readme.asset +++ /dev/null @@ -1,34 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fcf7219bab7fe46a1ad266029b2fee19, type: 3} - m_Name: Readme - m_EditorClassIdentifier: - icon: {fileID: 2800000, guid: 727a75301c3d24613a3ebcec4a24c2c8, type: 3} - title: URP Empty Template - sections: - - heading: Welcome to the Universal Render Pipeline - text: This template includes the settings and assets you need to start creating with the Universal Render Pipeline. - linkText: - url: - - heading: URP Documentation - text: - linkText: Read more about URP - url: https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest - - heading: Forums - text: - linkText: Get answers and support - url: https://forum.unity.com/forums/universal-render-pipeline.383/ - - heading: Report bugs - text: - linkText: Submit a report - url: https://unity3d.com/unity/qa/bug-reporting - loadedLayout: 1 diff --git a/Assets/Scripts/Visual.meta b/Assets/Scripts/Visual.meta new file mode 100644 index 0000000..1fc18fc --- /dev/null +++ b/Assets/Scripts/Visual.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1f823cbc83e54d88a90cd594398385d1 +timeCreated: 1666894558 \ No newline at end of file diff --git a/Assets/Scripts/Visual/RetroPostProcess.cs b/Assets/Scripts/Visual/RetroPostProcess.cs new file mode 100644 index 0000000..4c6999f --- /dev/null +++ b/Assets/Scripts/Visual/RetroPostProcess.cs @@ -0,0 +1,35 @@ +using UnityEngine; +using UnityEngine.Serialization; + +namespace Visual +{ + /// + /// https://luka712.github.io/2018/07/01/Pixelate-it-Shadertoy-Unity/#:~:text=First%20I%E2%80%99m%20going%20to%20create%20script%20for%20loading%20shader. + /// + [ExecuteInEditMode] + public class RetroPostProcess : MonoBehaviour + { + [FormerlySerializedAs("cellSize")] [SerializeField] + private Vector2 m_CellSize = new Vector2(4, 4); + + private Material _material; + private static readonly int ScreenWidth = Shader.PropertyToID("_ScreenWidth"); + private static readonly int ScreenHeight = Shader.PropertyToID("_ScreenHeight"); + private static readonly int CellSizeX = Shader.PropertyToID("_CellSizeX"); + private static readonly int CellSizeY = Shader.PropertyToID("_CellSizeY"); + + private void Awake() + { + _material = new Material(Shader.Find("Retroed")); + } + + private void OnRenderImage(RenderTexture source, RenderTexture destination) + { + _material.SetFloat(ScreenWidth, Screen.width); + _material.SetFloat(ScreenHeight, Screen.height); + _material.SetFloat(CellSizeX, m_CellSize.x); + _material.SetFloat(CellSizeY, m_CellSize.y); + Graphics.Blit(source, destination, _material); + } + } +} diff --git a/Assets/Scripts/Visual/RetroPostProcess.cs.meta b/Assets/Scripts/Visual/RetroPostProcess.cs.meta new file mode 100644 index 0000000..6a86493 --- /dev/null +++ b/Assets/Scripts/Visual/RetroPostProcess.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a44d4a4a2fcf4a49a34c1fe7813509b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Settings/URP-HighFidelity-Renderer.asset b/Assets/Settings/URP-HighFidelity-Renderer.asset index 90883f9..db0b805 100644 --- a/Assets/Settings/URP-HighFidelity-Renderer.asset +++ b/Assets/Settings/URP-HighFidelity-Renderer.asset @@ -1,5 +1,44 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!114 &-3191591094449869079 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b3d386ba5cd94485973aee1479b272e, type: 3} + m_Name: Retroed + m_EditorClassIdentifier: + m_Active: 1 + settings: + passTag: Retroed + Event: 300 + filterSettings: + RenderQueueType: 0 + LayerMask: + serializedVersion: 2 + m_Bits: 8192 + PassNames: [] + overrideMaterial: {fileID: 2100000, guid: bc45e5f0151133446b26221ec8ea680c, type: 2} + overrideMaterialPassIndex: 0 + overrideDepthState: 0 + depthCompareFunction: 4 + enableWrite: 1 + stencilSettings: + overrideStencilState: 0 + stencilReference: 0 + stencilCompareFunction: 8 + passOperation: 0 + failOperation: 0 + zFailOperation: 0 + cameraSettings: + overrideCamera: 0 + restoreCamera: 1 + offset: {x: 0, y: 0, z: 0, w: 0} + cameraFieldOfView: 60 --- !u!114 &-1878332245247344467 MonoBehaviour: m_ObjectHideFlags: 0 @@ -40,7 +79,8 @@ MonoBehaviour: type: 3} m_RendererFeatures: - {fileID: -1878332245247344467} - m_RendererFeatureMap: adc0de57c6d2eee5 + - {fileID: -3191591094449869079} + m_RendererFeatureMap: adc0de57c6d2eee5e9ee0333cf30b5d3 m_UseNativeRenderPass: 0 postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2} diff --git a/Assets/Settings/URP-HighFidelity.asset b/Assets/Settings/URP-HighFidelity.asset index 6248100..40e1106 100644 --- a/Assets/Settings/URP-HighFidelity.asset +++ b/Assets/Settings/URP-HighFidelity.asset @@ -27,6 +27,9 @@ MonoBehaviour: m_SupportsHDR: 1 m_MSAA: 4 m_RenderScale: 1 + m_UpscalingFilter: 0 + m_FsrOverrideSharpness: 0 + m_FsrSharpness: 0.92 m_MainLightRenderingMode: 1 m_MainLightShadowsSupported: 1 m_MainLightShadowmapResolution: 4096 @@ -48,6 +51,8 @@ MonoBehaviour: m_ShadowDepthBias: 1 m_ShadowNormalBias: 1 m_SoftShadowsSupported: 1 + m_ConservativeEnclosingSphere: 0 + m_NumIterationsEnclosingSphere: 64 m_AdditionalLightsCookieResolution: 4096 m_AdditionalLightsCookieFormat: 4 m_UseSRPBatcher: 1 diff --git a/Assets/Shaders.meta b/Assets/Shaders.meta new file mode 100644 index 0000000..4bab949 --- /dev/null +++ b/Assets/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0af3415c87b444145affb5364f460618 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Retroed.shader b/Assets/Shaders/Retroed.shader new file mode 100644 index 0000000..727ac91 --- /dev/null +++ b/Assets/Shaders/Retroed.shader @@ -0,0 +1,62 @@ +Shader "Retroed" +{ + Properties + { + _MainTex("Texture", 2D) = "white" {} + _ScreenWidth("screen width", float) = 320.0 + _ScreenHeight("screen height", float) = 240.0 + _CellSizeX("size of x cell", float) = 4.0 + _CellSizeY("size of y cell", float) = 4.0 + } + SubShader + { + // No culling or depth + Cull Off ZWrite Off ZTest Always + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + v2f vert(appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + return o; + } + + sampler2D _MainTex; + float _ScreenWidth; + float _ScreenHeight; + float _CellSizeX; + float _CellSizeY; + + fixed4 frag(v2f i) : SV_Target + { + float2 uv = i.uv; + + float pixelX = _ScreenWidth / _CellSizeX; + float pixelY = _ScreenHeight / _CellSizeY; + + return tex2D(_MainTex, float2(floor(pixelX * uv.x) / pixelX, floor(pixelY * uv.y) / pixelY)); + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Shaders/Retroed.shader.meta b/Assets/Shaders/Retroed.shader.meta new file mode 100644 index 0000000..16c238b --- /dev/null +++ b/Assets/Shaders/Retroed.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c4d7011496fb8f34ead8b47276ae3f0a +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/transparence.png b/Assets/Sprites/transparence.png new file mode 100644 index 0000000000000000000000000000000000000000..20938b8e74b8cbde021daf758f8ffb5ebf331984 GIT binary patch literal 4390 zcmeAS@N?(olHy`uVBq!ia0y~yV0s6_9Be?5kFt|b0V&4fAa^H*b?0PW0y!+{j=qiz z3>*8o|0J>k`J4qFk;M!Qe1}1p@p%4<6b1%?-JULvAr*0N@7~V49VXxqxcvWr#lJhh zOuKh!OQB^er-<8xBZ9s~-Pw%nlj6SYv6PVATUk@{=N}^jgT>bO^Wqp88ia*`&Ja+z z!^oiEu!EVwp`n1Cp@HEcAJ8?2WPuKBu?9MYqnv?(Lts?lXz+|CiqWhvT2hRbkE6B1 zXr(#YR2Xd_jW!EMTg{_=h0z`o!470Y-~Q>JUl-Z^`_9?mE%=V%`S%@j?oa=Gxu`Ds zT>NRq2T3i~2X>yF^7r`DJ<;ddpPt$B_x$p320fP@%yX{GpZ=L>X`J}Ke#QRyb3P9l zcL+S>E3o^olYT9!uCnUC%_a3mYfm%8^c1jLOrN>z{FJ}muMLcQ%}d$A3i*UzZa!`| z`P>Yv($=lxUmrA_}^{H%TTwNwT@ryb01vYl$1YX5n>3^qTu=ZMSi8g>S8 zU>JNe{QW}s&HY_spEWHW3;{+8_JOj~_p-uqjRfc}-_c<%5IiKC5WQJx zbGpa-uMG?b4g#H4rncZa-}jvh-GHirwegK}F2C27Z{B~!MkQh@;|`z|8|Hr9b=>x> zbCYd(12?b(e>>uON?%0uMm^>NU{5YV`t__cf|K9xy^trXZa-<0{)(^QIneI6eRH<0@B5Xg!(a`J&h0Zjze^sv zdqfr-xVQJjpIdWMCiiZ!_ Date: Fri, 28 Oct 2022 15:54:00 -0400 Subject: [PATCH 2/4] wip shaders!! --- Assets/Material/{Retroed.mat => CRTBlit.mat} | 26 +-- Assets/Material/CRTBlit.mat.meta | 8 + Assets/Material/PixelBlit.mat | 166 ++++++++++++++++++ .../{Retroed.mat.meta => PixelBlit.mat.meta} | 0 Assets/Scripts/Visual/Blit.cs | 123 +++++++++++++ Assets/Scripts/Visual/Blit.cs.meta | 3 + Assets/Scripts/Visual/RetroPostProcess.cs | 35 ---- .../Scripts/Visual/RetroPostProcess.cs.meta | 11 -- .../Settings/URP-HighFidelity-Renderer.asset | 82 ++++----- Assets/Shaders/CRTShader.shader | 134 ++++++++++++++ Assets/Shaders/CRTShader.shader.meta | 10 ++ .../{Retroed.shader => PixelShader.shader} | 2 +- ...ed.shader.meta => PixelShader.shader.meta} | 0 13 files changed, 502 insertions(+), 98 deletions(-) rename Assets/Material/{Retroed.mat => CRTBlit.mat} (86%) create mode 100644 Assets/Material/CRTBlit.mat.meta create mode 100644 Assets/Material/PixelBlit.mat rename Assets/Material/{Retroed.mat.meta => PixelBlit.mat.meta} (100%) create mode 100644 Assets/Scripts/Visual/Blit.cs create mode 100644 Assets/Scripts/Visual/Blit.cs.meta delete mode 100644 Assets/Scripts/Visual/RetroPostProcess.cs delete mode 100644 Assets/Scripts/Visual/RetroPostProcess.cs.meta create mode 100644 Assets/Shaders/CRTShader.shader create mode 100644 Assets/Shaders/CRTShader.shader.meta rename Assets/Shaders/{Retroed.shader => PixelShader.shader} (98%) rename Assets/Shaders/{Retroed.shader.meta => PixelShader.shader.meta} (100%) diff --git a/Assets/Material/Retroed.mat b/Assets/Material/CRTBlit.mat similarity index 86% rename from Assets/Material/Retroed.mat rename to Assets/Material/CRTBlit.mat index 698b0fe..7e59da5 100644 --- a/Assets/Material/Retroed.mat +++ b/Assets/Material/CRTBlit.mat @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!114 &-4790970344126815099 +--- !u!114 &-937696407428621231 MonoBehaviour: m_ObjectHideFlags: 11 m_CorrespondingSourceObject: {fileID: 0} @@ -20,8 +20,8 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Retroed - m_Shader: {fileID: 4800000, guid: c4d7011496fb8f34ead8b47276ae3f0a, type: 3} + m_Name: CRTBlit + m_Shader: {fileID: 4800000, guid: 7d830e9754227db4b89bacfdc753e135, type: 3} m_ValidKeywords: [] m_InvalidKeywords: [] m_LightmapFlags: 4 @@ -59,7 +59,7 @@ Material: m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} - m_Scale: {x: 4.49, y: 1} + m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: m_Texture: {fileID: 0} @@ -93,10 +93,7 @@ Material: m_Floats: - _AlphaClip: 0 - _Blend: 0 - - _BlendOp: 0 - _BumpScale: 1 - - _CellSizeX: 4 - - _CellSizeY: 4 - _ClearCoatMask: 0 - _ClearCoatSmoothness: 0 - _Cull: 2 @@ -113,9 +110,6 @@ Material: - _Parallax: 0.005 - _QueueOffset: 0 - _ReceiveShadows: 1 - - _SampleGI: 0 - - _ScreenHeight: 240 - - _ScreenWidth: 320 - _Smoothness: 0.5 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 @@ -123,6 +117,18 @@ Material: - _Surface: 0 - _WorkflowMode: 1 - _ZWrite: 1 + - u_bend: 1.32 + - u_noise_amount: 0.96 + - u_noise_size: 246.53 + - u_scanline_amount: -2.9 + - u_scanline_size_1: 1.09 + - u_scanline_size_2: 1.69 + - u_scanline_speed_1: 0.08 + - u_scanline_speed_2: 1.28 + - u_time: 15.02 + - u_vignette_edge_round: 0.44 + - u_vignette_size: 0.41 + - u_vignette_smoothness: 0.28 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Material/CRTBlit.mat.meta b/Assets/Material/CRTBlit.mat.meta new file mode 100644 index 0000000..a840c3c --- /dev/null +++ b/Assets/Material/CRTBlit.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a110daba21b580f4898ccf841727c0c2 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Material/PixelBlit.mat b/Assets/Material/PixelBlit.mat new file mode 100644 index 0000000..f9440db --- /dev/null +++ b/Assets/Material/PixelBlit.mat @@ -0,0 +1,166 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-4790970344126815099 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 5 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: PixelBlit + m_Shader: {fileID: 4800000, guid: c4d7011496fb8f34ead8b47276ae3f0a, type: 3} + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BASE_COLOR_MAP: + m_Texture: {fileID: 2800000, guid: 116e65d2b34493c439f545f71aa487b5, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EMISSION_COLOR_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _METALNESS_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 8.38, y: 5.31} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NORMAL_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SPECULAR_COLOR_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SPECULAR_IOR_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SPECULAR_ROUGHNESS_MAP: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaClip: 0 + - _Blend: 0 + - _BlendOp: 0 + - _BumpScale: 1 + - _CellSizeX: 2 + - _CellSizeY: 2 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _METALNESS: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueControl: 0 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _SPECULAR_IOR: 1.5 + - _SPECULAR_ROUGHNESS: 0 + - _SampleGI: 0 + - _ScreenHeight: 480 + - _ScreenWidth: 640 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BASE_COLOR: {r: 1, g: 1, b: 1, a: 1} + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EMISSION_COLOR: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SPECULAR_COLOR: {r: 1, g: 1, b: 1, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Material/Retroed.mat.meta b/Assets/Material/PixelBlit.mat.meta similarity index 100% rename from Assets/Material/Retroed.mat.meta rename to Assets/Material/PixelBlit.mat.meta diff --git a/Assets/Scripts/Visual/Blit.cs b/Assets/Scripts/Visual/Blit.cs new file mode 100644 index 0000000..30d0d6c --- /dev/null +++ b/Assets/Scripts/Visual/Blit.cs @@ -0,0 +1,123 @@ +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.Rendering.Universal; + +/* + * https://cyangamedev.wordpress.com/2020/06/22/urp-post-processing/ + */ + +namespace Shaders +{ + public class Blit : ScriptableRendererFeature + { + private class BlitPass : ScriptableRenderPass + { + public enum RenderTarget + { + Color, + RenderTexture, + } + + public Material blitMaterial = null; + public int blitShaderPassIndex = 0; + public FilterMode filterMode { get; set; } + + private RenderTargetIdentifier source { get; set; } + private RenderTargetHandle destination { get; set; } + + RenderTargetHandle m_TemporaryColorTexture; + string m_ProfilerTag; + + public BlitPass(RenderPassEvent renderPassEvent, Material blitMaterial, int blitShaderPassIndex, string tag) + { + this.renderPassEvent = renderPassEvent; + this.blitMaterial = blitMaterial; + this.blitShaderPassIndex = blitShaderPassIndex; + m_ProfilerTag = tag; + m_TemporaryColorTexture.Init("_TemporaryColorTexture"); + } + + public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination) + { + this.source = source; + this.destination = destination; + } + + public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) + { + CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); + + RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor; + opaqueDesc.depthBufferBits = 0; + + // Can't read and write to same color target, use a TemporaryRT + if (destination == RenderTargetHandle.CameraTarget) + { + cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode); + Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex); + Blit(cmd, m_TemporaryColorTexture.Identifier(), source); + } + else + { + Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex); + } + + context.ExecuteCommandBuffer(cmd); + CommandBufferPool.Release(cmd); + } + + public override void FrameCleanup(CommandBuffer cmd) + { + if (destination == RenderTargetHandle.CameraTarget) + cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id); + } + } + + [System.Serializable] + public class BlitSettings + { + public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques; + + public Material blitMaterial = null; + public int blitMaterialPassIndex = -1; + public Target destination = Target.Color; + public string textureId = "_BlitPassTexture"; + } + + public enum Target + { + Color, + Texture + } + + public BlitSettings settings = new BlitSettings(); + RenderTargetHandle m_RenderTextureHandle; + + BlitPass blitPass; + + public override void Create() + { + var passIndex = settings.blitMaterial != null ? settings.blitMaterial.passCount - 1 : 1; + settings.blitMaterialPassIndex = Mathf.Clamp(settings.blitMaterialPassIndex, -1, passIndex); + blitPass = new BlitPass(settings.Event, settings.blitMaterial, settings.blitMaterialPassIndex, name); + m_RenderTextureHandle.Init(settings.textureId); + } + + public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) + { + var src = renderer.cameraColorTarget; + var dest = (settings.destination == Target.Color) ? RenderTargetHandle.CameraTarget : m_RenderTextureHandle; + + if (settings.blitMaterial == null) + { + Debug.LogWarningFormat( + "Missing Blit Material. {0} blit pass will not execute. Check for missing reference in the assigned renderer.", + GetType().Name); + return; + } + + blitPass.Setup(src, dest); + renderer.EnqueuePass(blitPass); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Visual/Blit.cs.meta b/Assets/Scripts/Visual/Blit.cs.meta new file mode 100644 index 0000000..900b255 --- /dev/null +++ b/Assets/Scripts/Visual/Blit.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d2d5de177d814a8d8c64638ad49b1b1d +timeCreated: 1666983505 \ No newline at end of file diff --git a/Assets/Scripts/Visual/RetroPostProcess.cs b/Assets/Scripts/Visual/RetroPostProcess.cs deleted file mode 100644 index 4c6999f..0000000 --- a/Assets/Scripts/Visual/RetroPostProcess.cs +++ /dev/null @@ -1,35 +0,0 @@ -using UnityEngine; -using UnityEngine.Serialization; - -namespace Visual -{ - /// - /// https://luka712.github.io/2018/07/01/Pixelate-it-Shadertoy-Unity/#:~:text=First%20I%E2%80%99m%20going%20to%20create%20script%20for%20loading%20shader. - /// - [ExecuteInEditMode] - public class RetroPostProcess : MonoBehaviour - { - [FormerlySerializedAs("cellSize")] [SerializeField] - private Vector2 m_CellSize = new Vector2(4, 4); - - private Material _material; - private static readonly int ScreenWidth = Shader.PropertyToID("_ScreenWidth"); - private static readonly int ScreenHeight = Shader.PropertyToID("_ScreenHeight"); - private static readonly int CellSizeX = Shader.PropertyToID("_CellSizeX"); - private static readonly int CellSizeY = Shader.PropertyToID("_CellSizeY"); - - private void Awake() - { - _material = new Material(Shader.Find("Retroed")); - } - - private void OnRenderImage(RenderTexture source, RenderTexture destination) - { - _material.SetFloat(ScreenWidth, Screen.width); - _material.SetFloat(ScreenHeight, Screen.height); - _material.SetFloat(CellSizeX, m_CellSize.x); - _material.SetFloat(CellSizeY, m_CellSize.y); - Graphics.Blit(source, destination, _material); - } - } -} diff --git a/Assets/Scripts/Visual/RetroPostProcess.cs.meta b/Assets/Scripts/Visual/RetroPostProcess.cs.meta deleted file mode 100644 index 6a86493..0000000 --- a/Assets/Scripts/Visual/RetroPostProcess.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0a44d4a4a2fcf4a49a34c1fe7813509b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Settings/URP-HighFidelity-Renderer.asset b/Assets/Settings/URP-HighFidelity-Renderer.asset index db0b805..477e31b 100644 --- a/Assets/Settings/URP-HighFidelity-Renderer.asset +++ b/Assets/Settings/URP-HighFidelity-Renderer.asset @@ -1,44 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!114 &-3191591094449869079 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6b3d386ba5cd94485973aee1479b272e, type: 3} - m_Name: Retroed - m_EditorClassIdentifier: - m_Active: 1 - settings: - passTag: Retroed - Event: 300 - filterSettings: - RenderQueueType: 0 - LayerMask: - serializedVersion: 2 - m_Bits: 8192 - PassNames: [] - overrideMaterial: {fileID: 2100000, guid: bc45e5f0151133446b26221ec8ea680c, type: 2} - overrideMaterialPassIndex: 0 - overrideDepthState: 0 - depthCompareFunction: 4 - enableWrite: 1 - stencilSettings: - overrideStencilState: 0 - stencilReference: 0 - stencilCompareFunction: 8 - passOperation: 0 - failOperation: 0 - zFailOperation: 0 - cameraSettings: - overrideCamera: 0 - restoreCamera: 1 - offset: {x: 0, y: 0, z: 0, w: 0} - cameraFieldOfView: 60 --- !u!114 &-1878332245247344467 MonoBehaviour: m_ObjectHideFlags: 0 @@ -62,6 +23,25 @@ MonoBehaviour: DirectLightingStrength: 0.25 Radius: 0.25 SampleCount: 12 +--- !u!114 &-1742716298934962613 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2d5de177d814a8d8c64638ad49b1b1d, type: 3} + m_Name: PixelPass + m_EditorClassIdentifier: + m_Active: 0 + settings: + Event: 300 + blitMaterial: {fileID: 2100000, guid: bc45e5f0151133446b26221ec8ea680c, type: 2} + blitMaterialPassIndex: 0 + destination: 0 + textureId: _BlitPassTexture --- !u!114 &11400000 MonoBehaviour: m_ObjectHideFlags: 0 @@ -79,8 +59,9 @@ MonoBehaviour: type: 3} m_RendererFeatures: - {fileID: -1878332245247344467} - - {fileID: -3191591094449869079} - m_RendererFeatureMap: adc0de57c6d2eee5e9ee0333cf30b5d3 + - {fileID: -1742716298934962613} + - {fileID: 6059349672888060108} + m_RendererFeatureMap: adc0de57c6d2eee54bb6b269c2a0d0e7cc485f766c221754 m_UseNativeRenderPass: 0 postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2} @@ -120,3 +101,22 @@ MonoBehaviour: m_ClusteredRendering: 0 m_TileSize: 32 m_IntermediateTextureMode: 1 +--- !u!114 &6059349672888060108 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2d5de177d814a8d8c64638ad49b1b1d, type: 3} + m_Name: CRTPass + m_EditorClassIdentifier: + m_Active: 1 + settings: + Event: 550 + blitMaterial: {fileID: 2100000, guid: a110daba21b580f4898ccf841727c0c2, type: 2} + blitMaterialPassIndex: 0 + destination: 0 + textureId: _BlitPassTexture diff --git a/Assets/Shaders/CRTShader.shader b/Assets/Shaders/CRTShader.shader new file mode 100644 index 0000000..23310f2 --- /dev/null +++ b/Assets/Shaders/CRTShader.shader @@ -0,0 +1,134 @@ +Shader "CRTShader" +{ + Properties + { + u_time("u_time",float) = 0.5 + u_bend("u_bend",float) = 0.5 + u_scanline_size_1("u_scanline_size_1",float) = 0.5 + u_scanline_speed_1("u_scanline_speed_1",float) = 0.5 + u_scanline_size_2("u_scanline_size_2",float) = 0.5 + u_scanline_speed_2("u_scanline_speed_2",float) = 0.5 + u_scanline_amount("u_scanline_amount",float) = 0.5 + u_vignette_size("u_vignette_size",float) = 0.5 + u_vignette_smoothness("u_vignette_smoothness",float) = 0.5 + u_vignette_edge_round("u_vignette_edge_round",float) = 0.5 + u_noise_size("u_noise_size",float) = 0.5 + u_noise_amount("u_noise_amount",float) = 0.5 + } + SubShader + { + // No culling or depth + Cull Off ZWrite Off ZTest Always + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + v2f vert(appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + return o; + } + + sampler2D _MainTex; + + uniform float u_time; + uniform float u_bend; + uniform float u_scanline_size_1; + uniform float u_scanline_speed_1; + uniform float u_scanline_size_2; + uniform float u_scanline_speed_2; + uniform float u_scanline_amount; + uniform float u_vignette_size; + uniform float u_vignette_smoothness; + uniform float u_vignette_edge_round; + uniform float u_noise_size; + uniform float u_noise_amount; + uniform half2 u_red_offset; + uniform half2 u_green_offset; + uniform half2 u_blue_offset; + + half2 crt_coords(half2 uv, float bend) + { + uv -= 0.5; + uv *= 2.; + uv.x *= 1. + pow(abs(uv.y) / bend, 2.); + uv.y *= 1. + pow(abs(uv.x) / bend, 2.); + + uv /= 2.5; + return uv + 0.5; + } + + float vignette(half2 uv, float size, float smoothness, float edgeRounding) + { + uv -= .5; + uv *= size; + float amount = sqrt(pow(abs(uv.x), edgeRounding) + pow(abs(uv.y), edgeRounding)); + amount = 1. - amount; + return smoothstep(0, smoothness, amount); + } + + float scanline(half2 uv, float lines, float speed) + { + return sin(uv.y * lines + u_time * speed); + } + + float random(half2 uv) + { + return frac(sin(dot(uv, half2(15.1511, 42.5225))) * 12341.51611 * sin(u_time * 0.03)); + } + + float noise(half2 uv) + { + half2 i = floor(uv); + half2 f = frac(uv); + + float a = random(i); + float b = random(i + half2(1., 0.)); + float c = random(i + half2(0, 1.)); + float d = random(i + half2(1., 1.)); + + half2 u = smoothstep(0., 1., f); + + return lerp(a, b, u.x) + (c - a) * u.y * (1. - u.x) + (d - b) * u.x * u.y; + } + + fixed4 frag(v2f i) : SV_Target + { + half2 crt_uv = crt_coords(i.uv, u_bend); + fixed4 col; + col.r = tex2D(_MainTex, crt_uv + u_red_offset).r; + col.g = tex2D(_MainTex, crt_uv + u_green_offset).g; + col.b = tex2D(_MainTex, crt_uv + u_blue_offset).b; + col.a = tex2D(_MainTex, crt_uv).a; + + float s1 = scanline(i.uv, u_scanline_size_1, u_scanline_speed_1); + float s2 = scanline(i.uv, u_scanline_size_2, u_scanline_speed_2); + + col = lerp(col, fixed(s1 + s2), u_scanline_amount); + + return lerp(col, fixed(noise(i.uv * u_noise_size)), u_noise_amount) * vignette( + i.uv, u_vignette_size, u_vignette_smoothness, u_vignette_edge_round); + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Shaders/CRTShader.shader.meta b/Assets/Shaders/CRTShader.shader.meta new file mode 100644 index 0000000..4161a29 --- /dev/null +++ b/Assets/Shaders/CRTShader.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 7d830e9754227db4b89bacfdc753e135 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Retroed.shader b/Assets/Shaders/PixelShader.shader similarity index 98% rename from Assets/Shaders/Retroed.shader rename to Assets/Shaders/PixelShader.shader index 727ac91..e97241f 100644 --- a/Assets/Shaders/Retroed.shader +++ b/Assets/Shaders/PixelShader.shader @@ -1,4 +1,4 @@ -Shader "Retroed" +Shader "PixelShader" { Properties { diff --git a/Assets/Shaders/Retroed.shader.meta b/Assets/Shaders/PixelShader.shader.meta similarity index 100% rename from Assets/Shaders/Retroed.shader.meta rename to Assets/Shaders/PixelShader.shader.meta From 56cff00ba57ae163ac1f4ad0243d96a59abd8010 Mon Sep 17 00:00:00 2001 From: Jean Lamarre Date: Sat, 29 Oct 2022 03:12:54 -0400 Subject: [PATCH 3/4] quite good i think --- Assets/Material/CRTBlit.mat | 29 ++++++----- Assets/Scripts/Visual.meta | 3 -- .../Settings/URP-HighFidelity-Renderer.asset | 23 +-------- Assets/{Scripts/Visual => Shaders}/Blit.cs | 8 +++- .../{Scripts/Visual => Shaders}/Blit.cs.meta | 0 Assets/Shaders/BlitShaderGUI.cs | 19 ++++++++ Assets/Shaders/BlitShaderGUI.cs.meta | 3 ++ Assets/Shaders/CRTShader.shader | 48 ++++++++++++------- 8 files changed, 78 insertions(+), 55 deletions(-) delete mode 100644 Assets/Scripts/Visual.meta rename Assets/{Scripts/Visual => Shaders}/Blit.cs (95%) rename Assets/{Scripts/Visual => Shaders}/Blit.cs.meta (100%) create mode 100644 Assets/Shaders/BlitShaderGUI.cs create mode 100644 Assets/Shaders/BlitShaderGUI.cs.meta diff --git a/Assets/Material/CRTBlit.mat b/Assets/Material/CRTBlit.mat index 7e59da5..d0b02ec 100644 --- a/Assets/Material/CRTBlit.mat +++ b/Assets/Material/CRTBlit.mat @@ -117,21 +117,26 @@ Material: - _Surface: 0 - _WorkflowMode: 1 - _ZWrite: 1 - - u_bend: 1.32 - - u_noise_amount: 0.96 - - u_noise_size: 246.53 - - u_scanline_amount: -2.9 - - u_scanline_size_1: 1.09 - - u_scanline_size_2: 1.69 - - u_scanline_speed_1: 0.08 - - u_scanline_speed_2: 1.28 - - u_time: 15.02 - - u_vignette_edge_round: 0.44 - - u_vignette_size: 0.41 - - u_vignette_smoothness: 0.28 + - u_bend: 2.21 + - u_noise_amount: 0.012 + - u_noise_size: 337 + - u_scanlin_transparence1: 0.38 + - u_scanlin_transparence2: 0.098 + - u_scanline_amount: 0.019 + - u_scanline_size_1: 308 + - u_scanline_size_2: 521 + - u_scanline_speed_1: 94.13 + - u_scanline_speed_2: 14.83 + - u_time: 15.95 + - u_vignette_edge_round: 7 + - u_vignette_size: 1.89 + - u_vignette_smoothness: 0.56 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + - u_blue_offset: {r: 0, g: 0.002, b: 0, a: 0} + - u_green_offset: {r: 0, g: 0, b: 0, a: 0} + - u_red_offset: {r: 0, g: 0.002, b: 0, a: 0} m_BuildTextureStacks: [] diff --git a/Assets/Scripts/Visual.meta b/Assets/Scripts/Visual.meta deleted file mode 100644 index 1fc18fc..0000000 --- a/Assets/Scripts/Visual.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1f823cbc83e54d88a90cd594398385d1 -timeCreated: 1666894558 \ No newline at end of file diff --git a/Assets/Settings/URP-HighFidelity-Renderer.asset b/Assets/Settings/URP-HighFidelity-Renderer.asset index 477e31b..21757e6 100644 --- a/Assets/Settings/URP-HighFidelity-Renderer.asset +++ b/Assets/Settings/URP-HighFidelity-Renderer.asset @@ -23,25 +23,6 @@ MonoBehaviour: DirectLightingStrength: 0.25 Radius: 0.25 SampleCount: 12 ---- !u!114 &-1742716298934962613 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d2d5de177d814a8d8c64638ad49b1b1d, type: 3} - m_Name: PixelPass - m_EditorClassIdentifier: - m_Active: 0 - settings: - Event: 300 - blitMaterial: {fileID: 2100000, guid: bc45e5f0151133446b26221ec8ea680c, type: 2} - blitMaterialPassIndex: 0 - destination: 0 - textureId: _BlitPassTexture --- !u!114 &11400000 MonoBehaviour: m_ObjectHideFlags: 0 @@ -59,9 +40,8 @@ MonoBehaviour: type: 3} m_RendererFeatures: - {fileID: -1878332245247344467} - - {fileID: -1742716298934962613} - {fileID: 6059349672888060108} - m_RendererFeatureMap: adc0de57c6d2eee54bb6b269c2a0d0e7cc485f766c221754 + m_RendererFeatureMap: adc0de57c6d2eee5cc485f766c221754 m_UseNativeRenderPass: 0 postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2} @@ -120,3 +100,4 @@ MonoBehaviour: blitMaterialPassIndex: 0 destination: 0 textureId: _BlitPassTexture + alwaysRender: 1 diff --git a/Assets/Scripts/Visual/Blit.cs b/Assets/Shaders/Blit.cs similarity index 95% rename from Assets/Scripts/Visual/Blit.cs rename to Assets/Shaders/Blit.cs index 30d0d6c..c18c1c7 100644 --- a/Assets/Scripts/Visual/Blit.cs +++ b/Assets/Shaders/Blit.cs @@ -82,6 +82,7 @@ namespace Shaders public int blitMaterialPassIndex = -1; public Target destination = Target.Color; public string textureId = "_BlitPassTexture"; + public bool alwaysRender = false; } public enum Target @@ -116,8 +117,11 @@ namespace Shaders return; } - blitPass.Setup(src, dest); - renderer.EnqueuePass(blitPass); + if (Application.isPlaying || settings.alwaysRender) + { + blitPass.Setup(src, dest); + renderer.EnqueuePass(blitPass); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Visual/Blit.cs.meta b/Assets/Shaders/Blit.cs.meta similarity index 100% rename from Assets/Scripts/Visual/Blit.cs.meta rename to Assets/Shaders/Blit.cs.meta diff --git a/Assets/Shaders/BlitShaderGUI.cs b/Assets/Shaders/BlitShaderGUI.cs new file mode 100644 index 0000000..10af14f --- /dev/null +++ b/Assets/Shaders/BlitShaderGUI.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; + +namespace Shaders +{ + public class BlitShaderGUI : ShaderGUI + { + public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties) + { + // var propertiesList = properties.ToList() + // .Where(prop => prop.displayName != "Texture"); + // properties = propertiesList.ToArray(); + + base.OnGUI (materialEditor, properties); + } + } +} \ No newline at end of file diff --git a/Assets/Shaders/BlitShaderGUI.cs.meta b/Assets/Shaders/BlitShaderGUI.cs.meta new file mode 100644 index 0000000..73b1df4 --- /dev/null +++ b/Assets/Shaders/BlitShaderGUI.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ea9e1aab61914fdc984d1ba78a132f7c +timeCreated: 1667020752 \ No newline at end of file diff --git a/Assets/Shaders/CRTShader.shader b/Assets/Shaders/CRTShader.shader index 23310f2..016437d 100644 --- a/Assets/Shaders/CRTShader.shader +++ b/Assets/Shaders/CRTShader.shader @@ -1,20 +1,30 @@ -Shader "CRTShader" + Shader "CRTShader" { Properties { - u_time("u_time",float) = 0.5 - u_bend("u_bend",float) = 0.5 - u_scanline_size_1("u_scanline_size_1",float) = 0.5 - u_scanline_speed_1("u_scanline_speed_1",float) = 0.5 - u_scanline_size_2("u_scanline_size_2",float) = 0.5 - u_scanline_speed_2("u_scanline_speed_2",float) = 0.5 - u_scanline_amount("u_scanline_amount",float) = 0.5 - u_vignette_size("u_vignette_size",float) = 0.5 - u_vignette_smoothness("u_vignette_smoothness",float) = 0.5 - u_vignette_edge_round("u_vignette_edge_round",float) = 0.5 - u_noise_size("u_noise_size",float) = 0.5 - u_noise_amount("u_noise_amount",float) = 0.5 + _MainTex("Texture", 2D) = "Transparent" {} + u_time("Time",float) = 0.5 + u_bend("Bend",range(0.5, 5.0)) = 0.5 + u_scanlin_transparence1("Scanline 1 Transparence",range(0, 1)) = 0.5 + u_scanline_size_1("Scanline Size 1",range(0, 750)) = 0.5 + u_scanline_speed_1("Scanline Speed 1",float) = 0.5 + u_scanlin_transparence2("Scanline 2 Transparence",range(0, 1)) = 0.5 + u_scanline_size_2("Scanline Size 2",range(0, 750)) = 0.5 + u_scanline_speed_2("Scanline Speed2",float) = 0.5 + u_scanline_amount("Scanline Amount",range(0, 1)) = 0.5 + u_vignette_size("Vignette Size",range(0, 10)) = 0.5 + u_vignette_smoothness("Vignette Smoothness",range(0, 2)) = 0.5 + u_vignette_edge_round("Vignette Edge Round",range(0, 100)) = 0.5 + u_noise_size("Noise Size",range(0, 500 )) = 0.5 + u_noise_amount("Noise Amount",range(0, 0.3)) = 0.5 + [ShowAsVector2] u_red_offset("Red Offset",Vector) = (.25, .5, .5, 0) + [ShowAsVector2] u_green_offset("Green Offset",Vector) = (.25, .5, .5, 0) + [ShowAsVector2] u_blue_offset("Blue Offset",Vector) = (.25, .5, .5, 0) } + + // The Unity Editor uses the class ExampleCustomEditor to configure the Inspector for this shader asset + CustomEditor "Shaders.BlitShaderGUI" + SubShader { // No culling or depth @@ -52,8 +62,10 @@ Shader "CRTShader" uniform float u_time; uniform float u_bend; + uniform float u_scanlin_transparence1; uniform float u_scanline_size_1; uniform float u_scanline_speed_1; + uniform float u_scanlin_transparence2; uniform float u_scanline_size_2; uniform float u_scanline_speed_2; uniform float u_scanline_amount; @@ -86,13 +98,14 @@ Shader "CRTShader" return smoothstep(0, smoothness, amount); } - float scanline(half2 uv, float lines, float speed) + float scanline(half2 uv, float lines, float speed, float transparence) { - return sin(uv.y * lines + u_time * speed); + return sin(uv.y * lines + u_time * speed) * transparence; } float random(half2 uv) { + return frac(sin(dot(uv, half2(15.1511, 42.5225))) * 12341.51611 * sin(u_time * 0.03)); } @@ -113,6 +126,7 @@ Shader "CRTShader" fixed4 frag(v2f i) : SV_Target { + u_time = _Time; half2 crt_uv = crt_coords(i.uv, u_bend); fixed4 col; col.r = tex2D(_MainTex, crt_uv + u_red_offset).r; @@ -120,8 +134,8 @@ Shader "CRTShader" col.b = tex2D(_MainTex, crt_uv + u_blue_offset).b; col.a = tex2D(_MainTex, crt_uv).a; - float s1 = scanline(i.uv, u_scanline_size_1, u_scanline_speed_1); - float s2 = scanline(i.uv, u_scanline_size_2, u_scanline_speed_2); + float s1 = scanline(i.uv, u_scanline_size_1, u_scanline_speed_1, u_scanlin_transparence1); + float s2 = scanline(i.uv, u_scanline_size_2, u_scanline_speed_2,u_scanlin_transparence2); col = lerp(col, fixed(s1 + s2), u_scanline_amount); From d4eb08d7edd622a232237c9ae35064305c5f5c99 Mon Sep 17 00:00:00 2001 From: Jean Lamarre Date: Sat, 29 Oct 2022 03:54:34 -0400 Subject: [PATCH 4/4] =?UTF-8?q?fix=20menu=20UI=20cass=C3=A9=20a=20cause=20?= =?UTF-8?q?Shader=20+=20fineTouch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Material/CRTBlit.mat | 16 +++++++++----- Assets/Prefabs/MainMenuButtons.prefab | 6 ++--- Assets/Scenes/MainMenu.unity | 16 +++++++++----- Assets/Shaders/CRTShader.shader | 32 ++++++++++++++++++--------- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Assets/Material/CRTBlit.mat b/Assets/Material/CRTBlit.mat index d0b02ec..ca98651 100644 --- a/Assets/Material/CRTBlit.mat +++ b/Assets/Material/CRTBlit.mat @@ -117,18 +117,21 @@ Material: - _Surface: 0 - _WorkflowMode: 1 - _ZWrite: 1 - - u_bend: 2.21 + - u_bend: 3.15 + - u_blue_offset_y: 0.00403 + - u_green_offset_y: 0 - u_noise_amount: 0.012 - u_noise_size: 337 - - u_scanlin_transparence1: 0.38 + - u_red_offset_y: -0.00409 + - u_scanlin_transparence1: 0.194 - u_scanlin_transparence2: 0.098 - u_scanline_amount: 0.019 - u_scanline_size_1: 308 - u_scanline_size_2: 521 - u_scanline_speed_1: 94.13 - - u_scanline_speed_2: 14.83 + - u_scanline_speed_2: 30 - u_time: 15.95 - - u_vignette_edge_round: 7 + - u_vignette_edge_round: 8.5 - u_vignette_size: 1.89 - u_vignette_smoothness: 0.56 m_Colors: @@ -137,6 +140,9 @@ Material: - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - u_blue_offset: {r: 0, g: 0.002, b: 0, a: 0} + - u_blue_offset_y: {r: 0.25, g: 0.5, b: 0.5, a: 0} - u_green_offset: {r: 0, g: 0, b: 0, a: 0} - - u_red_offset: {r: 0, g: 0.002, b: 0, a: 0} + - u_green_offset_y: {r: 0.25, g: 0.5, b: 0.5, a: 0} + - u_red_offset: {r: 0, g: -0.002, b: 0, a: 0} + - u_red_offset_y: {r: 0.25, g: 0.5, b: 0.5, a: 0} m_BuildTextureStacks: [] diff --git a/Assets/Prefabs/MainMenuButtons.prefab b/Assets/Prefabs/MainMenuButtons.prefab index c5a3450..466c398 100644 --- a/Assets/Prefabs/MainMenuButtons.prefab +++ b/Assets/Prefabs/MainMenuButtons.prefab @@ -237,9 +237,9 @@ MonoBehaviour: m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} - m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_HighlightedColor: {r: 0.5377358, g: 0.5377358, b: 0.5377358, a: 1} + m_PressedColor: {r: 0.5754717, g: 0.3441972, b: 0.3441972, a: 1} + m_SelectedColor: {r: 0.5283019, g: 0.5283019, b: 0.5283019, a: 1} m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} m_ColorMultiplier: 1 m_FadeDuration: 0.1 diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity index 0a9c0f0..15dbccc 100644 --- a/Assets/Scenes/MainMenu.unity +++ b/Assets/Scenes/MainMenu.unity @@ -380,7 +380,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3} m_Name: m_EditorClassIdentifier: - m_FirstSelected: {fileID: 0} + m_FirstSelected: {fileID: 1335784365} m_sendNavigationEvents: 1 m_DragThreshold: 10 --- !u!4 &185700930 @@ -698,7 +698,7 @@ MonoBehaviour: m_BlockingObjects: 0 m_BlockingMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 255 --- !u!114 &753457326 MonoBehaviour: m_ObjectHideFlags: 0 @@ -918,7 +918,7 @@ PrefabInstance: - target: {fileID: 5917528464183523172, guid: 0bdc45a9254ade843b7ba60aaab62301, type: 3} propertyPath: m_fontSize - value: 11.85 + value: 10.05 objectReference: {fileID: 0} - target: {fileID: 5917528464644539588, guid: 0bdc45a9254ade843b7ba60aaab62301, type: 3} @@ -1073,7 +1073,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -77.453, y: -53.482} + m_AnchoredPosition: {x: -77.453, y: -53.481995} m_SizeDelta: {x: 154.907, y: 106.963} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1281004662 @@ -1173,6 +1173,12 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1281004660} m_CullTransparentMesh: 1 +--- !u!1 &1335784365 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 5917528464644539588, guid: 0bdc45a9254ade843b7ba60aaab62301, + type: 3} + m_PrefabInstance: {fileID: 5917528464004223745} + m_PrefabAsset: {fileID: 0} --- !u!1 &1451380979 GameObject: m_ObjectHideFlags: 0 @@ -1293,7 +1299,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 82.547, y: -53.407} + m_AnchoredPosition: {x: 82.547, y: -53.407013} m_SizeDelta: {x: -165.09, y: -106.81} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1703051055 diff --git a/Assets/Shaders/CRTShader.shader b/Assets/Shaders/CRTShader.shader index 016437d..8ae1136 100644 --- a/Assets/Shaders/CRTShader.shader +++ b/Assets/Shaders/CRTShader.shader @@ -10,16 +10,16 @@ u_scanline_speed_1("Scanline Speed 1",float) = 0.5 u_scanlin_transparence2("Scanline 2 Transparence",range(0, 1)) = 0.5 u_scanline_size_2("Scanline Size 2",range(0, 750)) = 0.5 - u_scanline_speed_2("Scanline Speed2",float) = 0.5 + u_scanline_speed_2("Scanline Speed 2",float) = 0.5 u_scanline_amount("Scanline Amount",range(0, 1)) = 0.5 u_vignette_size("Vignette Size",range(0, 10)) = 0.5 u_vignette_smoothness("Vignette Smoothness",range(0, 2)) = 0.5 u_vignette_edge_round("Vignette Edge Round",range(0, 100)) = 0.5 u_noise_size("Noise Size",range(0, 500 )) = 0.5 u_noise_amount("Noise Amount",range(0, 0.3)) = 0.5 - [ShowAsVector2] u_red_offset("Red Offset",Vector) = (.25, .5, .5, 0) - [ShowAsVector2] u_green_offset("Green Offset",Vector) = (.25, .5, .5, 0) - [ShowAsVector2] u_blue_offset("Blue Offset",Vector) = (.25, .5, .5, 0) + u_red_offset_y("Red Offset",range(-0.01,0.01)) = 0 + u_green_offset_y("Green Offset",range(-0.01,0.01)) = 0 + u_blue_offset_y("Blue Offset",range(-0.01,0.01)) = 0 } // The Unity Editor uses the class ExampleCustomEditor to configure the Inspector for this shader asset @@ -74,18 +74,28 @@ uniform float u_vignette_edge_round; uniform float u_noise_size; uniform float u_noise_amount; - uniform half2 u_red_offset; - uniform half2 u_green_offset; - uniform half2 u_blue_offset; + uniform float u_red_offset_y; + uniform float u_green_offset_y; + uniform float u_blue_offset_y; + + half2 u_color_offset(float offset) + { + return half2(0,offset); + } half2 crt_coords(half2 uv, float bend) { + // By subtracting 0.5, we go from 0 to 1 into -0.5 to 0.5 uv -= 0.5; + // Multiplying by puts us in -1 to 1 space. uv *= 2.; + + // Curves lines uv.x *= 1. + pow(abs(uv.y) / bend, 2.); uv.y *= 1. + pow(abs(uv.x) / bend, 2.); - uv /= 2.5; + //return coordinates to 0 to 1 space. + uv /= 2; return uv + 0.5; } @@ -129,9 +139,9 @@ u_time = _Time; half2 crt_uv = crt_coords(i.uv, u_bend); fixed4 col; - col.r = tex2D(_MainTex, crt_uv + u_red_offset).r; - col.g = tex2D(_MainTex, crt_uv + u_green_offset).g; - col.b = tex2D(_MainTex, crt_uv + u_blue_offset).b; + col.r = tex2D(_MainTex, crt_uv + u_color_offset(u_red_offset_y)).r; + col.g = tex2D(_MainTex, crt_uv + u_color_offset(u_green_offset_y)).g; + col.b = tex2D(_MainTex, crt_uv + u_color_offset(u_blue_offset_y)).b; col.a = tex2D(_MainTex, crt_uv).a; float s1 = scanline(i.uv, u_scanline_size_1, u_scanline_speed_1, u_scanlin_transparence1);