mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-30 22:54:21 +00:00 
			
		
		
		
	Added realtime reflections on the frame. They are a little bit hacky but don't have any impact on performances.
This commit is contained in:
		| @@ -99,11 +99,21 @@ ApplicationWindow { | ||||
|                         columns: 2 | ||||
|                         Text{text: "Frame texture"} | ||||
|                         ComboBox{ | ||||
|                             id: framescombobox | ||||
|                             Layout.fillWidth: true | ||||
|                             model: shadersettings.frames_list | ||||
|                             currentIndex: shadersettings.frames_index | ||||
|                             onCurrentIndexChanged: shadersettings.frames_index = currentIndex | ||||
|                         } | ||||
|                         CheckBox{ | ||||
|                             Layout.columnSpan: 2 | ||||
|                             Layout.fillWidth: true | ||||
|                             checked: shadersettings.frame_reflections | ||||
|                             text: qsTr("Frame reflections") | ||||
|                             onCheckedChanged: shadersettings.frame_reflections = checked | ||||
|                             enabled: framescombobox.model.get(framescombobox.currentIndex).reflections | ||||
|                         } | ||||
|  | ||||
|                         Item{Layout.fillHeight: true} | ||||
|                         ColorButton{ | ||||
|                             height: 50 | ||||
|   | ||||
| @@ -40,6 +40,12 @@ ShaderEffect { | ||||
|     property real brightness_flickering: shadersettings.brightness_flickering | ||||
|     property real horizontal_sincronization: shadersettings.horizontal_sincronization | ||||
|  | ||||
|     property bool frame_reflection_strength: shadersettings.frame_reflection_strength | ||||
|     property real disp_top: frame.item.displacementTop.toFixed(1) | ||||
|     property real disp_bottom: frame.item.displacementBottom | ||||
|     property real disp_left: frame.item.displacementLeft | ||||
|     property real disp_right: frame.item.displacementRight | ||||
|  | ||||
|     property real brightness: shadersettings.brightness * 1.5 + 0.5 | ||||
|  | ||||
|     property real deltay: 3 / parent.height | ||||
| @@ -69,10 +75,12 @@ ShaderEffect { | ||||
|                     uniform highp mat4 qt_Matrix; | ||||
|                     uniform highp float time; | ||||
|                     uniform sampler2D randomFunctionSource; | ||||
|                     uniform highp vec2 txt_Size; | ||||
|  | ||||
|                     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;" : "") + | ||||
| @@ -80,8 +88,10 @@ ShaderEffect { | ||||
|                         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)));" + | ||||
|                         originalCoord = qt_MultiTexCoord0; | ||||
|                         qt_TexCoord0.x = -"+disp_left.toFixed(1)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+(disp_left+disp_right).toFixed(1)+")) / txt_Size.x);" + | ||||
|                         "qt_TexCoord0.y = -"+disp_top.toFixed(1)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+(disp_top+disp_bottom).toFixed(1)+")) / txt_Size.y);" + | ||||
|                         "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+";" | ||||
|                         :   "") + | ||||
| @@ -100,6 +110,7 @@ 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; | ||||
| @@ -170,6 +181,8 @@ ShaderEffect { | ||||
|                 noise += horizontal_distortion * 0.5;" : "") | ||||
|         : "") + | ||||
|  | ||||
|         (frame_reflection_strength ? " | ||||
|             coords = abs(mod(floor(coords), 2.0) - fract(coords));" : "") + | ||||
|  | ||||
|         "float color = texture2D(source, coords).r;" + | ||||
|  | ||||
| @@ -180,7 +193,7 @@ ShaderEffect { | ||||
|             color += randomPass(coords) * glowing_line_strength;" : "") + | ||||
|  | ||||
|         (rasterization !== shadersettings.no_rasterization ? " | ||||
|             color = mix(color, color * getScanlineIntensity(qt_TexCoord0), "+ rasterization_strength +");" | ||||
|             color = mix(color, color * getScanlineIntensity(originalCoord), "+ rasterization_strength +");" | ||||
|         : "") + | ||||
|  | ||||
|         (bloom !== 0 ? " | ||||
|   | ||||
| @@ -81,6 +81,9 @@ Item{ | ||||
|     property int font_index: 0 | ||||
|     property var fonts_list: fontlist | ||||
|  | ||||
|     property bool frame_reflections: true | ||||
|     property real frame_reflection_strength: ((frame_reflections && framelist.get(frames_index).reflections) ? 1.0 : 0.0) * 0.4 | ||||
|  | ||||
|     property var profiles_list: profileslist | ||||
|     property int profiles_index: 0 | ||||
|     onProfiles_indexChanged: loadProfile(profiles_list.get(profiles_index).obj_name); | ||||
| @@ -105,9 +108,9 @@ Item{ | ||||
|  | ||||
|     ListModel{ | ||||
|         id: framelist | ||||
|         ListElement{text: "No frame"; source: "./frames/NoFrame.qml"} | ||||
|         ListElement{text: "Simple white frame"; source: "./frames/WhiteSimpleFrame.qml"} | ||||
|         ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"} | ||||
|         ListElement{text: "No frame"; source: "./frames/NoFrame.qml"; reflections: false} | ||||
|         ListElement{text: "Simple white frame"; source: "./frames/WhiteSimpleFrame.qml"; reflections: true} | ||||
|         ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"; reflections: true} | ||||
|     } | ||||
|  | ||||
|     ListModel{ | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE QtCreatorProject> | ||||
| <!-- Written by QtCreator 3.0.1, 2014-04-04T01:31:42. --> | ||||
| <!-- Written by QtCreator 3.0.1, 2014-04-05T12:53:24. --> | ||||
| <qtcreator> | ||||
|  <data> | ||||
|   <variable>ProjectExplorer.Project.ActiveTarget</variable> | ||||
|   | ||||
| @@ -14,10 +14,17 @@ TerminalFrame{ | ||||
|     borderBottom: 232 | ||||
|     imageSource: "../images/black-frame.png" | ||||
|     normalsSource: "../images/black-frame-normals.png" | ||||
|     sourceRect: Qt.rect(-80 * shadersettings.total_scaling, | ||||
|                         -90 * shadersettings.total_scaling, | ||||
|                         terminal.width + 160 * shadersettings.total_scaling, | ||||
|                         terminal.height + 180 * shadersettings.total_scaling) | ||||
|     sourceRect: Qt.rect(-15 * shadersettings.total_scaling, | ||||
|                         -15 * shadersettings.total_scaling, | ||||
|                         terminal.width + 30 * shadersettings.total_scaling, | ||||
|                         terminal.height + 30 * shadersettings.total_scaling) | ||||
|  | ||||
|     distortionCoefficient: 1.8 | ||||
|  | ||||
|     displacementLeft: 70.0 | ||||
|     displacementTop: 55.0 | ||||
|     displacementRight: 50.0 | ||||
|     displacementBottom: 38.0 | ||||
|  | ||||
|     shaderString: "FrameShader.qml" | ||||
| } | ||||
|   | ||||
| @@ -15,4 +15,9 @@ TerminalFrame{ | ||||
|                         -15, | ||||
|                         terminal.width + 15, | ||||
|                         terminal.height + 15) | ||||
|  | ||||
|     displacementLeft: 0 | ||||
|     displacementTop: 0 | ||||
|     displacementRight: 0 | ||||
|     displacementBottom: 0 | ||||
| } | ||||
|   | ||||
| @@ -13,10 +13,17 @@ TerminalFrame{ | ||||
|     borderBottom: 116 | ||||
|     imageSource: "../images/screen-frame.png" | ||||
|     normalsSource: "../images/screen-frame-normals.png" | ||||
|     sourceRect: Qt.rect(-65 * shadersettings.total_scaling, | ||||
|                         -75 * shadersettings.total_scaling, | ||||
|                         terminal.width + 130 * shadersettings.total_scaling, | ||||
|                         terminal.height + 150 * shadersettings.total_scaling) | ||||
|     sourceRect: Qt.rect(-10 * shadersettings.total_scaling, | ||||
|                         -5 * shadersettings.total_scaling, | ||||
|                         terminal.width + 20 * shadersettings.total_scaling, | ||||
|                         terminal.height+ 10 * shadersettings.total_scaling) | ||||
|  | ||||
|     distortionCoefficient: 1.3 | ||||
|  | ||||
|     displacementLeft: 43.0 | ||||
|     displacementTop: 40.0 | ||||
|     displacementRight: 35.0 | ||||
|     displacementBottom: 32.0 | ||||
|  | ||||
|     shaderString: "FrameShader.qml" | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ import QtQuick 2.1 | ||||
| ShaderEffect{ | ||||
|     property variant source: framesource | ||||
|     property variant normals: framesourcenormals | ||||
|     property real screen_distorsion: shadersettings.screen_distortion | ||||
|     property real screen_distorsion: shadersettings.screen_distortion * framecontainer.distortionCoefficient | ||||
|     property real ambient_light: shadersettings.ambient_light | ||||
|     property color font_color: shadersettings.font_color | ||||
|     property color background_color: shadersettings.background_color | ||||
| @@ -12,6 +12,8 @@ ShaderEffect{ | ||||
|     property real brightness_flickering: shadersettings.brightness_flickering | ||||
|     property real brightness: shadersettings.brightness * 1.5 + 0.5 | ||||
|  | ||||
|     property real frame_reflection_strength: shadersettings.frame_reflection_strength | ||||
|  | ||||
|     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), | ||||
| @@ -62,10 +64,12 @@ ShaderEffect{ | ||||
|                                 vec4 txt_normal = texture2D(normals, coords); | ||||
|                                 vec3 normal = normalize(txt_normal.rgb * 2.0 - 1.0); | ||||
|                                 vec3 light_dir = normalize(vec3(0.5,0.5, 0.0) - vec3(qt_TexCoord0, 0.0)); | ||||
|                                 float reflection = (dot(normal, light_dir) * 0.4 + 0.2) * brightness; | ||||
|                                 vec3 final_color = reflection_color.rgb * reflection * 0.5; | ||||
|                                 float reflection = (dot(normal, light_dir)); | ||||
|                                 float light = (reflection * 0.4 + 0.2) * brightness; | ||||
|                                 vec3 final_color = reflection_color.rgb * light * 0.5; | ||||
|                                 final_color += txt_color.rgb * ambient_light; | ||||
|                                 gl_FragColor = vec4(final_color * txt_normal.a, txt_color.a * qt_Opacity); | ||||
|                                 float reflection_alpha = (1.0 - reflection*0.4); | ||||
|                                 gl_FragColor = vec4(final_color * txt_normal.a, txt_color.a * qt_Opacity * reflection_alpha); | ||||
|                             }" | ||||
|  | ||||
|     onStatusChanged: console.log(log) //Print warning messages | ||||
|   | ||||
| @@ -13,6 +13,14 @@ Item{ | ||||
|     property rect sourceRect | ||||
|     property string shaderString | ||||
|  | ||||
|     //Values used to displace the texture in the screen. Used to make reflections correct. | ||||
|     property real displacementLeft | ||||
|     property real displacementTop | ||||
|     property real displacementRight | ||||
|     property real displacementBottom | ||||
|  | ||||
|     property real distortionCoefficient | ||||
|  | ||||
|     BorderImage{ | ||||
|         id: frameimage | ||||
|         anchors.centerIn: parent | ||||
|   | ||||
| @@ -73,6 +73,7 @@ ApplicationWindow{ | ||||
|         anchors.fill: parent | ||||
|         z: 2.1 | ||||
|         source: shadersettings.frame_source | ||||
|         opacity: 1.0 | ||||
|     } | ||||
|  | ||||
|     Item{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user