mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-01-18 12:15:27 +00:00
Merge pull request #190 from Swordfish90/unstable
New improved and faster frame effect.
This commit is contained in:
commit
2f94fa4e2f
@ -76,17 +76,8 @@ Item{
|
||||
|
||||
property int rasterization: no_rasterization
|
||||
|
||||
ListModel{
|
||||
id: framelist
|
||||
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}
|
||||
}
|
||||
|
||||
property string frame_source: frames_list.get(frames_index).source
|
||||
property int frames_index: 1
|
||||
property var frames_list: framelist
|
||||
|
||||
property alias profiles_list: profileslist
|
||||
property int profiles_index: 0
|
||||
|
||||
// FONTS //////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -121,7 +112,7 @@ Item{
|
||||
if (name === fontlist.get(i).name)
|
||||
return i;
|
||||
}
|
||||
return undefined;
|
||||
return 0; // If the font is not available returns the first one.
|
||||
}
|
||||
|
||||
function incrementScaling(){
|
||||
@ -154,12 +145,20 @@ Item{
|
||||
|
||||
// FRAMES /////////////////////////////////////////////////////////////////
|
||||
|
||||
property bool _frameReflections: true
|
||||
property bool _frameReflections: false
|
||||
property bool reflectionsAllowed: framelist.get(frames_index).reflections
|
||||
property bool frameReflections: _frameReflections && reflectionsAllowed
|
||||
|
||||
property alias profiles_list: profileslist
|
||||
property int profiles_index: 0
|
||||
ListModel{
|
||||
id: framelist
|
||||
ListElement{text: "No frame"; source: ""; reflections: false}
|
||||
ListElement{text: "Simple white frame"; source: "./frames/WhiteSimpleFrame.qml"; reflections: true}
|
||||
ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"; reflections: true}
|
||||
}
|
||||
|
||||
property string frame_source: frames_list.get(frames_index).source
|
||||
property int frames_index: 1
|
||||
property alias frames_list: framelist
|
||||
|
||||
// DB STORAGE /////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -31,14 +31,16 @@ Item{
|
||||
property ShaderEffectSource mainSource: kterminalSource
|
||||
property ShaderEffectSource blurredSource: blurredSourceLoader.item
|
||||
|
||||
property real fontWidth: 1.0
|
||||
property real screenScaling: 1.0
|
||||
property real scaleTexture: 1.0
|
||||
property alias title: ksession.title
|
||||
property alias kterminal: kterminal
|
||||
|
||||
anchors.leftMargin: frame.item.displacementLeft * appSettings.window_scaling
|
||||
anchors.rightMargin: frame.item.displacementRight * appSettings.window_scaling
|
||||
anchors.topMargin: frame.item.displacementTop * appSettings.window_scaling
|
||||
anchors.bottomMargin: frame.item.displacementBottom * appSettings.window_scaling
|
||||
anchors.leftMargin: frame.displacementLeft * appSettings.window_scaling
|
||||
anchors.rightMargin: frame.displacementRight * appSettings.window_scaling
|
||||
anchors.topMargin: frame.displacementTop * appSettings.window_scaling
|
||||
anchors.bottomMargin: frame.displacementBottom * appSettings.window_scaling
|
||||
|
||||
//The blur effect has to take into account the framerate
|
||||
property real mBlur: appSettings.motion_blur
|
||||
@ -76,8 +78,8 @@ Item{
|
||||
|
||||
QMLTermWidget {
|
||||
id: kterminal
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
width: Math.floor(parent.width / (screenScaling * fontWidth))
|
||||
height: Math.floor(parent.height / screenScaling)
|
||||
|
||||
colorScheme: "cool-retro-term"
|
||||
|
||||
@ -100,6 +102,8 @@ Item{
|
||||
width: terminal.fontMetrics.width * 0.75
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 1
|
||||
anchors.bottomMargin: 1
|
||||
color: "white"
|
||||
radius: width * 0.25
|
||||
opacity: 0.7
|
||||
@ -113,9 +117,8 @@ Item{
|
||||
font.pixelSize = pixelSize;
|
||||
font.family = fontLoader.name;
|
||||
|
||||
width = Qt.binding(function() {return Math.floor(terminalContainer.width / (screenScaling * fontWidth));});
|
||||
height = Qt.binding(function() {return Math.floor(terminalContainer.height / screenScaling);});
|
||||
|
||||
terminalContainer.fontWidth = fontWidth;
|
||||
terminalContainer.screenScaling= screenScaling;
|
||||
scaleTexture = Math.max(1.0, Math.round(screenScaling / 2));
|
||||
|
||||
kterminal.lineSpacing = lineSpacing;
|
||||
|
@ -49,10 +49,10 @@ ShaderEffect {
|
||||
|
||||
property bool frameReflections: appSettings.frameReflections
|
||||
|
||||
property real disp_top: (frame.item.displacementTop * appSettings.window_scaling) / height
|
||||
property real disp_bottom: (frame.item.displacementBottom * appSettings.window_scaling) / height
|
||||
property real disp_left: (frame.item.displacementLeft * appSettings.window_scaling) / width
|
||||
property real disp_right: (frame.item.displacementRight * appSettings.window_scaling) / width
|
||||
property real disp_top: (frame.displacementTop * appSettings.window_scaling) / height
|
||||
property real disp_bottom: (frame.displacementBottom * appSettings.window_scaling) / height
|
||||
property real disp_left: (frame.displacementLeft * appSettings.window_scaling) / width
|
||||
property real disp_right: (frame.displacementRight * appSettings.window_scaling) / width
|
||||
|
||||
property real screen_brightness: appSettings.brightness * 1.5 + 0.5
|
||||
|
||||
|
@ -19,6 +19,15 @@ ShaderTerminal{
|
||||
Loader{
|
||||
id: frame
|
||||
anchors.fill: parent
|
||||
|
||||
property real displacementLeft: item ? item.displacementLeft : 0
|
||||
property real displacementTop: item ? item.displacementTop : 0
|
||||
property real displacementRight: item ? item.displacementRight : 0
|
||||
property real displacementBottom: item ? item.displacementBottom : 0
|
||||
|
||||
asynchronous: true
|
||||
visible: status === Loader.Ready
|
||||
|
||||
z: 2.1
|
||||
source: appSettings.frame_source
|
||||
}
|
||||
|
@ -14,12 +14,11 @@ TerminalFrame{
|
||||
imageSource: "../images/black-frame.png"
|
||||
normalsSource: "../images/black-frame-normals.png"
|
||||
|
||||
distortionCoefficient: 1.9
|
||||
|
||||
displacementLeft: 80.0
|
||||
displacementTop: 65.0
|
||||
displacementRight: 80.0
|
||||
displacementBottom: 65.0
|
||||
|
||||
shaderString: "FrameShader.qml"
|
||||
staticDiffuseComponent: 1.0
|
||||
dinamycDiffuseComponent: 0.6
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
import QtQuick 2.2
|
||||
import "utils"
|
||||
|
||||
TerminalFrame{
|
||||
id: frame
|
||||
z: 2.1
|
||||
anchors.fill: parent
|
||||
addedWidth: 0
|
||||
addedHeight: 0
|
||||
borderLeft: 0
|
||||
borderRight: 0
|
||||
borderTop: 0
|
||||
borderBottom: 0
|
||||
|
||||
displacementLeft: 0
|
||||
displacementTop: 0
|
||||
displacementRight: 0
|
||||
displacementBottom: 0
|
||||
}
|
@ -14,12 +14,11 @@ TerminalFrame{
|
||||
imageSource: "../images/screen-frame.png"
|
||||
normalsSource: "../images/screen-frame-normals.png"
|
||||
|
||||
distortionCoefficient: 1.5
|
||||
|
||||
displacementLeft: 55
|
||||
displacementTop: 50
|
||||
displacementRight: 55
|
||||
displacementBottom: 50
|
||||
|
||||
shaderString: "FrameShader.qml"
|
||||
staticDiffuseComponent: 1.0
|
||||
dinamycDiffuseComponent: 0.6
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
Before Width: | Height: | Size: 507 KiB After Width: | Height: | Size: 498 KiB |
@ -1,103 +0,0 @@
|
||||
import QtQuick 2.2
|
||||
import QtGraphicalEffects 1.0
|
||||
|
||||
ShaderEffect{
|
||||
property variant source: framesource
|
||||
property variant normals: framesourcenormals
|
||||
property real screen_distorsion: appSettings.screen_distortion * framecontainer.distortionCoefficient
|
||||
property real ambient_light: appSettings.ambient_light
|
||||
property color font_color: appSettings.font_color
|
||||
property color background_color: appSettings.background_color
|
||||
property real brightness: appSettings.brightness * 1.5 + 0.5
|
||||
|
||||
property bool frameReflections: appSettings.frameReflections
|
||||
property variant lightSource: reflectionEffectSourceLoader.item
|
||||
|
||||
property real chroma_color: appSettings.chroma_color
|
||||
|
||||
Loader{
|
||||
id: reflectionEffectLoader
|
||||
width: parent.width * 0.33
|
||||
height: parent.height * 0.33
|
||||
active: frameReflections
|
||||
|
||||
sourceComponent: FastBlur{
|
||||
id: frameReflectionEffect
|
||||
radius: 128
|
||||
source: terminal.kterminal
|
||||
smooth: false
|
||||
}
|
||||
}
|
||||
|
||||
Loader{
|
||||
id: reflectionEffectSourceLoader
|
||||
active: frameReflections
|
||||
sourceComponent: ShaderEffectSource{
|
||||
id: frameReflectionSource
|
||||
sourceItem: reflectionEffectLoader.item
|
||||
hideSource: true
|
||||
smooth: true
|
||||
visible: false
|
||||
}
|
||||
}
|
||||
|
||||
blending: true
|
||||
|
||||
fragmentShader: "
|
||||
uniform sampler2D source;
|
||||
uniform sampler2D normals;
|
||||
uniform highp float screen_distorsion;
|
||||
uniform highp float ambient_light;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp float chroma_color;" +
|
||||
|
||||
(frameReflections ?
|
||||
"uniform sampler2D lightSource;" : "") + "
|
||||
|
||||
uniform vec4 font_color;
|
||||
uniform vec4 background_color;
|
||||
varying lowp float brightness;
|
||||
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
|
||||
vec2 distortCoordinates(vec2 coords){
|
||||
vec2 cc = coords - vec2(0.5);
|
||||
float dist = dot(cc, cc) * screen_distorsion;
|
||||
return (coords + cc * (1.0 + dist) * dist);
|
||||
}
|
||||
|
||||
float rgb2grey(vec3 v){
|
||||
return dot(v, vec3(0.21, 0.72, 0.04));
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 coords = distortCoordinates(qt_TexCoord0);
|
||||
vec4 txt_color = texture2D(source, coords);
|
||||
vec4 txt_normal = texture2D(normals, coords);
|
||||
vec3 normal = normalize(txt_normal.rgb * 2.0 - 1.0);
|
||||
vec3 light_direction = normalize(vec3(0.5, 0.5, 0.0) - vec3(qt_TexCoord0, 0.0));
|
||||
|
||||
float dotProd = dot(normal, light_direction);" +
|
||||
|
||||
(frameReflections ? "
|
||||
vec3 realLightColor = texture2D(lightSource, coords).rgb;
|
||||
float screenLight = rgb2grey(realLightColor);
|
||||
float clampedDotProd = clamp(dotProd, 0.05, 1.0);
|
||||
float diffuseReflection = clamp(screenLight * 1.5 * clampedDotProd, 0.0, 0.35);
|
||||
float reflectionAlpha = mix(1.0, 0.90, dotProd);
|
||||
vec3 lightColor = mix(font_color.rgb * screenLight, font_color.rgb * realLightColor, chroma_color);"
|
||||
: "
|
||||
float diffuseReflection = 0.0;
|
||||
float reflectionAlpha = 1.0;
|
||||
vec3 lightColor = font_color.rgb;") + "
|
||||
|
||||
|
||||
vec3 back_color = background_color.rgb * (0.2 + 0.5 * dotProd);
|
||||
vec3 front_color = lightColor * (0.05 + diffuseReflection);
|
||||
|
||||
vec4 dark_color = vec4((back_color + front_color) * txt_normal.a, txt_normal.a * reflectionAlpha);
|
||||
gl_FragColor = mix(dark_color, txt_color, ambient_light);
|
||||
}"
|
||||
|
||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
import QtQuick 2.2
|
||||
import QtGraphicalEffects 1.0
|
||||
|
||||
import "../../utils.js" as Utils
|
||||
|
||||
Item{
|
||||
id: framecontainer
|
||||
property int textureWidth: terminalWindow.width
|
||||
property int textureHeight: terminalWindow.height
|
||||
property int textureWidth: terminalContainer.width
|
||||
property int textureHeight: terminalContainer.height
|
||||
|
||||
property int addedWidth
|
||||
property int addedHeight
|
||||
@ -21,7 +24,9 @@ Item{
|
||||
property real displacementRight
|
||||
property real displacementBottom
|
||||
|
||||
property real distortionCoefficient
|
||||
// Material coefficients
|
||||
property real staticDiffuseComponent: 0.7
|
||||
property real dinamycDiffuseComponent: 1.0
|
||||
|
||||
BorderImage{
|
||||
id: frameimage
|
||||
@ -65,10 +70,140 @@ Item{
|
||||
textureSize: Qt.size(parent.width, parent.height)
|
||||
visible: false
|
||||
}
|
||||
|
||||
// REFLECTIONS ////////////////////////////////////////////////////////////
|
||||
Loader{
|
||||
id: reflectionEffectLoader
|
||||
width: parent.width * 0.33
|
||||
height: parent.height * 0.33
|
||||
active: appSettings.frameReflections
|
||||
|
||||
sourceComponent: FastBlur{
|
||||
id: frameReflectionEffect
|
||||
radius: 128
|
||||
source: terminal.kterminal
|
||||
smooth: false
|
||||
}
|
||||
}
|
||||
|
||||
Loader{
|
||||
id: reflectionEffectSourceLoader
|
||||
active: appSettings.frameReflections
|
||||
sourceComponent: ShaderEffectSource{
|
||||
id: frameReflectionSource
|
||||
sourceItem: reflectionEffectLoader.item
|
||||
hideSource: true
|
||||
smooth: true
|
||||
visible: false
|
||||
}
|
||||
}
|
||||
|
||||
// This texture represent the static light component.
|
||||
ShaderEffect {
|
||||
id: staticLight
|
||||
property alias source: framesource
|
||||
property alias normals: framesourcenormals
|
||||
property real screen_distorsion: appSettings.screen_distortion
|
||||
property size curvature_coefficients: Qt.size(width / mainShader.width, height / mainShader.height)
|
||||
property real ambient_light: appSettings.ambient_light
|
||||
property color font_color: appSettings.font_color
|
||||
property color background_color: appSettings.background_color
|
||||
property color reflectionColor: Utils.mix(font_color, background_color, 0.2)
|
||||
property real diffuseComponent: staticDiffuseComponent
|
||||
|
||||
anchors.centerIn: parent
|
||||
width: parent.width + (addedWidth / textureWidth) * parent.width
|
||||
height: parent.height + (addedHeight / textureHeight) * parent.height
|
||||
source: shaderString
|
||||
|
||||
blending: true
|
||||
|
||||
fragmentShader: "
|
||||
uniform highp sampler2D normals;
|
||||
uniform highp sampler2D source;
|
||||
uniform lowp float screen_distorsion;
|
||||
uniform highp vec2 curvature_coefficients;
|
||||
uniform lowp float ambient_light;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp vec4 reflectionColor;
|
||||
uniform lowp float diffuseComponent;
|
||||
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
|
||||
vec2 distortCoordinates(vec2 coords){
|
||||
vec2 cc = (coords - vec2(0.5)) * curvature_coefficients;
|
||||
float dist = dot(cc, cc) * screen_distorsion;
|
||||
return (coords + cc * (1.0 + dist) * dist);
|
||||
}
|
||||
|
||||
float rgb2grey(vec3 v){
|
||||
return dot(v, vec3(0.21, 0.72, 0.04));
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 coords = distortCoordinates(qt_TexCoord0);
|
||||
vec4 txtColor = texture2D(source, coords);
|
||||
vec4 txtNormal = texture2D(normals, coords);
|
||||
|
||||
vec3 normal = normalize(txtNormal.rgb * 2.0 - 1.0);
|
||||
vec2 lightDirection = normalize(vec2(0.5, 0.5) - coords);
|
||||
float dotProd = dot(normal, vec3(lightDirection, 0.0)) * diffuseComponent;
|
||||
|
||||
vec3 darkColor = dotProd * reflectionColor.rgb;
|
||||
gl_FragColor = vec4(mix(darkColor, txtColor.rgb, ambient_light), dotProd);
|
||||
}
|
||||
"
|
||||
|
||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: staticLightSource
|
||||
sourceItem: staticLight
|
||||
hideSource: true
|
||||
anchors.fill: staticLight
|
||||
live: true
|
||||
}
|
||||
|
||||
Loader{
|
||||
id: dynamicLightLoader
|
||||
anchors.fill: staticLight
|
||||
active: appSettings.frameReflections
|
||||
sourceComponent: ShaderEffect {
|
||||
property ShaderEffectSource lightMask: staticLightSource
|
||||
property ShaderEffectSource reflectionSource: reflectionEffectSourceLoader.item
|
||||
property real diffuseComponent: dinamycDiffuseComponent
|
||||
property real chroma_color: appSettings.chroma_color
|
||||
property color font_color: appSettings.font_color
|
||||
|
||||
visible: true
|
||||
blending: true
|
||||
|
||||
fragmentShader: "
|
||||
uniform sampler2D lightMask;
|
||||
uniform sampler2D reflectionSource;
|
||||
uniform lowp float diffuseComponent;
|
||||
uniform lowp float chroma_color;
|
||||
uniform highp vec4 font_color;
|
||||
uniform highp float qt_Opacity;
|
||||
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
|
||||
float rgb2grey(vec3 v){
|
||||
return dot(v, vec3(0.21, 0.72, 0.04));
|
||||
}
|
||||
|
||||
void main() {
|
||||
float alpha = texture2D(lightMask, qt_TexCoord0).a * diffuseComponent;
|
||||
vec3 reflectionColor = texture2D(reflectionSource, qt_TexCoord0).rgb;
|
||||
vec3 color = font_color.rgb * rgb2grey(reflectionColor);" +
|
||||
(chroma_color !== 0 ?
|
||||
"color = mix(color, font_color.rgb * reflectionColor, chroma_color);"
|
||||
: "") +
|
||||
"gl_FragColor = vec4(color, 1.0) * alpha;
|
||||
}
|
||||
"
|
||||
|
||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>frames/BlackRoughFrame.qml</file>
|
||||
<file>frames/NoFrame.qml</file>
|
||||
<file>frames/images/black-frame.png</file>
|
||||
<file>frames/images/screen-frame-normals.png</file>
|
||||
<file>frames/images/black-frame-normals.png</file>
|
||||
@ -9,7 +8,6 @@
|
||||
<file>frames/images/black-frame-original.png</file>
|
||||
<file>frames/images/screen-frame-original.png</file>
|
||||
<file>frames/WhiteSimpleFrame.qml</file>
|
||||
<file>frames/utils/FrameShader.qml</file>
|
||||
<file>frames/utils/TerminalFrame.qml</file>
|
||||
<file>SizeOverlay.qml</file>
|
||||
<file>ShaderTerminal.qml</file>
|
||||
|
Loading…
x
Reference in New Issue
Block a user