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