From de5a458cb037bb8e1e80c849c5e6525f9413b43a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 14 Feb 2015 12:09:41 -0500 Subject: Monitor stuff is looking pretty cool! --- shaders/blit.fragment | 12 ++++++++++ shaders/blit.vertex | 13 ++++++++++ shaders/fill.fragment | 10 ++++++++ shaders/fill.vertex | 8 +++++++ shaders/final.fragment | 56 +++++++++++++++++++++++++++++++++++++++++++ shaders/final.vertex | 14 +++++++++++ shaders/ntsc.fragment | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ shaders/ntsc.vertex | 11 +++++++++ 8 files changed, 188 insertions(+) create mode 100644 shaders/blit.fragment create mode 100644 shaders/blit.vertex create mode 100644 shaders/fill.fragment create mode 100644 shaders/fill.vertex create mode 100644 shaders/final.fragment create mode 100644 shaders/final.vertex create mode 100644 shaders/ntsc.fragment create mode 100644 shaders/ntsc.vertex (limited to 'shaders') diff --git a/shaders/blit.fragment b/shaders/blit.fragment new file mode 100644 index 0000000..07a0279 --- /dev/null +++ b/shaders/blit.fragment @@ -0,0 +1,12 @@ +#version 330 core + +in vec2 UV; + +out vec3 color; + +uniform sampler2D srctex; + +void main() +{ + color = texture(srctex, UV).xyz; +} diff --git a/shaders/blit.vertex b/shaders/blit.vertex new file mode 100644 index 0000000..4a9aa6a --- /dev/null +++ b/shaders/blit.vertex @@ -0,0 +1,13 @@ +#version 330 core + +layout(location = 0) in vec2 vertexPosition; +layout(location = 1) in vec2 texcoordPosition; + +out vec2 UV; + +void main() +{ + gl_Position = vec4(vertexPosition, 0.0f, 1.0f); + + UV = texcoordPosition; +} diff --git a/shaders/fill.fragment b/shaders/fill.fragment new file mode 100644 index 0000000..ab7d9c9 --- /dev/null +++ b/shaders/fill.fragment @@ -0,0 +1,10 @@ +#version 330 core + +out vec3 color; + +uniform vec3 vecColor; + +void main() +{ + color = vecColor; +} diff --git a/shaders/fill.vertex b/shaders/fill.vertex new file mode 100644 index 0000000..44445fe --- /dev/null +++ b/shaders/fill.vertex @@ -0,0 +1,8 @@ +#version 330 core + +layout(location = 0) in vec3 vertexPosition; + +void main() +{ + gl_Position = vec4(vertexPosition, 1); +} diff --git a/shaders/final.fragment b/shaders/final.fragment new file mode 100644 index 0000000..c900973 --- /dev/null +++ b/shaders/final.fragment @@ -0,0 +1,56 @@ +#version 330 core + +in vec2 UV; +in vec3 norm; + +out vec3 color; + +uniform sampler2D rendertex; +uniform sampler2D scanlinestex; + +const vec2 UVScalar = vec2(1.0, 1.0); +const vec2 UVOffset = vec2(0.0, 0.0); +const vec2 CRTMask_Scale = vec2(85.0, 153.6); +const vec2 CRTMask_Offset = vec2(0.0, 0.0); +const float Tuning_Overscan = 1.0; +const float Tuning_Dimming = 0.5; +const float Tuning_Satur = 1.35; +const float Tuning_ReflScalar = 0.3; +const float Tuning_Barrel = 0.12; +const float Tuning_Scanline_Brightness = 0.25; +const float Tuning_Scanline_Opacity = 0.5; +const float Tuning_Diff_Brightness = 0.5; +const float Tuning_Spec_Brightness = 0.35; +const float Tuning_Spec_Power = 50.0; +const float Tuning_Fres_Brightness = 1.0; +const vec3 Tuning_LightPos = vec3(5.0, -10.0, 0.0); + +vec4 sampleCRT(vec2 uv) +{ + vec2 ScaledUV = uv; + ScaledUV *= UVScalar; + ScaledUV += UVOffset; + + vec2 scanuv = ScaledUV * CRTMask_Scale; + vec3 scantex = texture(scanlinestex, scanuv).rgb; + scantex += Tuning_Scanline_Brightness; + scantex = mix(vec3(1,1,1), scantex, Tuning_Scanline_Opacity); + + vec2 overscanuv = (ScaledUV * Tuning_Overscan) - ((Tuning_Overscan - 1.0f) * 0.5f); + overscanuv = overscanuv - vec2(0.5, 0.5); + float rsq = (overscanuv.x*overscanuv.x) + (overscanuv.y*overscanuv.y); + overscanuv = overscanuv + (overscanuv * (Tuning_Barrel * rsq)) + vec2(0.5,0.5); + + vec3 comptex = texture(rendertex, overscanuv).rgb; + + vec4 emissive = vec4(comptex * scantex, 1); + float desat = dot(vec4(0.299, 0.587, 0.114, 0.0), emissive); + emissive = mix(vec4(desat, desat, desat, 1), emissive, Tuning_Satur); + + return emissive; +} + +void main() +{ + color = sampleCRT(UV).rgb; +} diff --git a/shaders/final.vertex b/shaders/final.vertex new file mode 100644 index 0000000..825eb49 --- /dev/null +++ b/shaders/final.vertex @@ -0,0 +1,14 @@ +#version 330 core + +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec3 vertexNormal; + +out vec2 UV; +out vec3 norm; + +void main() +{ + gl_Position = vec4(vertexPosition_modelspace,1); + UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; + norm = vertexNormal; +} diff --git a/shaders/ntsc.fragment b/shaders/ntsc.fragment new file mode 100644 index 0000000..12d6873 --- /dev/null +++ b/shaders/ntsc.fragment @@ -0,0 +1,64 @@ +#version 330 core + +in vec2 UV; + +out vec3 color; + +uniform sampler2D curFrameSampler; +uniform sampler2D NTSCArtifactSampler; +uniform sampler2D prevFrameSampler; + +const float Tuning_Sharp = 0.8; +const vec4 Tuning_Persistence = vec4(0.7,0.7,0.7,0.7); +const float Tuning_Bleed = 0.5; +const float Tuning_NTSC = 0.35; +uniform float NTSCLerp; + +const vec2 RcpScrWidth = vec2(1.0f / 320.f, 0.0f); +const vec2 RcpScrHeight = vec2(0.0f, 1.0f / 200.0f); + +float Brightness(vec4 InVal) +{ + return dot(InVal, vec4(0.299, 0.587, 0.114, 0.0)); +} + +const float SharpWeight[3] = float[3](1.0, -0.3162277, 0.1); + +void main() +{ + vec4 NTSCArtifact1 = texture(NTSCArtifactSampler, UV); + vec4 NTSCArtifact2 = texture(NTSCArtifactSampler, UV + RcpScrHeight); + vec4 NTSCArtifact = mix(NTSCArtifact1, NTSCArtifact2, NTSCLerp); + + vec2 LeftUV = UV - RcpScrWidth; + vec2 RightUV = UV + RcpScrWidth; + + vec4 Cur_Left = texture(curFrameSampler, LeftUV); + vec4 Cur_Local = texture(curFrameSampler, UV); + vec4 Cur_Right = texture(curFrameSampler, RightUV); + + vec4 Prev_Left = texture(prevFrameSampler, LeftUV); + vec4 Prev_Local = texture(prevFrameSampler, UV); + vec4 Prev_Right = texture(prevFrameSampler, RightUV); + + Cur_Local = clamp(Cur_Local + (((Cur_Left - Cur_Local) + (Cur_Right - Cur_Local)) * Tuning_NTSC), vec4(0,0,0,0), vec4(1,1,1,1)); + + float curBrt = Brightness(Cur_Local); + float offset = 0; + + for (int i=0; i<3; ++i) + { + vec2 StepSize = (RcpScrWidth * float(i+1)); + vec4 neighborleft = texture(curFrameSampler, UV - StepSize); + vec4 neighborright = texture(curFrameSampler, UV + StepSize); + + float NBrtL = Brightness(neighborleft); + float NBrtR = Brightness(neighborright); + offset += ((curBrt - NBrtL) + (curBrt - NBrtR)) * SharpWeight[i]; + } + + Cur_Local = clamp(Cur_Local + (offset * Tuning_Sharp * mix(vec4(1,1,1,1), NTSCArtifact, Tuning_NTSC)), vec4(0,0,0,0), vec4(1,1,1,1)); + Cur_Local = clamp(max(Cur_Local, Tuning_Persistence * (1.0 / (1.0 + (2.0 * Tuning_Bleed))) * (Prev_Local + ((Prev_Left + Prev_Right) * Tuning_Bleed))), vec4(0,0,0,0), vec4(1,1,1,1)); + + color = Cur_Local.xyz; +} diff --git a/shaders/ntsc.vertex b/shaders/ntsc.vertex new file mode 100644 index 0000000..81f8af3 --- /dev/null +++ b/shaders/ntsc.vertex @@ -0,0 +1,11 @@ +#version 330 core + +layout(location = 0) in vec3 vertexPosition_modelspace; + +out vec2 UV; + +void main() +{ + gl_Position = vec4(vertexPosition_modelspace,1); + UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; +} -- cgit 1.4.1