From 586c3855afb4ac4f704062cc9adb4e2fe5a4f80e Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 29 Jun 2016 17:56:19 +0200 Subject: Make FastGlow multi backend Change-Id: I869fe798d6e4ee0e61b6f99065338b6127d664d7 Reviewed-by: Mitch Curtis Reviewed-by: Andy Nichols --- src/controls/Shaders/+glslcore/blur.frag | 19 ++++++++++++++++ src/controls/Shaders/+glslcore/blur.vert | 21 +++++++++++++++++ src/controls/Shaders/+glslcore/glow.frag | 33 +++++++++++++++++++++++++++ src/controls/Shaders/+hlsl/blur.frag | 19 ++++++++++++++++ src/controls/Shaders/+hlsl/blur.vert | 30 ++++++++++++++++++++++++ src/controls/Shaders/+hlsl/glow.frag | 39 ++++++++++++++++++++++++++++++++ src/controls/Shaders/blur.frag | 15 ++++++++++++ src/controls/Shaders/blur.vert | 19 ++++++++++++++++ src/controls/Shaders/glow.frag | 29 ++++++++++++++++++++++++ src/controls/Shaders/shaders.pri | 10 ++++++++ 10 files changed, 234 insertions(+) create mode 100644 src/controls/Shaders/+glslcore/blur.frag create mode 100644 src/controls/Shaders/+glslcore/blur.vert create mode 100644 src/controls/Shaders/+glslcore/glow.frag create mode 100644 src/controls/Shaders/+hlsl/blur.frag create mode 100644 src/controls/Shaders/+hlsl/blur.vert create mode 100644 src/controls/Shaders/+hlsl/glow.frag create mode 100644 src/controls/Shaders/blur.frag create mode 100644 src/controls/Shaders/blur.vert create mode 100644 src/controls/Shaders/glow.frag create mode 100644 src/controls/Shaders/shaders.pri (limited to 'src/controls/Shaders') diff --git a/src/controls/Shaders/+glslcore/blur.frag b/src/controls/Shaders/+glslcore/blur.frag new file mode 100644 index 00000000..38895e10 --- /dev/null +++ b/src/controls/Shaders/+glslcore/blur.frag @@ -0,0 +1,19 @@ +#version 150 + +uniform sampler2D source; +uniform float qt_Opacity; + +in vec2 qt_TexCoord0; +in vec2 qt_TexCoord1; +in vec2 qt_TexCoord2; +in vec2 qt_TexCoord3; + +out vec4 fragColor; + +void main() { + vec4 sourceColor = (texture(source, qt_TexCoord0) + + texture(source, qt_TexCoord1) + + texture(source, qt_TexCoord2) + + texture(source, qt_TexCoord3)) * 0.25; + fragColor = sourceColor * qt_Opacity; +} diff --git a/src/controls/Shaders/+glslcore/blur.vert b/src/controls/Shaders/+glslcore/blur.vert new file mode 100644 index 00000000..1204c5fa --- /dev/null +++ b/src/controls/Shaders/+glslcore/blur.vert @@ -0,0 +1,21 @@ +#version 150 + +in vec4 qt_Vertex; +in vec2 qt_MultiTexCoord0; + +uniform mat4 qt_Matrix; +uniform float yStep; +uniform float xStep; + +out vec2 qt_TexCoord0; +out vec2 qt_TexCoord1; +out vec2 qt_TexCoord2; +out vec2 qt_TexCoord3; + +void main() { + qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); + qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); + qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); + qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); + gl_Position = qt_Matrix * qt_Vertex; +} diff --git a/src/controls/Shaders/+glslcore/glow.frag b/src/controls/Shaders/+glslcore/glow.frag new file mode 100644 index 00000000..e1b6b07f --- /dev/null +++ b/src/controls/Shaders/+glslcore/glow.frag @@ -0,0 +1,33 @@ +#version 150 + +uniform sampler2D source1; +uniform sampler2D source2; +uniform sampler2D source3; +uniform sampler2D source4; +uniform sampler2D source5; +uniform float weight1; +uniform float weight2; +uniform float weight3; +uniform float weight4; +uniform float weight5; +uniform vec4 color; +uniform float spread; +uniform float qt_Opacity; + +in vec2 qt_TexCoord0; + +out vec4 fragColor; + +float linearstep(float e0, float e1, float x) { + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); +} + +void main() { + vec4 sourceColor = texture(source1, qt_TexCoord0) * weight1; + sourceColor += texture(source2, qt_TexCoord0) * weight2; + sourceColor += texture(source3, qt_TexCoord0) * weight3; + sourceColor += texture(source4, qt_TexCoord0) * weight4; + sourceColor += texture(source5, qt_TexCoord0) * weight5; + sourceColor = mix(vec4(0), color, linearstep(0.0, spread, sourceColor.a)); + fragColor = sourceColor * qt_Opacity; +} diff --git a/src/controls/Shaders/+hlsl/blur.frag b/src/controls/Shaders/+hlsl/blur.frag new file mode 100644 index 00000000..3dbf6556 --- /dev/null +++ b/src/controls/Shaders/+hlsl/blur.frag @@ -0,0 +1,19 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float2 delta; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); + +float4 main(float4 position : SV_POSITION, + float2 coord0 : TEXCOORD0, + float2 coord1 : TEXCOORD1, + float2 coord2 : TEXCOORD2, + float2 coord3 : TEXCOORD3) : SV_TARGET +{ + return (source.Sample(sourceSampler, coord0) + source.Sample(sourceSampler, coord1) + + source.Sample(sourceSampler, coord2) + source.Sample(sourceSampler, coord3)) * 0.25 * qt_Opacity; +} diff --git a/src/controls/Shaders/+hlsl/blur.vert b/src/controls/Shaders/+hlsl/blur.vert new file mode 100644 index 00000000..08ff3cf3 --- /dev/null +++ b/src/controls/Shaders/+hlsl/blur.vert @@ -0,0 +1,30 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float xStep; + float yStep; +}; + +struct PSInput +{ + float4 position : SV_POSITION; + float2 coord0 : TEXCOORD0; + float2 coord1 : TEXCOORD1; + float2 coord2 : TEXCOORD2; + float2 coord3 : TEXCOORD3; +}; + +PSInput main(float4 position : POSITION, float2 coord : TEXCOORD0) +{ + PSInput result; + + result.position = mul(qt_Matrix, position); + + result.coord0 = float2(coord.x + xStep, coord.y + yStep * 0.36); + result.coord1 = float2(coord.x + xStep * 0.36, coord.y - yStep); + result.coord2 = float2(coord.x - xStep * 0.36, coord.y + yStep); + result.coord3 = float2(coord.x - xStep, coord.y - yStep * 0.36); + + return result; +} diff --git a/src/controls/Shaders/+hlsl/glow.frag b/src/controls/Shaders/+hlsl/glow.frag new file mode 100644 index 00000000..887d2087 --- /dev/null +++ b/src/controls/Shaders/+hlsl/glow.frag @@ -0,0 +1,39 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float weight1; + float weight2; + float weight3; + float weight4; + float weight5; + float spread; + float4 color; +}; + +Texture2D source1 : register(t0); +SamplerState sourceSampler1 : register(s0); +Texture2D source2 : register(t1); +SamplerState sourceSampler2 : register(s1); +Texture2D source3 : register(t2); +SamplerState sourceSampler3 : register(s2); +Texture2D source4 : register(t3); +SamplerState sourceSampler4 : register(s3); +Texture2D source5 : register(t4); +SamplerState sourceSampler5 : register(s4); + +float linearstep(float e0, float e1, float x) +{ + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); +} + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + float4 sourceColor = source1.Sample(sourceSampler1, coord) * weight1; + sourceColor += source2.Sample(sourceSampler2, coord) * weight2; + sourceColor += source3.Sample(sourceSampler3, coord) * weight3; + sourceColor += source4.Sample(sourceSampler4, coord) * weight4; + sourceColor += source5.Sample(sourceSampler5, coord) * weight5; + sourceColor = lerp(float4(0.0, 0.0, 0.0, 0.0), color, linearstep(0.0, spread, sourceColor.a)); + return sourceColor * qt_Opacity; +} diff --git a/src/controls/Shaders/blur.frag b/src/controls/Shaders/blur.frag new file mode 100644 index 00000000..54939d84 --- /dev/null +++ b/src/controls/Shaders/blur.frag @@ -0,0 +1,15 @@ +uniform lowp sampler2D source; +uniform lowp float qt_Opacity; + +varying highp vec2 qt_TexCoord0; +varying highp vec2 qt_TexCoord1; +varying highp vec2 qt_TexCoord2; +varying highp vec2 qt_TexCoord3; + +void main() { + highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) + + texture2D(source, qt_TexCoord1) + + texture2D(source, qt_TexCoord2) + + texture2D(source, qt_TexCoord3)) * 0.25; + gl_FragColor = sourceColor * qt_Opacity; +} diff --git a/src/controls/Shaders/blur.vert b/src/controls/Shaders/blur.vert new file mode 100644 index 00000000..d7862dda --- /dev/null +++ b/src/controls/Shaders/blur.vert @@ -0,0 +1,19 @@ +attribute highp vec4 qt_Vertex; +attribute highp vec2 qt_MultiTexCoord0; + +uniform highp mat4 qt_Matrix; +uniform highp float yStep; +uniform highp float xStep; + +varying highp vec2 qt_TexCoord0; +varying highp vec2 qt_TexCoord1; +varying highp vec2 qt_TexCoord2; +varying highp vec2 qt_TexCoord3; + +void main() { + qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36); + qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep); + qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep); + qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36); + gl_Position = qt_Matrix * qt_Vertex; +} diff --git a/src/controls/Shaders/glow.frag b/src/controls/Shaders/glow.frag new file mode 100644 index 00000000..56216cd6 --- /dev/null +++ b/src/controls/Shaders/glow.frag @@ -0,0 +1,29 @@ +uniform lowp sampler2D source1; +uniform lowp sampler2D source2; +uniform lowp sampler2D source3; +uniform lowp sampler2D source4; +uniform lowp sampler2D source5; +uniform mediump float weight1; +uniform mediump float weight2; +uniform mediump float weight3; +uniform mediump float weight4; +uniform mediump float weight5; +uniform highp vec4 color; +uniform highp float spread; +uniform lowp float qt_Opacity; + +varying mediump vec2 qt_TexCoord0; + +highp float linearstep(highp float e0, highp float e1, highp float x) { + return clamp((x - e0) / (e1 - e0), 0.0, 1.0); +} + +void main() { + lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1; + sourceColor += texture2D(source2, qt_TexCoord0) * weight2; + sourceColor += texture2D(source3, qt_TexCoord0) * weight3; + sourceColor += texture2D(source4, qt_TexCoord0) * weight4; + sourceColor += texture2D(source5, qt_TexCoord0) * weight5; + sourceColor = mix(vec4(0), color, linearstep(0.0, spread, sourceColor.a)); + gl_FragColor = sourceColor * qt_Opacity; +} diff --git a/src/controls/Shaders/shaders.pri b/src/controls/Shaders/shaders.pri new file mode 100644 index 00000000..197fd11e --- /dev/null +++ b/src/controls/Shaders/shaders.pri @@ -0,0 +1,10 @@ +SHADER_FILES = \ + $$PWD/blur.vert \ + $$PWD/blur.frag \ + $$PWD/glow.frag \ + $$PWD/+glslcore/blur.vert \ + $$PWD/+glslcore/blur.frag \ + $$PWD/+glslcore/glow.frag \ + $$PWD/+hlsl/blur.vert \ + $$PWD/+hlsl/blur.frag \ + $$PWD/+hlsl/glow.frag -- cgit v1.2.1