1#version 130 2 3// license:BSD-3-Clause 4// copyright-holders:Ryan Holtz 5//----------------------------------------------------------------------------- 6// Phosphor Effect 7//----------------------------------------------------------------------------- 8 9#if defined(VERTEX) 10 11#if __VERSION__ >= 130 12#define COMPAT_VARYING out 13#define COMPAT_ATTRIBUTE in 14#define COMPAT_TEXTURE texture 15#else 16#define COMPAT_VARYING varying 17#define COMPAT_ATTRIBUTE attribute 18#define COMPAT_TEXTURE texture2D 19#endif 20 21#ifdef GL_ES 22#define COMPAT_PRECISION mediump 23#else 24#define COMPAT_PRECISION 25#endif 26 27COMPAT_ATTRIBUTE vec4 VertexCoord; 28COMPAT_ATTRIBUTE vec4 COLOR; 29COMPAT_ATTRIBUTE vec4 TexCoord; 30COMPAT_VARYING vec4 COL0; 31COMPAT_VARYING vec4 TEX0; 32 33vec4 _oPosition1; 34uniform mat4 MVPMatrix; 35uniform COMPAT_PRECISION int FrameDirection; 36uniform COMPAT_PRECISION int FrameCount; 37uniform COMPAT_PRECISION vec2 OutputSize; 38uniform COMPAT_PRECISION vec2 TextureSize; 39uniform COMPAT_PRECISION vec2 InputSize; 40 41// compatibility #defines 42#define vTexCoord TEX0.xy 43#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize 44#define OutSize vec4(OutputSize, 1.0 / OutputSize) 45 46void main() 47{ 48 gl_Position = MVPMatrix * VertexCoord; 49 TEX0.xy = TexCoord.xy; 50} 51 52#elif defined(FRAGMENT) 53 54#ifdef GL_ES 55#ifdef GL_FRAGMENT_PRECISION_HIGH 56precision highp float; 57#else 58precision mediump float; 59#endif 60#define COMPAT_PRECISION mediump 61#else 62#define COMPAT_PRECISION 63#endif 64 65#if __VERSION__ >= 130 66#define COMPAT_VARYING in 67#define COMPAT_TEXTURE texture 68out COMPAT_PRECISION vec4 FragColor; 69#else 70#define COMPAT_VARYING varying 71#define FragColor gl_FragColor 72#define COMPAT_TEXTURE texture2D 73#endif 74 75uniform COMPAT_PRECISION int FrameDirection; 76uniform COMPAT_PRECISION int FrameCount; 77uniform COMPAT_PRECISION vec2 OutputSize; 78uniform COMPAT_PRECISION vec2 TextureSize; 79uniform COMPAT_PRECISION vec2 InputSize; 80uniform sampler2D Texture; 81uniform sampler2D PrevTexture; 82uniform sampler2D Prev1Texture; 83uniform sampler2D Prev2Texture; 84uniform sampler2D Prev3Texture; 85uniform sampler2D Prev4Texture; 86uniform sampler2D Prev5Texture; 87uniform sampler2D Prev6Texture; 88COMPAT_VARYING vec4 TEX0; 89 90// compatibility #defines 91#define Source Texture 92#define vTexCoord TEX0.xy 93 94#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize 95#define OutSize vec4(OutputSize, 1.0 / OutputSize) 96 97// effect toggles and multi 98uniform COMPAT_PRECISION float bloomtoggle, ntscsignal, scanlinetoggle, chromatoggle, 99 distortiontoggle, screenscale_x, screenscale_y, screenoffset_x, screenoffset_y, swapxy; 100// bloom params 101uniform COMPAT_PRECISION float bloomblendmode, bloomscale, bloomoverdrive_r, bloomoverdrive_g, bloomoverdrive_b, 102 level0weight, level1weight, level2weight, level3weight, level4weight, level5weight, level6weight, level7weight, level8weight; 103// uniform COMPAT_PRECISION float vectorscreen; // unused 104// post params 105uniform COMPAT_PRECISION float mask_width, mask_height, mask_offset_x, mask_offset_y, preparebloom, shadowtilemode, 106 power_r, power_g, power_b, floor_r, floor_g, floor_b, chromamode, conversiongain_x, conversiongain_y, conversiongain_z, 107 humbaralpha, backcolor_r, backcolor_g, backcolor_b, shadowalpha, shadowcount_x, shadowcount_y, shadowuv_x, shadowuv_y; 108// ntsc params // doesn't work here, so commenting all of them. 109// uniform COMPAT_PRECISION float avalue, bvalue, ccvalue, ovalue, pvalue, scantime, notchhalfwidth, yfreqresponse, ifreqresponse, qfreqresponse, signaloffset; 110// color params 111uniform COMPAT_PRECISION float col_red, col_grn, col_blu, col_offset_x, col_offset_y, col_offset_z, col_scale_x, 112 col_scale_y, col_scale_z, col_saturation; 113// deconverge params 114uniform COMPAT_PRECISION float converge_x_r, converge_x_g, converge_x_b, converge_y_r, converge_y_g, converge_y_b, 115 radial_conv_x_r, radial_conv_x_g, radial_conv_x_b, radial_conv_y_r, radial_conv_y_g, radial_conv_y_b; 116// scanline params 117uniform COMPAT_PRECISION float scanlinealpha, scanlinescale, scanlineheight, scanlinevariation, scanlineoffset, 118 scanlinebrightscale, scanlinebrightoffset; 119// defocus params 120uniform COMPAT_PRECISION float defocus_x, defocus_y; 121// phosphor params 122uniform COMPAT_PRECISION float deltatime, phosphor_r, phosphor_g, phosphor_b, phosphortoggle; 123// chroma params 124uniform COMPAT_PRECISION float ygain_r, ygain_g, ygain_b, chromaa_x, chromaa_y, chromab_x, chromab_y, chromac_x, chromac_y; 125// distortion params 126uniform COMPAT_PRECISION float distortion_amount, cubic_distortion_amount, distort_corner_amount, round_corner_amount, 127 smooth_border_amount, vignette_amount, reflection_amount, reflection_col_r, reflection_col_g, reflection_col_b; 128// vector params //doesn't work here, so commenting all of them. 129// uniform COMPAT_PRECISION float timeratio, timescale, lengthratio, lengthscale, beamsmooth; 130// I'm not going to bother supporting implementations without runtime parameters. 131 132bool Passthrough = !bool(phosphortoggle); 133 134float DeltaTime = deltatime; 135vec3 Phosphor = vec3(phosphor_r, phosphor_g, phosphor_b); 136 137const float F = 1.0; 138 139#define DiffuseSampler Source 140 141// no feedback so we'll fake it here 142vec3 PreviousSampler(vec2 coord){ 143 vec3 sum; 144 sum = pow(COMPAT_TEXTURE(Prev6Texture, coord).rgb, vec3(2.2)); 145 sum += pow(COMPAT_TEXTURE(Prev5Texture, coord).rgb, vec3(2.2)); 146 sum /= 2.0; 147 sum += pow(COMPAT_TEXTURE(Prev4Texture, coord).rgb, vec3(2.2)); 148 sum /= 2.0; 149 sum += pow(COMPAT_TEXTURE(Prev3Texture, coord).rgb, vec3(2.2)); 150 sum /= 2.0; 151 sum += pow(COMPAT_TEXTURE(Prev2Texture, coord).rgb, vec3(2.2)); 152 sum /= 2.0; 153 sum += pow(COMPAT_TEXTURE(Prev1Texture, coord).rgb, vec3(2.2)); 154 sum /= 2.0; 155 sum += pow(COMPAT_TEXTURE(PrevTexture, coord).rgb, vec3(2.2)); 156 sum /= 2.0; 157 return pow(sum, vec3(1.0/2.2)); 158} 159 160void main() 161{ 162 vec4 CurrY = COMPAT_TEXTURE(DiffuseSampler, vTexCoord); 163 vec3 PrevY = PreviousSampler(vTexCoord).rgb; 164 165 PrevY[0] *= (Phosphor[0] == 0.0) ? 0.0 : pow(Phosphor[0], F * DeltaTime); 166 PrevY[1] *= (Phosphor[1] == 0.0) ? 0.0 : pow(Phosphor[1], F * DeltaTime); 167 PrevY[2] *= (Phosphor[2] == 0.0) ? 0.0 : pow(Phosphor[2], F * DeltaTime); 168 float a = max(PrevY[0], CurrY[0]); 169 float b = max(PrevY[1], CurrY[1]); 170 float c = max(PrevY[2], CurrY[2]); 171 FragColor = Passthrough ? CurrY : vec4(a, b, c, CurrY.a); 172} 173#endif 174