1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-21 04:19:00 +00:00

Normals on the frame are now woriking correctly. The screen light coherently the frame.

This commit is contained in:
Filippo Scognamiglio 2014-03-24 11:09:34 +01:00
parent d0e4086d86
commit 87880e08fd
8 changed files with 56 additions and 75 deletions

View File

@ -16,5 +16,5 @@ TerminalFrame{
normalsSource: "../images/black-frame-normals.png"
sourceRect: Qt.rect(-80, -90, terminal.width + 160, terminal.height + 180)
shaderString: "WhiteFrameShader.qml"
shaderString: "FrameShader.qml"
}

View File

@ -5,8 +5,8 @@ TerminalFrame{
id: frame
z: 2.1
anchors.fill: parent
addedWidth: 190
addedHeight: 190
addedWidth: 140
addedHeight: 140
borderLeft: 116
borderRight: 116
borderTop: 116

View File

@ -12,8 +12,8 @@ TerminalFrame{
borderTop: 116
borderBottom: 116
imageSource: "../images/screen-frame.png"
//normalsSource: "../images/screen-frame-normals.png"
normalsSource: "../images/screen-frame-normals.png"
sourceRect: Qt.rect(-65, -75, terminal.width + 130, terminal.height + 150)
shaderString: "WhiteFrameShader.qml"
shaderString: "FrameShader.qml"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 KiB

After

Width:  |  Height:  |  Size: 507 KiB

View File

@ -0,0 +1,46 @@
import QtQuick 2.1
ShaderEffect{
property variant source: framesource
property variant normals: framesourcenormals
property real screen_distorsion: shadersettings.screen_distortion
property real ambient_light: shadersettings.ambient_light
property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color
property real brightness: shadercontainer.brightness
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),
1.0)
fragmentShader: "
uniform sampler2D source;
uniform sampler2D normals;
uniform highp float screen_distorsion;
uniform highp float ambient_light;
uniform vec4 reflection_color;
uniform highp 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);
}
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_dir = normalize(vec3(0.5,0.5, 0.0) - vec3(qt_TexCoord0, 0.0));
float reflection = dot(normal, light_dir) * 0.4 * brightness + 0.2;
vec3 final_color = reflection_color * reflection * 0.5;
final_color += txt_color * ambient_light;
gl_FragColor = vec4(final_color * txt_normal.a, txt_color.a);
}"
}

View File

@ -46,11 +46,11 @@ Item{
sourceItem: frameimage
hideSource: true
}
// ShaderEffectSource{
// id: framesourcenormals
// sourceItem: framenormals
// hideSource: true
// }
ShaderEffectSource{
id: framesourcenormals
sourceItem: framenormals
hideSource: true
}
Loader{
anchors.fill: frameimage
source: shaderString

View File

@ -1,65 +0,0 @@
import QtQuick 2.1
ShaderEffect{
property variant source: framesource
//property variant normals: framesourcenormals
property real screen_distorsion: shadersettings.screen_distortion
property real ambient_light: shadersettings.ambient_light
property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color
property real brightness: shadercontainer.brightness
// fragmentShader: "
// uniform sampler2D source;
// uniform sampler2D normals;
// uniform highp float screen_distorsion;
// uniform highp float ambient_light;
// uniform highp vec4 font_color;
// uniform highp vec4 background_color;
// uniform highp 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);
// }
// void main(){
// vec2 coords = distortCoordinates(qt_TexCoord0);
// vec4 txt_color = texture2D(source, coords);
// vec4 normala = texture2D(normals, coords);
// vec3 normal = normalize(normala.rgb) * txt_color.a;
// float reflection = dot(normal, vec3(1.0, 1.0, 0.0)) * 0.4 * brightness;
// vec3 reflection_color = mix(font_color, background_color, 0.7).rgb * reflection;
// vec3 final_color = mix(txt_color.rgb, reflection_color, 1.0 - ambient_light);
// gl_FragColor = vec4(final_color, txt_color.a);
// }"
fragmentShader: "
uniform sampler2D source;
uniform highp float screen_distorsion;
uniform highp float ambient_light;
uniform highp vec4 font_color;
uniform highp vec4 background_color;
uniform highp 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);
}
void main(){
vec2 coords = distortCoordinates(qt_TexCoord0);
vec4 txt_color = texture2D(source, coords);
vec3 reflection_color = mix(font_color, background_color, 0.7).rgb * 0.2 * brightness;
vec3 final_color = mix(txt_color.rgb, reflection_color, 1.0 - ambient_light);
gl_FragColor = vec4(final_color, txt_color.a);
}"
}