mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-02-21 20:39:00 +00:00
Refactor: extract noise and rasterization from terminal object.
This commit is contained in:
parent
6b9a2ed5d2
commit
9f943aa2d0
@ -27,6 +27,8 @@ import QMLTermWidget 1.0
|
|||||||
Item{
|
Item{
|
||||||
id: terminalContainer
|
id: terminalContainer
|
||||||
|
|
||||||
|
property size virtualResolution: Qt.size(kterminal.width, kterminal.height);
|
||||||
|
|
||||||
//Frame displacement properties. This makes the terminal the same size of the texture.
|
//Frame displacement properties. This makes the terminal the same size of the texture.
|
||||||
property real dtop: frame.item.displacementTop * shadersettings.window_scaling
|
property real dtop: frame.item.displacementTop * shadersettings.window_scaling
|
||||||
property real dleft:frame.item.displacementLeft * shadersettings.window_scaling
|
property real dleft:frame.item.displacementLeft * shadersettings.window_scaling
|
||||||
@ -42,7 +44,6 @@ Item{
|
|||||||
|
|
||||||
property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource
|
property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource
|
||||||
property variant bloomSource: bloomSourceLoader.item
|
property variant bloomSource: bloomSourceLoader.item
|
||||||
property variant rasterizationSource: rasterizationEffectSource
|
|
||||||
property variant staticNoiseSource: staticNoiseSource
|
property variant staticNoiseSource: staticNoiseSource
|
||||||
|
|
||||||
property alias kterminal: kterminal
|
property alias kterminal: kterminal
|
||||||
@ -338,115 +339,4 @@ Item{
|
|||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOISE ////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
ShaderEffect {
|
|
||||||
id: staticNoiseEffect
|
|
||||||
anchors.fill: parent
|
|
||||||
property real element_size: shadersettings.rasterization == shadersettings.no_rasterization ? 2 : 1
|
|
||||||
property size virtual_resolution: Qt.size(kterminal.width / element_size, kterminal.height / element_size)
|
|
||||||
|
|
||||||
blending: false
|
|
||||||
|
|
||||||
fragmentShader:
|
|
||||||
"uniform lowp float qt_Opacity;
|
|
||||||
varying highp vec2 qt_TexCoord0;
|
|
||||||
uniform highp vec2 virtual_resolution;" +
|
|
||||||
|
|
||||||
"highp float noise(vec2 co)
|
|
||||||
{
|
|
||||||
highp float a = 12.9898;
|
|
||||||
highp float b = 78.233;
|
|
||||||
highp float c = 43758.5453;
|
|
||||||
highp float dt= dot(co.xy ,vec2(a,b));
|
|
||||||
highp float sn= mod(dt,3.14);
|
|
||||||
return fract(sin(sn) * c);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 sw(vec2 p) {return vec2( floor(p.x) , floor(p.y) );}
|
|
||||||
vec2 se(vec2 p) {return vec2( ceil(p.x) , floor(p.y) );}
|
|
||||||
vec2 nw(vec2 p) {return vec2( floor(p.x) , ceil(p.y) );}
|
|
||||||
vec2 ne(vec2 p) {return vec2( ceil(p.x) , ceil(p.y) );}
|
|
||||||
|
|
||||||
float smoothNoise(vec2 p) {
|
|
||||||
vec2 inter = smoothstep(0., 1., fract(p));
|
|
||||||
float s = mix(noise(sw(p)), noise(se(p)), inter.x);
|
|
||||||
float n = mix(noise(nw(p)), noise(ne(p)), inter.x);
|
|
||||||
return mix(s, n, inter.y);
|
|
||||||
}" +
|
|
||||||
|
|
||||||
"void main() {" +
|
|
||||||
"gl_FragColor.a = smoothNoise(qt_TexCoord0 * virtual_resolution);" +
|
|
||||||
"}"
|
|
||||||
|
|
||||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
|
||||||
}
|
|
||||||
ShaderEffectSource{
|
|
||||||
id: staticNoiseSource
|
|
||||||
sourceItem: staticNoiseEffect
|
|
||||||
textureSize: Qt.size(parent.width, parent.height)
|
|
||||||
wrapMode: ShaderEffectSource.Repeat
|
|
||||||
smooth: true
|
|
||||||
hideSource: true
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
|
|
||||||
// RASTERIZATION //////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
ShaderEffect {
|
|
||||||
id: rasterizationEffect
|
|
||||||
width: parent.width
|
|
||||||
height: parent.height
|
|
||||||
property real outColor: 0.0
|
|
||||||
property real dispX: 5 / width
|
|
||||||
property real dispY: 5 / height
|
|
||||||
property size virtual_resolution: Qt.size(kterminal.width, kterminal.height)
|
|
||||||
|
|
||||||
blending: false
|
|
||||||
|
|
||||||
fragmentShader:
|
|
||||||
"uniform lowp float qt_Opacity;" +
|
|
||||||
|
|
||||||
"varying highp vec2 qt_TexCoord0;
|
|
||||||
uniform highp vec2 virtual_resolution;
|
|
||||||
uniform highp float dispX;
|
|
||||||
uniform highp float dispY;
|
|
||||||
uniform mediump float outColor;
|
|
||||||
|
|
||||||
highp float getScanlineIntensity(vec2 coords) {
|
|
||||||
highp float result = 1.0;" +
|
|
||||||
|
|
||||||
(mScanlines != shadersettings.no_rasterization ?
|
|
||||||
"result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
|
|
||||||
(mScanlines == shadersettings.pixel_rasterization ?
|
|
||||||
"result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}" +
|
|
||||||
|
|
||||||
"void main() {" +
|
|
||||||
"highp float color = getScanlineIntensity(qt_TexCoord0);" +
|
|
||||||
|
|
||||||
"float distance = length(vec2(0.5) - qt_TexCoord0);" +
|
|
||||||
"color = mix(color, 0.0, 1.2 * distance * distance);" +
|
|
||||||
|
|
||||||
"color *= outColor + smoothstep(0.00, dispX, qt_TexCoord0.x) * (1.0 - outColor);" +
|
|
||||||
"color *= outColor + smoothstep(0.00, dispY, qt_TexCoord0.y) * (1.0 - outColor);" +
|
|
||||||
"color *= outColor + (1.0 - smoothstep(1.00 - dispX, 1.00, qt_TexCoord0.x)) * (1.0 - outColor);" +
|
|
||||||
"color *= outColor + (1.0 - smoothstep(1.00 - dispY, 1.00, qt_TexCoord0.y)) * (1.0 - outColor);" +
|
|
||||||
|
|
||||||
"gl_FragColor.a = color;" +
|
|
||||||
"}"
|
|
||||||
|
|
||||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
|
||||||
}
|
|
||||||
ShaderEffectSource{
|
|
||||||
id: rasterizationEffectSource
|
|
||||||
sourceItem: rasterizationEffect
|
|
||||||
hideSource: true
|
|
||||||
smooth: true
|
|
||||||
wrapMode: ShaderEffectSource.ClampToEdge
|
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ import QtGraphicalEffects 1.0
|
|||||||
|
|
||||||
|
|
||||||
ShaderEffect {
|
ShaderEffect {
|
||||||
|
property ShaderEffectSource rasterizationSource
|
||||||
|
property ShaderEffectSource noiseSource
|
||||||
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 variant source: terminal.theSource
|
property variant source: terminal.theSource
|
||||||
property variant bloomSource: terminal.bloomSource
|
property variant bloomSource: terminal.bloomSource
|
||||||
property variant rasterizationSource: terminal.rasterizationSource
|
|
||||||
property variant noiseSource: terminal.staticNoiseSource
|
|
||||||
property real bloom_strength: shadersettings.bloom_strength * 2.5
|
property real bloom_strength: shadersettings.bloom_strength * 2.5
|
||||||
|
|
||||||
property real jitter: shadersettings.jitter * 0.007
|
property real jitter: shadersettings.jitter * 0.007
|
||||||
|
@ -4,7 +4,7 @@ ShaderTerminal{
|
|||||||
property alias title: terminal.title
|
property alias title: terminal.title
|
||||||
property alias terminalSize: terminal.terminalSize
|
property alias terminalSize: terminal.terminalSize
|
||||||
|
|
||||||
id: shadercontainer
|
id: mainShader
|
||||||
opacity: shadersettings.windowOpacity * 0.3 + 0.7
|
opacity: shadersettings.windowOpacity * 0.3 + 0.7
|
||||||
|
|
||||||
Loader{
|
Loader{
|
||||||
@ -13,8 +13,121 @@ ShaderTerminal{
|
|||||||
z: 2.1
|
z: 2.1
|
||||||
source: shadersettings.frame_source
|
source: shadersettings.frame_source
|
||||||
}
|
}
|
||||||
|
|
||||||
PreprocessedTerminal{
|
PreprocessedTerminal{
|
||||||
id: terminal
|
id: terminal
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOISE ////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ShaderEffect {
|
||||||
|
id: staticNoiseEffect
|
||||||
|
anchors.fill: parent
|
||||||
|
property real element_size: shadersettings.rasterization == shadersettings.no_rasterization ? 2 : 1
|
||||||
|
property alias __terminalHeight: terminal.virtualResolution.height
|
||||||
|
property alias __terminalWidth: terminal.virtualResolution.width
|
||||||
|
property size virtual_resolution: Qt.size(__terminalWidth / element_size, __terminalHeight / element_size)
|
||||||
|
|
||||||
|
blending: false
|
||||||
|
|
||||||
|
fragmentShader:
|
||||||
|
"uniform lowp float qt_Opacity;
|
||||||
|
varying highp vec2 qt_TexCoord0;
|
||||||
|
uniform highp vec2 virtual_resolution;" +
|
||||||
|
|
||||||
|
"highp float noise(vec2 co)
|
||||||
|
{
|
||||||
|
highp float a = 12.9898;
|
||||||
|
highp float b = 78.233;
|
||||||
|
highp float c = 43758.5453;
|
||||||
|
highp float dt= dot(co.xy ,vec2(a,b));
|
||||||
|
highp float sn= mod(dt,3.14);
|
||||||
|
return fract(sin(sn) * c);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 sw(vec2 p) {return vec2( floor(p.x) , floor(p.y) );}
|
||||||
|
vec2 se(vec2 p) {return vec2( ceil(p.x) , floor(p.y) );}
|
||||||
|
vec2 nw(vec2 p) {return vec2( floor(p.x) , ceil(p.y) );}
|
||||||
|
vec2 ne(vec2 p) {return vec2( ceil(p.x) , ceil(p.y) );}
|
||||||
|
|
||||||
|
float smoothNoise(vec2 p) {
|
||||||
|
vec2 inter = smoothstep(0., 1., fract(p));
|
||||||
|
float s = mix(noise(sw(p)), noise(se(p)), inter.x);
|
||||||
|
float n = mix(noise(nw(p)), noise(ne(p)), inter.x);
|
||||||
|
return mix(s, n, inter.y);
|
||||||
|
}" +
|
||||||
|
|
||||||
|
"void main() {" +
|
||||||
|
"gl_FragColor.a = smoothNoise(qt_TexCoord0 * virtual_resolution);" +
|
||||||
|
"}"
|
||||||
|
|
||||||
|
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||||
|
}
|
||||||
|
noiseSource: ShaderEffectSource{
|
||||||
|
id: staticNoiseSource
|
||||||
|
sourceItem: staticNoiseEffect
|
||||||
|
textureSize: Qt.size(mainShader.width, mainShader.height)
|
||||||
|
wrapMode: ShaderEffectSource.Repeat
|
||||||
|
smooth: true
|
||||||
|
hideSource: true
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderEffect {
|
||||||
|
id: rasterizationEffect
|
||||||
|
width: parent.width
|
||||||
|
height: parent.height
|
||||||
|
property real outColor: 0.0
|
||||||
|
property real dispX: (5 / width) * shadersettings.window_scaling
|
||||||
|
property real dispY: 5 / height * shadersettings.window_scaling
|
||||||
|
property size virtual_resolution: terminal.virtualResolution
|
||||||
|
|
||||||
|
blending: false
|
||||||
|
|
||||||
|
fragmentShader:
|
||||||
|
"uniform lowp float qt_Opacity;" +
|
||||||
|
|
||||||
|
"varying highp vec2 qt_TexCoord0;
|
||||||
|
uniform highp vec2 virtual_resolution;
|
||||||
|
uniform highp float dispX;
|
||||||
|
uniform highp float dispY;
|
||||||
|
uniform mediump float outColor;
|
||||||
|
|
||||||
|
highp float getScanlineIntensity(vec2 coords) {
|
||||||
|
highp float result = 1.0;" +
|
||||||
|
|
||||||
|
(shadersettings.rasterization != shadersettings.no_rasterization ?
|
||||||
|
"result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
|
||||||
|
(shadersettings.rasterization == shadersettings.pixel_rasterization ?
|
||||||
|
"result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}" +
|
||||||
|
|
||||||
|
"void main() {" +
|
||||||
|
"highp float color = getScanlineIntensity(qt_TexCoord0);" +
|
||||||
|
|
||||||
|
"float distance = length(vec2(0.5) - qt_TexCoord0);" +
|
||||||
|
"color = mix(color, 0.0, 1.2 * distance * distance);" +
|
||||||
|
|
||||||
|
"color *= outColor + smoothstep(0.00, dispX, qt_TexCoord0.x) * (1.0 - outColor);" +
|
||||||
|
"color *= outColor + smoothstep(0.00, dispY, qt_TexCoord0.y) * (1.0 - outColor);" +
|
||||||
|
"color *= outColor + (1.0 - smoothstep(1.00 - dispX, 1.00, qt_TexCoord0.x)) * (1.0 - outColor);" +
|
||||||
|
"color *= outColor + (1.0 - smoothstep(1.00 - dispY, 1.00, qt_TexCoord0.y)) * (1.0 - outColor);" +
|
||||||
|
|
||||||
|
"gl_FragColor.a = color;" +
|
||||||
|
"}"
|
||||||
|
|
||||||
|
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||||
|
}
|
||||||
|
|
||||||
|
rasterizationSource: ShaderEffectSource{
|
||||||
|
id: rasterizationEffectSource
|
||||||
|
sourceItem: rasterizationEffect
|
||||||
|
hideSource: true
|
||||||
|
smooth: true
|
||||||
|
wrapMode: ShaderEffectSource.ClampToEdge
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user