2024-11-09 19:19:36 +00:00
|
|
|
std::string outputFragmentShader = R"(
|
|
|
|
|
2024-11-06 20:15:09 +00:00
|
|
|
uniform sampler2D uTexture0; //line
|
|
|
|
uniform sampler2D uTexture1; //tight glow
|
|
|
|
uniform sampler2D uTexture2; //big glow
|
|
|
|
uniform sampler2D uTexture3; //screen
|
2024-12-28 21:23:56 +00:00
|
|
|
uniform sampler2D uTexture4; //reflection
|
|
|
|
uniform sampler2D uTexture5; //screen glow
|
2024-11-06 20:15:09 +00:00
|
|
|
uniform float uExposure;
|
|
|
|
uniform float uSaturation;
|
2024-11-09 21:37:20 +00:00
|
|
|
uniform float uNoise;
|
|
|
|
uniform float uTime;
|
|
|
|
uniform float uGlow;
|
2024-12-26 23:00:52 +00:00
|
|
|
uniform float uAmbient;
|
2024-12-28 15:37:19 +00:00
|
|
|
uniform float uFishEye;
|
2024-12-26 23:00:52 +00:00
|
|
|
uniform float uRealScreen;
|
|
|
|
uniform vec2 uOffset;
|
|
|
|
uniform vec2 uScale;
|
2024-11-06 20:15:09 +00:00
|
|
|
uniform vec3 uColour;
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
varying vec2 vTexCoordCanvas;
|
|
|
|
|
|
|
|
vec3 desaturate(vec3 color, float factor) {
|
|
|
|
vec3 lum = vec3(0.299, 0.587, 0.114);
|
|
|
|
vec3 gray = vec3(dot(lum, color));
|
|
|
|
return vec3(mix(color, gray, factor));
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:37:20 +00:00
|
|
|
float noise(in vec2 uv, in float time) {
|
|
|
|
return (fract(sin(dot(uv, vec2(12.9898,78.233)*2.0 + time)) * 43758.5453)) - 0.5;
|
2024-11-06 20:15:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2024-12-26 23:00:52 +00:00
|
|
|
vec2 linePos = (vTexCoordCanvas - 0.5) / uScale + 0.5 + uOffset;
|
2024-12-28 15:37:19 +00:00
|
|
|
|
|
|
|
// fish eye distortion
|
|
|
|
vec2 uv = linePos - vec2(0.5);
|
|
|
|
float uva = atan(uv.x, uv.y);
|
|
|
|
float uvd = sqrt(dot(uv, uv));
|
|
|
|
uvd = uvd * (1.0 + uFishEye * uvd * uvd);
|
|
|
|
linePos = vec2(0.5) + vec2(sin(uva), cos(uva)) * uvd;
|
|
|
|
|
2024-12-26 23:00:52 +00:00
|
|
|
vec4 line = texture2D(uTexture0, linePos);
|
2024-11-06 20:15:09 +00:00
|
|
|
// r components have grid; g components do not.
|
|
|
|
vec4 screen = texture2D(uTexture3, vTexCoord);
|
2024-12-26 23:00:52 +00:00
|
|
|
vec4 tightGlow = texture2D(uTexture1, linePos);
|
2024-12-28 15:37:19 +00:00
|
|
|
vec4 scatter = texture2D(uTexture2, linePos) + (1.0 - uRealScreen) * max(uAmbient - 0.35, 0.0);
|
2024-12-28 21:23:56 +00:00
|
|
|
|
|
|
|
if (uRealScreen > 0.5) {
|
|
|
|
vec4 reflection = texture2D(uTexture4, vTexCoord);
|
|
|
|
vec4 screenGlow = texture2D(uTexture5, vTexCoord);
|
|
|
|
scatter += screenGlow * reflection * max(1.0 - uAmbient, 0.0);
|
|
|
|
}
|
|
|
|
|
2024-11-18 19:36:01 +00:00
|
|
|
float light = line.r + uGlow * 1.5 * screen.g * screen.g * tightGlow.r;
|
2024-12-14 20:42:35 +00:00
|
|
|
light += uGlow * 0.3 * scatter.g * (2.0 + 1.0 * screen.g + 0.5 * screen.r);
|
2024-11-06 20:15:09 +00:00
|
|
|
float tlight = 1.0-pow(2.0, -uExposure*light);
|
2024-11-09 21:37:20 +00:00
|
|
|
float tlight2 = tlight * tlight * tlight;
|
2024-12-26 23:00:52 +00:00
|
|
|
gl_FragColor.rgb = mix(uColour, vec3(1.0), 0.3+tlight2*tlight2*0.5) * tlight;
|
|
|
|
if (uRealScreen > 0.5) {
|
|
|
|
float ambient = pow(2.0, uExposure) * uAmbient;
|
|
|
|
gl_FragColor.rgb += ambient * screen.rgb;
|
|
|
|
}
|
2024-11-06 20:15:09 +00:00
|
|
|
gl_FragColor.rgb = desaturate(gl_FragColor.rgb, 1.0 - uSaturation);
|
2024-11-09 21:37:20 +00:00
|
|
|
gl_FragColor.rgb += uNoise * noise(gl_FragCoord.xy, uTime);
|
2024-11-06 20:15:09 +00:00
|
|
|
gl_FragColor.a = 1.0;
|
|
|
|
}
|
2024-11-09 19:19:36 +00:00
|
|
|
|
|
|
|
)";
|