Skip to content

Commit 11752b7

Browse files
committed
Added a grille effect to the CRT shader
1 parent 0fd2115 commit 11752b7

File tree

8 files changed

+422
-174
lines changed

8 files changed

+422
-174
lines changed

URP-PSX/Assets/Scenes/Psx_PBR.unity

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ Light:
496496
serializedVersion: 10
497497
m_Type: 0
498498
m_Shape: 0
499-
m_Color: {r: 1, g: 1, b: 1, a: 1}
499+
m_Color: {r: 0.28040814, g: 0.49162373, b: 0.6415094, a: 1}
500500
m_Intensity: 70.23
501501
m_Range: 27.335835
502502
m_SpotAngle: 32.74557
@@ -574,7 +574,7 @@ Transform:
574574
m_GameObject: {fileID: 608079567}
575575
serializedVersion: 2
576576
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
577-
m_LocalPosition: {x: 9.22, y: -0.44, z: -0.02}
577+
m_LocalPosition: {x: 7.09, y: 3.28, z: -0.02}
578578
m_LocalScale: {x: 1, y: 1, z: 1}
579579
m_ConstrainProportionsScale: 0
580580
m_Children: []
@@ -614,7 +614,7 @@ Light:
614614
serializedVersion: 10
615615
m_Type: 2
616616
m_Shape: 0
617-
m_Color: {r: 1, g: 1, b: 1, a: 1}
617+
m_Color: {r: 0.2519677, g: 0.5767318, b: 0.8805031, a: 1}
618618
m_Intensity: 70.23
619619
m_Range: 27.335835
620620
m_SpotAngle: 32.74557
@@ -1457,6 +1457,14 @@ MonoBehaviour:
14571457
chromaticRed: {x: 0.002, y: -0.002}
14581458
chromaticGreen: {x: -0.002, y: 0.002}
14591459
chromaticBlue: {x: 0, y: 0}
1460+
grilleOpacity: 0.2
1461+
grilleCounterOpacity: 0.3
1462+
grilleResolution: 640
1463+
grilleCounterResolution: 380
1464+
grilleBrightness: 16
1465+
grilleUvRotation: 90
1466+
grilleUvMidPoint: 0.5
1467+
grilleShift: {x: 1, y: 1, z: 1}
14601468
--- !u!1001 &1364880466
14611469
PrefabInstance:
14621470
m_ObjectHideFlags: 0

URP-PSX/Assets/Scripts/CRT/CRTEffectController.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public class CRTEffectController : MonoBehaviour
2828
[SerializeField] protected Vector2 chromaticGreen = new Vector2();
2929
[SerializeField] protected Vector2 chromaticBlue = new Vector2();
3030

31+
[SerializeField] protected float grilleOpacity = 0.4f;
32+
[SerializeField] protected float grilleCounterOpacity = 0.2f;
33+
[SerializeField] protected float grilleResolution = 360.0f;
34+
[SerializeField] protected float grilleCounterResolution = 540.0f;
35+
[SerializeField] protected float grilleBrightness = 15.0f;
36+
[SerializeField] protected float grilleUvRotation = (90.0f);
37+
[SerializeField] protected float grilleUvMidPoint = 0.5f;
38+
[SerializeField] protected Vector3 grilleShift = new Vector3(1.0f, 1.0f, 1.0f);
39+
3140
protected void Update()
3241
{
3342
this.SetParams();
@@ -57,6 +66,15 @@ protected void SetParams()
5766
this.crt.chromaticRed.value = this.chromaticRed;
5867
this.crt.chromaticGreen.value = this.chromaticGreen;
5968
this.crt.chromaticBlue.value = this.chromaticBlue;
60-
69+
70+
this.crt.grilleOpacity.value = this.grilleOpacity;
71+
this.crt.grilleCounterOpacity.value = this.grilleCounterOpacity;
72+
this.crt.grilleResolution.value = this.grilleResolution;
73+
this.crt.grilleCounterResolution.value = this.grilleCounterResolution;
74+
this.crt.grilleBrightness.value = this.grilleBrightness;
75+
this.crt.grilleUvRotation.value = this.grilleUvRotation;
76+
this.crt.grilleUvMidPoint.value = this.grilleUvMidPoint;
77+
this.crt.grilleShift.value = this.grilleShift;
78+
6179
}
6280
}

URP-PSX/Assets/Scripts/CRT/CRTRenderFeature.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public class CRTPass : ScriptableRenderPass
5050
static readonly int ChromaticRed = Shader.PropertyToID("_ChromaticRed");
5151
static readonly int ChromaticGreen = Shader.PropertyToID("_ChromaticGreen");
5252
static readonly int ChromaticBlue = Shader.PropertyToID("_ChromaticBlue");
53+
54+
static readonly int GrilleOpacity = Shader.PropertyToID("_GrilleOpacity");
55+
static readonly int GrilleCounterOpacity = Shader.PropertyToID("_GrilleCounterOpacity");
56+
static readonly int GrilleResolution = Shader.PropertyToID("_GrilleResolution");
57+
static readonly int GrilleCounterResolution = Shader.PropertyToID("_GrilleCounterResolution");
58+
static readonly int GrilleBrightness = Shader.PropertyToID("_GrilleBrightness");
59+
static readonly int GrilleUvRotation = Shader.PropertyToID("_GrilleUvRotation");
60+
static readonly int GrilleUvMidPoint = Shader.PropertyToID("_GrilleUvMidPoint");
61+
static readonly int GrilleShift = Shader.PropertyToID("_GrilleShift");
5362

5463
Crt m_Crt;
5564
Material crtMaterial;
@@ -61,7 +70,7 @@ public CRTPass(RenderPassEvent evt)
6170
var shader = Shader.Find(shaderPath);
6271
if (shader == null)
6372
{
64-
Debug.LogError("Shader not found lol (crt).");
73+
Debug.LogError("Shader not found (crt).");
6574
return;
6675
}
6776

@@ -133,6 +142,15 @@ void Render(CommandBuffer cmd, ref RenderingData renderingData)
133142
this.crtMaterial.SetVector(ChromaticGreen, this.m_Crt.chromaticGreen.value);
134143
this.crtMaterial.SetVector(ChromaticBlue, this.m_Crt.chromaticBlue.value);
135144

145+
this.crtMaterial.SetFloat(GrilleOpacity, this.m_Crt.grilleOpacity.value);
146+
this.crtMaterial.SetFloat(GrilleCounterOpacity, this.m_Crt.grilleCounterOpacity.value);
147+
this.crtMaterial.SetFloat(GrilleResolution, this.m_Crt.grilleResolution.value);
148+
this.crtMaterial.SetFloat(GrilleCounterResolution, this.m_Crt.grilleCounterResolution.value);
149+
this.crtMaterial.SetFloat(GrilleBrightness, this.m_Crt.grilleBrightness.value);
150+
this.crtMaterial.SetFloat(GrilleUvRotation, this.m_Crt.grilleUvRotation.value);
151+
this.crtMaterial.SetFloat(GrilleUvMidPoint, this.m_Crt.grilleUvMidPoint.value);
152+
this.crtMaterial.SetVector(GrilleShift, this.m_Crt.grilleShift.value);
153+
136154
int shaderPass = 0;
137155
cmd.SetGlobalTexture(MainTexId, source);
138156
cmd.GetTemporaryRT(destination, w, h, 0, FilterMode.Point, RenderTextureFormat.Default);

URP-PSX/Assets/Scripts/CRT/Crt.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using Unity.Mathematics;
1+
using System;
2+
using Unity.Mathematics;
23
using UnityEngine;
34
using UnityEngine.Rendering;
45
using UnityEngine.Rendering.Universal;
56

67
public class Crt : VolumeComponent, IPostProcessComponent
78
{
8-
99
public FloatParameter scanlinesWeight = new FloatParameter(1f);
1010
public FloatParameter noiseWeight = new FloatParameter(1f);
11-
11+
1212
public FloatParameter screenBendX = new FloatParameter(1000.0f);
1313
public FloatParameter screenBendY = new FloatParameter(1000.0f);
1414
public FloatParameter vignetteAmount = new FloatParameter(0.0f);
@@ -19,10 +19,23 @@ public class Crt : VolumeComponent, IPostProcessComponent
1919
public FloatParameter scanlinesDensity = new FloatParameter(200.0f);
2020
public FloatParameter scanlinesSpeed = new FloatParameter(-10.0f);
2121
public FloatParameter noiseAmount = new FloatParameter(250.0f);
22+
2223
public Vector2Parameter chromaticRed = new Vector2Parameter(new Vector2());
2324
public Vector2Parameter chromaticGreen = new Vector2Parameter(new Vector2());
2425
public Vector2Parameter chromaticBlue = new Vector2Parameter(new Vector2());
2526

27+
// Grille Effect is a modified version of the shader from here:
28+
// https://godotshaders.com/shader/vhs-and-crt-monitor-effect/
29+
public FloatParameter grilleOpacity = new FloatParameter(0.4f);
30+
public FloatParameter grilleCounterOpacity = new FloatParameter(0.2f);
31+
public FloatParameter grilleResolution = new FloatParameter(360.0f);
32+
public FloatParameter grilleCounterResolution = new FloatParameter(540.0f);
33+
public FloatParameter grilleUvRotation = new FloatParameter((float)(90.0f));
34+
public FloatParameter grilleBrightness = new FloatParameter(15.0f);
35+
public FloatParameter grilleUvMidPoint = new FloatParameter(0.5f);
36+
public Vector3Parameter grilleShift = new Vector3Parameter(new Vector3(1.0f, 1.0f, 1.0f));
37+
38+
2639
//INTERFACE REQUIREMENT
2740
public bool IsActive() => true;
2841
public bool IsTileCompatible() => false;

0 commit comments

Comments
 (0)