Much improved frame reflections. This is a little bit heavier but much better looking. The code should be ok, but maybe the parameters might use some fine tuning.

This commit is contained in:
Filippo Scognamiglio 2014-07-06 23:57:47 +02:00
parent 2fe6d147d9
commit 93e40ade4a
6 changed files with 69 additions and 50 deletions

View File

@ -128,8 +128,9 @@ Item{
// FRAMES ///////////////////////////////////////////////////////////////// // FRAMES /////////////////////////////////////////////////////////////////
property bool frame_reflections: true property bool _frameReflections: true
property real frame_reflection_strength: ((frame_reflections && framelist.get(frames_index).reflections) ? 1.0 : 0.0) * 0.15 property bool reflectionsAllowed: framelist.get(frames_index).reflections
property bool frameReflections: _frameReflections && reflectionsAllowed
property alias profiles_list: profileslist property alias profiles_list: profileslist
property int profiles_index: 0 property int profiles_index: 0
@ -147,7 +148,8 @@ Item{
contrast: contrast, contrast: contrast,
ambient_light: ambient_light, ambient_light: ambient_light,
fontScalingIndexes: fontScalingIndexes, fontScalingIndexes: fontScalingIndexes,
fontIndexes: fontIndexes fontIndexes: fontIndexes,
frameReflections: _frameReflections
} }
return JSON.stringify(settings); return JSON.stringify(settings);
} }
@ -210,6 +212,8 @@ Item{
fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes
fontScalingIndexes = settings.fontScalingIndexes !== undefined ? settings.fontScalingIndexes : fontScalingIndexes fontScalingIndexes = settings.fontScalingIndexes !== undefined ? settings.fontScalingIndexes : fontScalingIndexes
_frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections;
} }
function loadProfileString(profileString){ function loadProfileString(profileString){

View File

@ -99,8 +99,15 @@ Tab{
anchors.right: parent.right anchors.right: parent.right
GridLayout{ GridLayout{
anchors.fill: parent anchors.fill: parent
rows: 2 rows: 3
columns: 3 columns: 3
CheckBox{
Layout.columnSpan: 3
checked: shadersettings._frameReflections
text: qsTr("Frame reflections")
onCheckedChanged: shadersettings._frameReflections = checked
enabled: shadersettings.reflectionsAllowed
}
CheckBox{ CheckBox{
property int fps: checked ? slider.value : 0 property int fps: checked ? slider.value : 0
onFpsChanged: shadersettings.fps = fps onFpsChanged: shadersettings.fps = fps

View File

@ -122,12 +122,6 @@ Tab{
currentIndex: shadersettings.frames_index currentIndex: shadersettings.frames_index
onCurrentIndexChanged: shadersettings.frames_index = currentIndex onCurrentIndexChanged: shadersettings.frames_index = currentIndex
} }
CheckBox{
checked: shadersettings.frame_reflections
text: qsTr("Reflections")
onCheckedChanged: shadersettings.frame_reflections = checked
enabled: framescombobox.model.get(framescombobox.currentIndex).reflections
}
} }
} }
} }

View File

@ -42,7 +42,7 @@ ShaderEffect {
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
property bool frame_reflection_strength: shadersettings.frame_reflection_strength property bool frameReflections: shadersettings.frameReflections
property real disp_top: frame.item.displacementTop * shadersettings.window_scaling property real disp_top: frame.item.displacementTop * shadersettings.window_scaling
property real disp_bottom: frame.item.displacementBottom * shadersettings.window_scaling property real disp_bottom: frame.item.displacementBottom * shadersettings.window_scaling
@ -51,7 +51,7 @@ ShaderEffect {
property real brightness: shadersettings.brightness * 1.5 + 0.5 property real brightness: shadersettings.brightness * 1.5 + 0.5
property real time: timeManager.time !== 0 ? timeManager.time : 1 property real time: timeManager.time
property variant randomFunctionSource: randfuncsource property variant randomFunctionSource: randfuncsource
blending: false blending: false
@ -138,7 +138,7 @@ ShaderEffect {
:" :"
vec2 coords = qt_TexCoord0;") + vec2 coords = qt_TexCoord0;") +
(frame_reflection_strength ? " (frameReflections ? "
vec2 inside = step(0.0, coords) - step(1.0, coords); vec2 inside = step(0.0, coords) - step(1.0, coords);
coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") + coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") +

View File

@ -21,7 +21,7 @@
import QtQuick 2.2 import QtQuick 2.2
Timer{ Timer{
property int time property real time
NumberAnimation on time { NumberAnimation on time {
from: 0 from: 0

View File

@ -1,4 +1,5 @@
import QtQuick 2.2 import QtQuick 2.2
import QtGraphicalEffects 1.0
ShaderEffect{ ShaderEffect{
property variant source: framesource property variant source: framesource
@ -7,49 +8,50 @@ ShaderEffect{
property real ambient_light: shadersettings.ambient_light property real ambient_light: shadersettings.ambient_light
property color font_color: shadersettings.font_color property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color property color background_color: shadersettings.background_color
property real time: timeManager.time
property variant randomFunctionSource: randfuncsource
property real brightness_flickering: shadersettings.brightness_flickering
property real brightness: shadersettings.brightness * 1.5 + 0.5 property real brightness: shadersettings.brightness * 1.5 + 0.5
property real frame_reflection_strength: shadersettings.frame_reflection_strength property bool frameReflections: shadersettings.frameReflections
property variant lightSource: reflectionEffectSourceLoader.item
property color reflection_color: Qt.rgba((font_color.r*0.3 + background_color.r*0.7), Loader{
(font_color.g*0.3 + background_color.g*0.7), id: reflectionEffectLoader
(font_color.b*0.3 + background_color.b*0.7), width: parent.width * 0.33
1.0) 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
}
}
blending: true blending: 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;
varying lowp float brightness;
void main() {
qt_TexCoord0 = qt_MultiTexCoord0;
brightness = "+brightness.toFixed(1)+";" +
(brightness_flickering !== 0 ?
"brightness -= texture2D(randomFunctionSource, vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0*2.0)))).r * "+brightness_flickering.toFixed(1)+";"
: "") + "
gl_Position = qt_Matrix * qt_Vertex;
}"
fragmentShader: " fragmentShader: "
uniform sampler2D source; uniform sampler2D source;
uniform sampler2D normals; uniform sampler2D normals;
uniform highp float screen_distorsion; uniform highp float screen_distorsion;
uniform highp float ambient_light; uniform highp float ambient_light;
uniform highp float qt_Opacity; uniform highp float qt_Opacity;" +
uniform vec4 reflection_color; (frameReflections ?
"uniform sampler2D lightSource;" : "") + "
uniform vec4 font_color;
uniform vec4 background_color;
varying lowp float brightness; varying lowp float brightness;
varying highp vec2 qt_TexCoord0; varying highp vec2 qt_TexCoord0;
@ -65,11 +67,23 @@ ShaderEffect{
vec4 txt_color = texture2D(source, coords); vec4 txt_color = texture2D(source, coords);
vec4 txt_normal = texture2D(normals, coords); vec4 txt_normal = texture2D(normals, coords);
vec3 normal = normalize(txt_normal.rgb * 2.0 - 1.0); 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)); vec3 light_direction = normalize(vec3(0.5, 0.5, 0.0) - vec3(qt_TexCoord0, 0.0));
float diffuse = dot(normal, light_dir);
float reflection = (diffuse * 0.6 + 0.4) * txt_normal.a; float dotProd = dot(normal, light_direction);" +
float reflection_alpha = (1.0 - diffuse*"+frame_reflection_strength.toFixed(1)+");
vec4 dark_color = vec4(reflection_color.rgb * reflection * 0.4, txt_normal.a * reflection_alpha); (frameReflections ? "
float screenLight = texture2D(lightSource, coords).r;
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);"
: "
float diffuseReflection = 0.0;
float reflectionAlpha = 1.0;") + "
vec3 back_color = background_color.rgb * (0.2 + 0.5 * dotProd);
vec3 front_color = font_color.rgb * (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); gl_FragColor = mix(dark_color, txt_color, ambient_light);
}" }"