diff options
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/blit.fragment | 12 | ||||
| -rw-r--r-- | shaders/blit.vertex | 13 | ||||
| -rw-r--r-- | shaders/fill.fragment | 10 | ||||
| -rw-r--r-- | shaders/fill.vertex | 8 | ||||
| -rw-r--r-- | shaders/final.fragment | 56 | ||||
| -rw-r--r-- | shaders/final.vertex | 14 | ||||
| -rw-r--r-- | shaders/ntsc.fragment | 64 | ||||
| -rw-r--r-- | shaders/ntsc.vertex | 11 |
8 files changed, 188 insertions, 0 deletions
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | in vec2 UV; | ||
| 4 | |||
| 5 | out vec3 color; | ||
| 6 | |||
| 7 | uniform sampler2D srctex; | ||
| 8 | |||
| 9 | void main() | ||
| 10 | { | ||
| 11 | color = texture(srctex, UV).xyz; | ||
| 12 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | layout(location = 0) in vec2 vertexPosition; | ||
| 4 | layout(location = 1) in vec2 texcoordPosition; | ||
| 5 | |||
| 6 | out vec2 UV; | ||
| 7 | |||
| 8 | void main() | ||
| 9 | { | ||
| 10 | gl_Position = vec4(vertexPosition, 0.0f, 1.0f); | ||
| 11 | |||
| 12 | UV = texcoordPosition; | ||
| 13 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | out vec3 color; | ||
| 4 | |||
| 5 | uniform vec3 vecColor; | ||
| 6 | |||
| 7 | void main() | ||
| 8 | { | ||
| 9 | color = vecColor; | ||
| 10 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | layout(location = 0) in vec3 vertexPosition; | ||
| 4 | |||
| 5 | void main() | ||
| 6 | { | ||
| 7 | gl_Position = vec4(vertexPosition, 1); | ||
| 8 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | in vec2 UV; | ||
| 4 | in vec3 norm; | ||
| 5 | |||
| 6 | out vec3 color; | ||
| 7 | |||
| 8 | uniform sampler2D rendertex; | ||
| 9 | uniform sampler2D scanlinestex; | ||
| 10 | |||
| 11 | const vec2 UVScalar = vec2(1.0, 1.0); | ||
| 12 | const vec2 UVOffset = vec2(0.0, 0.0); | ||
| 13 | const vec2 CRTMask_Scale = vec2(85.0, 153.6); | ||
| 14 | const vec2 CRTMask_Offset = vec2(0.0, 0.0); | ||
| 15 | const float Tuning_Overscan = 1.0; | ||
| 16 | const float Tuning_Dimming = 0.5; | ||
| 17 | const float Tuning_Satur = 1.35; | ||
| 18 | const float Tuning_ReflScalar = 0.3; | ||
| 19 | const float Tuning_Barrel = 0.12; | ||
| 20 | const float Tuning_Scanline_Brightness = 0.25; | ||
| 21 | const float Tuning_Scanline_Opacity = 0.5; | ||
| 22 | const float Tuning_Diff_Brightness = 0.5; | ||
| 23 | const float Tuning_Spec_Brightness = 0.35; | ||
| 24 | const float Tuning_Spec_Power = 50.0; | ||
| 25 | const float Tuning_Fres_Brightness = 1.0; | ||
| 26 | const vec3 Tuning_LightPos = vec3(5.0, -10.0, 0.0); | ||
| 27 | |||
| 28 | vec4 sampleCRT(vec2 uv) | ||
| 29 | { | ||
| 30 | vec2 ScaledUV = uv; | ||
| 31 | ScaledUV *= UVScalar; | ||
| 32 | ScaledUV += UVOffset; | ||
| 33 | |||
| 34 | vec2 scanuv = ScaledUV * CRTMask_Scale; | ||
| 35 | vec3 scantex = texture(scanlinestex, scanuv).rgb; | ||
| 36 | scantex += Tuning_Scanline_Brightness; | ||
| 37 | scantex = mix(vec3(1,1,1), scantex, Tuning_Scanline_Opacity); | ||
| 38 | |||
| 39 | vec2 overscanuv = (ScaledUV * Tuning_Overscan) - ((Tuning_Overscan - 1.0f) * 0.5f); | ||
| 40 | overscanuv = overscanuv - vec2(0.5, 0.5); | ||
| 41 | float rsq = (overscanuv.x*overscanuv.x) + (overscanuv.y*overscanuv.y); | ||
| 42 | overscanuv = overscanuv + (overscanuv * (Tuning_Barrel * rsq)) + vec2(0.5,0.5); | ||
| 43 | |||
| 44 | vec3 comptex = texture(rendertex, overscanuv).rgb; | ||
| 45 | |||
| 46 | vec4 emissive = vec4(comptex * scantex, 1); | ||
| 47 | float desat = dot(vec4(0.299, 0.587, 0.114, 0.0), emissive); | ||
| 48 | emissive = mix(vec4(desat, desat, desat, 1), emissive, Tuning_Satur); | ||
| 49 | |||
| 50 | return emissive; | ||
| 51 | } | ||
| 52 | |||
| 53 | void main() | ||
| 54 | { | ||
| 55 | color = sampleCRT(UV).rgb; | ||
| 56 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | layout(location = 0) in vec3 vertexPosition_modelspace; | ||
| 4 | layout(location = 1) in vec3 vertexNormal; | ||
| 5 | |||
| 6 | out vec2 UV; | ||
| 7 | out vec3 norm; | ||
| 8 | |||
| 9 | void main() | ||
| 10 | { | ||
| 11 | gl_Position = vec4(vertexPosition_modelspace,1); | ||
| 12 | UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; | ||
| 13 | norm = vertexNormal; | ||
| 14 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | in vec2 UV; | ||
| 4 | |||
| 5 | out vec3 color; | ||
| 6 | |||
| 7 | uniform sampler2D curFrameSampler; | ||
| 8 | uniform sampler2D NTSCArtifactSampler; | ||
| 9 | uniform sampler2D prevFrameSampler; | ||
| 10 | |||
| 11 | const float Tuning_Sharp = 0.8; | ||
| 12 | const vec4 Tuning_Persistence = vec4(0.7,0.7,0.7,0.7); | ||
| 13 | const float Tuning_Bleed = 0.5; | ||
| 14 | const float Tuning_NTSC = 0.35; | ||
| 15 | uniform float NTSCLerp; | ||
| 16 | |||
| 17 | const vec2 RcpScrWidth = vec2(1.0f / 320.f, 0.0f); | ||
| 18 | const vec2 RcpScrHeight = vec2(0.0f, 1.0f / 200.0f); | ||
| 19 | |||
| 20 | float Brightness(vec4 InVal) | ||
| 21 | { | ||
| 22 | return dot(InVal, vec4(0.299, 0.587, 0.114, 0.0)); | ||
| 23 | } | ||
| 24 | |||
| 25 | const float SharpWeight[3] = float[3](1.0, -0.3162277, 0.1); | ||
| 26 | |||
| 27 | void main() | ||
| 28 | { | ||
| 29 | vec4 NTSCArtifact1 = texture(NTSCArtifactSampler, UV); | ||
| 30 | vec4 NTSCArtifact2 = texture(NTSCArtifactSampler, UV + RcpScrHeight); | ||
| 31 | vec4 NTSCArtifact = mix(NTSCArtifact1, NTSCArtifact2, NTSCLerp); | ||
| 32 | |||
| 33 | vec2 LeftUV = UV - RcpScrWidth; | ||
| 34 | vec2 RightUV = UV + RcpScrWidth; | ||
| 35 | |||
| 36 | vec4 Cur_Left = texture(curFrameSampler, LeftUV); | ||
| 37 | vec4 Cur_Local = texture(curFrameSampler, UV); | ||
| 38 | vec4 Cur_Right = texture(curFrameSampler, RightUV); | ||
| 39 | |||
| 40 | vec4 Prev_Left = texture(prevFrameSampler, LeftUV); | ||
| 41 | vec4 Prev_Local = texture(prevFrameSampler, UV); | ||
| 42 | vec4 Prev_Right = texture(prevFrameSampler, RightUV); | ||
| 43 | |||
| 44 | 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)); | ||
| 45 | |||
| 46 | float curBrt = Brightness(Cur_Local); | ||
| 47 | float offset = 0; | ||
| 48 | |||
| 49 | for (int i=0; i<3; ++i) | ||
| 50 | { | ||
| 51 | vec2 StepSize = (RcpScrWidth * float(i+1)); | ||
| 52 | vec4 neighborleft = texture(curFrameSampler, UV - StepSize); | ||
| 53 | vec4 neighborright = texture(curFrameSampler, UV + StepSize); | ||
| 54 | |||
| 55 | float NBrtL = Brightness(neighborleft); | ||
| 56 | float NBrtR = Brightness(neighborright); | ||
| 57 | offset += ((curBrt - NBrtL) + (curBrt - NBrtR)) * SharpWeight[i]; | ||
| 58 | } | ||
| 59 | |||
| 60 | 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)); | ||
| 61 | 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)); | ||
| 62 | |||
| 63 | color = Cur_Local.xyz; | ||
| 64 | } | ||
| 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 @@ | |||
| 1 | #version 330 core | ||
| 2 | |||
| 3 | layout(location = 0) in vec3 vertexPosition_modelspace; | ||
| 4 | |||
| 5 | out vec2 UV; | ||
| 6 | |||
| 7 | void main() | ||
| 8 | { | ||
| 9 | gl_Position = vec4(vertexPosition_modelspace,1); | ||
| 10 | UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; | ||
| 11 | } | ||
