diff --git a/app/SettingsWindow.qml b/app/SettingsWindow.qml index 34ea734..aa39931 100644 --- a/app/SettingsWindow.qml +++ b/app/SettingsWindow.qml @@ -180,9 +180,9 @@ ApplicationWindow { _value: shadersettings.screen_distortion; } SettingComponent{ - name: "Screen flickering" - onValueChanged: shadersettings.screen_flickering = value; - _value: shadersettings.screen_flickering; + name: "Brightness flickering" + onValueChanged: shadersettings.brightness_flickering= value; + _value: shadersettings.brightness_flickering; } SettingComponent{ name: "Horizontal flickering" diff --git a/app/ShaderManager.qml b/app/ShaderManager.qml index 69569bb..50bbfcc 100644 --- a/app/ShaderManager.qml +++ b/app/ShaderManager.qml @@ -27,7 +27,6 @@ ShaderEffect { property variant source: theSource property variant bloomSource: bloomSource property size txt_Size: Qt.size(terminal.width, terminal.height) - property real time: 0 property real bloom: shadersettings.bloom_strength @@ -37,28 +36,15 @@ ShaderEffect { property real scanlines: shadersettings.scanlines ? 1.0 : 0.0 - //Manage brightness (the function might be improved) - property real screen_flickering: shadersettings.screen_flickering - property real _A: 0.4 + Math.random() * 0.4 - property real _B: 0.2 + Math.random() * 0.4 - property real _C: 1.2 - _A - _B - property real a: (0.0 + Math.random() * 0.4) * 0.05 - property real b: (0.1 + Math.random() * 0.4) * 0.05 - property real c: (0.4 + Math.random() * 0.4) * 0.05 - - property real randval: (_A * Math.cos(a * time + _B) + - _B * Math.sin(b * time + _C) + - _C * Math.cos(c * time + _A)) - - - property real brightness: screen_flickering * randval + property real brightness_flickering: shadersettings.brightness_flickering property real horizontal_sincronization: shadersettings.horizontal_sincronization - property real _neg_sinc: 1 - horizontal_sincronization - property real horizontal_distortion: randval > (_neg_sinc) ? (randval - _neg_sinc) * horizontal_sincronization : 0 property real deltay: 3 / terminal.height property real deltax: 3 / terminal.width + property real time: timetimer.time + property variant randomFunctionSource: randfuncsource + //Blurred texture used for bloom Loader{ anchors.fill: parent @@ -76,13 +62,34 @@ ShaderEffect { } } - Timer{ - id: timetimer - onTriggered: time += interval - interval: 16 - running: true - repeat: true - } + vertexShader: " + uniform highp mat4 qt_Matrix; + uniform highp float time; + uniform sampler2D randomFunctionSource; + + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + + varying highp vec2 qt_TexCoord0;" + + (brightness_flickering !== 0.0 ?" + varying lowp float brightness;" : "") + + (horizontal_sincronization !== 0.0 ?" + varying lowp float horizontal_distortion;" : "") + + " + void main() { + qt_TexCoord0 = qt_MultiTexCoord0; + vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0*2.0)));" + + (brightness_flickering !== 0.0 ? " + brightness = texture2D(randomFunctionSource, coords).g * "+brightness_flickering+";" + : "") + + + (horizontal_sincronization !== 0.0 ? " + float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g; + float negsinc = 1.0 - "+0.6*horizontal_sincronization+"; + horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * "+0.3*horizontal_sincronization+";" + : "") + + "gl_Position = qt_Matrix * qt_Vertex; + }" fragmentShader: " uniform sampler2D source; @@ -96,77 +103,89 @@ ShaderEffect { uniform highp float deltax; uniform highp float deltay;" + - (bloom !== 0 ? "uniform highp sampler2D bloomSource;" : "") + - (noise_strength !== 0 ? "uniform highp float noise_strength;" : "") + - (screen_distorsion !== 0 ? "uniform highp float screen_distorsion;" : "")+ - (glowing_line_strength !== 0 ? "uniform highp float glowing_line_strength;" : "")+ - "uniform lowp float brightness;" + + (bloom !== 0 ? " + uniform highp sampler2D bloomSource;" : "") + + (noise_strength !== 0 ? " + uniform highp float noise_strength;" : "") + + (screen_distorsion !== 0 ? " + uniform highp float screen_distorsion;" : "")+ + (glowing_line_strength !== 0 ? " + uniform highp float glowing_line_strength;" : "")+ + (brightness_flickering !== 0 ? " + varying lowp float brightness;" : "") + + (horizontal_sincronization !== 0 ? " + varying lowp float horizontal_distortion;" : "") + (scanlines != 0 ? "uniform highp float scanlines;" : "") + - (shadersettings.screen_flickering !== 0 ? "uniform highp float horizontal_distortion;" : "") + + " + highp float rand(vec2 co) + { + highp float a = 12.9898; + highp float b = 78.233; + highp float c = 43758.5453; + highp float dt= dot(co.xy ,vec2(a,b)); + highp float sn= mod(dt,3.14); + return fract(sin(sn) * c); + } + + float stepNoise(vec2 p){ + vec2 newP = p * txt_Size*0.5; + return rand(floor(newP) + fract(time / 100.0)); + } + + float getScanlineIntensity(vec2 pos){ + return abs(sin(pos.y * txt_Size.y)) * 0.5 + 0.5; + }" + - "highp float rand(vec2 co) - { - highp float a = 12.9898; - highp float b = 78.233; - highp float c = 43758.5453; - highp float dt= dot(co.xy ,vec2(a,b)); - highp float sn= mod(dt,3.14); - return fract(sin(sn) * c); - } - - float stepNoise(vec2 p){ - vec2 newP = p * txt_Size*0.5; - return rand(floor(newP) + fract(time / 100.0)); - } - - float getScanlineIntensity(vec2 pos){ - return abs(sin(pos.y * txt_Size.y)) * 0.5 + 0.5; - }" + - - - (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; - }" : "") + + (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; + }" : "") + "void main() {" + - "vec2 cc = vec2(0.5) - qt_TexCoord0;" + - "float distance = length(cc);" + + "vec2 cc = vec2(0.5) - qt_TexCoord0;" + + "float distance = length(cc);" + - (screen_distorsion !== 0 ? - "float distortion = dot(cc, cc) * screen_distorsion; - vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);" - :"vec2 coords = qt_TexCoord0;") + + (screen_distorsion !== 0 ? " + float distortion = dot(cc, cc) * screen_distorsion; + vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);" + :" + vec2 coords = qt_TexCoord0;") + - (shadersettings.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 * 0.3 * horizontal_distortion;" + - (noise_strength ? "noise_strength += horizontal_distortion * 0.5;" : "") - : "") + + (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_strength += horizontal_distortion * 0.5;" : "") + : "") + - "float color = texture2D(source, coords).r;" + - (bloom !== 0 ? "color += texture2D(bloomSource, coords).r *" + 2.5 * bloom + ";" : "") + + "float color = texture2D(source, coords).r;" + - (scanlines !== 0 ? - "float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 1.0;") + + (bloom !== 0 ? " + color += texture2D(bloomSource, coords).r *" + 2.5 * bloom + ";" : "") + - (noise_strength !== 0 ? - "color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") + + (scanlines !== 0 ? " + float scanline_alpha = getScanlineIntensity(coords);" + : + "float scanline_alpha = 1.0;") + - (glowing_line_strength !== 0 ? - "color += randomPass(coords) * glowing_line_strength;" : "") + + (noise_strength !== 0 ? " + color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") + - "vec3 finalColor = mix(background_color, font_color, color * scanline_alpha).rgb;" + - "finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance);" + + (glowing_line_strength !== 0 ? " + color += randomPass(coords) * glowing_line_strength;" : "") + - (screen_flickering !== 0 ? - "finalColor = mix(finalColor, vec3(0.0), brightness);" : "") + - "gl_FragColor = vec4(finalColor, 1.0); - }" + "vec3 finalColor = mix(background_color, font_color, color * scanline_alpha).rgb;" + + "finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance);" + + + (brightness_flickering !== 0 ? " + finalColor = mix(finalColor, vec3(0.0), brightness);" : "") + + " + gl_FragColor = vec4(finalColor, 1.0); + }" } diff --git a/app/ShaderSettings.qml b/app/ShaderSettings.qml index df6d657..cc558e8 100644 --- a/app/ShaderSettings.qml +++ b/app/ShaderSettings.qml @@ -46,7 +46,7 @@ Item{ property real bloom_strength: 0.6 property real horizontal_sincronization: 0.1 - property real screen_flickering: 0.12 + property real brightness_flickering: 0.12 property bool scanlines: false @@ -147,7 +147,7 @@ Item{ background_color = settings.background_color ? settings.background_color : background_color; font_color = settings.font_color ? settings.font_color : font_color; - screen_flickering = settings.screen_flickering ? settings.screen_flickering : screen_flickering; + brightness_flickering = settings.brightness_flickering ? settings.brightness_flickering : brightness_flickering; noise_strength = settings.noise_strength ? settings.noise_strength : noise_strength; screen_distortion = settings.screen_distortion ? settings.screen_distortion : screen_distortion; glowing_line_strength = settings.glowing_line_strength ? settings.glowing_line_strength : glowing_line_strength; @@ -168,7 +168,7 @@ Item{ contrast : contrast, background_color: background_color, font_color: font_color, - screen_flickering: screen_flickering, + brightness_flickering: brightness_flickering, noise_strength: noise_strength, screen_distortion: screen_distortion, glowing_line_strength: glowing_line_strength, @@ -204,17 +204,17 @@ Item{ ListElement{ text: "Default" obj_name: "DEFAULT" - obj_string: '{"ambient_light":0.3,"background_color":"#000000","font_color":"#00ff3b","font_index":0,"font_scaling":1,"frames_index":2,"glowing_line_strength":0.4,"noise_strength":0.1,"scanlines":true,"screen_distortion":0.15,"screen_flickering":0.07}' + obj_string: '{"ambient_light":0.3,"background_color":"#000000","font_color":"#00ff3b","font_index":0,"font_scaling":1,"frames_index":2,"glowing_line_strength":0.4,"noise_strength":0.1,"scanlines":true,"screen_distortion":0.15,"brightness_flickering":0.07}' } ListElement{ text: "Commodore 64" obj_name: "COMMODORE64" - obj_string: '{"ambient_light":0.2,"background_color":"#5048b2","font_color":"#8bcad1","font_index":2,"font_scaling":1,"frames_index":1,"glowing_line_strength":0.2,"noise_strength":0.05,"scanlines":false,"screen_distortion":0.1,"screen_flickering":0.03}' + obj_string: '{"ambient_light":0.2,"background_color":"#5048b2","font_color":"#8bcad1","font_index":2,"font_scaling":1,"frames_index":1,"glowing_line_strength":0.2,"noise_strength":0.05,"scanlines":false,"screen_distortion":0.1,"brightness_flickering":0.03}' } ListElement{ text: "IBM Dos" obj_name: "IBMDOS" - obj_string: '{"ambient_light":0.4,"background_color":"#000000","font_color":"#ffffff","font_index":3,"font_scaling":1,"frames_index":1,"glowing_line_strength":0,"noise_strength":0,"scanlines":false,"screen_distortion":0.05,"screen_flickering":0.00}' + obj_string: '{"ambient_light":0.4,"background_color":"#000000","font_color":"#ffffff","font_index":3,"font_scaling":1,"frames_index":1,"glowing_line_strength":0,"noise_strength":0,"scanlines":false,"screen_distortion":0.05,"brightness_flickering":0.00}' } } } diff --git a/app/Terminal.qml b/app/Terminal.qml index da98347..8851f1d 100644 --- a/app/Terminal.qml +++ b/app/Terminal.qml @@ -10,6 +10,7 @@ Item{ property real motionBlurCoefficient: (_minBlurCoefficient)*mBlur + (_maxBlurCoefficient)*(1.0-mBlur) property real _minBlurCoefficient: 0.015 property real _maxBlurCoefficient: 0.10 + anchors.fill: parent function loadKTerminal(){ kterminal.active = true; @@ -22,7 +23,9 @@ Item{ id: kterminal active: false anchors.fill: parent + sourceComponent: KTerminal { + id: ktermitem font.pointSize: shadersettings.fontSize font.family: shadersettings.font.name diff --git a/app/app.qmlproject.user b/app/app.qmlproject.user index f8461ca..b027a03 100644 --- a/app/app.qmlproject.user +++ b/app/app.qmlproject.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/app/frames/images/randfunction.png b/app/frames/images/randfunction.png new file mode 100644 index 0000000..dcb48e4 Binary files /dev/null and b/app/frames/images/randfunction.png differ diff --git a/app/frames/utils/FrameShader.qml b/app/frames/utils/FrameShader.qml index a24e75c..8e746a8 100644 --- a/app/frames/utils/FrameShader.qml +++ b/app/frames/utils/FrameShader.qml @@ -7,13 +7,36 @@ ShaderEffect{ property real ambient_light: shadersettings.ambient_light property color font_color: shadersettings.font_color property color background_color: shadersettings.background_color - property real brightness: shadercontainer.brightness + property real time: timetimer.time + property variant randomFunctionSource: randfuncsource + property real brightness_flickering: shadersettings.brightness_flickering property color reflection_color: Qt.rgba((font_color.r*0.3 + background_color.r*0.7), (font_color.g*0.3 + background_color.g*0.7), (font_color.b*0.3 + background_color.b*0.7), 1.0) + vertexShader: " + uniform highp mat4 qt_Matrix; + uniform highp float time; + uniform sampler2D randomFunctionSource; + + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + + varying highp vec2 qt_TexCoord0; + varying lowp float brightness; + + void main() { + qt_TexCoord0 = qt_MultiTexCoord0;" + + + (brightness_flickering !== 0 ? + "brightness = texture2D(randomFunctionSource, vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0*2.0)))).r * "+brightness_flickering+";" + : + "brightness = 0.0;") + " + + gl_Position = qt_Matrix * qt_Vertex; + }" fragmentShader: " uniform sampler2D source; @@ -22,7 +45,7 @@ ShaderEffect{ uniform highp float ambient_light; uniform vec4 reflection_color; - uniform highp float brightness; + varying lowp float brightness; varying highp vec2 qt_TexCoord0; diff --git a/app/main.qml b/app/main.qml index c465bbb..c875139 100644 --- a/app/main.qml +++ b/app/main.qml @@ -71,6 +71,27 @@ ApplicationWindow{ id: maincontainer anchors.fill: parent clip: true + Image{ + id: randtexture + source: "frames/images/randfunction.png" + width: 512 + height: 512 + } + ShaderEffectSource{ + id: randfuncsource + sourceItem: randtexture + live: false + hideSource: true + wrapMode: ShaderEffectSource.Repeat + } + Timer{ + id: timetimer + property real time: 0 + onTriggered: time += interval + interval: 16 + running: true + repeat: true + } Terminal{ id: terminal width: parent.width @@ -81,12 +102,6 @@ ApplicationWindow{ sourceItem: terminal sourceRect: frame.sourceRect } - ShaderManager{ - id: shadercontainer - anchors.fill: terminal - blending: true - z: 1.9 - } Loader{ id: frame property rect sourceRect: item.sourceRect @@ -95,6 +110,12 @@ ApplicationWindow{ z: 2.1 source: shadersettings.frame_source } + ShaderManager{ + id: shadercontainer + anchors.fill: parent + blending: true + z: 1.9 + } RadialGradient{ id: ambientreflection z: 2.0