1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-25 22:38:52 +00:00

Coefficients are now all passed as uniforms. This saves many shaders compilations when playing with settings.

This commit is contained in:
Filippo Scognamiglio 2014-08-08 22:57:51 +02:00
parent 589ebdc73f
commit 1c97a08b8d
3 changed files with 33 additions and 22 deletions

View File

@ -227,6 +227,7 @@ Item{
anchors.fill: parent anchors.fill: parent
property variant source: source property variant source: source
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation
property size virtual_resolution: parent.virtual_resolution property size virtual_resolution: parent.virtual_resolution
property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0), property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0),
mScanlines != shadersettings.no_rasterization ? deltay : 0) mScanlines != shadersettings.no_rasterization ? deltay : 0)
@ -242,7 +243,8 @@ Item{
uniform highp vec2 virtual_resolution;" + uniform highp vec2 virtual_resolution;" +
(mBlur !== 0 ? (mBlur !== 0 ?
"uniform lowp sampler2D blurredSource;" "uniform lowp sampler2D blurredSource;
uniform lowp float blurCoefficient;"
: "") + : "") +
"float rgb2grey(vec3 v){ "float rgb2grey(vec3 v){
@ -263,7 +265,7 @@ Item{
(mBlur !== 0 ? (mBlur !== 0 ?
"vec4 blur_color = texture2D(blurredSource, coords) * 256.0;" + "vec4 blur_color = texture2D(blurredSource, coords) * 256.0;" +
"blur_color.a = blur_color.a - blur_color.a * " + (1.0 - motionBlurCoefficient) * fpsAttenuation+ ";" + "blur_color.a = blur_color.a - blur_color.a * blurCoefficient;" +
"color = step(1.0, color.a) * color + step(color.a, 1.0) * blur_color;" "color = step(1.0, color.a) * color + step(color.a, 1.0) * blur_color;"
: "") + : "") +

View File

@ -29,7 +29,7 @@ ShaderEffect {
property variant rasterizationSource: terminal.rasterizationSource property variant rasterizationSource: terminal.rasterizationSource
property variant noiseSource: terminal.staticNoiseSource property variant noiseSource: terminal.staticNoiseSource
property size txt_Size: Qt.size(frame.sourceRect.width, frame.sourceRect.height) property size txt_Size: Qt.size(frame.sourceRect.width, frame.sourceRect.height)
property real bloom: shadersettings.bloom_strength * 2.5 property real bloom_strength: shadersettings.bloom_strength * 2.5
property int rasterization: shadersettings.rasterization property int rasterization: shadersettings.rasterization
@ -52,7 +52,7 @@ ShaderEffect {
property real disp_left: frame.item.displacementLeft * shadersettings.window_scaling property real disp_left: frame.item.displacementLeft * shadersettings.window_scaling
property real disp_right: frame.item.displacementRight * shadersettings.window_scaling property real disp_right: frame.item.displacementRight * shadersettings.window_scaling
property real brightness: shadersettings.brightness * 1.5 + 0.5 property real screen_brightness: shadersettings.brightness * 1.5 + 0.5
property real time: timeManager.time property real time: timeManager.time
property variant randomFunctionSource: randfuncsource property variant randomFunctionSource: randfuncsource
@ -94,22 +94,24 @@ ShaderEffect {
varying highp vec2 qt_TexCoord0;" + varying highp vec2 qt_TexCoord0;" +
(brightness_flickering !== 0.0 ?" (brightness_flickering !== 0.0 ?"
varying lowp float brightness;" : "") + varying lowp float brightness;
uniform lowp float brightness_flickering;" : "") +
(horizontal_sincronization !== 0.0 ?" (horizontal_sincronization !== 0.0 ?"
varying lowp float horizontal_distortion;" : "") + varying lowp float horizontal_distortion;
uniform lowp float horizontal_sincronization;" : "") +
" "
void main() { void main() {
qt_TexCoord0.x = -"+str(disp_left)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+str(disp_left+disp_right)+")) / txt_Size.x);" + " qt_TexCoord0.x = -"+str(disp_left)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+str(disp_left+disp_right)+")) / txt_Size.x);" + "
qt_TexCoord0.y = -"+str(disp_top)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+str(disp_top+disp_bottom)+")) / txt_Size.y);" + " qt_TexCoord0.y = -"+str(disp_top)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+str(disp_top+disp_bottom)+")) / txt_Size.y);" + "
vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" +
(brightness_flickering !== 0.0 ? " (brightness_flickering !== 0.0 ? "
brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * "+str(brightness_flickering)+";" brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;"
: "") + : "") +
(horizontal_sincronization !== 0.0 ? " (horizontal_sincronization !== 0.0 ? "
float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g; float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g;
float negsinc = 1.0 - "+str(0.6*horizontal_sincronization)+"; float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + "
horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * "+str(0.3*horizontal_sincronization)+";" horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;"
: "") + : "") +
"gl_Position = qt_Matrix * qt_Vertex; "gl_Position = qt_Matrix * qt_Vertex;
@ -124,10 +126,12 @@ ShaderEffect {
uniform highp vec4 font_color; uniform highp vec4 font_color;
uniform highp vec4 background_color; uniform highp vec4 background_color;
uniform highp sampler2D rasterizationSource;" + uniform highp sampler2D rasterizationSource;
uniform lowp float screen_brightness;" +
(bloom !== 0 ? " (bloom_strength !== 0 ? "
uniform highp sampler2D bloomSource;" : "") + uniform highp sampler2D bloomSource;
uniform lowp float bloom_strength;" : "") +
(noise_strength !== 0 ? " (noise_strength !== 0 ? "
uniform highp float noise_strength;" : "") + uniform highp float noise_strength;" : "") +
(noise_strength !== 0 || jitter !== 0 ? " (noise_strength !== 0 || jitter !== 0 ? "
@ -136,6 +140,10 @@ ShaderEffect {
uniform highp float screen_distorsion;" : "") + uniform highp float screen_distorsion;" : "") +
(glowing_line_strength !== 0 ? " (glowing_line_strength !== 0 ? "
uniform highp float glowing_line_strength;" : "") + uniform highp float glowing_line_strength;" : "") +
(chroma_color !== 0 ? "
uniform lowp float chroma_color;" : "") +
(jitter !== 0 ? "
uniform lowp float jitter;" : "") +
(brightness_flickering !== 0 ? " (brightness_flickering !== 0 ? "
varying lowp float brightness;" : "") + varying lowp float brightness;" : "") +
(horizontal_sincronization !== 0 ? " (horizontal_sincronization !== 0 ? "
@ -178,7 +186,7 @@ ShaderEffect {
(jitter !== 0 ? " (jitter !== 0 ? "
vec2 offset = vec2(texture2D(noiseSource, coords + fract(time / 57.0)).a, vec2 offset = vec2(texture2D(noiseSource, coords + fract(time / 57.0)).a,
texture2D(noiseSource, coords + fract(time / 251.0)).a) - 0.5; texture2D(noiseSource, coords + fract(time / 251.0)).a) - 0.5;
vec2 txt_coords = coords + offset * "+str(jitter)+";" vec2 txt_coords = coords + offset * jitter;"
: "vec2 txt_coords = coords;") + : "vec2 txt_coords = coords;") +
"float color = 0.0;" + "float color = 0.0;" +
@ -192,7 +200,7 @@ ShaderEffect {
(chroma_color !== 0 ? (chroma_color !== 0 ?
"vec4 realBackColor = texture2D(source, txt_coords);" + "vec4 realBackColor = texture2D(source, txt_coords);" +
"vec4 mixedColor = mix(font_color, realBackColor * font_color, "+ str(chroma_color) +");" + "vec4 mixedColor = mix(font_color, realBackColor * font_color, chroma_color);" +
"vec4 finalBackColor = mix(background_color, mixedColor, realBackColor.a);" + "vec4 finalBackColor = mix(background_color, mixedColor, realBackColor.a);" +
"vec3 finalColor = mix(finalBackColor, font_color, color).rgb;" "vec3 finalColor = mix(finalBackColor, font_color, color).rgb;"
@ -203,19 +211,19 @@ ShaderEffect {
"finalColor *= texture2D(rasterizationSource, coords).a;" + "finalColor *= texture2D(rasterizationSource, coords).a;" +
(bloom !== 0 ? (bloom_strength !== 0 ?
"vec3 bloomColor = texture2D(bloomSource, coords).rgb;" + "vec3 bloomColor = texture2D(bloomSource, coords).rgb;" +
(chroma_color !== 0 ? (chroma_color !== 0 ?
"bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, "+str(chroma_color)+");" "bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, chroma_color);"
: :
"bloomColor = font_color.rgb * rgb2grey(bloomColor);") + "bloomColor = font_color.rgb * rgb2grey(bloomColor);") +
"finalColor += bloomColor * "+str(bloom)+";" "finalColor += bloomColor * bloom_strength;"
: "") + : "") +
(brightness_flickering !== 0 ? " (brightness_flickering !== 0 ? "
finalColor *= brightness;" : "") + finalColor *= brightness;" : "") +
"gl_FragColor = vec4(finalColor *"+str(brightness)+", qt_Opacity);" + "gl_FragColor = vec4(finalColor * screen_brightness, qt_Opacity);" +
"}" "}"
onStatusChanged: if (log) console.log(log) //Print warning messages onStatusChanged: if (log) console.log(log) //Print warning messages

View File

@ -47,7 +47,8 @@ ShaderEffect{
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 lowp float chroma_color;" +
(frameReflections ? (frameReflections ?
"uniform sampler2D lightSource;" : "") + " "uniform sampler2D lightSource;" : "") + "
@ -83,7 +84,7 @@ ShaderEffect{
float clampedDotProd = clamp(dotProd, 0.05, 1.0); float clampedDotProd = clamp(dotProd, 0.05, 1.0);
float diffuseReflection = clamp(screenLight * 1.5 * clampedDotProd, 0.0, 0.35); float diffuseReflection = clamp(screenLight * 1.5 * clampedDotProd, 0.0, 0.35);
float reflectionAlpha = mix(1.0, 0.90, dotProd); float reflectionAlpha = mix(1.0, 0.90, dotProd);
vec3 lightColor = mix(font_color.rgb * screenLight, font_color.rgb * realLightColor, "+chroma_color.toFixed(2)+");" vec3 lightColor = mix(font_color.rgb * screenLight, font_color.rgb * realLightColor, chroma_color);"
: " : "
float diffuseReflection = 0.0; float diffuseReflection = 0.0;
float reflectionAlpha = 1.0; float reflectionAlpha = 1.0;