mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Improvements and speedups in scanline effect. It has been moved among the preprocessing effects.
This commit is contained in:
		| @@ -144,10 +144,10 @@ ApplicationWindow { | |||||||
|                 ColumnLayout{ |                 ColumnLayout{ | ||||||
|                     anchors.fill: parent |                     anchors.fill: parent | ||||||
|  |  | ||||||
|                     CheckBox{ |                     SettingComponent{ | ||||||
|                         text: "Scanlines" |                         name: "Scanlines" | ||||||
|                         checked: shadersettings.scanlines |                         onValueChanged: shadersettings.scanlines = value | ||||||
|                         onCheckedChanged: shadersettings.scanlines = checked; |                         _value: shadersettings.scanlines | ||||||
|                     } |                     } | ||||||
|                     SettingComponent{ |                     SettingComponent{ | ||||||
|                         name: "Bloom" |                         name: "Bloom" | ||||||
|   | |||||||
| @@ -34,8 +34,6 @@ ShaderEffect { | |||||||
|     property real screen_distorsion: shadersettings.screen_distortion |     property real screen_distorsion: shadersettings.screen_distortion | ||||||
|     property real glowing_line_strength: shadersettings.glowing_line_strength |     property real glowing_line_strength: shadersettings.glowing_line_strength | ||||||
|  |  | ||||||
|     property real scanlines: shadersettings.scanlines ? 1.0 : 0.0 |  | ||||||
|  |  | ||||||
|     property real brightness_flickering: shadersettings.brightness_flickering |     property real brightness_flickering: shadersettings.brightness_flickering | ||||||
|     property real horizontal_sincronization: shadersettings.horizontal_sincronization |     property real horizontal_sincronization: shadersettings.horizontal_sincronization | ||||||
|  |  | ||||||
| @@ -116,8 +114,6 @@ ShaderEffect { | |||||||
|     (horizontal_sincronization !== 0 ? " |     (horizontal_sincronization !== 0 ? " | ||||||
|         varying lowp float horizontal_distortion;" : "") + |         varying lowp float horizontal_distortion;" : "") + | ||||||
|  |  | ||||||
|     (scanlines != 0 ? "uniform highp float scanlines;" : "") + |  | ||||||
|  |  | ||||||
|     " |     " | ||||||
|     highp float rand(vec2 co) |     highp float rand(vec2 co) | ||||||
|     { |     { | ||||||
| @@ -132,13 +128,8 @@ ShaderEffect { | |||||||
|     float stepNoise(vec2 p){ |     float stepNoise(vec2 p){ | ||||||
|         vec2 newP = p * txt_Size*0.5; |         vec2 newP = p * txt_Size*0.5; | ||||||
|         return rand(floor(newP) + fract(time / 100.0)); |         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 ? " |     (glowing_line_strength !== 0 ? " | ||||||
|         float randomPass(vec2 coords){ |         float randomPass(vec2 coords){ | ||||||
|             return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0001))) * glowing_line_strength; |             return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0001))) * glowing_line_strength; | ||||||
| @@ -169,22 +160,18 @@ ShaderEffect { | |||||||
|         (bloom !== 0 ? " |         (bloom !== 0 ? " | ||||||
|             color += texture2D(bloomSource, coords).r *" + 2.5 * bloom + ";" : "") + |             color += texture2D(bloomSource, coords).r *" + 2.5 * bloom + ";" : "") + | ||||||
|  |  | ||||||
|         (scanlines !== 0 ? " |  | ||||||
|             float scanline_alpha = getScanlineIntensity(coords);" |  | ||||||
|         : |  | ||||||
|             "float scanline_alpha = 1.0;") + |  | ||||||
|  |  | ||||||
|         (noise_strength !== 0 ? " |         (noise_strength !== 0 ? " | ||||||
|             color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") + |             color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") + | ||||||
|  |  | ||||||
|         (glowing_line_strength !== 0 ? " |         (glowing_line_strength !== 0 ? " | ||||||
|             color += randomPass(coords) * glowing_line_strength;" : "") + |             color += randomPass(coords) * glowing_line_strength;" : "") + | ||||||
|  |  | ||||||
|         "vec3 finalColor = mix(background_color, font_color, color * scanline_alpha).rgb;" + |         "vec3 finalColor = mix(background_color, font_color, color).rgb;" + | ||||||
|         "finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance);" + |         "finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance);" + | ||||||
|  |  | ||||||
|         (brightness_flickering !== 0 ? " |         (brightness_flickering !== 0 ? " | ||||||
|             finalColor = mix(finalColor, vec3(0.0), brightness);" : "") + |             finalColor = mix(finalColor, vec3(0.0), brightness);" : "") + | ||||||
|  |  | ||||||
|         " |         " | ||||||
|         gl_FragColor = vec4(finalColor, 1.0); |         gl_FragColor = vec4(finalColor, 1.0); | ||||||
|     }" |     }" | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ Item{ | |||||||
|     property bool fullscreen: false |     property bool fullscreen: false | ||||||
|  |  | ||||||
|     property real ambient_light: 0.2 |     property real ambient_light: 0.2 | ||||||
|     property real contrast: 0.9 |     property real contrast: 0.8 | ||||||
|  |  | ||||||
|     function mix(c1, c2, alpha){ |     function mix(c1, c2, alpha){ | ||||||
|         return Qt.rgba(c1.r * alpha + c2.r * (1-alpha), |         return Qt.rgba(c1.r * alpha + c2.r * (1-alpha), | ||||||
| @@ -34,7 +34,7 @@ Item{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     //Private atttributes might need processing |     //Private atttributes might need processing | ||||||
|     property color _background_color: "#002200" |     property color _background_color: "#000000" | ||||||
|     property color _font_color: "#00ff00" |     property color _font_color: "#00ff00" | ||||||
|     property color font_color: mix(_font_color, _background_color, 0.5 + (contrast * 0.5)) |     property color font_color: mix(_font_color, _background_color, 0.5 + (contrast * 0.5)) | ||||||
|     property color background_color: mix(_background_color, _font_color, 0.5 + (contrast * 0.5)) |     property color background_color: mix(_background_color, _font_color, 0.5 + (contrast * 0.5)) | ||||||
| @@ -48,7 +48,7 @@ Item{ | |||||||
|     property real horizontal_sincronization: 0.1 |     property real horizontal_sincronization: 0.1 | ||||||
|     property real brightness_flickering: 0.12 |     property real brightness_flickering: 0.12 | ||||||
|  |  | ||||||
|     property bool scanlines: false |     property real scanlines: 0.0 | ||||||
|  |  | ||||||
|     property string frame_source: frames_list.get(frames_index).source |     property string frame_source: frames_list.get(frames_index).source | ||||||
|     property int frames_index: 2 |     property int frames_index: 2 | ||||||
| @@ -204,17 +204,17 @@ Item{ | |||||||
|         ListElement{ |         ListElement{ | ||||||
|             text: "Default" |             text: "Default" | ||||||
|             obj_name: "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,"brightness_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":0.0,"screen_distortion":0.15,"brightness_flickering":0.07}' | ||||||
|         } |         } | ||||||
|         ListElement{ |         ListElement{ | ||||||
|             text: "Commodore 64" |             text: "Commodore 64" | ||||||
|             obj_name: "COMMODORE64" |             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,"brightness_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":0.0,"screen_distortion":0.1,"brightness_flickering":0.03}' | ||||||
|         } |         } | ||||||
|         ListElement{ |         ListElement{ | ||||||
|             text: "IBM Dos" |             text: "IBM Dos" | ||||||
|             obj_name: "IBMDOS" |             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,"brightness_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":0.0,"screen_distortion":0.05,"brightness_flickering":0.00}' | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,11 +7,22 @@ Item{ | |||||||
|     id: terminalContainer |     id: terminalContainer | ||||||
|     property real mBloom: shadersettings.bloom_strength |     property real mBloom: shadersettings.bloom_strength | ||||||
|     property real mBlur: shadersettings.motion_blur |     property real mBlur: shadersettings.motion_blur | ||||||
|  |     property real scanlines: shadersettings.scanlines | ||||||
|     property real motionBlurCoefficient: (_minBlurCoefficient)*mBlur + (_maxBlurCoefficient)*(1.0-mBlur) |     property real motionBlurCoefficient: (_minBlurCoefficient)*mBlur + (_maxBlurCoefficient)*(1.0-mBlur) | ||||||
|     property real _minBlurCoefficient: 0.015 |     property real _minBlurCoefficient: 0.015 | ||||||
|     property real _maxBlurCoefficient: 0.10 |     property real _maxBlurCoefficient: 0.10 | ||||||
|     anchors.fill: parent |     anchors.fill: parent | ||||||
|  |  | ||||||
|  |     //Force reload of the blursource when settings change | ||||||
|  |     onScanlinesChanged: restartBlurredSource() | ||||||
|  |     onMBloomChanged: restartBlurredSource() | ||||||
|  |  | ||||||
|  |     function restartBlurredSource(){ | ||||||
|  |         if(!blurredSource) return; | ||||||
|  |  | ||||||
|  |         blurredSource.live = true; | ||||||
|  |         livetimer.restart() | ||||||
|  |     } | ||||||
|     function loadKTerminal(){ |     function loadKTerminal(){ | ||||||
|         kterminal.active = true; |         kterminal.active = true; | ||||||
|     } |     } | ||||||
| @@ -81,23 +92,38 @@ Item{ | |||||||
|         anchors.fill: parent |         anchors.fill: parent | ||||||
|         property variant source: source |         property variant source: source | ||||||
|         property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined |         property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined | ||||||
|  |         property size txt_size: Qt.size(width, height) | ||||||
|  |  | ||||||
|         z: 2 |         z: 2 | ||||||
|  |  | ||||||
|         fragmentShader: |         fragmentShader: | ||||||
|             "uniform lowp float qt_Opacity;" + |             "uniform lowp float qt_Opacity;" + | ||||||
|             "uniform lowp sampler2D source;" + |             "uniform lowp sampler2D source;" + | ||||||
|  |             "uniform lowp vec2 txt_size;" + | ||||||
|  |  | ||||||
|             "varying highp vec2 qt_TexCoord0;" + |             "varying highp vec2 qt_TexCoord0;" + | ||||||
|  |  | ||||||
|  |             "float getScanlineIntensity(vec2 coord){ | ||||||
|  |                 float h = coord.y * txt_size.y * 0.5; | ||||||
|  |                 return step(0.5, fract(h)); | ||||||
|  |             }" + | ||||||
|  |  | ||||||
|             (mBlur !== 0 ? |             (mBlur !== 0 ? | ||||||
|                  "uniform lowp sampler2D blurredSource;" : "") + |                  "uniform lowp sampler2D blurredSource;" | ||||||
|  |             : "") + | ||||||
|  |  | ||||||
|             "void main() {" + |             "void main() {" + | ||||||
|                 "float color = texture2D(source, qt_TexCoord0).r * 0.8 * 512.0;" + |                 "float color = texture2D(source, qt_TexCoord0).r * 0.8 * 512.0;" + | ||||||
|  |  | ||||||
|                 (mBlur !== 0 ? |                 (mBlur !== 0 ? | ||||||
|                      "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 512.0;" + |                      "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 512.0;" + | ||||||
|                  "color = mix(blurredSourceColor, color, " + motionBlurCoefficient + ");" : "" |                      "color = mix(blurredSourceColor, color, " + motionBlurCoefficient + ");" | ||||||
|              ) + |                 : "") + | ||||||
|  |  | ||||||
|  |                 (scanlines !== 0 ? " | ||||||
|  |                     color = mix(color, 1.0 * color*getScanlineIntensity(qt_TexCoord0), "+scanlines+");" | ||||||
|  |                 : "") + | ||||||
|  |  | ||||||
|                 "gl_FragColor = vec4(vec3(floor(color) / 512.0), 1.0);" + |                 "gl_FragColor = vec4(vec3(floor(color) / 512.0), 1.0);" + | ||||||
|             "}" |             "}" | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user