Skip to content

Commit 6fd51aa

Browse files
committed
新增【Vignette】系列后处理特效 | Add Vignette Effect Series
新增【Vignette】系列后处理特效 | Add Vignette Effect Series
1 parent f454f61 commit 6fd51aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1356
-0
lines changed

Assets/X-PostProcessing/Effects/AuroraVignette.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+

2+
//----------------------------------------------------------------------------------------------------------
3+
// X-PostProcessing Library
4+
// https://github.com/QianMo/X-PostProcessing-Library
5+
// Copyright (C) 2020 QianMo. All rights reserved.
6+
// Licensed under the MIT License
7+
// You may not use this file except in compliance with the License.You may obtain a copy of the License at
8+
// http://opensource.org/licenses/MIT
9+
//----------------------------------------------------------------------------------------------------------
10+
11+
using System;
12+
using UnityEngine;
13+
using UnityEngine.Rendering;
14+
using UnityEngine.Rendering.PostProcessing;
15+
16+
17+
namespace XPostProcessing
18+
{
19+
20+
[Serializable]
21+
[PostProcess(typeof(AuroraVignetteRenderer), PostProcessEvent.AfterStack, "X-PostProcessing/Vignette/AuroraVignette")]
22+
public class AuroraVignette : PostProcessEffectSettings
23+
{
24+
[Range(0.0f, 1.0f)]
25+
public FloatParameter vignetteArea = new FloatParameter { value = 0.8f };
26+
27+
[Range(0.0f, 1.0f)]
28+
public FloatParameter vignetteSmothness = new FloatParameter { value = 0.5f };
29+
30+
[Range(0.0f, 1.0f)]
31+
public FloatParameter vignetteFading = new FloatParameter { value = 1f };
32+
33+
[Range(0.1f, 1f)]
34+
public FloatParameter colorChange = new FloatParameter { value = 0.1f };
35+
36+
37+
[Range(0.0f, 2.0f)]
38+
public FloatParameter colorFactorR = new FloatParameter { value = 1.0f };
39+
40+
[Range(0.0f, 2.0f)]
41+
public FloatParameter colorFactorG = new FloatParameter { value = 1.0f };
42+
43+
[Range(0.0f, 2.0f)]
44+
public FloatParameter colorFactorB = new FloatParameter { value = 1.0f };
45+
46+
[Range(-2.0f, 2.0f)]
47+
public FloatParameter flowSpeed = new FloatParameter { value = 1.0f };
48+
49+
50+
51+
}
52+
53+
public sealed class AuroraVignetteRenderer : PostProcessEffectRenderer<AuroraVignette>
54+
{
55+
private Shader shader;
56+
private float TimeX = 1.0f;
57+
private const string PROFILER_TAG = "X-AuroraVignette";
58+
59+
public override void Init()
60+
{
61+
shader = Shader.Find("Hidden/X-PostProcessing/AuroraVignette");
62+
}
63+
64+
public override void Release()
65+
{
66+
base.Release();
67+
}
68+
69+
static class ShaderIDs
70+
{
71+
internal static readonly int vignetteArea = Shader.PropertyToID("_VignetteArea");
72+
internal static readonly int vignetteSmothness = Shader.PropertyToID("_VignetteSmothness");
73+
internal static readonly int colorChange = Shader.PropertyToID("_ColorChange");
74+
internal static readonly int colorFactor = Shader.PropertyToID("_ColorFactor");
75+
internal static readonly int TimeX = Shader.PropertyToID("_TimeX");
76+
internal static readonly int vignetteFading = Shader.PropertyToID("_Fading");
77+
}
78+
79+
public override void Render(PostProcessRenderContext context)
80+
{
81+
CommandBuffer cmd = context.command;
82+
PropertySheet sheet = context.propertySheets.Get(shader);
83+
cmd.BeginSample(PROFILER_TAG);
84+
85+
TimeX += Time.deltaTime;
86+
if (TimeX > 100)
87+
{
88+
TimeX = 0;
89+
}
90+
91+
sheet.properties.SetFloat(ShaderIDs.vignetteArea, settings.vignetteArea);
92+
sheet.properties.SetFloat(ShaderIDs.vignetteSmothness, settings.vignetteSmothness);
93+
sheet.properties.SetFloat(ShaderIDs.colorChange, settings.colorChange * 10f);
94+
sheet.properties.SetVector(ShaderIDs.colorFactor, new Vector3(settings.colorFactorR, settings.colorFactorG, settings.colorFactorB));
95+
sheet.properties.SetFloat(ShaderIDs.TimeX, TimeX * settings.flowSpeed);
96+
sheet.properties.SetFloat(ShaderIDs.vignetteFading, settings.vignetteFading);
97+
98+
cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
99+
cmd.EndSample(PROFILER_TAG);
100+
}
101+
}
102+
}
103+

Assets/X-PostProcessing/Effects/AuroraVignette/AuroraVignette.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/X-PostProcessing/Effects/AuroraVignette/Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+

2+
//----------------------------------------------------------------------------------------------------------
3+
// X-PostProcessing Library
4+
// https://github.com/QianMo/X-PostProcessing-Library
5+
// Copyright (C) 2020 QianMo. All rights reserved.
6+
// Licensed under the MIT License
7+
// You may not use this file except in compliance with the License.You may obtain a copy of the License at
8+
// http://opensource.org/licenses/MIT
9+
//----------------------------------------------------------------------------------------------------------
10+
11+
using System.Collections;
12+
using System.Collections.Generic;
13+
using UnityEngine;
14+
using UnityEditor;
15+
16+
using UnityEditor.Rendering.PostProcessing;
17+
using UnityEngine.Rendering.PostProcessing;
18+
19+
namespace XPostProcessing
20+
{
21+
[PostProcessEditor(typeof(AuroraVignette))]
22+
public sealed class AuroraVignetteEditor : PostProcessEffectEditor<AuroraVignette>
23+
{
24+
25+
SerializedParameterOverride vignetteArea;
26+
SerializedParameterOverride vignetteSmothness;
27+
SerializedParameterOverride vignetteFading;
28+
SerializedParameterOverride colorChange;
29+
SerializedParameterOverride colorFactorR;
30+
SerializedParameterOverride colorFactorG;
31+
SerializedParameterOverride colorFactorB;
32+
SerializedParameterOverride flowSpeed;
33+
34+
35+
public override void OnEnable()
36+
{
37+
vignetteArea = FindParameterOverride(x => x.vignetteArea);
38+
vignetteSmothness = FindParameterOverride(x => x.vignetteSmothness);
39+
vignetteFading = FindParameterOverride(x => x.vignetteFading);
40+
colorChange = FindParameterOverride(x => x.colorChange);
41+
colorFactorR = FindParameterOverride(x => x.colorFactorR);
42+
colorFactorG = FindParameterOverride(x => x.colorFactorG);
43+
colorFactorB = FindParameterOverride(x => x.colorFactorB);
44+
flowSpeed = FindParameterOverride(x => x.flowSpeed);
45+
}
46+
47+
public override string GetDisplayTitle()
48+
{
49+
return XPostProcessingEditorUtility.DISPLAY_TITLE_PREFIX + base.GetDisplayTitle();
50+
}
51+
52+
public override void OnInspectorGUI()
53+
{
54+
EditorUtilities.DrawHeaderLabel("Vignette");
55+
PropertyField(vignetteFading);
56+
PropertyField(vignetteArea);
57+
PropertyField(vignetteSmothness);
58+
59+
EditorUtilities.DrawHeaderLabel("Speed");
60+
PropertyField(flowSpeed);
61+
62+
EditorUtilities.DrawHeaderLabel("Color Adjustment");
63+
PropertyField(colorChange);
64+
PropertyField(colorFactorR);
65+
PropertyField(colorFactorG);
66+
PropertyField(colorFactorB);
67+
}
68+
69+
}
70+
}
71+

Assets/X-PostProcessing/Effects/AuroraVignette/Editor/AuroraVignetteEditor.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/X-PostProcessing/Effects/AuroraVignette/Shader.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
//----------------------------------------------------------------------------------------------------------
3+
// X-PostProcessing Library
4+
// https://github.com/QianMo/X-PostProcessing-Library
5+
// Copyright (C) 2020 QianMo. All rights reserved.
6+
// Licensed under the MIT License
7+
// You may not use this file except in compliance with the License.You may obtain a copy of the License at
8+
// http://opensource.org/licenses/MIT
9+
//----------------------------------------------------------------------------------------------------------
10+
11+
Shader "Hidden/X-PostProcessing/AuroraVignette"
12+
{
13+
HLSLINCLUDE
14+
15+
#include "../../../Shaders/StdLib.hlsl"
16+
#include "../../../Shaders/XPostProcessing.hlsl"
17+
18+
uniform half _VignetteArea;
19+
uniform half _VignetteSmothness;
20+
uniform half _ColorChange;
21+
uniform half4 _Color;
22+
uniform half _TimeX;
23+
uniform half3 _ColorFactor;
24+
uniform half _Fading;
25+
26+
half4 Frag(VaryingsDefault i): SV_Target
27+
{
28+
float2 uv = i.texcoord;
29+
float2 uv0 = uv - float2(0.5 + 0.5 * sin(1.4 * 6.28 * uv.x + 2.8 * _TimeX), 0.5);
30+
float3 wave = float3(0.5 * (cos(sqrt(dot(uv0, uv0)) * 5.6) + 1.0), cos(4.62 * dot(uv, uv) + _TimeX), cos(distance(uv, float2(1.6 * cos(_TimeX * 2.0), 1.0 * sin(_TimeX * 1.7))) * 1.3));
31+
half waveFactor = dot(wave, _ColorFactor) / _ColorChange;
32+
half vignetteIndensity = 1.0 - smoothstep(_VignetteArea, _VignetteArea - 0.05 - _VignetteSmothness, length(float2(0.5, 0.5) - uv));
33+
half3 AuroraColor = half3
34+
(
35+
_ColorFactor.r * 0.5 * (sin(1.28 * waveFactor + _TimeX * 3.45) + 1.0),
36+
_ColorFactor.g * 0.5 * (sin(1.28 * waveFactor + _TimeX * 3.15) + 1.0),
37+
_ColorFactor.b * 0.4 * (sin(1.28 * waveFactor + _TimeX * 1.26) + 1.0)
38+
);
39+
half3 finalColor = lerp(SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv).rgb, AuroraColor, vignetteIndensity * _Fading);
40+
return half4(finalColor, 1.0);
41+
}
42+
43+
ENDHLSL
44+
45+
SubShader
46+
{
47+
Cull Off ZWrite Off ZTest Always
48+
49+
Pass
50+
{
51+
HLSLPROGRAM
52+
53+
#pragma vertex VertDefault
54+
#pragma fragment Frag
55+
56+
ENDHLSL
57+
58+
}
59+
}
60+
}
61+
62+

Assets/X-PostProcessing/Effects/AuroraVignette/Shader/AuroraVignette.shader.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/X-PostProcessing/Effects/RapidOldTVVignette.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/X-PostProcessing/Effects/RapidOldTVVignette/Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
using UnityEditor.Rendering.PostProcessing;
7+
using UnityEngine.Rendering.PostProcessing;
8+
9+
namespace XPostProcessing
10+
{
11+
[PostProcessEditor(typeof(RapidOldTVVignette))]
12+
public sealed class RapidOldTVVignetteEditor : PostProcessEffectEditor<RapidOldTVVignette>
13+
{
14+
15+
SerializedParameterOverride vignetteType;
16+
SerializedParameterOverride vignetteIndensity;
17+
SerializedParameterOverride vignetteCenter;
18+
SerializedParameterOverride vignetteColor;
19+
20+
public override void OnEnable()
21+
{
22+
vignetteType = FindParameterOverride(x => x.vignetteType);
23+
vignetteIndensity = FindParameterOverride(x => x.vignetteIndensity);
24+
vignetteCenter = FindParameterOverride(x => x.vignetteCenter);
25+
vignetteColor = FindParameterOverride(x => x.vignetteColor);
26+
}
27+
28+
public override string GetDisplayTitle()
29+
{
30+
return XPostProcessingEditorUtility.DISPLAY_TITLE_PREFIX + base.GetDisplayTitle();
31+
}
32+
33+
public override void OnInspectorGUI()
34+
{
35+
36+
PropertyField(vignetteType);
37+
PropertyField(vignetteIndensity);
38+
PropertyField(vignetteCenter);
39+
40+
if (vignetteType.value.enumValueIndex == 1)
41+
{
42+
PropertyField(vignetteColor);
43+
}
44+
}
45+
46+
}
47+
}

Assets/X-PostProcessing/Effects/RapidOldTVVignette/Editor/RapidOldTVVignetteEditor.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)