mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Some cleanups. Improved noise, now virtual resolution aware.
This commit is contained in:
		| @@ -247,11 +247,6 @@ Window { | ||||
|                                                       shadersettings.rasterization = shadersettings.pixel_rasterization | ||||
|                             } | ||||
|                         } | ||||
|                         SimpleSlider{ | ||||
|                             Layout.fillWidth: true | ||||
|                             value: shadersettings.rasterization_strength | ||||
|                             onValueChanged: shadersettings.rasterization_strength = value | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 GroupBox{ | ||||
|   | ||||
| @@ -30,14 +30,13 @@ ShaderEffect { | ||||
|     property real bloom: shadersettings.bloom_strength | ||||
|  | ||||
|     property int rasterization: shadersettings.rasterization | ||||
|     property real rasterization_strength: shadersettings.rasterization_strength | ||||
|     property real _verticalResDensity: shadersettings.font.virtualResolution.height + shadersettings.font.lineSpacing | ||||
|     property real _horizontalResDensity: shadersettings.font.virtualResolution.width | ||||
|     property real _lines: frame.sourceRect.height / terminal.paintedFontSize.height | ||||
|     property real _columns: frame.sourceRect.width / terminal.paintedFontSize.width | ||||
|     property real verticalPixelDensity: shadersettings.font.virtualResolution.height + shadersettings.font.lineSpacing | ||||
|     property real horizontalPixelDensity: shadersettings.font.virtualResolution.width | ||||
|     property size num_scanlines: Qt.size(_columns * horizontalPixelDensity, _lines * verticalPixelDensity) | ||||
|     property real scanlineHeight: frame.sourceRect.height / num_scanlines.height | ||||
|     property real scanlineWidth: frame.sourceRect.width / num_scanlines.width | ||||
|     property size virtual_resolution: Qt.size(_columns * _horizontalResDensity, _lines * _verticalResDensity) | ||||
|     property real scanlineHeight: frame.sourceRect.height / virtual_resolution.height | ||||
|     property real scanlineWidth: frame.sourceRect.width / virtual_resolution.width | ||||
|  | ||||
|     property real noise_strength: shadersettings.noise_strength | ||||
|     property real screen_distorsion: shadersettings.screen_distortion | ||||
| @@ -61,6 +60,10 @@ ShaderEffect { | ||||
|     property real time: timetimer.time | ||||
|     property variant randomFunctionSource: randfuncsource | ||||
|  | ||||
|     function str(num){ | ||||
|         return num.toFixed(8); | ||||
|     } | ||||
|  | ||||
|     //Blurred texture used for bloom | ||||
|     Loader{ | ||||
|         anchors.fill: parent | ||||
| @@ -87,27 +90,27 @@ ShaderEffect { | ||||
|         attribute highp vec4 qt_Vertex; | ||||
|         attribute highp vec2 qt_MultiTexCoord0; | ||||
|  | ||||
|                     varying highp vec2 originalCoord; | ||||
|         varying highp vec2 qt_TexCoord0;" + | ||||
|  | ||||
|         (brightness_flickering !== 0.0 ?" | ||||
|             varying lowp float brightness;" : "") + | ||||
|         (horizontal_sincronization !== 0.0 ?" | ||||
|             varying lowp float horizontal_distortion;" : "") + | ||||
|         " | ||||
|         void main() { | ||||
|                         originalCoord = qt_MultiTexCoord0; | ||||
|                         qt_TexCoord0.x = -"+disp_left.toFixed(8)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+(disp_left+disp_right).toFixed(8)+")) / txt_Size.x);" + | ||||
|                         "qt_TexCoord0.y = -"+disp_top.toFixed(8)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+(disp_top+disp_bottom).toFixed(8)+")) / txt_Size.y);" + | ||||
|                         "vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + | ||||
|             qt_TexCoord0.x = -"+str(disp_left)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+str(disp_left+disp_right)+")) / txt_Size.x);" + " | ||||
|             qt_TexCoord0.y = -"+str(disp_top)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+str(disp_top+disp_bottom)+")) / txt_Size.y);" + " | ||||
|             vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + | ||||
|             (brightness_flickering !== 0.0 ? " | ||||
|                             brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * "+brightness_flickering.toFixed(2)+";" | ||||
|                 brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * "+str(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+";" | ||||
|                 float negsinc = 1.0 - "+str(0.6*horizontal_sincronization)+"; | ||||
|                 horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * "+str(0.3*horizontal_sincronization)+";" | ||||
|             : "") + | ||||
|  | ||||
|             "gl_Position = qt_Matrix * qt_Vertex; | ||||
|         }" | ||||
|  | ||||
| @@ -117,10 +120,11 @@ ShaderEffect { | ||||
|         uniform highp float time; | ||||
|         uniform highp vec2 txt_Size; | ||||
|         varying highp vec2 qt_TexCoord0; | ||||
|             varying highp vec2 originalCoord; | ||||
|  | ||||
|         uniform highp vec4 font_color; | ||||
|             uniform highp vec4 background_color;" + | ||||
|         uniform highp vec4 background_color; | ||||
|  | ||||
|         uniform highp vec2 virtual_resolution;" + | ||||
|  | ||||
|         (bloom !== 0 ? " | ||||
|             uniform highp sampler2D bloomSource;" : "") + | ||||
| @@ -137,9 +141,9 @@ ShaderEffect { | ||||
|  | ||||
|         (rasterization !== shadersettings.no_rasterization ? " | ||||
|         float getScanlineIntensity(vec2 coord){ | ||||
|         float result = abs(sin(coord.y * "+(num_scanlines.height * Math.PI).toFixed(8)+"));" + | ||||
|             float result = abs(sin(coord.y * virtual_resolution.y * "+str(Math.PI)+" ));" + | ||||
|             (rasterization === shadersettings.pixel_rasterization ? " | ||||
|             result *= abs(sin(coord.x * "+(num_scanlines.width * Math.PI).toFixed(8)+"));" : "") + | ||||
|                 result *= abs(sin(coord.x * virtual_resolution.x * "+str(Math.PI)+"));" : "") + | ||||
|             "return result; | ||||
|         }" : "") + | ||||
|  | ||||
| @@ -155,7 +159,7 @@ ShaderEffect { | ||||
|         } | ||||
|  | ||||
|         float stepNoise(vec2 p){ | ||||
|         vec2 newP = p * txt_Size*0.5; | ||||
|             vec2 newP = p * virtual_resolution; | ||||
|             return rand(floor(newP) + fract(time / 100.0)); | ||||
|         }" + | ||||
|  | ||||
| @@ -192,25 +196,24 @@ ShaderEffect { | ||||
|  | ||||
|             (rasterization !== shadersettings.no_rasterization ? " | ||||
|                 vec2 txt_coords = coords; | ||||
|             txt_coords.y = floor(coords.y * "+num_scanlines.height.toFixed(8)+") / "+num_scanlines.height.toFixed(8)+";" + | ||||
|                 txt_coords.y = floor(coords.y * virtual_resolution.y) / virtual_resolution.y;" + | ||||
|                 (rasterization === shadersettings.pixel_rasterization ? | ||||
|                 "txt_coords.x = floor(coords.x * "+num_scanlines.width.toFixed(8)+") / "+num_scanlines.width.toFixed(8)+";" : "") | ||||
|                     "txt_coords.x = floor(coords.x * virtual_resolution.x) / virtual_resolution.x;" : "") | ||||
|             : " vec2 txt_coords = coords;") + | ||||
|  | ||||
|         "float color = texture2D(source, txt_coords + vec2("+(deltax * 0.5).toFixed(8)+", "+(deltay * 0.5).toFixed(8)+")).r;" + | ||||
|             "float color = texture2D(source, txt_coords + vec2("+str(deltax * 0.5)+", "+str(deltay * 0.5)+")).r;" + | ||||
|  | ||||
|             (noise_strength !== 0 ? " | ||||
|                 color += stepNoise(coords) * noise * (1.0 - distance * distance * 2.0);" : "") + | ||||
|  | ||||
|             (rasterization !== shadersettings.no_rasterization ? " | ||||
|                 color = color * getScanlineIntensity(coords);" : "") + | ||||
|  | ||||
|             (glowing_line_strength !== 0 ? " | ||||
|                 color += randomPass(txt_coords) * glowing_line_strength;" : "") + | ||||
|  | ||||
|         (rasterization !== shadersettings.no_rasterization ? " | ||||
|             color = mix(texture2D(source, coords).r, color * getScanlineIntensity(coords), "+ rasterization_strength.toFixed(8) +");" | ||||
|         : "") + | ||||
|  | ||||
|             (bloom !== 0 ? " | ||||
|             color += texture2D(bloomSource, coords).r *" + (2.5 * bloom).toFixed(8) + ";" : "") + | ||||
|                 color += texture2D(bloomSource, coords).r *" + str(2.5 * bloom) + ";" : "") + | ||||
|  | ||||
|             "vec3 finalColor = mix(background_color, font_color, color).rgb;" + | ||||
|             "finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance);" + | ||||
| @@ -218,7 +221,7 @@ ShaderEffect { | ||||
|             (brightness_flickering !== 0 ? " | ||||
|                 finalColor *= brightness;" : "") + | ||||
|  | ||||
|         "gl_FragColor = vec4(finalColor *"+brightness.toFixed(8)+", qt_Opacity); | ||||
|             "gl_FragColor = vec4(finalColor *"+str(brightness)+", qt_Opacity); | ||||
|         }" | ||||
|  | ||||
|      onStatusChanged: if (log) console.log(log) //Print warning messages | ||||
|   | ||||
| @@ -68,7 +68,6 @@ Item{ | ||||
|     readonly property int pixel_rasterization: 2 | ||||
|  | ||||
|     property int rasterization: no_rasterization | ||||
|     property real rasterization_strength: 0.5 | ||||
|  | ||||
|     property string frame_source: frames_list.get(frames_index).source | ||||
|     property int frames_index: 1 | ||||
| @@ -241,7 +240,6 @@ Item{ | ||||
|             font_index: font_index, | ||||
|             motion_blur: motion_blur, | ||||
|             bloom_strength: bloom_strength, | ||||
|             rasterization_strength: rasterization_strength, | ||||
|             rasterization: rasterization | ||||
|         } | ||||
|         return JSON.stringify(settings); | ||||
| @@ -305,7 +303,6 @@ Item{ | ||||
|  | ||||
|         font_index = settings.font_index !== undefined ? settings.font_index : font_index; | ||||
|  | ||||
|         rasterization_strength = settings.rasterization_strength !== undefined ?  settings.rasterization_strength : rasterization_strength; | ||||
|         rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; | ||||
|     } | ||||
|  | ||||
| @@ -362,7 +359,7 @@ Item{ | ||||
|         id: profileslist | ||||
|         ListElement{ | ||||
|             text: "Default" | ||||
|             obj_string: '{"background_color":"#000000","bloom_strength":0.6,"brightness_flickering":0.12,"font_color":"#ff9400","font_index":0,"frames_index":1,"glowing_line_strength":0.4,"horizontal_sincronization":0.1,"motion_blur":0.65,"noise_strength":0.1,"rasterization":1,"rasterization_strength":0.5,"screen_distortion":0.15}' | ||||
|             obj_string: '{"background_color":"#000000","bloom_strength":0.6,"brightness_flickering":0.12,"font_color":"#ff9400","font_index":0,"frames_index":1,"glowing_line_strength":0.4,"horizontal_sincronization":0.1,"motion_blur":0.65,"noise_strength":0.1,"rasterization":1,"screen_distortion":0.15}' | ||||
|             builtin: true | ||||
|         } | ||||
|         ListElement{ | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE QtCreatorProject> | ||||
| <!-- Written by QtCreator 3.0.1, 2014-05-31T13:16:10. --> | ||||
| <!-- Written by QtCreator 3.0.1, 2014-05-31T21:19:31. --> | ||||
| <qtcreator> | ||||
|  <data> | ||||
|   <variable>ProjectExplorer.Project.ActiveTarget</variable> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user