2013-12-28 14:52:10 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2013 "Filippo Scognamiglio"
|
2014-09-03 22:19:34 +02:00
|
|
|
* https://github.com/Swordfish90/cool-retro-term
|
2013-12-28 14:52:10 +01:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* This file is part of cool-retro-term.
|
2013-12-28 14:52:10 +01:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* cool-retro-term is free software: you can redistribute it and/or modify
|
2013-12-28 14:52:10 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2014-04-17 13:56:13 +02:00
|
|
|
import QtQuick 2.2
|
2014-03-26 20:26:20 +01:00
|
|
|
import QtGraphicalEffects 1.0
|
2013-12-28 14:37:43 +01:00
|
|
|
|
2014-09-10 00:59:53 +02:00
|
|
|
|
2013-12-28 14:37:43 +01:00
|
|
|
ShaderEffect {
|
|
|
|
property color font_color: shadersettings.font_color
|
|
|
|
property color background_color: shadersettings.background_color
|
2014-06-06 23:55:33 +02:00
|
|
|
property variant source: terminal.theSource
|
|
|
|
property variant bloomSource: terminal.bloomSource
|
2014-06-07 12:03:34 +02:00
|
|
|
property variant rasterizationSource: terminal.rasterizationSource
|
2014-06-11 00:54:47 +02:00
|
|
|
property variant noiseSource: terminal.staticNoiseSource
|
2014-08-08 22:57:51 +02:00
|
|
|
property real bloom_strength: shadersettings.bloom_strength * 2.5
|
2014-03-26 20:26:20 +01:00
|
|
|
|
2014-06-20 12:30:42 +02:00
|
|
|
property real jitter: shadersettings.jitter * 0.007
|
|
|
|
|
2013-12-28 14:37:43 +01:00
|
|
|
property real noise_strength: shadersettings.noise_strength
|
|
|
|
property real screen_distorsion: shadersettings.screen_distortion
|
|
|
|
property real glowing_line_strength: shadersettings.glowing_line_strength
|
|
|
|
|
2014-08-01 00:04:59 +02:00
|
|
|
property real chroma_color: shadersettings.chroma_color;
|
|
|
|
|
2014-08-11 19:23:03 +02:00
|
|
|
property real rgb_shift: shadersettings.rgb_shift * 0.2
|
|
|
|
|
2014-03-31 14:13:51 +02:00
|
|
|
property real brightness_flickering: shadersettings.brightness_flickering
|
2014-03-26 19:23:47 +01:00
|
|
|
property real horizontal_sincronization: shadersettings.horizontal_sincronization
|
2014-03-25 16:30:07 +01:00
|
|
|
|
2014-07-06 23:57:47 +02:00
|
|
|
property bool frameReflections: shadersettings.frameReflections
|
2014-04-20 22:59:46 +02:00
|
|
|
|
2014-09-14 00:45:34 +02:00
|
|
|
property real disp_top: frame.item.displacementTop / height
|
|
|
|
property real disp_bottom: frame.item.displacementBottom / height
|
|
|
|
property real disp_left: frame.item.displacementLeft / width
|
|
|
|
property real disp_right: frame.item.displacementRight / width
|
2014-04-05 15:14:52 +02:00
|
|
|
|
2014-08-08 22:57:51 +02:00
|
|
|
property real screen_brightness: shadersettings.brightness * 1.5 + 0.5
|
2014-03-31 17:26:51 +02:00
|
|
|
|
2014-07-06 23:57:47 +02:00
|
|
|
property real time: timeManager.time
|
2014-03-31 14:13:51 +02:00
|
|
|
property variant randomFunctionSource: randfuncsource
|
|
|
|
|
2014-10-04 14:09:49 +02:00
|
|
|
// If something goes wrong activate the fallback version of the shader.
|
|
|
|
property bool fallBack: false
|
|
|
|
|
2014-06-11 00:54:47 +02:00
|
|
|
blending: false
|
|
|
|
|
2014-07-12 01:51:53 +02:00
|
|
|
//Smooth random texture used for flickering effect.
|
|
|
|
Image{
|
|
|
|
id: randtexture
|
|
|
|
source: "frames/images/randfunction.png"
|
|
|
|
width: 512
|
|
|
|
height: 512
|
|
|
|
sourceSize.width: 512
|
|
|
|
sourceSize.height: 256
|
|
|
|
fillMode: Image.TileVertically
|
|
|
|
}
|
|
|
|
ShaderEffectSource{
|
|
|
|
id: randfuncsource
|
|
|
|
sourceItem: randtexture
|
|
|
|
live: false
|
|
|
|
hideSource: true
|
|
|
|
wrapMode: ShaderEffectSource.Repeat
|
|
|
|
}
|
|
|
|
|
|
|
|
//Print the number with a reasonable precision for the shader.
|
2014-05-31 21:28:25 +02:00
|
|
|
function str(num){
|
|
|
|
return num.toFixed(8);
|
|
|
|
}
|
|
|
|
|
2014-03-31 14:13:51 +02:00
|
|
|
vertexShader: "
|
2014-05-31 21:28:25 +02:00
|
|
|
uniform highp mat4 qt_Matrix;
|
|
|
|
uniform highp float time;
|
2014-09-14 00:45:34 +02:00
|
|
|
|
|
|
|
uniform highp float disp_left;
|
|
|
|
uniform highp float disp_right;
|
|
|
|
uniform highp float disp_top;
|
|
|
|
uniform highp float disp_bottom;
|
2014-05-31 21:28:25 +02:00
|
|
|
|
|
|
|
attribute highp vec4 qt_Vertex;
|
|
|
|
attribute highp vec2 qt_MultiTexCoord0;
|
|
|
|
|
|
|
|
varying highp vec2 qt_TexCoord0;" +
|
|
|
|
|
2014-10-04 14:09:49 +02:00
|
|
|
(!fallBack ? "
|
|
|
|
uniform sampler2D randomFunctionSource;" : "") +
|
|
|
|
|
|
|
|
(!fallBack && brightness_flickering !== 0.0 ?"
|
2014-08-08 22:57:51 +02:00
|
|
|
varying lowp float brightness;
|
|
|
|
uniform lowp float brightness_flickering;" : "") +
|
2014-10-04 14:09:49 +02:00
|
|
|
(!fallBack && horizontal_sincronization !== 0.0 ?"
|
2014-08-08 22:57:51 +02:00
|
|
|
varying lowp float horizontal_distortion;
|
|
|
|
uniform lowp float horizontal_sincronization;" : "") +
|
2014-05-31 21:28:25 +02:00
|
|
|
"
|
|
|
|
void main() {
|
2014-09-14 02:43:48 +02:00
|
|
|
qt_TexCoord0.x = (qt_MultiTexCoord0.x - disp_left) / (1.0 - disp_left - disp_right);
|
|
|
|
qt_TexCoord0.y = (qt_MultiTexCoord0.y - disp_top) / (1.0 - disp_top - disp_bottom);
|
2014-05-31 21:28:25 +02:00
|
|
|
vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" +
|
2014-10-04 14:09:49 +02:00
|
|
|
(!fallBack && brightness_flickering !== 0.0 ? "
|
2014-08-08 22:57:51 +02:00
|
|
|
brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;"
|
2014-05-31 21:28:25 +02:00
|
|
|
: "") +
|
|
|
|
|
2014-10-04 14:09:49 +02:00
|
|
|
(!fallBack && horizontal_sincronization !== 0.0 ? "
|
2014-05-31 21:28:25 +02:00
|
|
|
float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g;
|
2014-08-08 22:57:51 +02:00
|
|
|
float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + "
|
|
|
|
horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;"
|
2014-05-31 21:28:25 +02:00
|
|
|
: "") +
|
|
|
|
|
|
|
|
"gl_Position = qt_Matrix * qt_Vertex;
|
|
|
|
}"
|
2013-12-28 14:37:43 +01:00
|
|
|
|
|
|
|
fragmentShader: "
|
2014-05-31 21:28:25 +02:00
|
|
|
uniform sampler2D source;
|
|
|
|
uniform highp float qt_Opacity;
|
|
|
|
uniform highp float time;
|
|
|
|
varying highp vec2 qt_TexCoord0;
|
|
|
|
|
|
|
|
uniform highp vec4 font_color;
|
2014-06-07 12:03:34 +02:00
|
|
|
uniform highp vec4 background_color;
|
2014-08-08 22:57:51 +02:00
|
|
|
uniform highp sampler2D rasterizationSource;
|
|
|
|
uniform lowp float screen_brightness;" +
|
2013-12-28 14:37:43 +01:00
|
|
|
|
2014-08-08 22:57:51 +02:00
|
|
|
(bloom_strength !== 0 ? "
|
|
|
|
uniform highp sampler2D bloomSource;
|
|
|
|
uniform lowp float bloom_strength;" : "") +
|
2014-05-31 21:28:25 +02:00
|
|
|
(noise_strength !== 0 ? "
|
2014-06-20 12:30:42 +02:00
|
|
|
uniform highp float noise_strength;" : "") +
|
2014-09-13 22:18:11 +02:00
|
|
|
(noise_strength !== 0 || jitter !== 0 || rgb_shift ? "
|
2014-06-11 00:54:47 +02:00
|
|
|
uniform lowp sampler2D noiseSource;" : "") +
|
2014-05-31 21:28:25 +02:00
|
|
|
(screen_distorsion !== 0 ? "
|
2014-08-08 22:57:51 +02:00
|
|
|
uniform highp float screen_distorsion;" : "") +
|
2014-05-31 21:28:25 +02:00
|
|
|
(glowing_line_strength !== 0 ? "
|
2014-08-08 22:57:51 +02:00
|
|
|
uniform highp float glowing_line_strength;" : "") +
|
|
|
|
(chroma_color !== 0 ? "
|
|
|
|
uniform lowp float chroma_color;" : "") +
|
|
|
|
(jitter !== 0 ? "
|
|
|
|
uniform lowp float jitter;" : "") +
|
2014-08-11 19:23:03 +02:00
|
|
|
(rgb_shift !== 0 ? "
|
|
|
|
uniform lowp float rgb_shift;" : "") +
|
2014-10-04 14:09:49 +02:00
|
|
|
|
|
|
|
(fallBack && (brightness_flickering || horizontal_sincronization) ? "
|
|
|
|
uniform lowp sampler2D randomFunctionSource;" : "") +
|
|
|
|
(fallBack && horizontal_sincronization !== 0 ? "
|
|
|
|
uniform lowp float horizontal_sincronization;" : "") +
|
|
|
|
(fallBack && brightness_flickering !== 0.0 ?"
|
|
|
|
uniform lowp float brightness_flickering;" : "") +
|
|
|
|
(!fallBack && brightness_flickering !== 0 ? "
|
2014-05-31 21:28:25 +02:00
|
|
|
varying lowp float brightness;" : "") +
|
2014-10-04 14:09:49 +02:00
|
|
|
(!fallBack && horizontal_sincronization !== 0 ? "
|
2014-05-31 21:28:25 +02:00
|
|
|
varying lowp float horizontal_distortion;" : "") +
|
|
|
|
|
|
|
|
(glowing_line_strength !== 0 ? "
|
|
|
|
float randomPass(vec2 coords){
|
|
|
|
return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0001))) * glowing_line_strength;
|
|
|
|
}" : "") +
|
2014-04-03 15:22:39 +02:00
|
|
|
|
2014-08-03 14:43:36 +02:00
|
|
|
"float rgb2grey(vec3 v){
|
|
|
|
return dot(v, vec3(0.21, 0.72, 0.04));
|
|
|
|
}" +
|
2014-03-26 01:22:02 +01:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
"void main() {" +
|
|
|
|
"vec2 cc = vec2(0.5) - qt_TexCoord0;" +
|
|
|
|
"float distance = length(cc);" +
|
2014-04-06 17:59:19 +02:00
|
|
|
|
2014-10-04 14:09:49 +02:00
|
|
|
//FallBack if there are problem
|
|
|
|
(fallBack && (brightness_flickering || horizontal_sincronization) ? "
|
|
|
|
vec2 randCoords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" : "") +
|
|
|
|
|
|
|
|
(fallBack && brightness_flickering !== 0.0 ? "
|
|
|
|
float brightness = 1.0 + (texture2D(randomFunctionSource, randCoords).g - 0.5) * brightness_flickering;"
|
|
|
|
: "") +
|
|
|
|
|
|
|
|
(fallBack && horizontal_sincronization !== 0.0 ? "
|
|
|
|
float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) - randCoords) * 0.5).g;
|
|
|
|
float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + "
|
|
|
|
float horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;"
|
|
|
|
: "") +
|
|
|
|
|
2014-03-31 14:13:51 +02:00
|
|
|
(noise_strength ? "
|
2014-05-31 21:28:25 +02:00
|
|
|
float noise = noise_strength;" : "") +
|
2013-12-28 14:37:43 +01:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
(screen_distorsion !== 0 ? "
|
|
|
|
float distortion = dot(cc, cc) * screen_distorsion;
|
|
|
|
vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);"
|
|
|
|
:"
|
|
|
|
vec2 coords = qt_TexCoord0;") +
|
2014-05-29 01:13:31 +02:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
(horizontal_sincronization !== 0 ? "
|
|
|
|
float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0));
|
|
|
|
h_distortion += 0.5 * cos(time*0.04 + 0.03 + coords.y*50.0*fract(time/10.0 + 0.4));
|
|
|
|
coords.x = coords.x + h_distortion * horizontal_distortion;" +
|
|
|
|
(noise_strength ? "
|
|
|
|
noise += horizontal_distortion;" : "")
|
|
|
|
: "") +
|
2013-12-28 14:37:43 +01:00
|
|
|
|
2014-06-20 12:30:42 +02:00
|
|
|
(jitter !== 0 ? "
|
|
|
|
vec2 offset = vec2(texture2D(noiseSource, coords + fract(time / 57.0)).a,
|
|
|
|
texture2D(noiseSource, coords + fract(time / 251.0)).a) - 0.5;
|
2014-08-08 22:57:51 +02:00
|
|
|
vec2 txt_coords = coords + offset * jitter;"
|
2014-06-20 12:30:42 +02:00
|
|
|
: "vec2 txt_coords = coords;") +
|
|
|
|
|
2014-07-31 22:41:54 +02:00
|
|
|
"float color = 0.0;" +
|
2014-04-03 15:06:16 +02:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
(noise_strength !== 0 ? "
|
2014-06-20 01:54:14 +02:00
|
|
|
float noiseVal = texture2D(noiseSource, qt_TexCoord0 + vec2(fract(time / 51.0), fract(time / 237.0))).a;
|
|
|
|
color += noiseVal * noise * (1.0 - distance * 1.3);" : "") +
|
2014-04-03 15:06:16 +02:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
(glowing_line_strength !== 0 ? "
|
2014-06-06 23:55:33 +02:00
|
|
|
color += randomPass(coords) * glowing_line_strength;" : "") +
|
2014-07-31 22:41:54 +02:00
|
|
|
|
2014-09-13 22:18:11 +02:00
|
|
|
|
|
|
|
"vec3 txt_color = texture2D(source, txt_coords).rgb;
|
|
|
|
float greyscale_color = rgb2grey(txt_color) + color;" +
|
|
|
|
|
2014-08-03 14:43:36 +02:00
|
|
|
(chroma_color !== 0 ?
|
2014-08-11 19:23:03 +02:00
|
|
|
(rgb_shift !== 0 ? "
|
|
|
|
float rgb_noise = abs(texture2D(noiseSource, vec2(fract(time/(1024.0 * 256.0)), fract(time/(1024.0*1024.0)))).a - 0.5);
|
2014-09-13 22:18:11 +02:00
|
|
|
float rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).r;
|
|
|
|
float bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).b;
|
|
|
|
txt_color.r = rcolor;
|
|
|
|
txt_color.b = bcolor;
|
|
|
|
greyscale_color = 0.33 * (rcolor + bcolor);" : "") +
|
|
|
|
|
|
|
|
"vec3 mixedColor = mix(font_color.rgb, txt_color * font_color.rgb, chroma_color);
|
|
|
|
vec3 finalBackColor = mix(background_color.rgb, mixedColor, greyscale_color);
|
|
|
|
vec3 finalColor = mix(finalBackColor, font_color.rgb, color).rgb;"
|
2014-08-03 14:43:36 +02:00
|
|
|
:
|
2014-09-13 22:18:11 +02:00
|
|
|
"vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") +
|
2014-08-01 00:04:59 +02:00
|
|
|
|
2014-06-20 01:54:14 +02:00
|
|
|
"finalColor *= texture2D(rasterizationSource, coords).a;" +
|
2014-06-06 23:55:33 +02:00
|
|
|
|
2014-08-08 22:57:51 +02:00
|
|
|
(bloom_strength !== 0 ?
|
2014-09-14 01:00:38 +02:00
|
|
|
"vec4 bloomFullColor = texture2D(bloomSource, coords);
|
|
|
|
vec3 bloomColor = bloomFullColor.rgb;
|
2014-09-14 12:20:49 +02:00
|
|
|
vec2 minBound = step(vec2(0.0), coords);
|
|
|
|
vec2 maxBound = step(coords, vec2(1.0));
|
|
|
|
float bloomAlpha = bloomFullColor.a * minBound.x * minBound.y * maxBound.x * maxBound.y;" +
|
2014-08-03 14:43:36 +02:00
|
|
|
(chroma_color !== 0 ?
|
2014-08-08 22:57:51 +02:00
|
|
|
"bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, chroma_color);"
|
2014-08-03 14:43:36 +02:00
|
|
|
:
|
|
|
|
"bloomColor = font_color.rgb * rgb2grey(bloomColor);") +
|
2014-09-14 01:00:38 +02:00
|
|
|
"finalColor += bloomColor * bloom_strength * bloomAlpha;"
|
2014-08-03 14:43:36 +02:00
|
|
|
: "") +
|
2014-07-11 01:20:14 +02:00
|
|
|
|
2014-05-31 21:28:25 +02:00
|
|
|
(brightness_flickering !== 0 ? "
|
|
|
|
finalColor *= brightness;" : "") +
|
2014-03-31 16:57:51 +02:00
|
|
|
|
2014-08-08 22:57:51 +02:00
|
|
|
"gl_FragColor = vec4(finalColor * screen_brightness, qt_Opacity);" +
|
2014-07-31 22:41:54 +02:00
|
|
|
"}"
|
2014-04-04 02:32:52 +02:00
|
|
|
|
2014-10-04 14:09:49 +02:00
|
|
|
onStatusChanged: {
|
|
|
|
// Print warning messages
|
|
|
|
if (log)
|
|
|
|
console.log(log);
|
|
|
|
|
|
|
|
// Activate fallback mode
|
|
|
|
if (status == ShaderEffect.Error) {
|
|
|
|
fallBack = true;
|
|
|
|
}
|
|
|
|
}
|
2013-12-28 14:37:43 +01:00
|
|
|
}
|