├── FluidSim-VotexConfinement ├── Advection.shader ├── Block.shader ├── DisplayRainow.shader ├── Divergence.shader ├── Pressure.shader ├── Substract.shader ├── VorConfinement.shader ├── VortexStreetManager.cs └── Vorticity.shader ├── HDRP-Volume-Post ├── GrayScale.cs ├── GrayScale.shader ├── RGBSplit.cs ├── RGBSplit.shader ├── ScanLine.cs ├── ScanLine.shader ├── WaveJitter.cs └── WaveJitter.shader ├── ProcedureAnim-WaterCaustics └── Caustics.shader ├── RayMarching-Cloud ├── CloudManager.cs ├── CloudMarching.shader └── M_Cloud.mat ├── URP-DisneyPBR_NPR ├── C_NPR.shader ├── C_PBR.shader └── NormalTool.cs ├── URP-Fur └── C_Fur.shader ├── URP-Noise-Ocean └── C_Water.shader └── URP-Volume-Post ├── RenderFeature ├── PostProcessFeature.cs └── PostProcessFeature.cs.meta ├── Shaders.meta ├── Shaders ├── Blur.meta ├── Blur │ ├── Bokeh.shader │ ├── Bokeh.shader.meta │ ├── GaussianBlur.shader │ ├── GaussianBlur.shader.meta │ ├── IrisBlur.shader │ ├── IrisBlur.shader.meta │ ├── Kawase.shader │ ├── Kawase.shader.meta │ ├── TentBlur.shader │ ├── TentBlur.shader.meta │ ├── TiltShift.shader │ └── TiltShift.shader.meta ├── Glitch.meta └── Glitch │ ├── AnalogNoise.shader │ ├── AnalogNoise.shader.meta │ ├── RGBSplit.shader │ ├── RGBSplit.shader.meta │ ├── ScanLineJitter.shader │ ├── ScanLineJitter.shader.meta │ ├── WaveJitter.shader │ └── WaveJitter.shader.meta ├── Volumes.meta └── Volumes ├── Blur.meta ├── Blur ├── BlurVolume.asset ├── BlurVolume.asset.meta ├── Bokeh.cs ├── Bokeh.cs.meta ├── GaussianBlur.cs ├── GaussianBlur.cs.meta ├── IrisBlur.cs ├── IrisBlur.cs.meta ├── Kawase.cs ├── Kawase.cs.meta ├── TentBlur.cs ├── TentBlur.cs.meta ├── TiltShift.cs └── TiltShift.cs.meta ├── CustomPostVolume.cs ├── CustomPostVolume.cs.meta ├── Glitch.meta ├── Glitch ├── AnalogNoise.cs ├── AnalogNoise.cs.meta ├── GlitchVolume 1.asset ├── GlitchVolume 1.asset.meta ├── RGBSplit.cs ├── RGBSplit.cs.meta ├── ScanLineJitter.cs ├── ScanLineJitter.cs.meta ├── WaveJitter.cs └── WaveJitter.cs.meta ├── PostVolumeBase.cs └── PostVolumeBase.cs.meta /FluidSim-VotexConfinement/Advection.shader: -------------------------------------------------------------------------------- 1 | Shader "VortexStreet/AdvectionVelocity_K" 2 | { 3 | Properties 4 | { 5 | VelocityTex("VelocityTex", 2D) = "white" {} 6 | QuantityTex("Quantity", 2D) = "white" {} 7 | BlockTex("BlockTex", 2D) = "white" {} 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | // make fog work 19 | #pragma multi_compile_fog 20 | 21 | #include "UnityCG.cginc" 22 | 23 | struct appdata 24 | { 25 | float4 vertex : POSITION; 26 | float2 uv : TEXCOORD0; 27 | }; 28 | 29 | struct v2f 30 | { 31 | float2 uv : TEXCOORD0; 32 | UNITY_FOG_COORDS(1) 33 | float4 vertex : SV_POSITION; 34 | }; 35 | 36 | sampler2D VelocityTex; 37 | sampler2D BlockTex; 38 | float4 VelocityTex_TexelSize; 39 | sampler2D QuantityTex; 40 | 41 | float dt; 42 | 43 | v2f vert (appdata v) 44 | { 45 | v2f o; 46 | o.vertex = UnityObjectToClipPos(v.vertex); 47 | o.uv = v.uv; 48 | return o; 49 | } 50 | float4 frag(v2f i) :SV_Target{ 51 | float4 col = float4(1,1,1,1); 52 | // backtrace 53 | float2 last_pos = i.uv - dt*tex2D(VelocityTex, i.uv); 54 | // semi-Lagrangian: bi-linear interpolation 55 | col.xy = tex2D(QuantityTex, last_pos).xy; // advection: q = q 56 | 57 | // fluid-solid coupling 58 | if(tex2D(BlockTex, i.uv).x > 0.99f)col.xy = float2(0.0f, 0.0f); 59 | 60 | if (i.uv.x < 0.01f)col.xy = float2(1.0f, 0.0f); 61 | if (i.uv.x > 0.99f)col.xy = float2(-0.8f, 0.3); 62 | return col; 63 | } 64 | ENDCG 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/Block.shader: -------------------------------------------------------------------------------- 1 | Shader "Vortex/Block_K" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags { "RenderType"="Opaque" } 10 | LOD 100 11 | 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vert 16 | #pragma fragment frag 17 | // make fog work 18 | #pragma multi_compile_fog 19 | 20 | #include "UnityCG.cginc" 21 | 22 | struct appdata 23 | { 24 | float4 vertex : POSITION; 25 | float2 uv : TEXCOORD0; 26 | }; 27 | 28 | struct v2f 29 | { 30 | float2 uv : TEXCOORD0; 31 | UNITY_FOG_COORDS(1) 32 | float4 vertex : SV_POSITION; 33 | }; 34 | 35 | sampler2D _MainTex; 36 | float4 _MainTex_ST; 37 | 38 | v2f vert (appdata v) 39 | { 40 | v2f o; 41 | o.vertex = UnityObjectToClipPos(v.vertex); 42 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 43 | UNITY_TRANSFER_FOG(o,o.vertex); 44 | return o; 45 | } 46 | 47 | fixed4 frag (v2f i) : SV_Target 48 | { 49 | // sample the texture 50 | fixed4 col = tex2D(_MainTex, i.uv); 51 | // apply fog 52 | UNITY_APPLY_FOG(i.fogCoord, col); 53 | return col; 54 | } 55 | ENDCG 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/DisplayRainow.shader: -------------------------------------------------------------------------------- 1 | Shader "VortexStreet/DisplayRainow" 2 | { 3 | Properties 4 | { 5 | _MainTex("Texture", 2D) = "white" {} 6 | BlockTex("BlockTex", 2D) = "white" {} 7 | } 8 | SubShader 9 | { 10 | Tags { "RenderType"="Opaque" } 11 | LOD 100 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | // make fog work 19 | #pragma multi_compile_fog 20 | 21 | #include "UnityCG.cginc" 22 | 23 | struct appdata 24 | { 25 | float4 vertex : POSITION; 26 | float2 uv : TEXCOORD0; 27 | }; 28 | 29 | struct v2f 30 | { 31 | float2 uv : TEXCOORD0; 32 | UNITY_FOG_COORDS(1) 33 | float4 vertex : SV_POSITION; 34 | }; 35 | 36 | sampler2D _MainTex; 37 | float4 _MainTex_ST; 38 | sampler2D BlockTex; 39 | 40 | v2f vert (appdata v) 41 | { 42 | v2f o; 43 | o.vertex = UnityObjectToClipPos(v.vertex); 44 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 45 | UNITY_TRANSFER_FOG(o,o.vertex); 46 | return o; 47 | } 48 | 49 | float4 frag (v2f i) : SV_Target 50 | { 51 | float4 col = tex2D(_MainTex, i.uv); 52 | float x = (col.x + 1.0) / 2;//value的值在-1到1之间,x的值在0到1之间 53 | if (x < 0.25) col = float4(0.0, 4.0 * x, 1.0, 1.0f); 54 | else if (x < 0.5) col = float4(0.0, 1.0, 1.0 + 4.0 * (0.25 - x), 1.0f); 55 | else if (x < 0.75) col = float4(4.0 * (x - 0.5), 1.0, 0.0, 1.0f); 56 | else col = float4(1.0, 1.0 + 4.0 * (0.75 - x), 0.0,1.0f); 57 | if (tex2D(BlockTex, i.uv).x > 0.9f)col = float4(0.0f, 0.0f, 0.0f, 1.0f); 58 | return col; 59 | } 60 | ENDCG 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/Divergence.shader: -------------------------------------------------------------------------------- 1 | Shader "EulerEquation/Divergence" 2 | { 3 | Properties 4 | { 5 | 6 | _MainTex("Texture", 2D) = "white" {} 7 | _VelocityTex("Texture", 2D) = "white" {} 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | LOD 100 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | // make fog work 20 | #pragma multi_compile_fog 21 | 22 | #include "UnityCG.cginc" 23 | 24 | struct appdata 25 | { 26 | float4 vertex : POSITION; 27 | float2 uv : TEXCOORD0; 28 | }; 29 | 30 | struct v2f 31 | { 32 | float2 uv : TEXCOORD0; 33 | UNITY_FOG_COORDS(1) 34 | float4 vertex : SV_POSITION; 35 | }; 36 | 37 | 38 | sampler2D _MainTex; 39 | sampler2D _VelocityTex; 40 | float2 _VelocityTex_TexelSize; 41 | float2 _MainTex_TexelSize; 42 | float4 _MainTex_ST; 43 | 44 | v2f vert (appdata v) 45 | { 46 | v2f o; 47 | o.vertex = UnityObjectToClipPos(v.vertex); 48 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 49 | UNITY_TRANSFER_FOG(o,o.vertex); 50 | return o; 51 | } 52 | 53 | fixed4 frag (v2f i) : SV_Target 54 | { 55 | float Top = tex2D(_VelocityTex, i.uv + float2(0.0f, _VelocityTex_TexelSize.y)).y; 56 | float Bottom = tex2D(_VelocityTex, i.uv + float2(0.0f, -_VelocityTex_TexelSize.y)).y; 57 | float Right = tex2D(_VelocityTex, i.uv + float2(_VelocityTex_TexelSize.x, 0.0f)).x; 58 | float Left = tex2D(_VelocityTex, i.uv + float2(-_VelocityTex_TexelSize.x, 0.0f)).x; 59 | float divergence = 0.5f * (Right - Left + Top - Bottom); // delta x = 1 60 | return float4(divergence, 0.0f, 0.0f, 0.0f); 61 | } 62 | ENDCG 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/Pressure.shader: -------------------------------------------------------------------------------- 1 | Shader "Smoke2d/Pressure_S" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | PressureTex("PressureTex", 2D) = "white" {} 7 | DivergenceTex("DivergenceTex", 2D) = "white" {} 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | LOD 100 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | // make fog work 20 | #pragma multi_compile_fog 21 | 22 | #include "UnityCG.cginc" 23 | 24 | struct appdata 25 | { 26 | float4 vertex : POSITION; 27 | float2 uv : TEXCOORD0; 28 | }; 29 | 30 | struct v2f 31 | { 32 | float2 uv : TEXCOORD0; 33 | UNITY_FOG_COORDS(1) 34 | float4 vertex : SV_POSITION; 35 | }; 36 | 37 | sampler2D PressureTex; 38 | sampler2D DivergenceTex; 39 | float4 PressureTex_TexelSize; 40 | sampler2D _MainTex; 41 | float4 _MainTex_ST; 42 | 43 | v2f vert (appdata v) 44 | { 45 | v2f o; 46 | o.vertex = UnityObjectToClipPos(v.vertex); 47 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 48 | UNITY_TRANSFER_FOG(o,o.vertex); 49 | return o; 50 | } 51 | 52 | float4 frag(v2f i) :SV_Target{ 53 | float L = tex2D(PressureTex,saturate(i.uv - float2(PressureTex_TexelSize.x,0.0f))).x; 54 | float R = tex2D(PressureTex,saturate(i.uv + float2(PressureTex_TexelSize.x, 0.0f))).x; 55 | float T = tex2D(PressureTex,saturate(i.uv + float2(0.0f, PressureTex_TexelSize.y))).x; 56 | float B = tex2D(PressureTex,saturate(i.uv - float2(0.0f, PressureTex_TexelSize.y))).x; 57 | 58 | float C = tex2D(PressureTex,i.uv).x; 59 | 60 | float divergence = tex2D(DivergenceTex,i.uv).x; 61 | // Jacobi Iteration 62 | float pressure = (L + R + B + T - divergence) * 0.25; 63 | return float4(pressure,0.,0.,1.); 64 | } 65 | ENDCG 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/Substract.shader: -------------------------------------------------------------------------------- 1 | Shader "Smoke2d/Substract" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | VelocityTex("VelocityTex", 2D) = "white" {} 7 | PressureTex ("Tex_Pressure", 2D) = "white" {} 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | LOD 100 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | // make fog work 20 | #pragma multi_compile_fog 21 | 22 | #include "UnityCG.cginc" 23 | 24 | struct appdata 25 | { 26 | float4 vertex : POSITION; 27 | float2 uv : TEXCOORD0; 28 | }; 29 | 30 | struct v2f 31 | { 32 | float2 uv : TEXCOORD0; 33 | UNITY_FOG_COORDS(1) 34 | float4 vertex : SV_POSITION; 35 | }; 36 | 37 | sampler2D PressureTex; 38 | sampler2D VelocityTex; 39 | float4 PressureTex_TexelSize; 40 | sampler2D _MainTex; 41 | float4 _MainTex_ST; 42 | float dt; 43 | 44 | v2f vert (appdata v) 45 | { 46 | v2f o; 47 | o.vertex = UnityObjectToClipPos(v.vertex); 48 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 49 | UNITY_TRANSFER_FOG(o,o.vertex); 50 | return o; 51 | } 52 | 53 | float4 frag(v2f i) :SV_Target 54 | { 55 | 56 | float L = tex2D(PressureTex,saturate(i.uv - float2(PressureTex_TexelSize.x,0.0f))).x; 57 | float R = tex2D(PressureTex,saturate(i.uv + float2(PressureTex_TexelSize.x, 0.0f))).x; 58 | float T = tex2D(PressureTex,saturate(i.uv + float2(0.0f, PressureTex_TexelSize.y))).x; 59 | float B = tex2D(PressureTex,saturate(i.uv - float2(0.0f, PressureTex_TexelSize.y))).x; 60 | 61 | float2 velocity = tex2D(VelocityTex, i.uv).xy; 62 | velocity.xy -= float2(R - L,T - B); 63 | return float4(velocity,0.,1.); 64 | } 65 | ENDCG 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/VorConfinement.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/VorConfinement" 2 | { 3 | Properties 4 | { 5 | VelocityTex ("VelocityTex", 2D) = "white" {} 6 | VorticityTex ("VorticityTex", 2D) = "white" {} 7 | } 8 | SubShader 9 | { 10 | Tags { "RenderType"="Opaque" } 11 | 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vert 16 | #pragma fragment frag 17 | 18 | #include "UnityCG.cginc" 19 | 20 | sampler2D VelocityTex; 21 | sampler2D VorticityTex; 22 | 23 | float4 VorticityTex_TexelSize; 24 | float curl_strength; 25 | float dt; 26 | 27 | struct appdata 28 | { 29 | float4 vertex : POSITION; 30 | float2 uv : TEXCOORD0; 31 | }; 32 | 33 | struct v2f 34 | { 35 | float2 uv : TEXCOORD0; 36 | float4 vertex : SV_POSITION; 37 | }; 38 | 39 | 40 | v2f vert (appdata v) 41 | { 42 | v2f o; 43 | o.vertex = UnityObjectToClipPos(v.vertex); 44 | o.uv = v.uv; 45 | return o; 46 | } 47 | 48 | float4 frag (v2f i) : SV_Target 49 | { 50 | float4 col = float4(0,0,0,1); 51 | float L = tex2D(VorticityTex, i.uv - float2(VorticityTex_TexelSize.x, 0.0)).z; 52 | float R = tex2D(VorticityTex, i.uv + float2(VorticityTex_TexelSize.x, 0.0)).z; 53 | float B = tex2D(VorticityTex, i.uv - float2(0.0, VorticityTex_TexelSize.y)).z; 54 | float T = tex2D(VorticityTex, i.uv + float2(0.0, VorticityTex_TexelSize.y)).z; 55 | float C = tex2D(VorticityTex, i.uv).z; 56 | 57 | float2 N = float2(T-B, L-R); 58 | float2 force = curl_strength * C * N/(length(N)+0.01); 59 | 60 | float2 velocity = tex2D(VelocityTex, i.uv).xy; 61 | col.xy = velocity + force * dt; 62 | col.z = 0.0; 63 | return col; 64 | } 65 | ENDCG 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/VortexStreetManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class VortexStreetManager : MonoBehaviour 7 | { 8 | public Material DivergenceMat; 9 | public Material PressureMat; 10 | public Material SubtractMat; 11 | public Material AdvectionVelocityMat; 12 | public Material BlockMat; 13 | public Material DisplayRainbowMat; 14 | public Material VorticityMat; 15 | public Material VorticityConfineMat; 16 | private int TexWidth = Screen.width; 17 | private int TexHeight = Screen.height; 18 | 19 | private RenderTexture VorticityRT; 20 | private RenderTexture DivergenceRT; 21 | private RenderTexture DyeRT; 22 | private RenderTexture DyeRT2; 23 | private RenderTexture VelocityRT; 24 | private RenderTexture VelocityRT2; 25 | private RenderTexture PressureRT; 26 | private RenderTexture PressureRT2; 27 | private RenderTexture InitDyeRT; 28 | private RenderTexture BlockRT; 29 | 30 | 31 | public float dt = 0.01f; 32 | public float curl_strength = 0; 33 | 34 | private void Awake() 35 | { 36 | Application.targetFrameRate = 60; 37 | } 38 | 39 | void Start() 40 | { 41 | DivergenceRT = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.RHalf); DivergenceRT.Create(); 42 | VelocityRT = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.RGHalf); VelocityRT.Create(); 43 | VelocityRT2 = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.RGHalf); VelocityRT2.Create(); 44 | PressureRT = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.RHalf); PressureRT.Create(); 45 | PressureRT2 = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.RHalf); PressureRT2.Create(); 46 | BlockRT = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.ARGBHalf); BlockRT.Create(); 47 | VorticityRT = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.ARGBHalf); VorticityRT.Create(); 48 | 49 | DivergenceRT.filterMode = FilterMode.Bilinear; 50 | VelocityRT.filterMode = FilterMode.Bilinear; 51 | VelocityRT2.filterMode = FilterMode.Bilinear; 52 | PressureRT.filterMode = FilterMode.Bilinear; 53 | PressureRT2.filterMode = FilterMode.Bilinear; 54 | BlockRT.filterMode = FilterMode.Bilinear; 55 | VorticityRT.filterMode = FilterMode.Bilinear; 56 | 57 | PressureRT.wrapMode = TextureWrapMode.Clamp; 58 | PressureRT2.wrapMode = TextureWrapMode.Clamp; 59 | VorticityRT.wrapMode = TextureWrapMode.Clamp; 60 | 61 | Graphics.Blit(null, BlockRT, BlockMat); 62 | } 63 | 64 | void OnRenderImage(RenderTexture source, RenderTexture destination) 65 | { 66 | // Step 1: Advection 67 | // sub-step 1.1: advect the velocity field 68 | AdvectionVelocityMat.SetTexture("VelocityTex", VelocityRT2); 69 | AdvectionVelocityMat.SetTexture("BlockTex", BlockRT); 70 | AdvectionVelocityMat.SetTexture("QuantityTex", VelocityRT2); 71 | AdvectionVelocityMat.SetFloat("dt", dt); 72 | Graphics.Blit(VelocityRT2, VelocityRT, AdvectionVelocityMat); 73 | 74 | // sub-step 1.2: advect the dye field 75 | // TODO: 76 | // sub-step 1.3: swap 77 | Graphics.Blit(VelocityRT, VelocityRT2); 78 | 79 | // Step 2: Add body forces 80 | // for smoke, ignore the gravity force 81 | // for water, ignore the viscose force 82 | 83 | // Step 3: Compute Divergence 84 | DivergenceMat.SetTexture("VelocityTex", VelocityRT2); 85 | Graphics.Blit(VelocityRT2, DivergenceRT, DivergenceMat); 86 | 87 | // Step 4: Vorticity Confinement 88 | // sub-step 4.1: compute vorticity 89 | VorticityMat.SetTexture("VelocityTex", VelocityRT2); 90 | Graphics.Blit(VelocityRT2, VorticityRT, VorticityMat); 91 | // sub-step 4.2: update velocity field 92 | VorticityConfineMat.SetTexture("VelocityTex", VelocityRT2); 93 | VorticityConfineMat.SetTexture("VorticityTex", VorticityRT); 94 | VorticityConfineMat.SetFloat("curl_strength", curl_strength); 95 | VorticityConfineMat.SetFloat("dt", dt); 96 | Graphics.Blit(VelocityRT2, VelocityRT, VorticityConfineMat); 97 | Graphics.Blit(VelocityRT, VelocityRT2); 98 | 99 | // Step 5: Solve poisson's equation: Ap=d 100 | PressureMat.SetTexture("DivergenceTex", DivergenceRT); 101 | for (int i = 0; i < 100; i++) 102 | { 103 | PressureMat.SetTexture("PressureTex", PressureRT2); 104 | Graphics.Blit(PressureRT2, PressureRT, PressureMat); 105 | Graphics.Blit(PressureRT, PressureRT2); 106 | } 107 | 108 | // Step 6: Projection (divergence-free flow) 109 | SubtractMat.SetTexture("PressureTex", PressureRT2); 110 | SubtractMat.SetTexture("VelocityTex", VelocityRT2); 111 | SubtractMat.SetFloat("dt", dt); 112 | Graphics.Blit(VelocityRT2, VelocityRT, SubtractMat); 113 | Graphics.Blit(VelocityRT, VelocityRT2); 114 | 115 | 116 | // Step 7: Display 117 | DisplayRainbowMat.SetTexture("BlockTex", BlockRT); 118 | Graphics.Blit(VelocityRT2, destination, DisplayRainbowMat); 119 | //Graphics.Blit(PressureRT2, destination, DisplayRainbowMat); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /FluidSim-VotexConfinement/Vorticity.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/Vorticity" 2 | { 3 | Properties 4 | { 5 | VelocityTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags { "RenderType"="Opaque" } 10 | 11 | Pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | #include "UnityCG.cginc" 18 | 19 | struct appdata 20 | { 21 | float4 vertex : POSITION; 22 | float2 uv : TEXCOORD0; 23 | }; 24 | 25 | struct v2f 26 | { 27 | float2 uv : TEXCOORD0; 28 | float4 vertex : SV_POSITION; 29 | }; 30 | 31 | sampler2D VelocityTex; 32 | float4 VelocityTex_TexelSize; 33 | 34 | v2f vert (appdata v) 35 | { 36 | v2f o; 37 | o.vertex = UnityObjectToClipPos(v.vertex); 38 | o.uv = v.uv; 39 | UNITY_TRANSFER_FOG(o,o.vertex); 40 | return o; 41 | } 42 | 43 | float4 frag (v2f i) : SV_Target 44 | { 45 | float4 col = float4(0,0,0,1); 46 | float2 L = tex2D(VelocityTex, i.uv - float2(VelocityTex_TexelSize.x, 0.0)).xy; 47 | float2 R = tex2D(VelocityTex, i.uv + float2(VelocityTex_TexelSize.x, 0.0)).xy; 48 | float2 B = tex2D(VelocityTex, i.uv - float2(0.0, VelocityTex_TexelSize.y)).xy; 49 | float2 T = tex2D(VelocityTex, i.uv + float2(0.0, VelocityTex_TexelSize.y)).xy; 50 | 51 | col.xy = float2(0, 0); 52 | col.z = (R.y-L.y - (T.x-B.x)) * 0.5f; // along the z axis 53 | 54 | return col; 55 | } 56 | ENDCG 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /HDRP-Volume-Post/GrayScale.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | using UnityEngine.Rendering.HighDefinition; 4 | using System; 5 | 6 | [Serializable, VolumeComponentMenu("Post-processing/Custom/GrayScale")] 7 | public sealed class GrayScale : CustomPostProcessVolumeComponent, IPostProcessComponent 8 | { 9 | [Tooltip("Controls the intensity of the effect.")] 10 | public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, 0f, 1f); 11 | 12 | Material m_Material; 13 | 14 | public bool IsActive() => m_Material != null && intensity.value > 0f; 15 | 16 | public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; 17 | 18 | public override void Setup() 19 | { 20 | if (Shader.Find("Hidden/Shader/GrayScale") != null) 21 | m_Material = new Material(Shader.Find("Hidden/Shader/GrayScale")); 22 | } 23 | 24 | public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) 25 | { 26 | if (m_Material == null) 27 | return; 28 | 29 | m_Material.SetFloat("_Intensity", intensity.value); 30 | cmd.Blit(source, destination, m_Material, 0); 31 | } 32 | 33 | public override void Cleanup() => CoreUtils.Destroy(m_Material); 34 | 35 | } -------------------------------------------------------------------------------- /HDRP-Volume-Post/GrayScale.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Shader/GrayScale" 2 | { 3 | Properties 4 | { 5 | // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex 6 | _MainTex("Main Texture", 2DArray) = "grey" {} 7 | } 8 | 9 | HLSLINCLUDE 10 | 11 | #pragma target 4.5 12 | #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch 13 | 14 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 15 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" 16 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 17 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl" 18 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl" 19 | 20 | struct Attributes 21 | { 22 | uint vertexID : SV_VertexID; 23 | UNITY_VERTEX_INPUT_INSTANCE_ID 24 | }; 25 | 26 | struct Varyings 27 | { 28 | float4 positionCS : SV_POSITION; 29 | float2 texcoord : TEXCOORD0; 30 | UNITY_VERTEX_OUTPUT_STEREO 31 | 32 | }; 33 | 34 | Varyings Vert(Attributes input) 35 | { 36 | Varyings output; 37 | 38 | UNITY_SETUP_INSTANCE_ID(input); 39 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); 40 | 41 | output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); 42 | output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID); 43 | 44 | return output; 45 | } 46 | 47 | // List of properties to control your post process effect 48 | float _Intensity; 49 | TEXTURE2D_X(_MainTex); 50 | 51 | float4 CustomPostProcess(Varyings input) : SV_Target 52 | { 53 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); 54 | 55 | float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, input.texcoord).xyz; 56 | 57 | // Apply greyscale effect 58 | float3 color = lerp(sourceColor, Luminance(sourceColor), _Intensity); 59 | 60 | return float4(color, 1); 61 | } 62 | 63 | ENDHLSL 64 | 65 | SubShader 66 | { 67 | Pass 68 | { 69 | Name "GrayScale" 70 | 71 | ZWrite Off 72 | ZTest Always 73 | Blend Off 74 | Cull Off 75 | 76 | HLSLPROGRAM 77 | #pragma fragment CustomPostProcess 78 | #pragma vertex Vert 79 | ENDHLSL 80 | } 81 | } 82 | 83 | Fallback Off 84 | } -------------------------------------------------------------------------------- /HDRP-Volume-Post/RGBSplit.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | using UnityEngine.Rendering.HighDefinition; 4 | using System; 5 | 6 | [Serializable, VolumeComponentMenu("Post-processing/Custom/RGBSplit")] 7 | public sealed class RGBSplit : CustomPostProcessVolumeComponent, IPostProcessComponent 8 | { 9 | //float _Frequency; 10 | //float _Speed; 11 | //float _Amount; 12 | //float _RGBSplit; 13 | 14 | [Tooltip("Controls the intensity of the effect.")] 15 | public ClampedFloatParameter _Intensity = new ClampedFloatParameter(0f, 0f, 0.3f); 16 | 17 | 18 | Material m_Material; 19 | 20 | public bool IsActive() => m_Material != null && _Intensity.value > 0f && active; 21 | 22 | public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; 23 | 24 | public override void Setup() 25 | { 26 | if (Shader.Find("Hidden/Shader/RGBSplit") != null) 27 | m_Material = new Material(Shader.Find("Hidden/Shader/RGBSplit")); 28 | } 29 | 30 | public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) 31 | { 32 | if (m_Material == null) 33 | return; 34 | 35 | m_Material.SetFloat("_Intensity", _Intensity.value); 36 | cmd.Blit(source, destination, m_Material, 0); 37 | } 38 | 39 | public override void Cleanup() => CoreUtils.Destroy(m_Material); 40 | } 41 | -------------------------------------------------------------------------------- /HDRP-Volume-Post/RGBSplit.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Shader/RGBSplit" 2 | { 3 | Properties 4 | { 5 | // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex 6 | _MainTex("Main Texture", 2DArray) = "grey" {} 7 | } 8 | 9 | HLSLINCLUDE 10 | 11 | #pragma target 4.5 12 | #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch 13 | 14 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 15 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" 16 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 17 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl" 18 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl" 19 | 20 | 21 | float randomNoise(float x, float y) 22 | { 23 | return frac(sin(dot(float2(x, y), float2(12.9898, 78.233))) * 43758.5453); 24 | } 25 | 26 | struct Attributes 27 | { 28 | uint vertexID : SV_VertexID; 29 | UNITY_VERTEX_INPUT_INSTANCE_ID 30 | }; 31 | 32 | struct Varyings 33 | { 34 | float4 positionCS : SV_POSITION; 35 | float2 uv : TEXCOORD0; 36 | UNITY_VERTEX_OUTPUT_STEREO 37 | }; 38 | 39 | Varyings Vert(Attributes input) 40 | { 41 | Varyings output; 42 | UNITY_SETUP_INSTANCE_ID(input); 43 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); 44 | output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); 45 | output.uv = GetFullScreenTriangleTexCoord(input.vertexID); 46 | return output; 47 | } 48 | 49 | // List of properties to control your post process effect 50 | float _Intensity; 51 | TEXTURE2D_X(_MainTex); 52 | 53 | float4 CustomPostProcess(Varyings i) : SV_Target 54 | { 55 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); 56 | 57 | float4 fragColor = float4(0,0,0,1); 58 | 59 | float3 color = float4(0,0,0,0); 60 | 61 | float splitAmount = _Intensity * randomNoise(_Time.y, 2); 62 | 63 | half ColorR = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, float2(i.uv.x + splitAmount, i.uv.y)).x; 64 | half ColorG = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, i.uv).y; 65 | half ColorB = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, float2(i.uv.x - splitAmount, i.uv.y)).z; 66 | 67 | color = float3(ColorR, ColorG, ColorB); 68 | 69 | fragColor.xyz = color.xyz; 70 | 71 | fragColor = saturate(fragColor); 72 | 73 | return fragColor; 74 | } 75 | 76 | ENDHLSL 77 | 78 | SubShader 79 | { 80 | Tags{ "RenderPipeline" = "HDRenderPipeline" } 81 | Pass 82 | { 83 | Name "WaveJitter" 84 | 85 | ZWrite Off 86 | ZTest Always 87 | Blend Off 88 | Cull Off 89 | 90 | HLSLPROGRAM 91 | #pragma fragment CustomPostProcess 92 | #pragma vertex Vert 93 | ENDHLSL 94 | } 95 | } 96 | Fallback Off 97 | } 98 | -------------------------------------------------------------------------------- /HDRP-Volume-Post/ScanLine.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | using UnityEngine.Rendering.HighDefinition; 4 | using System; 5 | 6 | [Serializable, VolumeComponentMenu("Post-processing/Custom/ScanLine")] 7 | public sealed class ScanLine : CustomPostProcessVolumeComponent, IPostProcessComponent 8 | { 9 | [Tooltip("Controls the intensity of the effect.")] 10 | public ClampedFloatParameter _Radius = new ClampedFloatParameter(0f, 0f, 1.0f); 11 | public ClampedFloatParameter _Width = new ClampedFloatParameter(0f, 0.001f, 0.1f); 12 | public Vector4Parameter _Center = new Vector4Parameter(new Vector4(0,0,0,0)); 13 | public ColorParameter _Color = new ColorParameter(Color.white); 14 | public ColorParameter _Color_End = new ColorParameter(Color.white); 15 | 16 | Material m_Material; 17 | 18 | public bool IsActive() => m_Material != null && active && _Radius.value > 0; 19 | 20 | public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; 21 | 22 | public override void Setup() 23 | { 24 | if (Shader.Find("Hidden/Shader/ScanLine") != null) 25 | m_Material = new Material(Shader.Find("Hidden/Shader/ScanLine")); 26 | } 27 | 28 | public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) 29 | { 30 | if (m_Material == null) 31 | return; 32 | 33 | m_Material.SetFloat("_Radius", _Radius.value); 34 | m_Material.SetFloat("_Width", _Width.value); 35 | m_Material.SetVector("_Center", _Center.value); 36 | m_Material.SetColor("_Color", _Color.value); 37 | m_Material.SetColor("_Color_End", _Color_End.value); 38 | cmd.Blit(source, destination, m_Material, 0); 39 | } 40 | 41 | public override void Cleanup() => CoreUtils.Destroy(m_Material); 42 | 43 | } -------------------------------------------------------------------------------- /HDRP-Volume-Post/ScanLine.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Shader/ScanLine" 2 | { 3 | Properties 4 | { 5 | // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex 6 | _MainTex("Main Texture", 2DArray) = "grey" {} 7 | } 8 | 9 | HLSLINCLUDE 10 | 11 | #pragma target 4.5 12 | #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch 13 | 14 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 15 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" 16 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 17 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl" 18 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl" 19 | 20 | float2 grad( int2 z ) // replace this anything that returns a random vector 21 | { 22 | // 2D to 1D (feel free to replace by some other) 23 | int n = z.x+z.y*11111; 24 | 25 | // Hugo Elias hash (feel free to replace by another one) 26 | n = (n<<13)^n; 27 | n = (n*(n*n*15731+789221)+1376312589)>>16; 28 | 29 | #if 0 30 | 31 | // simple random vectors 32 | return float2(cos(float(n)),sin(float(n))); 33 | 34 | #else 35 | 36 | // Perlin style vectors 37 | n &= 7; 38 | float2 gr = float2(n&1,n>>1)*2.0-1.0; 39 | return ( n>=6 ) ? float2(0.0,gr.x) : 40 | ( n>=4 ) ? float2(gr.x,0.0) : 41 | gr; 42 | #endif 43 | } 44 | float GradientNoise( in float2 p ) 45 | { 46 | int2 i = int2(floor( p )); 47 | float2 f = frac( p ); 48 | 49 | float2 u = f*f*(3.0-2.0*f); // feel free to replace by a quintic smoothstep instead 50 | 51 | return lerp( lerp( dot( grad( i+int2(0,0) ), f-float2(0.0,0.0) ), 52 | dot( grad( i+int2(1,0) ), f-float2(1.0,0.0) ), u.x), 53 | lerp( dot( grad( i+int2(0,1) ), f-float2(0.0,1.0) ), 54 | dot( grad( i+int2(1,1) ), f-float2(1.0,1.0) ), u.x), u.y); 55 | } 56 | 57 | 58 | struct Attributes 59 | { 60 | uint vertexID : SV_VertexID; 61 | UNITY_VERTEX_INPUT_INSTANCE_ID 62 | }; 63 | 64 | struct Varyings 65 | { 66 | float4 positionCS : SV_POSITION; 67 | float2 texcoord : TEXCOORD0; 68 | UNITY_VERTEX_OUTPUT_STEREO 69 | 70 | }; 71 | 72 | Varyings Vert(Attributes input) 73 | { 74 | Varyings output; 75 | 76 | UNITY_SETUP_INSTANCE_ID(input); 77 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); 78 | 79 | output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); 80 | output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID); 81 | 82 | return output; 83 | } 84 | 85 | // List of properties to control your post process effect 86 | float _Radius; 87 | float _Width; 88 | float4 _Center; 89 | float4 _Color; 90 | float4 _Color_End; 91 | TEXTURE2D_X(_MainTex); 92 | 93 | float4 CustomPostProcess(Varyings input) : SV_Target 94 | { 95 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); 96 | 97 | float4 fragColor = float4(1,1,1,1); 98 | 99 | _Radius = pow(frac(_Radius + _Time.y*0.1f), 2); 100 | 101 | float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, input.texcoord).xyz; 102 | 103 | float depth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, input.texcoord).x; 104 | float3 worldPos = ComputeWorldSpacePosition(input.texcoord, depth, UNITY_MATRIX_I_VP); 105 | worldPos += _WorldSpaceCameraPos; 106 | 107 | 108 | // :: Test :: 109 | // uint scale = 10; 110 | // // Scale, mirror and snap the coordinates. 111 | // uint3 worldIntPos = uint3(abs(worldPos.xyz * scale)); 112 | // // Divide the surface into squares. Calculate the color ID value. 113 | // bool white = ((worldIntPos.x) & 1) ^ (worldIntPos.y & 1) ^ (worldIntPos.z & 1); 114 | // // Color the square based on the ID value (black or white). 115 | // half4 color = white ? half4(1,1,1,1) : half4(0,0,0,1); 116 | // 117 | // // Set the color to black in the proximity to the far clipping 118 | // if(depth < 0.0001) 119 | // return half4(0,0,0,1); 120 | // 121 | // fragColor = color; 122 | 123 | 124 | fragColor.xyz = length(worldPos); 125 | 126 | float maxDis = 500.0f; 127 | float dis = distance(worldPos, _Center) / maxDis; 128 | float delta = smoothstep(_Radius-_Width, _Radius+_Width, dis)*(1-step(_Radius, dis)); 129 | 130 | fragColor.xyz = sourceColor + pow(delta * lerp(_Color*3.0, _Color_End*3.0, dis * 20.f), 3.0); 131 | return fragColor; 132 | } 133 | 134 | ENDHLSL 135 | 136 | SubShader 137 | { 138 | Pass 139 | { 140 | Name "ScanLine" 141 | 142 | ZWrite Off 143 | ZTest Always 144 | Blend Off 145 | Cull Off 146 | 147 | HLSLPROGRAM 148 | #pragma fragment CustomPostProcess 149 | #pragma vertex Vert 150 | ENDHLSL 151 | } 152 | } 153 | 154 | Fallback Off 155 | } -------------------------------------------------------------------------------- /HDRP-Volume-Post/WaveJitter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | using UnityEngine.Rendering.HighDefinition; 4 | using System; 5 | 6 | [Serializable, VolumeComponentMenu("Post-processing/Custom/WaveJitter")] 7 | public sealed class WaveJitter : CustomPostProcessVolumeComponent, IPostProcessComponent 8 | { 9 | //float _Frequency; 10 | //float _Speed; 11 | //float _Amount; 12 | //float _RGBSplit; 13 | 14 | [Tooltip("Controls the intensity of the effect.")] 15 | public ClampedFloatParameter _Frequency = new ClampedFloatParameter(0f, 0f, 1f); 16 | public ClampedFloatParameter _Speed = new ClampedFloatParameter(0f, 0f, 1f); 17 | public ClampedFloatParameter _Amount = new ClampedFloatParameter(0f, 0f, 1f); 18 | public ClampedFloatParameter _RGBSplit = new ClampedFloatParameter(0f, 0f, 1f); 19 | 20 | 21 | Material m_Material; 22 | 23 | public bool IsActive() => m_Material != null && _Frequency.value > 0f && active; 24 | 25 | public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; 26 | 27 | public override void Setup() 28 | { 29 | if (Shader.Find("Hidden/Shader/WaveJitter") != null) 30 | m_Material = new Material(Shader.Find("Hidden/Shader/WaveJitter")); 31 | } 32 | 33 | public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) 34 | { 35 | if (m_Material == null) 36 | return; 37 | 38 | m_Material.SetFloat("_Frequency", _Frequency.value); 39 | m_Material.SetFloat("_Speed", _Speed.value); 40 | m_Material.SetFloat("_Amount", _Amount.value); 41 | m_Material.SetFloat("_RGBSplit", _RGBSplit.value); 42 | cmd.Blit(source, destination, m_Material, 0); 43 | } 44 | 45 | public override void Cleanup() => CoreUtils.Destroy(m_Material); 46 | } 47 | -------------------------------------------------------------------------------- /HDRP-Volume-Post/WaveJitter.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Shader/WaveJitter" 2 | { 3 | Properties 4 | { 5 | // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex 6 | _MainTex("Main Texture", 2DArray) = "grey" {} 7 | } 8 | 9 | HLSLINCLUDE 10 | 11 | #pragma target 4.5 12 | #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch 13 | 14 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" 15 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" 16 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" 17 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl" 18 | #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl" 19 | 20 | float _Frequency; 21 | float _Speed; 22 | float _Amount; 23 | float _RGBSplit; 24 | 25 | float snoise(float2 x) 26 | { 27 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 28 | } 29 | 30 | struct Attributes 31 | { 32 | uint vertexID : SV_VertexID; 33 | UNITY_VERTEX_INPUT_INSTANCE_ID 34 | }; 35 | 36 | struct Varyings 37 | { 38 | float4 positionCS : SV_POSITION; 39 | float2 uv : TEXCOORD0; 40 | UNITY_VERTEX_OUTPUT_STEREO 41 | }; 42 | 43 | Varyings Vert(Attributes input) 44 | { 45 | Varyings output; 46 | UNITY_SETUP_INSTANCE_ID(input); 47 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); 48 | output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); 49 | output.uv = GetFullScreenTriangleTexCoord(input.vertexID); 50 | return output; 51 | } 52 | 53 | // List of properties to control your post process effect 54 | float _Intensity; 55 | TEXTURE2D_X(_MainTex); 56 | 57 | float4 CustomPostProcess(Varyings i) : SV_Target 58 | { 59 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); 60 | 61 | float4 fragColor = float4(0,0,0,1); 62 | 63 | half strength = 0.5 + 0.5 *cos(_Time.y * _Frequency); 64 | 65 | // Prepare UV 66 | float uv_y = i.uv.y * _ScreenParams.y; 67 | float noise_wave_1 = snoise(float2(uv_y * 0.01, _Time.y * _Speed * 20)) * (strength * _Amount * 32.0); 68 | float noise_wave_2 = snoise(float2(uv_y * 0.02, _Time.y * _Speed * 10)) * (strength * _Amount * 4.0); 69 | float noise_wave_x = noise_wave_1 * noise_wave_2 / _ScreenParams.x; 70 | float uv_x = i.uv.x + noise_wave_x; 71 | 72 | float rgbSplit_uv_x = (_RGBSplit * 50 + (20.0 * strength + 1.0)) * noise_wave_x / _ScreenParams.x; 73 | 74 | // Sample RGB Color- 75 | half4 colorG = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, float2(uv_x, i.uv.y)); 76 | half4 colorRB = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, float2(uv_x + rgbSplit_uv_x, i.uv.y)); 77 | 78 | fragColor = half4(colorRB.r, colorG.g, colorRB.b, colorRB.a + colorG.a); 79 | 80 | fragColor = saturate(fragColor); 81 | 82 | return fragColor; 83 | } 84 | 85 | ENDHLSL 86 | 87 | SubShader 88 | { 89 | Tags{ "RenderPipeline" = "HDRenderPipeline" } 90 | Pass 91 | { 92 | Name "WaveJitter" 93 | 94 | ZWrite Off 95 | ZTest Always 96 | Blend Off 97 | Cull Off 98 | 99 | HLSLPROGRAM 100 | #pragma fragment CustomPostProcess 101 | #pragma vertex Vert 102 | ENDHLSL 103 | } 104 | } 105 | Fallback Off 106 | } 107 | -------------------------------------------------------------------------------- /ProcedureAnim-WaterCaustics/Caustics.shader: -------------------------------------------------------------------------------- 1 | Shader "Homework/01_1" 2 | { 3 | Properties 4 | { 5 | _WaveFrequency("Frequency", Range(0.1, 10)) = 3.5 6 | _Speed("Speed", Range(0.1, 3)) = 0.5 7 | _TAU("Scale", Range(1,10)) = 6.28318530718 8 | _Inten("Brightness", Range(0.0005, 0.02)) = 0.005 9 | _FOO("FOO", Range(1,500)) = 250.0 10 | 11 | } 12 | SubShader 13 | { 14 | Tags 15 | { 16 | "RenderPipeline" = "UniversalPipeline" 17 | "LightMode"="UniversalForward" 18 | } 19 | 20 | Pass 21 | { 22 | HLSLPROGRAM 23 | #pragma vertex vert 24 | #pragma fragment frag 25 | 26 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 27 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 28 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 29 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 30 | 31 | CBUFFER_START(UnityPerMaterial) 32 | float _FOO; 33 | float _WaveFrequency; 34 | float _Speed; 35 | float _TAU; 36 | float _Inten; 37 | CBUFFER_END 38 | 39 | 40 | struct Attributes 41 | { 42 | float4 positionOS : SV_POSITION; 43 | float3 normalOS : NORMAL; 44 | float2 uv : TEXCOORD0; 45 | }; 46 | 47 | struct Varyings 48 | { 49 | float3 positionWS : TEXCOORD0; 50 | float4 positionCS : SV_POSITION; 51 | float2 uv : TEXCOORD2; 52 | float3 normalWS : TEXCOORD3; 53 | float4 screenPos : TEXCOORD4; 54 | }; 55 | 56 | Varyings vert(Attributes i) 57 | { 58 | Varyings o; 59 | o.positionWS = TransformObjectToWorld(i.positionOS); 60 | o.positionCS = TransformWorldToHClip(o.positionWS); 61 | o.uv = i.uv; 62 | o.normalWS = TransformObjectToWorldNormal(i.normalOS); 63 | o.screenPos = ComputeScreenPos(o.positionCS); 64 | 65 | return o; 66 | } 67 | 68 | float4 frag(Varyings v) : SV_Target 69 | { 70 | float3 o = float3(1,1,1); 71 | float time = _Time.g * _Speed; 72 | float2 uv = v.screenPos.xy / v.screenPos.w; 73 | 74 | float2 p = uv*_TAU - _FOO; 75 | float2 i = p; 76 | 77 | float c = 1.0; 78 | float inten = _Inten; 79 | 80 | float MAX_ITER = 5; 81 | float n = 0; //0~5 82 | 83 | //0 84 | float t = time * (1.0 - _WaveFrequency/float(n+1)); 85 | i = p + float2(cos(t-i.x)+sin(t+i.y), sin(t-i.y)+cos(t+i.x)); 86 | c += 1.0/(inten*length(float2(p.x / sin(i.x+t), p.y / cos(i.y+t)))); 87 | n++; 88 | 89 | // 1 90 | t = time * (1.0 - _WaveFrequency/float(n+1)); 91 | i = p + float2(cos(t-i.x)+sin(t+i.y), sin(t-i.y)+cos(t+i.x)); 92 | c += 1.0/length(float2(p.x / (sin(i.x+t)/inten), p.y / (cos(i.y+t)/inten))); 93 | n++; 94 | 95 | //2 96 | t = time * (1.0 - _WaveFrequency/float(n+1)); 97 | i = p + float2(cos(t-i.x)+sin(t+i.y), sin(t-i.y)+cos(t+i.x)); 98 | c += 1.0/length(float2(p.x / (sin(i.x+t)/inten), p.y / (cos(i.y+t)/inten))); 99 | n++; 100 | 101 | //3 102 | t = time * (1.0 - _WaveFrequency/float(n+1)); 103 | i = p + float2(cos(t-i.x)+sin(t+i.y), sin(t-i.y)+cos(t+i.x)); 104 | c += 1.0/length(float2(p.x / (sin(i.x+t)/inten), p.y / (cos(i.y+t)/inten))); 105 | n++; 106 | 107 | //4 108 | t = time * (1.0 - _WaveFrequency/float(n+1)); 109 | i = p + float2(cos(t-i.x)+sin(t+i.y), sin(t-i.y)+cos(t+i.x)); 110 | c += 1.0/length(float2(p.x / (sin(i.x+t)/inten), p.y / (cos(i.y+t)/inten))); 111 | 112 | c /= float(MAX_ITER); 113 | c = 1.17-pow(c, 1.4); 114 | o = float3(pow(abs(c), 8.0)*float3(1,1,1)); 115 | o = clamp(o + float3(0.0, 0.35, 0.5), 0.0, 1.0); 116 | 117 | return float4(o,1); 118 | } 119 | 120 | ENDHLSL 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /RayMarching-Cloud/CloudManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CloudManager : MonoBehaviour 6 | { 7 | public Material M_CloudMarching; 8 | 9 | private RenderTexture RT_marchingResult; 10 | 11 | private int TexWidth = Screen.width; 12 | private int TexHeight = Screen.height; 13 | 14 | private void Awake() 15 | { 16 | Application.targetFrameRate = 60; 17 | } 18 | 19 | // Start is called before the first frame update 20 | void Start() 21 | { 22 | RT_marchingResult = new RenderTexture(TexWidth, TexHeight, 0, RenderTextureFormat.ARGBHalf); 23 | RT_marchingResult.Create(); 24 | } 25 | 26 | // Update is called once per frame 27 | void Update() 28 | { 29 | 30 | } 31 | 32 | private void OnRenderImage(RenderTexture src, RenderTexture dest) 33 | { 34 | if (Input.GetKey(KeyCode.N)) 35 | { 36 | Graphics.Blit(null, RT_marchingResult, M_CloudMarching); 37 | } 38 | Graphics.Blit(RT_marchingResult, dest); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /RayMarching-Cloud/CloudMarching.shader: -------------------------------------------------------------------------------- 1 | Shader "Rendering/CloudMarching" 2 | { 3 | Properties 4 | { 5 | } 6 | SubShader 7 | { 8 | Tags { "RenderType"="Opaque" } 9 | 10 | Pass 11 | { 12 | CGPROGRAM 13 | #pragma vertex vert 14 | #pragma fragment frag 15 | 16 | #include "UnityCG.cginc" 17 | 18 | float3x3 m = float3x3( 0.00, 0.80, 0.60, 19 | -0.80, 0.36, -0.48, 20 | -0.60, -0.48, 0.64 ); 21 | float hash( float n ) 22 | { 23 | return frac(sin(n)*43758.5453); 24 | } 25 | 26 | //梯度噪声产生的纹理具有连续性,所以经常用来模拟山脉、云朵等具有连续性的物质,该类噪声的典型代表是Perlin Noise。 27 | float noise( in float3 x ) 28 | { 29 | float3 p = floor(x); 30 | float3 f = frac(x); 31 | 32 | f = f*f*(3.0-2.0*f); //老版一维perlin noise 33 | //https://blog.csdn.net/candycat1992/article/details/50346469 34 | //https://zhuanlan.zhihu.com/p/68507311 35 | 36 | float n = p.x + p.y*57.0 + 113.0*p.z; 37 | 38 | float res = lerp(lerp(lerp( hash(n+ 0.0), hash(n+ 1.0),f.x), 39 | lerp( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), 40 | lerp(lerp( hash(n+113.0), hash(n+114.0),f.x), 41 | lerp( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); 42 | return res; 43 | } 44 | 45 | //Fractal Brownian Motion 46 | //分型布朗运动 47 | float fbm( float3 p ) 48 | { 49 | float f; 50 | f = 0.5000f*noise( p ); 51 | p = mul(p,m)*2.02f; 52 | f += 0.2500f*noise( p ); 53 | p = mul(p,m)*2.03f; 54 | f += 0.12500f*noise( p ); 55 | p = mul(p,m)*2.01f; 56 | f += 0.06250f*noise( p ); 57 | return f; 58 | } 59 | ///////////////////////////////////// 60 | 61 | float stepUp(float t, float len, float smo) 62 | { 63 | float tt = fmod(t += smo, len); 64 | float stp = floor(t / len) - 1.0; 65 | return smoothstep(0.0, smo, tt) + stp; 66 | } 67 | 68 | //polynomial smooth minimum 69 | //多项式平滑最小值 70 | //https://zhuanlan.zhihu.com/p/281600585 71 | // iq's smin 72 | float smin( float d1, float d2, float k ) { 73 | float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 ); 74 | return lerp( d2, d1, h ) - k*h*(1.0-h); } 75 | 76 | float sdTorus( float3 p, float2 t ) 77 | { 78 | float2 q = float2(length(p.xz)-t.x,p.y); 79 | return length(q)-t.y; 80 | } 81 | 82 | float sdSphere (float3 p, float3 c, float r) 83 | { 84 | return distance(p,c) - r; 85 | } 86 | 87 | float sdUnion (float sd1, float sd2) 88 | { 89 | return min(sd1, sd2); 90 | } 91 | 92 | 93 | float map( in float3 p ) 94 | { 95 | float3 q = p - float3(0.0,0.5,1.0)*_Time.y; 96 | float f = fbm(q); 97 | 98 | float sd_torus = sdTorus(p * 2.0, float2(6.0, 0.005)); 99 | float sd_sphere1 = sdSphere(p * 2.0+float3(0,-5+8*sin(_Time.y*2.0),0), float3(0,0,0), 0.005); 100 | float sd_sphere2 = sdSphere(p * 2.0+float3(0,-8*sin(_Time.y*2.0),0), float3(0,0,0), 0.005); 101 | 102 | //float sd_sphere1_noise = 1. - sd_sphere1 + f * 3.5; 103 | float sd = sdUnion(sd_sphere1, sd_sphere2); 104 | 105 | float sd_noise = 1. - sd + f * 3.5; 106 | 107 | return min(max(0.0,sd_noise), 1.0); 108 | 109 | 110 | } 111 | 112 | float jitter; 113 | 114 | #define MAX_STEPS 48 115 | #define SHADOW_STEPS 8 116 | #define VOLUME_LENGTH 15. 117 | #define SHADOW_LENGTH 2. 118 | 119 | // https://shaderbits.com/blog/creating-volumetric-ray-marcher 120 | float4 cloudMarch(float3 p, float3 ray) 121 | { 122 | 123 | float stepLength = VOLUME_LENGTH / float(MAX_STEPS); 124 | float shadowStepLength = SHADOW_LENGTH / float(SHADOW_STEPS); 125 | float3 light = normalize(float3(1.0, 2.0, 1.0)); 126 | 127 | float4 sum = float4(0., 0., 0., 1.); 128 | 129 | float3 pos = p + ray * jitter * stepLength; 130 | 131 | for (int i = 0; i < MAX_STEPS; i++) 132 | { 133 | if (sum.a < 0.1) { 134 | break; 135 | } 136 | float d = map(pos); //sdf 137 | 138 | if( d > 0.001) 139 | { 140 | float3 lpos = pos + light * jitter * shadowStepLength; 141 | float shadow = 0.; 142 | 143 | for (int s = 0; s < SHADOW_STEPS; s++) 144 | { 145 | lpos += light * shadowStepLength; 146 | float lsample = map(lpos); 147 | shadow += lsample; 148 | } 149 | 150 | //totalDensity 151 | // = sum(sampleDensity(lpos) * stepSize) 152 | float density = clamp(d * VOLUME_LENGTH / float(MAX_STEPS), 0.0, 1.0); 153 | //density = map() 154 | density = sin(_Time.y * .3 - 1.7) * 1. + 0.9; 155 | 156 | //transmittance 157 | // = exp(density1 * lightAbsorption) 158 | // *exp(density2 * lightAbsorption) 159 | // *...0 160 | float ss = exp(-shadow * SHADOW_LENGTH / float(SHADOW_STEPS) * 1.0); 161 | 162 | sum.rgb += ss * density * float3(1.1, 0.9, .5) * sum.a; 163 | //sum.rgb *= s; 164 | sum.a *= 1.-density; 165 | 166 | sum.rgb += exp(-map(pos + float3(0,0.25,0.0)) * .2) * density * float3(0.15, 0.45, 1.1) * sum.a; 167 | } 168 | pos += ray * stepLength; 169 | } 170 | 171 | //return sum * vec4(1.1, 0.9, .5, 1); 172 | return sum; 173 | } 174 | 175 | float3x3 camera(float3 ro, float3 ta, float cr ) 176 | { 177 | float3 cw = normalize(ta - ro); 178 | float3 cp = float3(sin(cr), cos(cr),0.); 179 | float3 cu = normalize( cross(cw,cp) ); 180 | float3 cv = normalize( cross(cu,cw) ); 181 | return float3x3( cu, cv, cw ); 182 | } 183 | 184 | struct appdata 185 | { 186 | float4 vertex : POSITION; 187 | float2 uv : TEXCOORD0; 188 | }; 189 | 190 | struct v2f 191 | { 192 | float2 uv : TEXCOORD0; 193 | float4 vertex : SV_POSITION; 194 | }; 195 | 196 | float dt; 197 | float4 HeightTex_TexelSize; 198 | 199 | v2f vert (appdata v) 200 | { 201 | v2f o; 202 | o.vertex = UnityObjectToClipPos(v.vertex); 203 | o.uv = v.uv; 204 | return o; 205 | } 206 | float4 frag(v2f i) :SV_Target{ 207 | float2 p = 2*(i.uv-0.5f); //<-1, 1> 208 | //TODO:replace one line 209 | //jitter = hash(p.x + p.y * 57.0 + iTime); 210 | jitter = 0.1; 211 | 212 | float3 ro = float3(cos(_Time.y * .333) * 8.0, -5.5, sin(_Time.y * .333) * 8.0); 213 | float3 ta = float3(0.0, 1., 0.0); 214 | float3x3 c = camera(ro, ta, 0.0); 215 | float3 ray = mul(normalize(float3(p, 1.75)), c); 216 | float4 col = cloudMarch(ro, ray); 217 | float3 result = col.rgb + lerp(float3(0.3, 0.6, 1.0), float3(0.05, 0.35, 1.0), p.y + 0.75) * (col.a); 218 | 219 | float sundot = clamp(dot(ray,normalize(float3(1.0, 2.0, 1.0))),0.0,1.0); 220 | result += 0.4*float3(1.0,0.7,0.3)*pow( sundot, 4.0 ); 221 | 222 | result = pow(result, float3(1,1,1)*(1.0/2.2)); 223 | //result = col.rgb; 224 | return float4(result,1); 225 | } 226 | ENDCG 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /RayMarching-Cloud/M_Cloud.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 8 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: M_Cloud 11 | m_Shader: {fileID: 4800000, guid: bb48aed5a1dd24a47914fdcafdb8ce3a, type: 3} 12 | m_ValidKeywords: [] 13 | m_InvalidKeywords: [] 14 | m_LightmapFlags: 4 15 | m_EnableInstancingVariants: 0 16 | m_DoubleSidedGI: 0 17 | m_CustomRenderQueue: -1 18 | stringTagMap: {} 19 | disabledShaderPasses: [] 20 | m_SavedProperties: 21 | serializedVersion: 3 22 | m_TexEnvs: [] 23 | m_Ints: [] 24 | m_Floats: [] 25 | m_Colors: [] 26 | m_BuildTextureStacks: [] 27 | -------------------------------------------------------------------------------- /URP-DisneyPBR_NPR/C_NPR.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/PBR_NPR" 2 | { 3 | Properties 4 | { 5 | _MainTex ("BaseColor", 2D) = "white" {} 6 | 7 | [Header(PBR Light)][Space(10)] 8 | _WeightPBR("Weight PBR", Range(0, 1))=1.0 9 | _DiffusePBR("Diffuse PBR", Range(0, 1)) = 0.276 10 | _roughness ("Roughness" , Range(0, 1)) = 0.555 11 | _metallic ("Metallic" , Range(0, 1)) = 0.495 12 | _subsurface ("Subsurface" , Range(0, 1)) = 0.467 13 | _anisotropic ("Anisotropic" , Range(0, 1)) = 0 14 | _specular ("Specular" , Range(0, 1)) = 1 15 | _specularTint ("Specular Tint", Range(0, 1)) = 0.489 16 | _sheenTint ("Sheen Tint" , Range(0, 1)) = 0.5 17 | _sheen ("Sheen" , Range(0, 1)) = 0.5 18 | _clearcoat ("Clearcoar" , Range(0, 1)) = 0.5 19 | _clearcoatGloss ("Clearcoat Gloss", Range(0, 1)) = 1 20 | _ior ("index of refraction", Range(0, 10)) = 10 21 | 22 | [Header(NPR Light)][Space(10)] 23 | _WeightNPR("Weight NPR", Range(0, 1))=1.0 24 | _RampTex("Ramp Tex", 2D) = "white" {} 25 | _RampOffset("Ramp Offset", Range(-1,1)) = 0 26 | _StepSmoothness("Step Smoothness", Range(0.01, 0.2)) = 0.05 27 | _NPR_Color1("NPR Color 1", color) = (1,1,1,1) 28 | _NPR_Color2("NPR Color 2", color) = (1,1,1,1) 29 | 30 | 31 | [Header(Env Light)][Space(10)] 32 | _WeightEnvLight("Weight EnvLight", Range(0, 1)) = 0.1 33 | [NoScaleOffset] _Cubemap ("Envmap", cube) = "_Skybox" {} 34 | _CubemapMip ("Envmap Mip", Range(0, 7)) = 0 35 | _IBL_LUT("Precomputed integral LUT", 2D) = "white" {} 36 | _FresnelPow ("FresnelPow", Range(0, 5)) = 1 37 | _FresnelColor ("FresnelColor", Color) = (1,1,1,1) 38 | 39 | [Header(Outline)][Space(10)] 40 | _OutlineColor("Outline Color", color) = (1,1,1,1) 41 | _OutlineWidth("Outline Width", Range(0, 0.2)) = 0.1 42 | 43 | 44 | [Header(Rim Light)][Space(10)] 45 | _RimThickness ("Thickness", Range(0.8, 0.99999)) = 0.88 46 | _RimOffset ("RimOffset", Range(0, 1)) = 0.364 47 | _RimCol ("Rim Color", Color) = (1, 1, 1, 1) 48 | 49 | [Enum(UnityEngine.Rendering.CullMode)]_CullMode("CullMode", float) = 2 50 | _ZOffset("Depth Offset", Range(-500, 500)) = 0 51 | } 52 | SubShader 53 | { 54 | // Depth 55 | Pass 56 | { 57 | Name "DepthOnly" 58 | Tags{"LightMode" = "DepthOnly"} 59 | 60 | ZWrite On 61 | ColorMask 0 62 | Cull[_Cull] 63 | 64 | HLSLPROGRAM 65 | #pragma exclude_renderers gles gles3 glcore 66 | #pragma target 4.5 67 | 68 | #pragma vertex DepthOnlyVertex 69 | #pragma fragment DepthOnlyFragment 70 | 71 | #pragma shader_feature_local_fragment _ALPHATEST_ON 72 | #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 73 | 74 | #pragma multi_compile_instancing 75 | #pragma multi_compile _ DOTS_INSTANCING_ON 76 | 77 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 78 | #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" 79 | ENDHLSL 80 | } 81 | 82 | // Shading 83 | Pass 84 | { 85 | Tags 86 | { 87 | "RenderPipiline"="UniversalPipeline" 88 | "LightMode"="UniversalForward" 89 | "RenderType"="Opaque" 90 | } 91 | 92 | ZWrite On 93 | Offset [_ZOffset], 0 94 | 95 | HLSLPROGRAM 96 | #pragma vertex vert 97 | #pragma fragment frag 98 | 99 | //#pragma shader_feature _Enum_BRDF_Simple _Enum_BRDF_Disney 100 | 101 | #pragma multi_compile _ _MAIN_LIGHT_SHADOWS 102 | #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE 103 | #pragma multi_compile _ _SHADOWS_SOFT 104 | 105 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 106 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 107 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 108 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 109 | 110 | // PBR Light 111 | float _WeightPBR; 112 | float _DiffusePBR; 113 | float _roughness; 114 | float _specular; 115 | float _specularTint; 116 | float _sheenTint; 117 | float _metallic; 118 | float _anisotropic; 119 | float _sheen; 120 | float _clearcoatGloss; 121 | float _subsurface; 122 | float _clearcoat; 123 | float _ior; 124 | 125 | // RimLight 126 | float _RimThickness; 127 | float _RimOffset; 128 | float4 _RimCol; 129 | 130 | // EnvLight 131 | float _WeightEnvLight; 132 | samplerCUBE _Cubemap; 133 | float _CubemapMip; 134 | float _FresnelPow; 135 | float4 _FresnelColor; 136 | 137 | // NPR 138 | float _WeightNPR; 139 | float _RampOffset; 140 | float _StepSmoothness; 141 | float4 _NPR_Color1; 142 | float4 _NPR_Color2; 143 | 144 | TEXTURE2D(_IBL_LUT); 145 | SAMPLER(sampler_IBL_LUT); 146 | 147 | CBUFFER_START(UnityPerMaterial) 148 | 149 | TEXTURE2D(_MainTex); 150 | SAMPLER(sampler_MainTex); 151 | 152 | TEXTURE2D(_RampTex); 153 | SAMPLER(sampler_RampTex); 154 | 155 | TEXTURE2D_X_FLOAT(_CameraDepthTexture); 156 | SAMPLER(sampler_CameraDepthTexture); 157 | 158 | CBUFFER_END 159 | 160 | struct Attributes 161 | { 162 | float4 positionOS : POSITION; 163 | float2 uv : TEXCOORD0; 164 | float4 normalOS : NORMAL; 165 | float4 tangentOS : TANGENT; 166 | }; 167 | 168 | struct Varyings 169 | { 170 | float4 positionCS : POSITION; 171 | float2 uv : TEXCOORD0; 172 | float3 positionWS : TEXCOORD1; 173 | float3 normalWS : TEXCOORD2; 174 | float4 screenPos : TEXCOORD3; 175 | float3 tangentWS : TEXCOORD4; 176 | float3 bitangentWS : TEXCOORD5; 177 | }; 178 | 179 | /// 180 | /// helper 181 | /// 182 | float3 mon2lin(float3 x) 183 | { 184 | return float3(pow(x[0], 2.2), pow(x[1], 2.2), pow(x[2], 2.2)); 185 | } 186 | float sqr(float x) { return x*x; } 187 | 188 | /// 189 | /// PBR direct 190 | /// 191 | 192 | float3 compute_F0(float eta) 193 | { 194 | return pow((eta-1)/(eta+1), 2); 195 | } 196 | float3 F_fresnelSchlick(float VdotH, float3 F0) // F 197 | { 198 | return F0 + (1.0 - F0) * pow(1.0 - VdotH, 5.0); 199 | } 200 | float3 F_SimpleSchlick(float HdotL, float3 F0) 201 | { 202 | return lerp(exp2((-5.55473*HdotL-6.98316)*HdotL), 1, F0); 203 | } 204 | 205 | float SchlickFresnel(float u) 206 | { 207 | float m = clamp(1-u, 0, 1); 208 | float m2 = m*m; 209 | return m2*m2*m; // pow(m,5) 210 | } 211 | float3 fresnelSchlickRoughness(float cosTheta, float3 F0, float roughness) 212 | { 213 | return F0 + (max(float3(1.0 - roughness,1.0 - roughness,1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0); 214 | } 215 | 216 | float GTR1(float NdotH, float a) 217 | { 218 | if (a >= 1) return 1/PI; 219 | float a2 = a*a; 220 | float t = 1 + (a2-1)*NdotH*NdotH; 221 | return (a2-1) / (PI*log(a2)*t); 222 | } 223 | 224 | float D_GTR2(float NdotH, float a) // D 225 | { 226 | float a2 = a*a; 227 | float t = 1 + (a2-1)*NdotH*NdotH; 228 | return a2 / (PI * t*t); 229 | } 230 | 231 | // X: tangent 232 | // Y: bitangent 233 | // ax: roughness along x-axis 234 | float GTR2_aniso(float NdotH, float HdotX, float HdotY, float ax, float ay) 235 | { 236 | return 1 / (PI * ax*ay * sqr( sqr(HdotX/ax) + sqr(HdotY/ay) + NdotH*NdotH )); 237 | } 238 | 239 | float smithG_GGX(float NdotV, float alphaG) 240 | { 241 | float a = alphaG*alphaG; 242 | float b = NdotV*NdotV; 243 | return 1 / (NdotV + sqrt(a + b - a*b)); 244 | } 245 | 246 | float GeometrySchlickGGX(float NdotV, float k) 247 | { 248 | float nom = NdotV; 249 | float denom = NdotV * (1.0 - k) + k; 250 | 251 | return nom / denom; 252 | } 253 | 254 | float G_Smith(float3 N, float3 V, float3 L) 255 | { 256 | float k = pow(_roughness+1, 2)/8; 257 | float NdotV = max(dot(N, V), 0.0); 258 | float NdotL = max(dot(N, L), 0.0); 259 | float ggx1 = GeometrySchlickGGX(NdotV, k); 260 | float ggx2 = GeometrySchlickGGX(NdotL, k); 261 | 262 | return ggx1 * ggx2; 263 | } 264 | 265 | float smithG_GGX_aniso(float NdotV, float VdotX, float VdotY, float ax, float ay) 266 | { 267 | return 1 / (NdotV + sqrt( sqr(VdotX*ax) + sqr(VdotY*ay) + sqr(NdotV) )); 268 | } 269 | 270 | float3 Diffuse_Burley_Disney( float3 DiffuseColor, float Roughness, float NoV, float NoL, float VoH ) 271 | { 272 | float FD90 = 0.5 + 2 * VoH * VoH * Roughness; 273 | float FdV = 1 + (FD90 - 1) * pow(1 - NoV, 5); 274 | float FdL = 1 + (FD90 - 1) * pow(1 - NoL, 5); 275 | return DiffuseColor * ((1 / PI) * FdV * FdL); 276 | } 277 | 278 | float3 Diffuse_Simple(float3 DiffuseColor, float3 F, float NdotL) 279 | { 280 | float3 KD = (1-F)*(1-_metallic); 281 | return KD*DiffuseColor*GetMainLight().color*NdotL; 282 | } 283 | 284 | float SSS( float3 L, float3 V, float3 N, float3 baseColor) 285 | { 286 | float NdotL = dot(N,L); 287 | float NdotV = dot(N,V); 288 | if (NdotL < 0 || NdotV < 0) 289 | { 290 | //NdotL = 0.15f; 291 | } 292 | float3 H = normalize(L+V); 293 | float LdotH = dot(L,H); 294 | 295 | float3 Cdlin = mon2lin(baseColor); 296 | if (NdotL < 0 || NdotV < 0) 297 | { 298 | return (1/PI)*Cdlin * (1-_metallic); 299 | } 300 | 301 | float FL = SchlickFresnel(NdotL), FV = SchlickFresnel(NdotV); 302 | float Fd90 = 0.5 + 2 * LdotH*LdotH * _roughness; 303 | float Fd = lerp(1.0, Fd90, FL) * lerp(1.0, Fd90, FV); 304 | 305 | float Fss90 = LdotH*LdotH*_roughness; 306 | float Fss = lerp(1.0, Fss90, FL) * lerp(1.0, Fss90, FV); 307 | float ss = 1.25 * (Fss * (1 / (NdotL + NdotV) - .5) + .5); 308 | 309 | 310 | return (1/PI) * lerp(Fd, ss, _subsurface)*Cdlin * (1-_metallic); 311 | } 312 | 313 | float3 BRDF_Simple( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 314 | { 315 | float NdotL = dot(N,L); 316 | float NdotV = dot(N,V); 317 | 318 | float3 H = normalize(L+V); 319 | float NdotH = dot(N,H); 320 | float LdotH = dot(L,H); 321 | float VdotH = dot(V,H); 322 | float HdotL = dot(H,L); 323 | 324 | float D; 325 | 326 | if (_anisotropic < 0.1f) 327 | { 328 | D = D_GTR2(NdotH, _roughness); 329 | } 330 | else 331 | { 332 | float aspect = sqrt(1-_anisotropic*.9); 333 | float ax = max(.001, sqr(_roughness)/aspect); 334 | float ay = max(.001, sqr(_roughness)*aspect); 335 | D = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); 336 | } 337 | 338 | //float F = F_fresnelSchlick(VdotH, compute_F0(_ior)); 339 | float3 F = F_SimpleSchlick(HdotL, compute_F0(_ior)); 340 | float G = G_Smith(N,V,L); 341 | 342 | float3 brdf = D*F*G / (4*NdotL*NdotV); 343 | 344 | float3 brdf_diff = Diffuse_Simple(baseColor, F, NdotL); 345 | 346 | return saturate(brdf * GetMainLight().color * NdotL * PI + brdf_diff); 347 | } 348 | 349 | float3 BRDF_Disney( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 350 | { 351 | float NdotL = dot(N,L); 352 | float NdotV = dot(N,V); 353 | 354 | if (NdotL < 0 || NdotV < 0) 355 | { 356 | NdotL=0.1f; 357 | } 358 | 359 | float3 H = normalize(L+V); 360 | float NdotH = dot(N,H); 361 | float LdotH = dot(L,H); 362 | 363 | 364 | float3 Cdlin = mon2lin(baseColor); 365 | float Cdlum = .3*Cdlin.x + .6*Cdlin.y + .1*Cdlin.z; // luminance approx. 366 | 367 | float3 Ctint = Cdlum > 0 ? Cdlin/Cdlum : float3(1,1,1); // normalize lum. to isolate hue+sat 368 | float3 Cspec0 = lerp(_specular*.08*lerp(float3(1,1,1), Ctint, _specularTint), Cdlin, _metallic); 369 | float3 Csheen = lerp(float3(1,1,1), Ctint, _sheenTint); 370 | 371 | // Diffuse fresnel - go from 1 at normal incidence to .5 at grazing 372 | // and mix in diffuse retro-reflection based on roughness 373 | float FL = SchlickFresnel(NdotL), FV = SchlickFresnel(NdotV); 374 | float Fd90 = 0.5 + 2 * LdotH*LdotH * _roughness; 375 | float Fd = lerp(1.0, Fd90, FL) * lerp(1.0, Fd90, FV); 376 | 377 | // Based on Hanrahan-Krueger brdf approximation of isotropic bssrdf 378 | // 1.25 scale is used to (roughly) preserve albedo 379 | // Fss90 used to "flatten" retroreflection based on roughness 380 | float Fss90 = LdotH*LdotH*_roughness; 381 | float Fss = lerp(1.0, Fss90, FL) * lerp(1.0, Fss90, FV); 382 | float ss = 1.25 * (Fss * (1 / (NdotL + NdotV) - .5) + .5); 383 | 384 | // specular 385 | float aspect = sqrt(1-_anisotropic*.9); 386 | float ax = max(.001, sqr(_roughness)/aspect); 387 | float ay = max(.001, sqr(_roughness)*aspect); 388 | float Ds = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); 389 | float FH = SchlickFresnel(LdotH); 390 | float3 Fs = lerp(Cspec0, float3(1,1,1), FH); 391 | float Gs; 392 | Gs = smithG_GGX_aniso(NdotL, dot(L, X), dot(L, Y), ax, ay); 393 | Gs *= smithG_GGX_aniso(NdotV, dot(V, X), dot(V, Y), ax, ay); 394 | 395 | // sheen 396 | float3 Fsheen = FH * _sheen * Csheen; 397 | 398 | // clearcoat (ior = 1.5 -> F0 = 0.04) 399 | float Dr = GTR1(NdotH, lerp(.1,.001,_clearcoatGloss)); 400 | float Fr = lerp(.04, 1.0, FH); 401 | float Gr = smithG_GGX(NdotL, .25) * smithG_GGX(NdotV, .25); 402 | 403 | return saturate(((1/PI) * lerp(Fd, ss, _subsurface)*Cdlin + Fsheen) 404 | * (1-_metallic) 405 | + Gs*Fs*Ds + .25*_clearcoat*Gr*Fr*Dr); 406 | } 407 | 408 | /// 409 | /// PBR indirect 410 | /// 411 | float3 F_Indir(float NdotV,float3 F0,float roughness) 412 | { 413 | float Fre=exp2((-5.55473*NdotV-6.98316)*NdotV); 414 | return F0+Fre*saturate(1-roughness-F0); 415 | } 416 | // sample spherical harmonics 417 | float3 Env_Diffuse(float3 N) 418 | { 419 | real4 SHCoefficients[7]; 420 | SHCoefficients[0] = unity_SHAr; 421 | SHCoefficients[1] = unity_SHAg; 422 | SHCoefficients[2] = unity_SHAb; 423 | SHCoefficients[3] = unity_SHBr; 424 | SHCoefficients[4] = unity_SHBg; 425 | SHCoefficients[5] = unity_SHBb; 426 | SHCoefficients[6] = unity_SHC; 427 | 428 | return max(float3(0, 0, 0), SampleSH9(SHCoefficients, N)); 429 | } 430 | 431 | // sample reflection probe 432 | float3 Env_SpecularProbe(float3 N, float3 V) 433 | { 434 | float3 reflectWS = reflect(-V, N); 435 | float mip = _roughness * (1.7 - 0.7 * _roughness) * 6; 436 | 437 | float4 specColorProbe = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectWS, mip); 438 | float3 decode_specColorProbe = DecodeHDREnvironment(specColorProbe, unity_SpecCube0_HDR); 439 | return decode_specColorProbe; 440 | } 441 | 442 | float3 BRDF_Indirect_Simple( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 443 | { 444 | float3 relfectWS = reflect(-V, N); 445 | float3 env_Cubemap = texCUBElod(_Cubemap, float4(relfectWS, _CubemapMip)).rgb; 446 | float fresnel = pow(max(0.0, 1.0 - dot(N,V)), _FresnelPow); 447 | float3 env_Fresnel = env_Cubemap * fresnel + _FresnelColor * fresnel; 448 | 449 | return env_Fresnel; 450 | } 451 | float3 BRDF_Indirect( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 452 | { 453 | // diff 454 | float3 F = F_Indir(dot(N,V), compute_F0(_ior), _roughness); 455 | float3 env_diff = Env_Diffuse(N)*(1-F)*(1-_metallic)*baseColor; 456 | 457 | // specular 458 | float3 env_specProbe = Env_SpecularProbe(N,V); 459 | float3 Flast = fresnelSchlickRoughness(max(dot(N,V), 0.0), compute_F0(_ior), _roughness); 460 | float2 envBDRF = SAMPLE_TEXTURE2D(_IBL_LUT, sampler_IBL_LUT, float2(dot(N,V), _roughness)).rg; 461 | float3 env_specular = env_specProbe * (Flast * envBDRF.r + envBDRF.g); 462 | 463 | return saturate(env_diff + env_specular); 464 | } 465 | 466 | 467 | Varyings vert(Attributes v) 468 | { 469 | Varyings o; 470 | o.uv = v.uv; 471 | o.positionWS = TransformObjectToWorld(v.positionOS); 472 | o.positionCS = TransformWorldToHClip(o.positionWS); 473 | o.normalWS = TransformObjectToWorldNormal(v.normalOS); 474 | o.screenPos = ComputeScreenPos(o.positionCS); 475 | 476 | o.tangentWS = normalize(mul(unity_ObjectToWorld, float4(v.tangentOS.xyz, 0.0)).xyz); 477 | o.bitangentWS = normalize(cross(o.normalWS, o.tangentWS) * v.tangentOS.w); 478 | 479 | return o; 480 | } 481 | 482 | 483 | float4 frag(Varyings i) : SV_TARGET 484 | { 485 | float4 o = (0,0,0,1); 486 | 487 | // :: initialize :: 488 | Light mainLight = GetMainLight(); 489 | float3 N = normalize(i.normalWS); 490 | float3 L = normalize(mainLight.direction); 491 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.positionWS); 492 | float3 H = normalize(L + V); 493 | float3 X = normalize(i.tangentWS); 494 | float3 Y = normalize(i.bitangentWS); 495 | 496 | float NdotL = dot(N, L); 497 | float NdotV = dot(N, V); 498 | float VdotH = dot(V, H); 499 | 500 | float4 BaseColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); 501 | 502 | 503 | float3 Front = unity_ObjectToWorld._12_22_32; // 角色朝向 504 | 505 | // :: PBR :: 506 | float3 brdf_simple = BRDF_Simple(L, V, N, X, Y, BaseColor); 507 | float3 brdf_disney = BRDF_Disney(L, V, N, X, Y, BaseColor); 508 | float3 sss = SSS(L, V, N, BaseColor); 509 | 510 | float3 pbr_result = brdf_simple; 511 | 512 | 513 | // :: PBR Env Light :: 514 | float3 brdf_env_simple = BRDF_Indirect_Simple(L, V, N, X, Y, BaseColor); 515 | float3 brdf_env = BRDF_Indirect(L, V, N, X, Y, BaseColor); 516 | 517 | float3 env_result = brdf_env; 518 | 519 | // :: NPR :: 520 | float3 npr_ramp = BaseColor * SAMPLE_TEXTURE2D(_RampTex, sampler_RampTex, float2(NdotL/2 + 0.5 + _RampOffset, 0.5f)); 521 | float3 npr_color_2 = BaseColor * lerp(_NPR_Color1, _NPR_Color2, smoothstep(_RampOffset-_StepSmoothness, _RampOffset+_StepSmoothness, NdotL/2 + 0.5)); 522 | 523 | float3 npr_result = npr_color_2; 524 | 525 | // :: Rim Light :: 526 | float3 normalVS = mul(UNITY_MATRIX_V, float4(N, 0.0)).xyz; 527 | float2 screenPos01 = i.screenPos.xy / i.screenPos.w; 528 | 529 | float2 ScreenUV_Ori = float2(i.positionCS.x / _ScreenParams.x, i.positionCS.y / _ScreenParams.y); 530 | float2 ScreenUV_Off = ScreenUV_Ori + normalVS.xy * _RimOffset*0.01; 531 | 532 | float depthTex_Ori = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, ScreenUV_Ori); 533 | float depthTex_Off = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, ScreenUV_Off); 534 | 535 | float depthOri = Linear01Depth(depthTex_Ori, _ZBufferParams); 536 | float depthOff = Linear01Depth(depthTex_Off, _ZBufferParams); 537 | 538 | float RimThreshold = 1 - _RimThickness; 539 | float diff = depthOff-depthOri; 540 | float rimMask = smoothstep(RimThreshold * 0.001f, RimThreshold * 0.0015f, diff); 541 | 542 | o.xyz = _WeightPBR * pbr_result + _WeightEnvLight * env_result + _WeightNPR * npr_result; 543 | o.xyz = max(o.xyz, rimMask * _RimCol.xyz); 544 | 545 | return o; 546 | } 547 | 548 | ENDHLSL 549 | } 550 | 551 | // Shadow 552 | Pass 553 | { 554 | Name "ShadowCaster" 555 | Tags{"LightMode" = "ShadowCaster"} 556 | 557 | ZWrite On 558 | ZTest LEqual 559 | ColorMask 0 560 | Cull[_Cull] 561 | 562 | HLSLPROGRAM 563 | #pragma exclude_renderers gles gles3 glcore 564 | #pragma target 4.5 565 | 566 | #pragma shader_feature_local_fragment _ALPHATEST_ON 567 | #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 568 | 569 | #pragma multi_compile_instancing 570 | #pragma multi_compile _ DOTS_INSTANCING_ON 571 | 572 | #pragma vertex ShadowPassVertex 573 | #pragma fragment ShadowPassFragment 574 | 575 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 576 | 577 | #ifndef UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED 578 | #define UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED 579 | 580 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 581 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 582 | 583 | float3 _LightDirection; 584 | 585 | struct Attributes 586 | { 587 | float4 positionOS : POSITION; 588 | float3 normalOS : NORMAL; 589 | float2 texcoord : TEXCOORD0; 590 | UNITY_VERTEX_INPUT_INSTANCE_ID 591 | }; 592 | 593 | struct Varyings 594 | { 595 | float4 positionCS : SV_POSITION; 596 | }; 597 | 598 | float4 GetShadowPositionHClipSpace(Attributes input) 599 | { 600 | float3 positionWS = TransformObjectToWorld(input.positionOS.xyz); 601 | float3 normalWS = TransformObjectToWorldNormal(input.normalOS); 602 | 603 | float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection)); 604 | 605 | return positionCS; 606 | 607 | } 608 | 609 | Varyings ShadowPassVertex(Attributes input) 610 | { 611 | Varyings output; 612 | UNITY_SETUP_INSTANCE_ID(input); 613 | 614 | output.positionCS = GetShadowPositionHClipSpace(input); 615 | return output; 616 | } 617 | 618 | half4 ShadowPassFragment(Varyings input) : SV_TARGET 619 | { 620 | return 0; 621 | } 622 | 623 | #endif 624 | 625 | 626 | ENDHLSL 627 | } 628 | 629 | Pass 630 | { 631 | Name "Outline" 632 | 633 | Cull [_CullMode] 634 | 635 | HLSLPROGRAM 636 | #pragma vertex vert 637 | #pragma fragment frag 638 | 639 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 640 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 641 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 642 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 643 | 644 | float4 _OutlineColor; 645 | float _OutlineWidth; 646 | 647 | struct Attributes 648 | { 649 | float4 positionOS : POSITION; 650 | float3 normalOS : NORMAL; 651 | }; 652 | 653 | struct Varyings 654 | { 655 | float4 positionCS : SV_POSITION; 656 | }; 657 | 658 | Varyings vert(Attributes v) 659 | { 660 | Varyings o; 661 | o.positionCS = TransformObjectToHClip(v.positionOS + v.normalOS * _OutlineWidth); 662 | return o; 663 | } 664 | float4 frag(Varyings i) : SV_TARGET 665 | { 666 | return _OutlineColor; 667 | } 668 | ENDHLSL 669 | } 670 | } 671 | FallBack "Diffuse" 672 | } 673 | -------------------------------------------------------------------------------- /URP-DisneyPBR_NPR/C_PBR.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/PBR_Raw" 2 | { 3 | Properties 4 | { 5 | _MainTex ("BaseColor", 2D) = "white" {} 6 | 7 | 8 | [Header(PBR Light)][Space(10)] 9 | _WeightPBR("Weight PBR", Range(0, 1))=1.0 10 | _DiffusePBR("Diffuse PBR", Range(0, 1)) = 0.3 11 | _roughness ("Roughness" , Range(0, 1)) = 0.5 12 | _metallic ("Metallic" , Range(0, 1)) = 0.5 13 | _subsurface ("Subsurface" , Range(0, 1)) = 0.5 14 | _anisotropic ("Anisotropic" , Range(0, 1)) = 0.5 15 | _specular ("Specular" , Range(0, 1)) = 0.5 16 | _specularTint ("Specular Tint", Range(0, 1)) = 0.5 17 | _sheenTint ("Sheen Tint" , Range(0, 1)) = 0.5 18 | _sheen ("Sheen" , Range(0, 1)) = 0.5 19 | _clearcoat ("Clearcoar" , Range(0, 1)) = 0.5 20 | _clearcoatGloss ("Clearcoat Gloss", Range(0, 1)) = 0.5 21 | _ior ("index of refraction", Range(0, 10)) = 3 22 | 23 | 24 | [Header(Env Light)][Space(10)] 25 | _WeightEnvLight("Weight EnvLight", Range(0, 1)) = 0.1 26 | [NoScaleOffset] _Cubemap ("Envmap", cube) = "_Skybox" {} 27 | _CubemapMip ("Envmap Mip", Range(0, 7)) = 0 28 | _IBL_LUT("Precomputed integral LUT", 2D) = "white" {} 29 | _FresnelPow ("FresnelPow", Range(0, 5)) = 1 30 | _FresnelColor ("FresnelColor", Color) = (1,1,1,1) 31 | 32 | 33 | [Header(Rim Light)][Space(10)] 34 | _RimThickness ("Thickness", Range(0.8, 0.99999)) = 0.88 35 | _RimOffset ("RimOffset", Range(0, 1)) = 0.36 36 | _RimCol ("Rim Color", Color) = (1, 1, 1, 1) 37 | 38 | 39 | _ZOffset("Depth Offset", Range(-500, 500)) = 0 40 | } 41 | SubShader 42 | { 43 | // Depth 44 | Pass 45 | { 46 | Name "DepthOnly" 47 | Tags{"LightMode" = "DepthOnly"} 48 | 49 | ZWrite On 50 | ColorMask 0 51 | Cull[_Cull] 52 | 53 | HLSLPROGRAM 54 | #pragma exclude_renderers gles gles3 glcore 55 | #pragma target 4.5 56 | 57 | #pragma vertex DepthOnlyVertex 58 | #pragma fragment DepthOnlyFragment 59 | 60 | #pragma shader_feature_local_fragment _ALPHATEST_ON 61 | #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 62 | 63 | #pragma multi_compile_instancing 64 | #pragma multi_compile _ DOTS_INSTANCING_ON 65 | 66 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 67 | #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" 68 | ENDHLSL 69 | } 70 | 71 | // Shading 72 | Pass 73 | { 74 | Tags 75 | { 76 | "RenderPipiline"="UniversalPipeline" 77 | "RenderType"="Opaque" 78 | } 79 | 80 | ZWrite On 81 | Offset [_ZOffset], 0 82 | 83 | HLSLPROGRAM 84 | #pragma vertex vert 85 | #pragma fragment frag 86 | 87 | #pragma multi_compile _ _MAIN_LIGHT_SHADOWS 88 | #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE 89 | #pragma multi_compile _ _SHADOWS_SOFT 90 | 91 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 92 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 93 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 94 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 95 | 96 | // PBR Light 97 | float _WeightPBR; 98 | float _DiffusePBR; 99 | float _roughness; 100 | float _specular; 101 | float _specularTint; 102 | float _sheenTint; 103 | float _metallic; 104 | float _anisotropic; 105 | float _sheen; 106 | float _clearcoatGloss; 107 | float _subsurface; 108 | float _clearcoat; 109 | float _ior; 110 | 111 | // RimLight 112 | float _RimThickness; 113 | float _RimOffset; 114 | float4 _RimCol; 115 | 116 | // EnvLight 117 | float _WeightEnvLight; 118 | samplerCUBE _Cubemap; 119 | float _CubemapMip; 120 | float _FresnelPow; 121 | float4 _FresnelColor; 122 | 123 | TEXTURE2D(_IBL_LUT); 124 | SAMPLER(sampler_IBL_LUT); 125 | 126 | CBUFFER_START(UnityPerMaterial) 127 | 128 | TEXTURE2D(_MainTex); 129 | SAMPLER(sampler_MainTex); 130 | 131 | TEXTURE2D_X_FLOAT(_CameraDepthTexture); 132 | SAMPLER(sampler_CameraDepthTexture); 133 | 134 | CBUFFER_END 135 | 136 | struct Attributes 137 | { 138 | float4 positionOS : POSITION; 139 | float2 uv : TEXCOORD0; 140 | float4 normalOS : NORMAL; 141 | float4 tangentOS : TANGENT; 142 | }; 143 | 144 | struct Varyings 145 | { 146 | float4 positionCS : POSITION; 147 | float2 uv : TEXCOORD0; 148 | float3 positionWS : TEXCOORD1; 149 | float3 normalWS : TEXCOORD2; 150 | float4 screenPos : TEXCOORD3; 151 | float3 tangentWS : TEXCOORD4; 152 | float3 bitangentWS : TEXCOORD5; 153 | }; 154 | 155 | /// 156 | /// helper 157 | /// 158 | float3 mon2lin(float3 x) 159 | { 160 | return float3(pow(x[0], 2.2), pow(x[1], 2.2), pow(x[2], 2.2)); 161 | } 162 | float sqr(float x) { return x*x; } 163 | 164 | /// 165 | /// PBR direct 166 | /// 167 | 168 | float3 compute_F0(float eta) 169 | { 170 | return pow((eta-1)/(eta+1), 2); 171 | } 172 | float3 F_fresnelSchlick(float VdotH, float3 F0) // F 173 | { 174 | return F0 + (1.0 - F0) * pow(1.0 - VdotH, 5.0); 175 | } 176 | float3 F_SimpleSchlick(float HdotL, float3 F0) 177 | { 178 | return lerp(exp2((-5.55473*HdotL-6.98316)*HdotL), 1, F0); 179 | } 180 | 181 | float SchlickFresnel(float u) 182 | { 183 | float m = clamp(1-u, 0, 1); 184 | float m2 = m*m; 185 | return m2*m2*m; // pow(m,5) 186 | } 187 | float3 fresnelSchlickRoughness(float cosTheta, float3 F0, float roughness) 188 | { 189 | return F0 + (max(float3(1.0 - roughness,1.0 - roughness,1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0); 190 | } 191 | 192 | float GTR1(float NdotH, float a) 193 | { 194 | if (a >= 1) return 1/PI; 195 | float a2 = a*a; 196 | float t = 1 + (a2-1)*NdotH*NdotH; 197 | return (a2-1) / (PI*log(a2)*t); 198 | } 199 | 200 | float D_GTR2(float NdotH, float a) // D 201 | { 202 | float a2 = a*a; 203 | float t = 1 + (a2-1)*NdotH*NdotH; 204 | return a2 / (PI * t*t); 205 | } 206 | 207 | // X: tangent 208 | // Y: bitangent 209 | // ax: roughness along x-axis 210 | float GTR2_aniso(float NdotH, float HdotX, float HdotY, float ax, float ay) 211 | { 212 | return 1 / (PI * ax*ay * sqr( sqr(HdotX/ax) + sqr(HdotY/ay) + NdotH*NdotH )); 213 | } 214 | 215 | float smithG_GGX(float NdotV, float alphaG) 216 | { 217 | float a = alphaG*alphaG; 218 | float b = NdotV*NdotV; 219 | return 1 / (NdotV + sqrt(a + b - a*b)); 220 | } 221 | 222 | float GeometrySchlickGGX(float NdotV, float k) 223 | { 224 | float nom = NdotV; 225 | float denom = NdotV * (1.0 - k) + k; 226 | 227 | return nom / denom; 228 | } 229 | 230 | float G_Smith(float3 N, float3 V, float3 L) 231 | { 232 | float k = pow(_roughness+1, 2)/8; 233 | float NdotV = max(dot(N, V), 0.0); 234 | float NdotL = max(dot(N, L), 0.0); 235 | float ggx1 = GeometrySchlickGGX(NdotV, k); 236 | float ggx2 = GeometrySchlickGGX(NdotL, k); 237 | 238 | return ggx1 * ggx2; 239 | } 240 | 241 | float smithG_GGX_aniso(float NdotV, float VdotX, float VdotY, float ax, float ay) 242 | { 243 | return 1 / (NdotV + sqrt( sqr(VdotX*ax) + sqr(VdotY*ay) + sqr(NdotV) )); 244 | } 245 | 246 | float3 Diffuse_Burley_Disney( float3 DiffuseColor, float Roughness, float NoV, float NoL, float VoH ) 247 | { 248 | float FD90 = 0.5 + 2 * VoH * VoH * Roughness; 249 | float FdV = 1 + (FD90 - 1) * pow(1 - NoV, 5); 250 | float FdL = 1 + (FD90 - 1) * pow(1 - NoL, 5); 251 | return DiffuseColor * ((1 / PI) * FdV * FdL); 252 | } 253 | 254 | float3 Diffuse_Simple(float3 DiffuseColor, float3 F, float NdotL) 255 | { 256 | float3 KD = (1-F)*(1-_metallic); 257 | return KD*DiffuseColor*GetMainLight().color*NdotL; 258 | } 259 | 260 | float SSS( float3 L, float3 V, float3 N, float3 baseColor) 261 | { 262 | float NdotL = dot(N,L); 263 | float NdotV = dot(N,V); 264 | if (NdotL < 0 || NdotV < 0) 265 | { 266 | //NdotL = 0.15f; 267 | } 268 | float3 H = normalize(L+V); 269 | float LdotH = dot(L,H); 270 | 271 | float3 Cdlin = mon2lin(baseColor); 272 | if (NdotL < 0 || NdotV < 0) 273 | { 274 | return (1/PI)*Cdlin * (1-_metallic); 275 | } 276 | 277 | float FL = SchlickFresnel(NdotL), FV = SchlickFresnel(NdotV); 278 | float Fd90 = 0.5 + 2 * LdotH*LdotH * _roughness; 279 | float Fd = lerp(1.0, Fd90, FL) * lerp(1.0, Fd90, FV); 280 | 281 | float Fss90 = LdotH*LdotH*_roughness; 282 | float Fss = lerp(1.0, Fss90, FL) * lerp(1.0, Fss90, FV); 283 | float ss = 1.25 * (Fss * (1 / (NdotL + NdotV) - .5) + .5); 284 | 285 | 286 | return (1/PI) * lerp(Fd, ss, _subsurface)*Cdlin * (1-_metallic); 287 | } 288 | 289 | float3 BRDF_Simple( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 290 | { 291 | float NdotL = dot(N,L); 292 | float NdotV = dot(N,V); 293 | 294 | float3 H = normalize(L+V); 295 | float NdotH = dot(N,H); 296 | float LdotH = dot(L,H); 297 | float VdotH = dot(V,H); 298 | float HdotL = dot(H,L); 299 | 300 | float D; 301 | 302 | if (_anisotropic < 0.1f) 303 | { 304 | D = D_GTR2(NdotH, _roughness); 305 | } 306 | else 307 | { 308 | float aspect = sqrt(1-_anisotropic*.9); 309 | float ax = max(.001, sqr(_roughness)/aspect); 310 | float ay = max(.001, sqr(_roughness)*aspect); 311 | D = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); 312 | } 313 | 314 | //float F = F_fresnelSchlick(VdotH, compute_F0(_ior)); 315 | float3 F = F_SimpleSchlick(HdotL, compute_F0(_ior)); 316 | float G = G_Smith(N,V,L); 317 | 318 | float3 brdf = D*F*G / (4*NdotL*NdotV); 319 | 320 | float3 brdf_diff = Diffuse_Simple(baseColor, F, NdotL); 321 | 322 | return saturate(brdf * GetMainLight().color * NdotL * PI + brdf_diff); 323 | } 324 | 325 | float3 BRDF_Disney( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 326 | { 327 | float NdotL = dot(N,L); 328 | float NdotV = dot(N,V); 329 | 330 | if (NdotL < 0 || NdotV < 0) 331 | { 332 | NdotL=0.1f; 333 | } 334 | 335 | float3 H = normalize(L+V); 336 | float NdotH = dot(N,H); 337 | float LdotH = dot(L,H); 338 | 339 | 340 | float3 Cdlin = mon2lin(baseColor); 341 | float Cdlum = .3*Cdlin.x + .6*Cdlin.y + .1*Cdlin.z; // luminance approx. 342 | 343 | float3 Ctint = Cdlum > 0 ? Cdlin/Cdlum : float3(1,1,1); // normalize lum. to isolate hue+sat 344 | float3 Cspec0 = lerp(_specular*.08*lerp(float3(1,1,1), Ctint, _specularTint), Cdlin, _metallic); 345 | float3 Csheen = lerp(float3(1,1,1), Ctint, _sheenTint); 346 | 347 | // Diffuse fresnel - go from 1 at normal incidence to .5 at grazing 348 | // and mix in diffuse retro-reflection based on roughness 349 | float FL = SchlickFresnel(NdotL), FV = SchlickFresnel(NdotV); 350 | float Fd90 = 0.5 + 2 * LdotH*LdotH * _roughness; 351 | float Fd = lerp(1.0, Fd90, FL) * lerp(1.0, Fd90, FV); 352 | 353 | // Based on Hanrahan-Krueger brdf approximation of isotropic bssrdf 354 | // 1.25 scale is used to (roughly) preserve albedo 355 | // Fss90 used to "flatten" retroreflection based on roughness 356 | float Fss90 = LdotH*LdotH*_roughness; 357 | float Fss = lerp(1.0, Fss90, FL) * lerp(1.0, Fss90, FV); 358 | float ss = 1.25 * (Fss * (1 / (NdotL + NdotV) - .5) + .5); 359 | 360 | // specular 361 | float aspect = sqrt(1-_anisotropic*.9); 362 | float ax = max(.001, sqr(_roughness)/aspect); 363 | float ay = max(.001, sqr(_roughness)*aspect); 364 | float Ds = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); 365 | float FH = SchlickFresnel(LdotH); 366 | float3 Fs = lerp(Cspec0, float3(1,1,1), FH); 367 | float Gs; 368 | Gs = smithG_GGX_aniso(NdotL, dot(L, X), dot(L, Y), ax, ay); 369 | Gs *= smithG_GGX_aniso(NdotV, dot(V, X), dot(V, Y), ax, ay); 370 | 371 | // sheen 372 | float3 Fsheen = FH * _sheen * Csheen; 373 | 374 | // clearcoat (ior = 1.5 -> F0 = 0.04) 375 | float Dr = GTR1(NdotH, lerp(.1,.001,_clearcoatGloss)); 376 | float Fr = lerp(.04, 1.0, FH); 377 | float Gr = smithG_GGX(NdotL, .25) * smithG_GGX(NdotV, .25); 378 | 379 | return saturate(((1/PI) * lerp(Fd, ss, _subsurface)*Cdlin + Fsheen) 380 | * (1-_metallic) 381 | + Gs*Fs*Ds + .25*_clearcoat*Gr*Fr*Dr); 382 | } 383 | 384 | /// 385 | /// PBR indirect 386 | /// 387 | float3 F_Indir(float NdotV,float3 F0,float roughness) 388 | { 389 | float Fre=exp2((-5.55473*NdotV-6.98316)*NdotV); 390 | return F0+Fre*saturate(1-roughness-F0); 391 | } 392 | // sample spherical harmonics 393 | float3 Env_Diffuse(float3 N) 394 | { 395 | real4 SHCoefficients[7]; 396 | SHCoefficients[0] = unity_SHAr; 397 | SHCoefficients[1] = unity_SHAg; 398 | SHCoefficients[2] = unity_SHAb; 399 | SHCoefficients[3] = unity_SHBr; 400 | SHCoefficients[4] = unity_SHBg; 401 | SHCoefficients[5] = unity_SHBb; 402 | SHCoefficients[6] = unity_SHC; 403 | 404 | return max(float3(0, 0, 0), SampleSH9(SHCoefficients, N)); 405 | } 406 | 407 | // sample reflection probe 408 | float3 Env_SpecularProbe(float3 N, float3 V) 409 | { 410 | float3 reflectWS = reflect(-V, N); 411 | float mip = _roughness * (1.7 - 0.7 * _roughness) * 6; 412 | 413 | float4 specColorProbe = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectWS, mip); 414 | float3 decode_specColorProbe = DecodeHDREnvironment(specColorProbe, unity_SpecCube0_HDR); 415 | return decode_specColorProbe; 416 | } 417 | 418 | float3 BRDF_Indirect_Simple( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 419 | { 420 | float3 relfectWS = reflect(-V, N); 421 | float3 env_Cubemap = texCUBElod(_Cubemap, float4(relfectWS, _CubemapMip)).rgb; 422 | float fresnel = pow(max(0.0, 1.0 - dot(N,V)), _FresnelPow); 423 | float3 env_Fresnel = env_Cubemap * fresnel + _FresnelColor * fresnel; 424 | 425 | return env_Fresnel; 426 | } 427 | float3 BRDF_Indirect( float3 L, float3 V, float3 N, float3 X, float3 Y, float3 baseColor) 428 | { 429 | // diff 430 | float3 F = F_Indir(dot(N,V), compute_F0(_ior), _roughness); 431 | float3 env_diff = Env_Diffuse(N)*(1-F)*(1-_metallic)*baseColor; 432 | 433 | // specular 434 | float3 env_specProbe = Env_SpecularProbe(N,V); 435 | float3 Flast = fresnelSchlickRoughness(max(dot(N,V), 0.0), compute_F0(_ior), _roughness); 436 | float2 envBDRF = SAMPLE_TEXTURE2D(_IBL_LUT, sampler_IBL_LUT, float2(dot(N,V), _roughness)).rg; 437 | float3 env_specular = env_specProbe * (Flast * envBDRF.r + envBDRF.g); 438 | 439 | return saturate(env_diff + env_specular); 440 | } 441 | 442 | 443 | Varyings vert(Attributes v) 444 | { 445 | Varyings o; 446 | o.uv = v.uv; 447 | o.positionWS = TransformObjectToWorld(v.positionOS); 448 | o.positionCS = TransformWorldToHClip(o.positionWS); 449 | o.normalWS = TransformObjectToWorldNormal(v.normalOS); 450 | o.screenPos = ComputeScreenPos(o.positionCS); 451 | 452 | o.tangentWS = normalize(mul(unity_ObjectToWorld, float4(v.tangentOS.xyz, 0.0)).xyz); 453 | o.bitangentWS = normalize(cross(o.normalWS, o.tangentWS) * v.tangentOS.w); 454 | 455 | return o; 456 | } 457 | 458 | 459 | float4 frag(Varyings i) : SV_TARGET 460 | { 461 | float4 o = (0,0,0,1); 462 | 463 | // :: initialize :: 464 | Light mainLight = GetMainLight(); 465 | float3 N = normalize(i.normalWS); 466 | float3 L = normalize(mainLight.direction); 467 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.positionWS); 468 | float3 H = normalize(L + V); 469 | float3 X = normalize(i.tangentWS); 470 | float3 Y = normalize(i.bitangentWS); 471 | 472 | float NdotL = dot(N, L); 473 | float NdotV = dot(N, V); 474 | float VdotH = dot(V, H); 475 | 476 | float4 BaseColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); 477 | 478 | 479 | float3 Front = unity_ObjectToWorld._12_22_32; // 角色朝向 480 | 481 | // :: PBR :: 482 | float3 brdf_simple = BRDF_Simple(L, V, N, X, Y, BaseColor); 483 | float3 brdf_disney = BRDF_Disney(L, V, N, X, Y, BaseColor); 484 | float3 sss = SSS(L, V, N, BaseColor); 485 | 486 | float3 pbr_result = brdf_simple; 487 | 488 | 489 | // :: PBR Env Light :: 490 | float3 brdf_env_simple = BRDF_Indirect_Simple(L, V, N, X, Y, BaseColor); 491 | float3 brdf_env = BRDF_Indirect(L, V, N, X, Y, BaseColor); 492 | 493 | float3 env_result = brdf_env; 494 | 495 | 496 | // :: Rim Light :: 497 | float3 normalVS = mul(UNITY_MATRIX_V, float4(N, 0.0)).xyz; 498 | float2 screenPos01 = i.screenPos.xy / i.screenPos.w; 499 | 500 | float2 ScreenUV_Ori = float2(i.positionCS.x / _ScreenParams.x, i.positionCS.y / _ScreenParams.y); 501 | float2 ScreenUV_Off = ScreenUV_Ori + normalVS.xy * _RimOffset*0.01; 502 | 503 | float depthTex_Ori = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, ScreenUV_Ori); 504 | float depthTex_Off = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, ScreenUV_Off); 505 | 506 | float depthOri = Linear01Depth(depthTex_Ori, _ZBufferParams); 507 | float depthOff = Linear01Depth(depthTex_Off, _ZBufferParams); 508 | 509 | float RimThreshold = 1 - _RimThickness; 510 | float diff = depthOff-depthOri; 511 | float rimMask = smoothstep(RimThreshold * 0.001f, RimThreshold * 0.0015f, diff); 512 | 513 | o.xyz = _WeightPBR * pbr_result + _WeightEnvLight * env_result; 514 | o.xyz = max(o.xyz, rimMask * _RimCol.xyz); 515 | 516 | return o; 517 | } 518 | 519 | ENDHLSL 520 | } 521 | 522 | // Shadow 523 | Pass 524 | { 525 | Name "ShadowCaster" 526 | Tags{"LightMode" = "ShadowCaster"} 527 | 528 | ZWrite On 529 | ZTest LEqual 530 | ColorMask 0 531 | Cull[_Cull] 532 | 533 | HLSLPROGRAM 534 | #pragma exclude_renderers gles gles3 glcore 535 | #pragma target 4.5 536 | 537 | #pragma shader_feature_local_fragment _ALPHATEST_ON 538 | #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 539 | 540 | #pragma multi_compile_instancing 541 | #pragma multi_compile _ DOTS_INSTANCING_ON 542 | 543 | #pragma vertex ShadowPassVertex 544 | #pragma fragment ShadowPassFragment 545 | 546 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 547 | 548 | #ifndef UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED 549 | #define UNIVERSAL_SHADOW_CASTER_PASS_INCLUDED 550 | 551 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 552 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 553 | 554 | float3 _LightDirection; 555 | 556 | struct Attributes 557 | { 558 | float4 positionOS : POSITION; 559 | float3 normalOS : NORMAL; 560 | float2 texcoord : TEXCOORD0; 561 | UNITY_VERTEX_INPUT_INSTANCE_ID 562 | }; 563 | 564 | struct Varyings 565 | { 566 | float4 positionCS : SV_POSITION; 567 | }; 568 | 569 | float4 GetShadowPositionHClipSpace(Attributes input) 570 | { 571 | float3 positionWS = TransformObjectToWorld(input.positionOS.xyz); 572 | float3 normalWS = TransformObjectToWorldNormal(input.normalOS); 573 | 574 | float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection)); 575 | 576 | return positionCS; 577 | 578 | } 579 | 580 | Varyings ShadowPassVertex(Attributes input) 581 | { 582 | Varyings output; 583 | UNITY_SETUP_INSTANCE_ID(input); 584 | 585 | output.positionCS = GetShadowPositionHClipSpace(input); 586 | return output; 587 | } 588 | 589 | half4 ShadowPassFragment(Varyings input) : SV_TARGET 590 | { 591 | return 0; 592 | } 593 | 594 | #endif 595 | 596 | 597 | ENDHLSL 598 | } 599 | } 600 | FallBack "Diffuse" 601 | } 602 | -------------------------------------------------------------------------------- /URP-DisneyPBR_NPR/NormalTool.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | // Referrence:: https://zhuanlan.zhihu.com/p/493802718 7 | public class NormalTool : MonoBehaviour 8 | { 9 | [MenuItem("Tools/Model/模型平均法线写入顶点色,并创建资产")] 10 | public static void WriteAverageNormalToTangentTool() 11 | { 12 | MeshFilter[] meshFilters = Selection.activeGameObject.GetComponentsInChildren(); 13 | foreach (var meshFilter in meshFilters) 14 | { 15 | Mesh mesh = Object.Instantiate(meshFilter.sharedMesh); 16 | WriteAverageNormalToTangent(mesh); 17 | CreateTangentMesh(mesh,meshFilter); 18 | } 19 | 20 | SkinnedMeshRenderer[] skinnedMeshRenders = Selection.activeGameObject.GetComponentsInChildren(); 21 | foreach (var skinnedMeshRender in skinnedMeshRenders) 22 | { 23 | Mesh mesh = Object.Instantiate(skinnedMeshRender.sharedMesh); 24 | WriteAverageNormalToTangent(mesh); 25 | CreateTangentMesh(mesh, skinnedMeshRender); 26 | } 27 | } 28 | private static void WriteAverageNormalToTangent(Mesh rMesh) 29 | { 30 | Dictionary tAverageNormalDic = new Dictionary(); 31 | for (int i = 0; i < rMesh.vertexCount; i++) 32 | { 33 | if (!tAverageNormalDic.ContainsKey(rMesh.vertices[i])) 34 | { 35 | tAverageNormalDic.Add(rMesh.vertices[i], rMesh.normals[i]); 36 | } 37 | else 38 | { 39 | //对当前顶点的所有法线进行平滑处理 40 | tAverageNormalDic[rMesh.vertices[i]] = (tAverageNormalDic[rMesh.vertices[i]] + rMesh.normals[i]).normalized; 41 | } 42 | } 43 | 44 | Vector3[] tAverageNormals = new Vector3[rMesh.vertexCount]; 45 | for (int i = 0; i < rMesh.vertexCount; i++) 46 | { 47 | tAverageNormals[i] = tAverageNormalDic[rMesh.vertices[i]]; 48 | } 49 | 50 | //Vector4[] tTangents = new Vector4[rMesh.vertexCount]; 51 | Color[] tColors = new Color[rMesh.vertexCount]; 52 | for (int i = 0; i < rMesh.vertexCount; i++) 53 | { 54 | //tTangents[i] = new Vector4(tAverageNormals[i].x,tAverageNormals[i].y,tAverageNormals[i].z,0); 55 | tColors[i] = new Color(tAverageNormals[i].x, tAverageNormals[i].y, tAverageNormals[i].z, 0); 56 | } 57 | 58 | rMesh.colors = tColors; 59 | //rMesh.tangents = tTangents; 60 | } 61 | 62 | //在当前路径创建切线模型 63 | private static void CreateTangentMesh(Mesh rMesh, SkinnedMeshRenderer rSkinMeshRenders) 64 | { 65 | string[] path = AssetDatabase.GetAssetPath(rSkinMeshRenders).Split("/"); 66 | string createPath = ""; 67 | for (int i = 0; i < path.Length - 1; i++) 68 | { 69 | createPath += path[i] + "/"; 70 | } 71 | string newMeshPath = createPath + rSkinMeshRenders.name + "_Tangent.mesh"; 72 | Debug.Log("存储模型位置:" + newMeshPath); 73 | AssetDatabase.CreateAsset(rMesh, newMeshPath); 74 | } 75 | //在当前路径创建切线模型 76 | private static void CreateTangentMesh(Mesh rMesh, MeshFilter rMeshFilter) 77 | { 78 | string[] path = AssetDatabase.GetAssetPath(rMeshFilter).Split("/"); 79 | string createPath = ""; 80 | for (int i = 0; i < path.Length - 1; i++) 81 | { 82 | createPath += path[i] + "/"; 83 | } 84 | string newMeshPath = createPath + rMeshFilter.name + "_Tangent.mesh"; 85 | //rMeshFilter.mesh.colors = rMesh.colors; 86 | Debug.Log("存储模型位置:" + newMeshPath); 87 | AssetDatabase.CreateAsset(rMesh, newMeshPath); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /URP-Volume-Post/RenderFeature/PostProcessFeature.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | public class PostProcessFeature : ScriptableRendererFeature 8 | { 9 | class CustomRenderPass : ScriptableRenderPass 10 | { 11 | private List components; 12 | private List activeComponents; 13 | private List profilingSamplers; 14 | 15 | private RenderTargetHandle source; 16 | private RenderTargetHandle destination; 17 | private RenderTargetHandle tempRT0; 18 | private RenderTargetHandle tempRT1; 19 | 20 | public bool SetupComponents() 21 | { 22 | activeComponents.Clear(); 23 | for (int i = 0; i < components.Count; i++) 24 | { 25 | components[i].Setup(); 26 | if (components[i].IsActive()) 27 | { 28 | activeComponents.Add(i); 29 | } 30 | } 31 | return activeComponents.Count != 0; 32 | } 33 | 34 | public void Setup(RenderTargetHandle source, RenderTargetHandle destination) 35 | { 36 | this.source = source; 37 | this.destination = destination; 38 | } 39 | public CustomRenderPass(List volumeComponents) 40 | { 41 | components = volumeComponents; 42 | activeComponents = new List(volumeComponents.Count); 43 | profilingSamplers = volumeComponents.Select(c => new ProfilingSampler(c.ToString())).ToList(); 44 | 45 | tempRT0.Init("_TemporaryRenderTexture0"); 46 | tempRT1.Init("_TemporaryRenderTexture1"); 47 | } 48 | 49 | // Here you can implement the rendering logic. 50 | // Use ScriptableRenderContext to issue drawing commands or execute command buffers 51 | // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html 52 | // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline. 53 | public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) 54 | { 55 | var cmd = CommandBufferPool.Get("Custom PostProcess after PostProcess"); 56 | 57 | var descriptor = renderingData.cameraData.cameraTargetDescriptor; 58 | descriptor.msaaSamples = 1; 59 | descriptor.depthBufferBits = 0; 60 | 61 | RenderTargetIdentifier buff0, buff1; 62 | bool rt1Used = false; 63 | cmd.GetTemporaryRT(tempRT0.id, descriptor); 64 | buff0 = tempRT0.id; 65 | 66 | // 如果destination没有初始化,则需要获取RT,主要是destinaton为_AfterPostProcessTexture的情况 67 | if (destination != RenderTargetHandle.CameraTarget && !destination.HasInternalRenderTargetId()) 68 | { 69 | cmd.GetTemporaryRT(destination.id, descriptor); 70 | } 71 | 72 | 73 | 74 | 75 | cmd.GetTemporaryRT(tempRT1.id, descriptor); 76 | buff1 = tempRT1.id; 77 | rt1Used = true; 78 | 79 | // source -> buff0 80 | cmd.Blit(source.Identifier(), buff0); 81 | for (int i = 0; i < activeComponents.Count; i++) 82 | { 83 | int index = activeComponents[i]; 84 | var component = components[index]; 85 | using (new ProfilingScope(cmd, profilingSamplers[index])) 86 | { 87 | // buff0 -> buff1 88 | component.Render(cmd, ref renderingData, buff0, buff1); 89 | } 90 | // buff1 -> buff0 91 | CoreUtils.Swap(ref buff0, ref buff1); 92 | } 93 | 94 | 95 | // buff0 -> destination 96 | cmd.Blit(buff0, destination.Identifier()); 97 | 98 | 99 | cmd.ReleaseTemporaryRT(tempRT0.id); 100 | if (rt1Used) 101 | cmd.ReleaseTemporaryRT(tempRT1.id); 102 | 103 | context.ExecuteCommandBuffer(cmd); 104 | CommandBufferPool.Release(cmd); 105 | } 106 | 107 | } 108 | 109 | [System.Serializable] 110 | public class Settings 111 | { 112 | public RenderPassEvent passEvent = RenderPassEvent.AfterRenderingPostProcessing; 113 | } 114 | 115 | public Settings settings = new Settings(); 116 | private List components; 117 | CustomRenderPass m_ScriptablePass; 118 | private RenderTargetHandle afterPostProcessTexture; 119 | 120 | /// 121 | public override void Create() 122 | { 123 | var stack = VolumeManager.instance.stack; 124 | components = VolumeManager.instance.baseComponentTypeArray 125 | .Where(t => t.IsSubclassOf(typeof(PostVolumeComponentBase))) 126 | .Select(t => stack.GetComponent(t) as PostVolumeComponentBase) 127 | .ToList(); 128 | m_ScriptablePass = new CustomRenderPass(components); 129 | 130 | // Configures where the render pass should be injected. 131 | m_ScriptablePass.renderPassEvent = settings.passEvent; 132 | 133 | afterPostProcessTexture.Init("_AfterPostProcessTexture"); 134 | } 135 | 136 | // Here you can inject one or multiple render passes in the renderer. 137 | // This method is called when setting up the renderer once per-camera. 138 | public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) 139 | { 140 | if (renderingData.cameraData.postProcessEnabled && m_ScriptablePass.SetupComponents()) 141 | { 142 | var source = new RenderTargetHandle(renderer.cameraColorTarget); 143 | source = renderingData.cameraData.resolveFinalTarget ? afterPostProcessTexture : source; 144 | m_ScriptablePass.Setup(source, source); 145 | renderer.EnqueuePass(m_ScriptablePass); 146 | } 147 | } 148 | } 149 | 150 | 151 | -------------------------------------------------------------------------------- /URP-Volume-Post/RenderFeature/PostProcessFeature.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc116eb5235d0474eb1d5a58015945c5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1e44da25ab7959458ed33cc0a65a36a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 599262351fb4eb84283ef8a7ca7199c9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/Bokeh.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/Bokeh" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Radius; 26 | int _Iteration; 27 | 28 | 29 | 30 | TEXTURE2D(_MainTex); 31 | SAMPLER(sampler_MainTex); 32 | 33 | float4 _MainTex_TexelSize; 34 | 35 | float randomNoise(float x) 36 | { 37 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 38 | } 39 | 40 | 41 | struct Attributes 42 | { 43 | float4 positionOS : POSITION; 44 | float2 uv : TEXCOORD0; 45 | }; 46 | struct Varyings 47 | { 48 | float4 positionCS : POSITION; 49 | float2 uv : TEXCOORD0; 50 | }; 51 | 52 | Varyings vert(Attributes v) 53 | { 54 | Varyings o; 55 | o.positionCS = TransformObjectToHClip(v.positionOS); 56 | o.uv = v.uv; 57 | return o; 58 | } 59 | 60 | float4 frag(Varyings i) : SV_TARGET 61 | { 62 | float4 fragColor = float4(0,0,0,1); 63 | 64 | // :: Golden angle :: 65 | // float c = cos(2.39996323f); 66 | // float s = sin(2.39996323f); 67 | float c = -0.7374; 68 | float s = 0.6755; 69 | 70 | half2x2 rot = half2x2(c, s, -s, c); 71 | half4 accumulator = 0.0; 72 | half4 divisor = 0.0; 73 | 74 | half r = 1.0; 75 | half2 axis = half2(0.0, _Radius); 76 | 77 | for (int j = 0; j < _Iteration + 1; j++) 78 | { 79 | // (r-1.0): increase from 0 slower and slower, converge to 1 80 | r += 1.0 / r; 81 | // rotate the axis 82 | axis = mul(rot, axis); 83 | half4 bokeh = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(i.uv + _MainTex_TexelSize.xy * (r - 1.0) * axis)); 84 | accumulator += bokeh * bokeh; 85 | divisor += bokeh; 86 | } 87 | half4 color = accumulator / divisor; 88 | 89 | fragColor.xyz = color.xyz; 90 | 91 | fragColor = saturate(fragColor); 92 | return fragColor; 93 | } 94 | 95 | 96 | ENDHLSL 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/Bokeh.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c9fe29cd70189840b5a69c78ce1cc6e 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/GaussianBlur.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/GaussianBlur" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float4 _BlurOffset; 26 | 27 | TEXTURE2D(_MainTex); 28 | SAMPLER(sampler_MainTex); 29 | 30 | struct Attributes 31 | { 32 | float4 positionOS : POSITION; 33 | float2 uv : TEXCOORD0; 34 | }; 35 | struct Varyings 36 | { 37 | float4 positionCS : POSITION; 38 | float2 uv : TEXCOORD0; 39 | }; 40 | 41 | Varyings vert(Attributes v) 42 | { 43 | Varyings o; 44 | o.positionCS = TransformObjectToHClip(v.positionOS); 45 | o.uv = v.uv; 46 | return o; 47 | } 48 | 49 | float4 frag(Varyings i) : SV_TARGET 50 | { 51 | float4 fragColor = float4(0,0,0,1); 52 | 53 | float4 uv01 = i.uv.xyxy + _BlurOffset.xyxy * float4(1, 1, -1, -1) * 1.0; 54 | float4 uv23 = i.uv.xyxy + _BlurOffset.xyxy * float4(1, 1, -1, -1) * 2.0; 55 | float4 uv45 = i.uv.xyxy + _BlurOffset.xyxy * float4(1, 1, -1, -1) * 6.0; 56 | 57 | float4 color = float4(0,0,0,0); 58 | 59 | // 6/256 60 | color += 0.40 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); 61 | // 4/256 62 | color += 0.15 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv01.xy); 63 | color += 0.15 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv01.zw); 64 | color += 0.10 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv23.xy); 65 | color += 0.10 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv23.zw); 66 | color += 0.05 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv45.xy); 67 | color += 0.05 * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv45.zw); 68 | 69 | 70 | 71 | fragColor.xyz = color.xyz; 72 | 73 | fragColor = saturate(fragColor); 74 | return fragColor; 75 | } 76 | 77 | 78 | ENDHLSL 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/GaussianBlur.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a9606fdc166bbf49862a242058de62f 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/IrisBlur.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/IrisBlur" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Radius; 26 | int _Iteration; 27 | 28 | float _Offset; 29 | float _Area; 30 | 31 | TEXTURE2D(_MainTex); 32 | SAMPLER(sampler_MainTex); 33 | 34 | float4 _MainTex_TexelSize; 35 | 36 | float IrisMask(float2 uv) 37 | { 38 | float2 center = uv * 2.0 - 1.0 + _Offset; // [0,1] -> [-1,1] 39 | return dot(center, center) * _Area; 40 | } 41 | 42 | 43 | struct Attributes 44 | { 45 | float4 positionOS : POSITION; 46 | float2 uv : TEXCOORD0; 47 | }; 48 | struct Varyings 49 | { 50 | float4 positionCS : POSITION; 51 | float2 uv : TEXCOORD0; 52 | }; 53 | 54 | Varyings vert(Attributes v) 55 | { 56 | Varyings o; 57 | o.positionCS = TransformObjectToHClip(v.positionOS); 58 | o.uv = v.uv; 59 | return o; 60 | } 61 | 62 | float4 frag(Varyings i) : SV_TARGET 63 | { 64 | float4 fragColor = float4(0,0,0,1); 65 | 66 | // :: Golden angle :: 67 | // float c = cos(2.39996323f); 68 | // float s = sin(2.39996323f); 69 | float c = -0.7374; 70 | float s = 0.6755; 71 | 72 | half2x2 rot = half2x2(c, s, -s, c); 73 | half4 accumulator = 0.0; 74 | half4 divisor = 0.0; 75 | 76 | half r = 1.0; 77 | 78 | // original code: half2 axis = half2(0.0, _Radius); 79 | // add Tilt Shift Mask 80 | half2 axis = half2(0.0, _Radius * saturate(IrisMask(i.uv))); 81 | 82 | for (int j = 0; j < _Iteration + 1; j++) 83 | { 84 | // (r-1.0): increase from 0 slower and slower, converge to 1 85 | r += 1.0 / r; 86 | // rotate the axis 87 | axis = mul(rot, axis); 88 | half4 bokeh = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(i.uv + _MainTex_TexelSize.xy * (r - 1.0) * axis)); 89 | accumulator += bokeh * bokeh; 90 | divisor += bokeh; 91 | } 92 | half4 color = accumulator / divisor; 93 | 94 | fragColor.xyz = color.xyz; 95 | 96 | fragColor = saturate(fragColor); 97 | return fragColor; 98 | } 99 | 100 | 101 | ENDHLSL 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/IrisBlur.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d4cb21eeb2ce554c81c796073732a3b 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/Kawase.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/Kawase" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _BlurRadius; 26 | 27 | 28 | 29 | TEXTURE2D(_MainTex); 30 | SAMPLER(sampler_MainTex); 31 | 32 | float4 _MainTex_TexelSize; 33 | 34 | float randomNoise(float x) 35 | { 36 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 37 | } 38 | 39 | 40 | struct Attributes 41 | { 42 | float4 positionOS : POSITION; 43 | float2 uv : TEXCOORD0; 44 | }; 45 | struct Varyings 46 | { 47 | float4 positionCS : POSITION; 48 | float2 uv : TEXCOORD0; 49 | }; 50 | 51 | Varyings vert(Attributes v) 52 | { 53 | Varyings o; 54 | o.positionCS = TransformObjectToHClip(v.positionOS); 55 | o.uv = v.uv; 56 | return o; 57 | } 58 | 59 | float4 frag(Varyings i) : SV_TARGET 60 | { 61 | float4 fragColor = float4(0,0,0,1); 62 | 63 | half4 sceneColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); 64 | 65 | float4 color = float4(0,0,0,0); 66 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + float2(-_BlurRadius-1.0, -_BlurRadius-1.0)*_MainTex_TexelSize.xy); 67 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + float2( _BlurRadius+1.0, -_BlurRadius-1.0)*_MainTex_TexelSize.xy); 68 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + float2(-_BlurRadius-1.0, _BlurRadius+1.0)*_MainTex_TexelSize.xy); 69 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + float2( _BlurRadius+1.0, _BlurRadius+1.0)*_MainTex_TexelSize.xy); 70 | 71 | color *= 0.25f; 72 | 73 | fragColor.xyz = color.xyz; 74 | 75 | fragColor = saturate(fragColor); 76 | return fragColor; 77 | } 78 | 79 | 80 | ENDHLSL 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/Kawase.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d275efe59d1d9546b8df1cfe429b1a2 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/TentBlur.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/TentBlur" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Offset; 26 | 27 | TEXTURE2D(_MainTex); 28 | SAMPLER(sampler_MainTex); 29 | float4 _MainTex_TexelSize; 30 | 31 | struct Attributes 32 | { 33 | float4 positionOS : POSITION; 34 | float2 uv : TEXCOORD0; 35 | }; 36 | struct Varyings 37 | { 38 | float4 positionCS : POSITION; 39 | float2 uv : TEXCOORD0; 40 | }; 41 | 42 | Varyings vert(Attributes v) 43 | { 44 | Varyings o; 45 | o.positionCS = TransformObjectToHClip(v.positionOS); 46 | o.uv = v.uv; 47 | return o; 48 | } 49 | 50 | float4 frag(Varyings i) : SV_TARGET 51 | { 52 | float4 fragColor = float4(0,0,0,1); 53 | 54 | float2 uv = i.uv; 55 | float4 d = _Offset * _MainTex_TexelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0); 56 | 57 | float4 color = float4(0,0,0,0); 58 | 59 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - d.xy); 60 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - d.wy) * 2.0; // 1 MAD 61 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - d.zy); // 1 MAD 62 | 63 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + d.zw) * 2.0; // 1 MAD 64 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv) * 4.0; // 1 MAD 65 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + d.xw) * 2.0; // 1 MAD 66 | 67 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + d.zy); 68 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + d.wy) * 2.0; // 1 MAD 69 | color += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + d.xy); 70 | 71 | color *= 1.0 / 16.0; 72 | 73 | fragColor.xyz = color.xyz; 74 | 75 | fragColor = saturate(fragColor); 76 | return fragColor; 77 | } 78 | 79 | 80 | ENDHLSL 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/TentBlur.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0cab072e689bee14cac9783ae578bde8 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/TiltShift.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Blur/TiltShift" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Radius; 26 | int _Iteration; 27 | 28 | float _Offset; 29 | float _Area; 30 | float _Spread; 31 | 32 | TEXTURE2D(_MainTex); 33 | SAMPLER(sampler_MainTex); 34 | 35 | float4 _MainTex_TexelSize; 36 | 37 | float TiltShiftMask(float2 uv) 38 | { 39 | float centerY = uv.y * 2.0 - 1.0 + _Offset; // [0,1] -> [-1,1] 40 | return pow(abs(centerY * _Area), _Spread); 41 | } 42 | 43 | 44 | struct Attributes 45 | { 46 | float4 positionOS : POSITION; 47 | float2 uv : TEXCOORD0; 48 | }; 49 | struct Varyings 50 | { 51 | float4 positionCS : POSITION; 52 | float2 uv : TEXCOORD0; 53 | }; 54 | 55 | Varyings vert(Attributes v) 56 | { 57 | Varyings o; 58 | o.positionCS = TransformObjectToHClip(v.positionOS); 59 | o.uv = v.uv; 60 | return o; 61 | } 62 | 63 | float4 frag(Varyings i) : SV_TARGET 64 | { 65 | float4 fragColor = float4(0,0,0,1); 66 | 67 | // :: Golden angle :: 68 | // float c = cos(2.39996323f); 69 | // float s = sin(2.39996323f); 70 | float c = -0.7374; 71 | float s = 0.6755; 72 | 73 | half2x2 rot = half2x2(c, s, -s, c); 74 | half4 accumulator = 0.0; 75 | half4 divisor = 0.0; 76 | 77 | half r = 1.0; 78 | 79 | // original code: half2 axis = half2(0.0, _Radius); 80 | // add Tilt Shift Mask 81 | half2 axis = half2(0.0, _Radius * saturate(TiltShiftMask(i.uv))); 82 | 83 | for (int j = 0; j < _Iteration + 1; j++) 84 | { 85 | // (r-1.0): increase from 0 slower and slower, converge to 1 86 | r += 1.0 / r; 87 | // rotate the axis 88 | axis = mul(rot, axis); 89 | half4 bokeh = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(i.uv + _MainTex_TexelSize.xy * (r - 1.0) * axis)); 90 | accumulator += bokeh * bokeh; 91 | divisor += bokeh; 92 | } 93 | half4 color = accumulator / divisor; 94 | 95 | fragColor.xyz = color.xyz; 96 | 97 | fragColor = saturate(fragColor); 98 | return fragColor; 99 | } 100 | 101 | 102 | ENDHLSL 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Blur/TiltShift.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee1b6ebee437dfb4f975552fc9d6fc10 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89595d114415cce4da0705d033ed39aa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/AnalogNoise.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Glitch/AnalogNoise" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Speed; 26 | float _LuminanceJitterThreshold; 27 | float _Fading; 28 | 29 | 30 | TEXTURE2D(_MainTex); 31 | SAMPLER(sampler_MainTex); 32 | 33 | float randomNoise(float x) 34 | { 35 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 36 | } 37 | 38 | 39 | struct Attributes 40 | { 41 | float4 positionOS : POSITION; 42 | float2 uv : TEXCOORD0; 43 | }; 44 | struct Varyings 45 | { 46 | float4 positionCS : POSITION; 47 | float2 uv : TEXCOORD0; 48 | }; 49 | 50 | Varyings vert(Attributes v) 51 | { 52 | Varyings o; 53 | o.positionCS = TransformObjectToHClip(v.positionOS); 54 | o.uv = v.uv; 55 | return o; 56 | } 57 | 58 | float4 frag(Varyings i) : SV_TARGET 59 | { 60 | float4 fragColor = float4(0,0,0,1); 61 | 62 | half4 sceneColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); 63 | half4 noiseColor = sceneColor; 64 | 65 | half luminance = dot(noiseColor.rgb, float3(0.22, 0.707, 0.071)); 66 | if (randomNoise(float2(_Time.x * _Speed, _Time.x * _Speed)) > _LuminanceJitterThreshold) 67 | { 68 | noiseColor = float4(luminance, luminance, luminance, luminance); 69 | } 70 | 71 | float noiseX = randomNoise(_Time.x * _Speed + i.uv / float2(-213, 5.53)); 72 | float noiseY = randomNoise(_Time.x * _Speed - i.uv / float2(213, -5.53)); 73 | float noiseZ = randomNoise(_Time.x * _Speed + i.uv / float2(213, 5.53)); 74 | 75 | noiseColor.rgb += 0.25 * float3(noiseX,noiseY,noiseZ) - 0.125; 76 | 77 | noiseColor = lerp(sceneColor, noiseColor, _Fading); 78 | 79 | fragColor.xyz = noiseColor; 80 | 81 | fragColor = saturate(fragColor); 82 | return fragColor; 83 | } 84 | 85 | 86 | ENDHLSL 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/AnalogNoise.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2357780fa217ed8489df046f6a289b34 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/RGBSplit.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Glitch/RGBSplit" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Intensity; 26 | 27 | TEXTURE2D(_MainTex); 28 | SAMPLER(sampler_MainTex); 29 | 30 | float randomNoise(float x, float y) 31 | { 32 | return frac(sin(dot(float2(x, y), float2(12.9898, 78.233))) * 43758.5453); 33 | } 34 | 35 | 36 | struct Attributes 37 | { 38 | float4 positionOS : POSITION; 39 | float2 uv : TEXCOORD0; 40 | }; 41 | struct Varyings 42 | { 43 | float4 positionCS : POSITION; 44 | float2 uv : TEXCOORD0; 45 | }; 46 | 47 | Varyings vert(Attributes v) 48 | { 49 | Varyings o; 50 | o.positionCS = TransformObjectToHClip(v.positionOS); 51 | o.uv = v.uv; 52 | return o; 53 | } 54 | 55 | float4 frag(Varyings i) : SV_TARGET 56 | { 57 | float4 fragColor = float4(0,0,0,1); 58 | 59 | float3 color = float4(0,0,0,0); 60 | 61 | float splitAmount = _Intensity * randomNoise(_Time.y, 2); 62 | 63 | half ColorR = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(i.uv.x + splitAmount, i.uv.y)).x; 64 | half ColorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv).y; 65 | half ColorB = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(i.uv.x - splitAmount, i.uv.y)).z; 66 | 67 | color = float3(ColorR, ColorG, ColorB); 68 | 69 | fragColor.xyz = color.xyz; 70 | 71 | fragColor = saturate(fragColor); 72 | return fragColor; 73 | } 74 | 75 | 76 | ENDHLSL 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/RGBSplit.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf6b77123c2f63d46b80bac11ac15a1c 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/ScanLineJitter.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Glitch/ScanLineJitter" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Amount; 26 | float _Frequency; 27 | float _Threshold; 28 | 29 | 30 | TEXTURE2D(_MainTex); 31 | SAMPLER(sampler_MainTex); 32 | 33 | float randomNoise(float x) 34 | { 35 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 36 | } 37 | 38 | 39 | struct Attributes 40 | { 41 | float4 positionOS : POSITION; 42 | float2 uv : TEXCOORD0; 43 | }; 44 | struct Varyings 45 | { 46 | float4 positionCS : POSITION; 47 | float2 uv : TEXCOORD0; 48 | }; 49 | 50 | Varyings vert(Attributes v) 51 | { 52 | Varyings o; 53 | o.positionCS = TransformObjectToHClip(v.positionOS); 54 | o.uv = v.uv; 55 | return o; 56 | } 57 | 58 | float4 frag(Varyings i) : SV_TARGET 59 | { 60 | float4 fragColor = float4(0,0,0,1); 61 | 62 | half strength = 0.5 + 0.5 * cos(_Time.y * _Frequency); 63 | 64 | float jitter = randomNoise(i.uv.x + _Time.y) * 2 - 1; 65 | jitter *= step(_Threshold, abs(jitter)) * _Amount * strength; 66 | 67 | float4 sceneColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, frac(i.uv + float2(0, jitter))); 68 | 69 | fragColor.xyz = sceneColor; 70 | 71 | fragColor = saturate(fragColor); 72 | return fragColor; 73 | } 74 | 75 | 76 | ENDHLSL 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/ScanLineJitter.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c7c02e61f6129624e8a677a909c28ab2 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/WaveJitter.shader: -------------------------------------------------------------------------------- 1 | Shader "CustomPost/Glitch/WaveJitter" 2 | { 3 | Properties 4 | { 5 | _MainTex("Base Map", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags 10 | { 11 | "RenderingPipeline" = "UniversalForward" 12 | } 13 | 14 | Pass 15 | { 16 | HLSLPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 22 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" 23 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" 24 | 25 | float _Frequency; 26 | float _Speed; 27 | float _Amount; 28 | float _RGBSplit; 29 | 30 | 31 | TEXTURE2D(_MainTex); 32 | SAMPLER(sampler_MainTex); 33 | 34 | float snoise(float2 x) 35 | { 36 | return frac(sin(dot(x, float2(12.9898, 78.233))) * 43758.5453); 37 | } 38 | 39 | 40 | struct Attributes 41 | { 42 | float4 positionOS : POSITION; 43 | float2 uv : TEXCOORD0; 44 | }; 45 | struct Varyings 46 | { 47 | float4 positionCS : POSITION; 48 | float2 uv : TEXCOORD0; 49 | }; 50 | 51 | Varyings vert(Attributes v) 52 | { 53 | Varyings o; 54 | o.positionCS = TransformObjectToHClip(v.positionOS); 55 | o.uv = v.uv; 56 | return o; 57 | } 58 | 59 | float4 frag(Varyings i) : SV_TARGET 60 | { 61 | float4 fragColor = float4(0,0,0,1); 62 | 63 | 64 | half strength = 0.5 + 0.5 *cos(_Time.y * _Frequency); 65 | 66 | // Prepare UV 67 | float uv_y = i.uv.y * _ScreenParams.y; 68 | float noise_wave_1 = snoise(float2(uv_y * 0.01, _Time.y * _Speed * 20)) * (strength * _Amount * 32.0); 69 | float noise_wave_2 = snoise(float2(uv_y * 0.02, _Time.y * _Speed * 10)) * (strength * _Amount * 4.0); 70 | float noise_wave_x = noise_wave_1 * noise_wave_2 / _ScreenParams.x; 71 | float uv_x = i.uv.x + noise_wave_x; 72 | 73 | float rgbSplit_uv_x = (_RGBSplit * 50 + (20.0 * strength + 1.0)) * noise_wave_x / _ScreenParams.x; 74 | 75 | // Sample RGB Color- 76 | half4 colorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(uv_x, i.uv.y)); 77 | half4 colorRB = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, float2(uv_x + rgbSplit_uv_x, i.uv.y)); 78 | 79 | fragColor = half4(colorRB.r, colorG.g, colorRB.b, colorRB.a + colorG.a); 80 | 81 | fragColor = saturate(fragColor); 82 | return fragColor; 83 | } 84 | 85 | 86 | ENDHLSL 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /URP-Volume-Post/Shaders/Glitch/WaveJitter.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f8fb1fbc9b13434aa01f36842d37d97 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | preprocessorOverride: 0 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b5a1764e74bd5b408555e21218fb95d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 476f519b0a1491d418c7b4030956435d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/BlurVolume.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &-7079961559512987328 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 3 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 0} 13 | m_Name: CustomBokeh 14 | m_EditorClassIdentifier: Assembly-CSharp::CustomBokeh 15 | active: 0 16 | renderPassEvent: 600 17 | Iteration: 18 | m_OverrideState: 0 19 | m_Value: 0 20 | BlurRadius: 21 | m_OverrideState: 0 22 | m_Value: 0 23 | --- !u!114 &-6345114920378229098 24 | MonoBehaviour: 25 | m_ObjectHideFlags: 3 26 | m_CorrespondingSourceObject: {fileID: 0} 27 | m_PrefabInstance: {fileID: 0} 28 | m_PrefabAsset: {fileID: 0} 29 | m_GameObject: {fileID: 0} 30 | m_Enabled: 1 31 | m_EditorHideFlags: 0 32 | m_Script: {fileID: 0} 33 | m_Name: CustomTentBlurVolume 34 | m_EditorClassIdentifier: Assembly-CSharp::CustomTentBlurVolume 35 | active: 0 36 | renderPassEvent: 600 37 | Iteration: 38 | m_OverrideState: 1 39 | m_Value: 5 40 | Offset: 41 | m_OverrideState: 1 42 | m_Value: 2.85 43 | --- !u!114 &-6193170422579254706 44 | MonoBehaviour: 45 | m_ObjectHideFlags: 3 46 | m_CorrespondingSourceObject: {fileID: 0} 47 | m_PrefabInstance: {fileID: 0} 48 | m_PrefabAsset: {fileID: 0} 49 | m_GameObject: {fileID: 0} 50 | m_Enabled: 1 51 | m_EditorHideFlags: 0 52 | m_Script: {fileID: 11500000, guid: e0249561ca6f1814aa8a756fdf4a62eb, type: 3} 53 | m_Name: Bokeh 54 | m_EditorClassIdentifier: 55 | active: 0 56 | k__BackingField: 57 | renderPassEvent: 600 58 | Iteration: 59 | m_OverrideState: 1 60 | m_Value: 9 61 | BlurRadius: 62 | m_OverrideState: 1 63 | m_Value: 2 64 | _material: {fileID: 0} 65 | --- !u!114 &-4609580019215870465 66 | MonoBehaviour: 67 | m_ObjectHideFlags: 3 68 | m_CorrespondingSourceObject: {fileID: 0} 69 | m_PrefabInstance: {fileID: 0} 70 | m_PrefabAsset: {fileID: 0} 71 | m_GameObject: {fileID: 0} 72 | m_Enabled: 1 73 | m_EditorHideFlags: 0 74 | m_Script: {fileID: 0} 75 | m_Name: CustomGaussianBlur 76 | m_EditorClassIdentifier: Assembly-CSharp::CustomGaussianBlur 77 | active: 0 78 | renderPassEvent: 600 79 | Iteration: 80 | m_OverrideState: 1 81 | m_Value: 1 82 | BlurOffsetX: 83 | m_OverrideState: 1 84 | m_Value: 0 85 | BlurOffsetY: 86 | m_OverrideState: 1 87 | m_Value: 0.00005 88 | --- !u!114 &-3907849405920709095 89 | MonoBehaviour: 90 | m_ObjectHideFlags: 3 91 | m_CorrespondingSourceObject: {fileID: 0} 92 | m_PrefabInstance: {fileID: 0} 93 | m_PrefabAsset: {fileID: 0} 94 | m_GameObject: {fileID: 0} 95 | m_Enabled: 1 96 | m_EditorHideFlags: 0 97 | m_Script: {fileID: 0} 98 | m_Name: TentBlurVolume 99 | m_EditorClassIdentifier: Assembly-CSharp::TentBlurVolume 100 | active: 0 101 | renderPassEvent: 600 102 | Iteration: 103 | m_OverrideState: 0 104 | m_Value: 5 105 | Offset: 106 | m_OverrideState: 0 107 | m_Value: 0 108 | --- !u!114 &-305585667615808239 109 | MonoBehaviour: 110 | m_ObjectHideFlags: 3 111 | m_CorrespondingSourceObject: {fileID: 0} 112 | m_PrefabInstance: {fileID: 0} 113 | m_PrefabAsset: {fileID: 0} 114 | m_GameObject: {fileID: 0} 115 | m_Enabled: 1 116 | m_EditorHideFlags: 0 117 | m_Script: {fileID: 11500000, guid: 0edf629585fd9b14cb0a063981c9b24b, type: 3} 118 | m_Name: TiltShift 119 | m_EditorClassIdentifier: 120 | active: 0 121 | k__BackingField: 122 | renderPassEvent: 600 123 | Iteration: 124 | m_OverrideState: 1 125 | m_Value: 9 126 | BlurRadius: 127 | m_OverrideState: 1 128 | m_Value: 2.93 129 | _Offset: 130 | m_OverrideState: 1 131 | m_Value: -0.53 132 | _Area: 133 | m_OverrideState: 1 134 | m_Value: 2.21 135 | _Spread: 136 | m_OverrideState: 1 137 | m_Value: 3.12 138 | _material: {fileID: 0} 139 | --- !u!114 &11400000 140 | MonoBehaviour: 141 | m_ObjectHideFlags: 0 142 | m_CorrespondingSourceObject: {fileID: 0} 143 | m_PrefabInstance: {fileID: 0} 144 | m_PrefabAsset: {fileID: 0} 145 | m_GameObject: {fileID: 0} 146 | m_Enabled: 1 147 | m_EditorHideFlags: 0 148 | m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3} 149 | m_Name: BlurVolume 150 | m_EditorClassIdentifier: 151 | components: 152 | - {fileID: 6969591198395683711} 153 | --- !u!114 &58565147881667119 154 | MonoBehaviour: 155 | m_ObjectHideFlags: 3 156 | m_CorrespondingSourceObject: {fileID: 0} 157 | m_PrefabInstance: {fileID: 0} 158 | m_PrefabAsset: {fileID: 0} 159 | m_GameObject: {fileID: 0} 160 | m_Enabled: 1 161 | m_EditorHideFlags: 0 162 | m_Script: {fileID: 0} 163 | m_Name: CustomGaussianBlur 164 | m_EditorClassIdentifier: Assembly-CSharp::CustomGaussianBlur 165 | active: 0 166 | renderPassEvent: 600 167 | Iteration: 168 | m_OverrideState: 1 169 | m_Value: 3 170 | BlurOffsetX: 171 | m_OverrideState: 1 172 | m_Value: 0.0018 173 | BlurOffsetY: 174 | m_OverrideState: 1 175 | m_Value: 0.0027 176 | --- !u!114 &454168849348750463 177 | MonoBehaviour: 178 | m_ObjectHideFlags: 3 179 | m_CorrespondingSourceObject: {fileID: 0} 180 | m_PrefabInstance: {fileID: 0} 181 | m_PrefabAsset: {fileID: 0} 182 | m_GameObject: {fileID: 0} 183 | m_Enabled: 1 184 | m_EditorHideFlags: 0 185 | m_Script: {fileID: 0} 186 | m_Name: TentBlurVolume 187 | m_EditorClassIdentifier: Assembly-CSharp::TentBlurVolume 188 | active: 0 189 | k__BackingField: 190 | renderPassEvent: 600 191 | _material: {fileID: 0} 192 | Iteration: 193 | m_OverrideState: 1 194 | m_Value: 10 195 | Offset: 196 | m_OverrideState: 1 197 | m_Value: 3.3 198 | --- !u!114 &815534691534537972 199 | MonoBehaviour: 200 | m_ObjectHideFlags: 3 201 | m_CorrespondingSourceObject: {fileID: 0} 202 | m_PrefabInstance: {fileID: 0} 203 | m_PrefabAsset: {fileID: 0} 204 | m_GameObject: {fileID: 0} 205 | m_Enabled: 1 206 | m_EditorHideFlags: 0 207 | m_Script: {fileID: 0} 208 | m_Name: CustomIrisBlur 209 | m_EditorClassIdentifier: Assembly-CSharp::CustomIrisBlur 210 | active: 1 211 | renderPassEvent: 600 212 | Iteration: 213 | m_OverrideState: 1 214 | m_Value: 9 215 | BlurRadius: 216 | m_OverrideState: 1 217 | m_Value: 4.21 218 | _Offset: 219 | m_OverrideState: 1 220 | m_Value: 0.299 221 | _Area: 222 | m_OverrideState: 1 223 | m_Value: 3.33 224 | --- !u!114 &1811751036411358504 225 | MonoBehaviour: 226 | m_ObjectHideFlags: 3 227 | m_CorrespondingSourceObject: {fileID: 0} 228 | m_PrefabInstance: {fileID: 0} 229 | m_PrefabAsset: {fileID: 0} 230 | m_GameObject: {fileID: 0} 231 | m_Enabled: 1 232 | m_EditorHideFlags: 0 233 | m_Script: {fileID: 0} 234 | m_Name: CustomKawase 235 | m_EditorClassIdentifier: Assembly-CSharp::CustomKawase 236 | active: 0 237 | renderPassEvent: 600 238 | Iteration: 239 | m_OverrideState: 1 240 | m_Value: 9 241 | RTDownScaling: 242 | m_OverrideState: 1 243 | m_Value: 2.14 244 | BlurRadius: 245 | m_OverrideState: 1 246 | m_Value: 0.68 247 | --- !u!114 &6969591198395683711 248 | MonoBehaviour: 249 | m_ObjectHideFlags: 3 250 | m_CorrespondingSourceObject: {fileID: 0} 251 | m_PrefabInstance: {fileID: 0} 252 | m_PrefabAsset: {fileID: 0} 253 | m_GameObject: {fileID: 0} 254 | m_Enabled: 1 255 | m_EditorHideFlags: 0 256 | m_Script: {fileID: 0} 257 | m_Name: CustomGaussianBlur 258 | m_EditorClassIdentifier: Assembly-CSharp::CustomGaussianBlur 259 | active: 1 260 | renderPassEvent: 600 261 | Iteration: 262 | m_OverrideState: 1 263 | m_Value: 2 264 | BlurOffsetX: 265 | m_OverrideState: 1 266 | m_Value: 0.0014 267 | BlurOffsetY: 268 | m_OverrideState: 1 269 | m_Value: 0.00246 270 | --- !u!114 &7154021695622566149 271 | MonoBehaviour: 272 | m_ObjectHideFlags: 3 273 | m_CorrespondingSourceObject: {fileID: 0} 274 | m_PrefabInstance: {fileID: 0} 275 | m_PrefabAsset: {fileID: 0} 276 | m_GameObject: {fileID: 0} 277 | m_Enabled: 1 278 | m_EditorHideFlags: 0 279 | m_Script: {fileID: 0} 280 | m_Name: CustomTiltShift 281 | m_EditorClassIdentifier: Assembly-CSharp::CustomTiltShift 282 | active: 0 283 | renderPassEvent: 600 284 | Iteration: 285 | m_OverrideState: 1 286 | m_Value: 6 287 | BlurRadius: 288 | m_OverrideState: 1 289 | m_Value: 3.43 290 | _Offset: 291 | m_OverrideState: 1 292 | m_Value: -0.56 293 | _Area: 294 | m_OverrideState: 1 295 | m_Value: 1.73 296 | _Spread: 297 | m_OverrideState: 1 298 | m_Value: 1.9 299 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/BlurVolume.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94e8993fba93ccd47969c0bdf533aee5 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/Bokeh.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/Bokeh")] 8 | public class CustomBokeh : PostVolumeComponentBase 9 | { 10 | public ClampedIntParameter Iteration = new ClampedIntParameter(0, 0, 10); 11 | public ClampedFloatParameter BlurRadius = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 12 | 13 | private Material _material; 14 | public override void Setup() 15 | { 16 | if (_material == null) 17 | { 18 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/Bokeh"); 19 | } 20 | } 21 | 22 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 23 | RenderTargetIdentifier destination) 24 | { 25 | if (_material == null) 26 | { 27 | return; 28 | } 29 | 30 | cmd.SetGlobalFloat("_Radius", BlurRadius.value); 31 | cmd.SetGlobalInteger("_Iteration", Iteration.value); 32 | cmd.Blit(source, destination, _material); 33 | 34 | } 35 | 36 | public override bool IsActive() 37 | { 38 | return active; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/Bokeh.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0249561ca6f1814aa8a756fdf4a62eb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/GaussianBlur.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/GaussianBlur")] 8 | public class CustomGaussianBlur : PostVolumeComponentBase 9 | { 10 | private Material _material; 11 | 12 | public ClampedIntParameter Iteration = new ClampedIntParameter(2, 0, 8); 13 | 14 | public ClampedFloatParameter BlurOffsetX = new ClampedFloatParameter(0.0f, 0f, 0.005f); 15 | public ClampedFloatParameter BlurOffsetY = new ClampedFloatParameter(0.0f, 0f, 0.005f); 16 | public override void Setup() 17 | { 18 | if (_material == null) 19 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/GaussianBlur"); 20 | } 21 | 22 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 23 | RenderTargetIdentifier destination) 24 | { 25 | if (_material == null) 26 | return; 27 | 28 | // cmd.GetTemporaryRT(ShaderIDs.BufferRT1, RTWidth, RTHeight, 0, FilterMode.Bilinear); 29 | 30 | RenderTargetIdentifier buff0, buff1; 31 | RenderTargetHandle tempRT0 = new RenderTargetHandle(), tempRT1 = new RenderTargetHandle(); 32 | 33 | tempRT0.Init("RT0"); 34 | tempRT1.Init("RT1"); 35 | 36 | var descriptor = renderingData.cameraData.cameraTargetDescriptor; 37 | cmd.GetTemporaryRT(tempRT0.id, descriptor); 38 | cmd.GetTemporaryRT(tempRT1.id, descriptor); 39 | buff0 = tempRT0.id; 40 | buff1 = tempRT1.id; 41 | 42 | 43 | float X = BlurOffsetX.value, Y = BlurOffsetY.value; 44 | 45 | cmd.Blit(source, buff0); 46 | for (int i = 0; i < Iteration.value; i++) 47 | { 48 | cmd.SetGlobalColor(Shader.PropertyToID("_BlurOffset"), new Vector4(X, 0, 0, 0)); 49 | cmd.Blit(buff0, buff1, _material); 50 | 51 | cmd.SetGlobalColor(Shader.PropertyToID("_BlurOffset"), new Vector4(0, Y, 0, 0)); 52 | cmd.Blit(buff1, buff0, _material); 53 | } 54 | 55 | cmd.Blit(buff0, destination); 56 | cmd.ReleaseTemporaryRT(tempRT0.id); 57 | cmd.ReleaseTemporaryRT(tempRT1.id); 58 | } 59 | 60 | public override bool IsActive() 61 | { 62 | return active; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/GaussianBlur.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80296b076a2232d4c98e30129fd60467 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/IrisBlur.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/IrisBlur")] 8 | public class CustomIrisBlur : PostVolumeComponentBase 9 | { 10 | public ClampedIntParameter Iteration = new ClampedIntParameter(0, 0, 10); 11 | public ClampedFloatParameter BlurRadius = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 12 | public ClampedFloatParameter _Offset = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 13 | public ClampedFloatParameter _Area = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 14 | 15 | private Material _material; 16 | public override void Setup() 17 | { 18 | if (_material == null) 19 | { 20 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/IrisBlur"); 21 | } 22 | } 23 | 24 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 25 | RenderTargetIdentifier destination) 26 | { 27 | if (_material == null) 28 | { 29 | return; 30 | } 31 | 32 | cmd.SetGlobalFloat("_Radius", BlurRadius.value); 33 | cmd.SetGlobalInteger("_Iteration", Iteration.value); 34 | 35 | cmd.SetGlobalFloat("_Offset", _Offset.value); 36 | cmd.SetGlobalFloat("_Area", _Area.value); 37 | cmd.Blit(source, destination, _material); 38 | 39 | } 40 | 41 | public override bool IsActive() 42 | { 43 | return active; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/IrisBlur.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cc24f8630fdeed439a0faa7339c08a1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/Kawase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/KawaseBlur")] 8 | public class CustomKawase : PostVolumeComponentBase 9 | { 10 | public ClampedIntParameter Iteration = new ClampedIntParameter(0, 0, 10); 11 | 12 | public ClampedFloatParameter RTDownScaling = new ClampedFloatParameter(1.0f, 0.1f, 4.0f); 13 | public ClampedFloatParameter BlurRadius = new ClampedFloatParameter(0.0f, 0.0f, 2.0f); 14 | private Material _material; 15 | public override void Setup() 16 | { 17 | if (_material == null) 18 | { 19 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/Kawase"); 20 | } 21 | } 22 | 23 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 24 | RenderTargetIdentifier destination) 25 | { 26 | if (_material == null) 27 | { 28 | return; 29 | } 30 | 31 | RenderTargetIdentifier buff0, buff1; 32 | RenderTargetHandle tempRT0 = new RenderTargetHandle(), tempRT1 = new RenderTargetHandle(); 33 | 34 | tempRT0.Init("RT0"); 35 | tempRT1.Init("RT1"); 36 | 37 | var descriptor = renderingData.cameraData.cameraTargetDescriptor; 38 | cmd.GetTemporaryRT(tempRT0.id, descriptor); 39 | cmd.GetTemporaryRT(tempRT1.id, descriptor); 40 | buff0 = tempRT0.id; 41 | buff1 = tempRT1.id; 42 | 43 | cmd.Blit(source, buff0); 44 | for (int i = 0; i < Iteration.value; i++) 45 | { 46 | cmd.SetGlobalFloat("_BlurRadius", i/RTDownScaling.value + BlurRadius.value); 47 | cmd.Blit(buff0, buff1, _material); 48 | cmd.Blit(buff1, buff0, _material); 49 | } 50 | 51 | cmd.Blit(buff0, destination); 52 | cmd.ReleaseTemporaryRT(tempRT0.id); 53 | cmd.ReleaseTemporaryRT(tempRT1.id); 54 | } 55 | 56 | public override bool IsActive() 57 | { 58 | return active; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/Kawase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fb2ef7f304bca0428aaf453b52ea961 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/TentBlur.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/TentBlur")] 8 | public class CustomTentBlurVolume : PostVolumeComponentBase 9 | { 10 | 11 | private Material _material; 12 | 13 | public ClampedIntParameter Iteration = new ClampedIntParameter(5, 0, 15); 14 | public ClampedFloatParameter Offset = new ClampedFloatParameter(0.0f, 0.0f, 10.0f); 15 | 16 | public override void Setup() 17 | { 18 | if (_material == null) 19 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/TentBlur"); 20 | } 21 | 22 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 23 | RenderTargetIdentifier destination) 24 | { 25 | if (_material == null) 26 | return; 27 | 28 | RenderTargetIdentifier buff0, buff1; 29 | RenderTargetHandle tempRT0 = new RenderTargetHandle(), tempRT1 = new RenderTargetHandle(); 30 | 31 | tempRT0.Init("RT0"); 32 | tempRT1.Init("RT1"); 33 | 34 | var descriptor = renderingData.cameraData.cameraTargetDescriptor; 35 | cmd.GetTemporaryRT(tempRT0.id, descriptor); 36 | cmd.GetTemporaryRT(tempRT1.id, descriptor); 37 | buff0 = tempRT0.id; 38 | buff1 = tempRT1.id; 39 | 40 | cmd.Blit(source, buff0); 41 | cmd.SetGlobalFloat(Shader.PropertyToID("_Offset"), Offset.value); 42 | for (int i = 0; i < Iteration.value; i++) 43 | { 44 | cmd.Blit(buff0, buff1, _material); 45 | cmd.Blit(buff1, buff0, _material); 46 | } 47 | 48 | cmd.Blit(buff0, destination, _material); 49 | 50 | cmd.ReleaseTemporaryRT(tempRT0.id); 51 | cmd.ReleaseTemporaryRT(tempRT1.id); 52 | } 53 | 54 | public override bool IsActive() 55 | { 56 | return active; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/TentBlur.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5443528364477784fbec2809f7d46fcd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/TiltShift.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Blur/TiltShift")] 8 | public class CustomTiltShift : PostVolumeComponentBase 9 | { 10 | public ClampedIntParameter Iteration = new ClampedIntParameter(0, 0, 10); 11 | public ClampedFloatParameter BlurRadius = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 12 | public ClampedFloatParameter _Offset = new ClampedFloatParameter(0.0f, -1.0f, 1.0f); 13 | public ClampedFloatParameter _Area = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 14 | public ClampedFloatParameter _Spread = new ClampedFloatParameter(0.0f, 0.0f, 5.0f); 15 | 16 | private Material _material; 17 | public override void Setup() 18 | { 19 | if (_material == null) 20 | { 21 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Blur/TiltShift"); 22 | } 23 | } 24 | 25 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 26 | RenderTargetIdentifier destination) 27 | { 28 | if (_material == null) 29 | { 30 | return; 31 | } 32 | 33 | cmd.SetGlobalFloat("_Radius", BlurRadius.value); 34 | cmd.SetGlobalInteger("_Iteration", Iteration.value); 35 | 36 | cmd.SetGlobalFloat("_Offset", _Offset.value); 37 | cmd.SetGlobalFloat("_Area", _Area.value); 38 | cmd.SetGlobalFloat("_Spread", _Spread.value); 39 | cmd.Blit(source, destination, _material); 40 | 41 | } 42 | 43 | public override bool IsActive() 44 | { 45 | return active; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Blur/TiltShift.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0edf629585fd9b14cb0a063981c9b24b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/CustomPostVolume.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("Custom/PostProcess")] 8 | public class CustomPostVolumeComponent : PostVolumeComponentBase 9 | { 10 | 11 | public ClampedFloatParameter foo = new ClampedFloatParameter(.5f, 0, 1f); 12 | 13 | 14 | public override void Setup() 15 | { 16 | 17 | } 18 | 19 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 20 | RenderTargetIdentifier destination) 21 | { 22 | cmd.Blit(source, destination); 23 | } 24 | 25 | public override bool IsActive() 26 | { 27 | return active; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/CustomPostVolume.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1914f45fbdbd1134d8cc3c4e30cfd684 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad570737411ad624a85c4cc7ad01386b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/AnalogNoise.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Glitch/AnalogNoise")] 8 | public class CustomAnalogNoise : PostVolumeComponentBase 9 | { 10 | public ClampedFloatParameter _Speed = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 11 | public ClampedFloatParameter _LuminanceJitterThreshold = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 12 | public ClampedFloatParameter _Fading = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 13 | 14 | private Material _material; 15 | public override void Setup() 16 | { 17 | if (_material == null) 18 | { 19 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Glitch/AnalogNoise"); 20 | } 21 | } 22 | 23 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 24 | RenderTargetIdentifier destination) 25 | { 26 | if (_material == null) 27 | { 28 | return; 29 | } 30 | cmd.SetGlobalFloat("_Speed", _Speed.value); 31 | cmd.SetGlobalFloat("_LuminanceJitterThreshold", _LuminanceJitterThreshold.value); 32 | cmd.SetGlobalFloat("_Fading", _Fading.value); 33 | cmd.Blit(source, destination, _material); 34 | } 35 | 36 | public override bool IsActive() 37 | { 38 | return active; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/AnalogNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b50307de327fca4482e03370f280521 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/GlitchVolume 1.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &-8784489221033238310 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 3 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 0} 13 | m_Name: CustomRGBSplit 14 | m_EditorClassIdentifier: Assembly-CSharp::CustomRGBSplit 15 | active: 0 16 | renderPassEvent: 600 17 | Intensity: 18 | m_OverrideState: 1 19 | m_Value: 0 20 | --- !u!114 &-8521088472518461455 21 | MonoBehaviour: 22 | m_ObjectHideFlags: 3 23 | m_CorrespondingSourceObject: {fileID: 0} 24 | m_PrefabInstance: {fileID: 0} 25 | m_PrefabAsset: {fileID: 0} 26 | m_GameObject: {fileID: 0} 27 | m_Enabled: 1 28 | m_EditorHideFlags: 0 29 | m_Script: {fileID: 11500000, guid: 3f363964b193b584a9c54d1dd19a195d, type: 3} 30 | m_Name: WaveJitter 31 | m_EditorClassIdentifier: 32 | active: 0 33 | k__BackingField: 34 | renderPassEvent: 600 35 | Frequency: 36 | m_OverrideState: 1 37 | m_Value: 4.09 38 | Speed: 39 | m_OverrideState: 1 40 | m_Value: 0.13 41 | Amount: 42 | m_OverrideState: 1 43 | m_Value: 1 44 | RGBSplit: 45 | m_OverrideState: 1 46 | m_Value: 1 47 | _material: {fileID: 0} 48 | --- !u!114 &-7567262039225638707 49 | MonoBehaviour: 50 | m_ObjectHideFlags: 3 51 | m_CorrespondingSourceObject: {fileID: 0} 52 | m_PrefabInstance: {fileID: 0} 53 | m_PrefabAsset: {fileID: 0} 54 | m_GameObject: {fileID: 0} 55 | m_Enabled: 1 56 | m_EditorHideFlags: 0 57 | m_Script: {fileID: 0} 58 | m_Name: CustomWaveJitter 59 | m_EditorClassIdentifier: Assembly-CSharp::CustomWaveJitter 60 | active: 0 61 | renderPassEvent: 600 62 | Frequency: 63 | m_OverrideState: 1 64 | m_Value: 1.88 65 | Speed: 66 | m_OverrideState: 1 67 | m_Value: 0.47 68 | Amount: 69 | m_OverrideState: 1 70 | m_Value: 0.75 71 | RGBSplit: 72 | m_OverrideState: 1 73 | m_Value: 1.47 74 | --- !u!114 &-1565898290561207543 75 | MonoBehaviour: 76 | m_ObjectHideFlags: 3 77 | m_CorrespondingSourceObject: {fileID: 0} 78 | m_PrefabInstance: {fileID: 0} 79 | m_PrefabAsset: {fileID: 0} 80 | m_GameObject: {fileID: 0} 81 | m_Enabled: 1 82 | m_EditorHideFlags: 0 83 | m_Script: {fileID: 0} 84 | m_Name: CustomScanLineJitter 85 | m_EditorClassIdentifier: Assembly-CSharp::CustomScanLineJitter 86 | active: 0 87 | renderPassEvent: 600 88 | _Amount: 89 | m_OverrideState: 1 90 | m_Value: 0.1 91 | _Frequency: 92 | m_OverrideState: 1 93 | m_Value: 0.75 94 | _Threshold: 95 | m_OverrideState: 1 96 | m_Value: 0.27 97 | --- !u!114 &11400000 98 | MonoBehaviour: 99 | m_ObjectHideFlags: 0 100 | m_CorrespondingSourceObject: {fileID: 0} 101 | m_PrefabInstance: {fileID: 0} 102 | m_PrefabAsset: {fileID: 0} 103 | m_GameObject: {fileID: 0} 104 | m_Enabled: 1 105 | m_EditorHideFlags: 0 106 | m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3} 107 | m_Name: GlitchVolume 1 108 | m_EditorClassIdentifier: 109 | components: 110 | - {fileID: 5180963760641819422} 111 | - {fileID: 2060619412712593437} 112 | - {fileID: 7580347146514720483} 113 | - {fileID: -1565898290561207543} 114 | --- !u!114 &2060619412712593437 115 | MonoBehaviour: 116 | m_ObjectHideFlags: 3 117 | m_CorrespondingSourceObject: {fileID: 0} 118 | m_PrefabInstance: {fileID: 0} 119 | m_PrefabAsset: {fileID: 0} 120 | m_GameObject: {fileID: 0} 121 | m_Enabled: 1 122 | m_EditorHideFlags: 0 123 | m_Script: {fileID: 0} 124 | m_Name: CustomRGBSplit 125 | m_EditorClassIdentifier: Assembly-CSharp::CustomRGBSplit 126 | active: 0 127 | renderPassEvent: 600 128 | Intensity: 129 | m_OverrideState: 1 130 | m_Value: 0.016 131 | --- !u!114 &3143661457206686555 132 | MonoBehaviour: 133 | m_ObjectHideFlags: 3 134 | m_CorrespondingSourceObject: {fileID: 0} 135 | m_PrefabInstance: {fileID: 0} 136 | m_PrefabAsset: {fileID: 0} 137 | m_GameObject: {fileID: 0} 138 | m_Enabled: 1 139 | m_EditorHideFlags: 0 140 | m_Script: {fileID: 11500000, guid: 001fe824d56af2e45aa9053a11fa0d89, type: 3} 141 | m_Name: RGBSplit 142 | m_EditorClassIdentifier: 143 | active: 0 144 | k__BackingField: 145 | renderPassEvent: 600 146 | Intensity: 147 | m_OverrideState: 0 148 | m_Value: 0.03 149 | _material: {fileID: 0} 150 | --- !u!114 &5180963760641819422 151 | MonoBehaviour: 152 | m_ObjectHideFlags: 3 153 | m_CorrespondingSourceObject: {fileID: 0} 154 | m_PrefabInstance: {fileID: 0} 155 | m_PrefabAsset: {fileID: 0} 156 | m_GameObject: {fileID: 0} 157 | m_Enabled: 1 158 | m_EditorHideFlags: 0 159 | m_Script: {fileID: 0} 160 | m_Name: CustomAnalogNoise 161 | m_EditorClassIdentifier: Assembly-CSharp::CustomAnalogNoise 162 | active: 0 163 | renderPassEvent: 600 164 | _Speed: 165 | m_OverrideState: 1 166 | m_Value: 0.7 167 | _LuminanceJitterThreshold: 168 | m_OverrideState: 1 169 | m_Value: 0.82 170 | _Fading: 171 | m_OverrideState: 1 172 | m_Value: 0.77 173 | --- !u!114 &7031561717706268873 174 | MonoBehaviour: 175 | m_ObjectHideFlags: 3 176 | m_CorrespondingSourceObject: {fileID: 0} 177 | m_PrefabInstance: {fileID: 0} 178 | m_PrefabAsset: {fileID: 0} 179 | m_GameObject: {fileID: 0} 180 | m_Enabled: 1 181 | m_EditorHideFlags: 0 182 | m_Script: {fileID: 0} 183 | m_Name: CustomAnalogNoise 184 | m_EditorClassIdentifier: Assembly-CSharp::CustomAnalogNoise 185 | active: 0 186 | renderPassEvent: 600 187 | _Speed: 188 | m_OverrideState: 1 189 | m_Value: 0.05 190 | _LuminanceJitterThreshold: 191 | m_OverrideState: 1 192 | m_Value: 0.711 193 | _Fading: 194 | m_OverrideState: 1 195 | m_Value: 0.674 196 | --- !u!114 &7580347146514720483 197 | MonoBehaviour: 198 | m_ObjectHideFlags: 3 199 | m_CorrespondingSourceObject: {fileID: 0} 200 | m_PrefabInstance: {fileID: 0} 201 | m_PrefabAsset: {fileID: 0} 202 | m_GameObject: {fileID: 0} 203 | m_Enabled: 1 204 | m_EditorHideFlags: 0 205 | m_Script: {fileID: 0} 206 | m_Name: CustomWaveJitter 207 | m_EditorClassIdentifier: Assembly-CSharp::CustomWaveJitter 208 | active: 0 209 | renderPassEvent: 600 210 | Frequency: 211 | m_OverrideState: 1 212 | m_Value: 1.56 213 | Speed: 214 | m_OverrideState: 1 215 | m_Value: 0.44 216 | Amount: 217 | m_OverrideState: 1 218 | m_Value: 0.78 219 | RGBSplit: 220 | m_OverrideState: 1 221 | m_Value: 0.84 222 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/GlitchVolume 1.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d11391d33cc90b44a44368b6fb81019 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/RGBSplit.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Glitch/RGBSplit")] 8 | public class CustomRGBSplit : PostVolumeComponentBase 9 | { 10 | public ClampedFloatParameter Intensity = new ClampedFloatParameter(0.0f, 0.0f, 0.1f); 11 | private Material _material; 12 | public override void Setup() 13 | { 14 | if (_material == null) 15 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Glitch/RGBSplit"); 16 | } 17 | 18 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 19 | RenderTargetIdentifier destination) 20 | { 21 | if (_material == null) 22 | return; 23 | 24 | cmd.SetGlobalFloat(Shader.PropertyToID("_Intensity"), Intensity.value); 25 | cmd.Blit(source, destination, _material); 26 | } 27 | 28 | public override bool IsActive() 29 | { 30 | return active; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/RGBSplit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 001fe824d56af2e45aa9053a11fa0d89 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/ScanLineJitter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Rendering.Universal; 6 | 7 | [VolumeComponentMenu("CustomPost/Glitch/ScanLineJitter")] 8 | public class CustomScanLineJitter : PostVolumeComponentBase 9 | { 10 | public ClampedFloatParameter _Amount = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 11 | public ClampedFloatParameter _Frequency = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 12 | public ClampedFloatParameter _Threshold = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); 13 | 14 | private Material _material; 15 | public override void Setup() 16 | { 17 | if (_material == null) 18 | { 19 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Glitch/ScanLineJitter"); 20 | } 21 | } 22 | 23 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 24 | RenderTargetIdentifier destination) 25 | { 26 | if (_material == null) 27 | { 28 | return; 29 | } 30 | cmd.SetGlobalFloat("_Amount", _Amount.value); 31 | cmd.SetGlobalFloat("_Frequency", _Frequency.value); 32 | cmd.SetGlobalFloat("_Threshold", _Threshold.value); 33 | cmd.Blit(source, destination, _material); 34 | } 35 | 36 | public override bool IsActive() 37 | { 38 | return active; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/ScanLineJitter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc0f51a2f787e9e4ca372c6a6e328e38 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/WaveJitter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.Rendering; 6 | using UnityEngine.Rendering.Universal; 7 | 8 | [VolumeComponentMenu("CustomPost/Glitch/WaveJitter")] 9 | public class CustomWaveJitter : PostVolumeComponentBase 10 | { 11 | public ClampedFloatParameter Frequency = new ClampedFloatParameter(0.0f, 0.0f,5.0f); 12 | public ClampedFloatParameter Speed = new ClampedFloatParameter(0.0f, 0.0f,5.0f); 13 | public ClampedFloatParameter Amount = new ClampedFloatParameter(0.0f, 0.0f,5.0f); 14 | public ClampedFloatParameter RGBSplit = new ClampedFloatParameter(0.0f, 0.0f,5.0f); 15 | 16 | private Material _material; 17 | public override void Setup() 18 | { 19 | if (_material == null) 20 | _material = CoreUtils.CreateEngineMaterial("CustomPost/Glitch/WaveJitter"); 21 | } 22 | 23 | public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, 24 | RenderTargetIdentifier destination) 25 | { 26 | if (_material == null) 27 | return; 28 | cmd.SetGlobalFloat(Shader.PropertyToID("_Frequency"), Frequency.value); 29 | cmd.SetGlobalFloat(Shader.PropertyToID("_Speed"), Speed.value); 30 | cmd.SetGlobalFloat(Shader.PropertyToID("_Amount"), Amount.value); 31 | cmd.SetGlobalFloat(Shader.PropertyToID("_RGBSplit"), RGBSplit.value); 32 | cmd.Blit(source, destination, _material); 33 | } 34 | 35 | public override bool IsActive() 36 | { 37 | return active; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/Glitch/WaveJitter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f363964b193b584a9c54d1dd19a195d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/PostVolumeBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.Rendering; 6 | using UnityEngine.Rendering.Universal; 7 | 8 | 9 | public abstract class PostVolumeComponentBase : VolumeComponent, IPostProcessComponent, IDisposable 10 | { 11 | 12 | public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing; 13 | 14 | 15 | /// 初始化,将在RenderPass加入队列时调用 16 | public abstract void Setup(); 17 | 18 | /// 执行渲染 19 | public abstract void Render(CommandBuffer cmd, ref RenderingData renderingData, RenderTargetIdentifier source, RenderTargetIdentifier destination); 20 | 21 | #region IPostProcessComponent 22 | /// 返回当前组件是否处于激活状态 23 | public abstract bool IsActive(); 24 | 25 | public virtual bool IsTileCompatible() => false; 26 | #endregion 27 | 28 | #region IDisposable 29 | public void Dispose() 30 | { 31 | Dispose(true); 32 | GC.SuppressFinalize(this); 33 | } 34 | 35 | /// 释放资源 36 | public virtual void Dispose(bool disposing) {} 37 | #endregion 38 | } 39 | -------------------------------------------------------------------------------- /URP-Volume-Post/Volumes/PostVolumeBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cd553bb82000e64693e3371035be76b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | --------------------------------------------------------------------------------