Skip to content

Commit 1c1b73e

Browse files
committed
[General] fix
1 parent 48726cc commit 1c1b73e

15 files changed

Lines changed: 436 additions & 400 deletions

File tree

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,5 @@
11
#version 330 core
22
#extension GL_ARB_separate_shader_objects : enable
33

4-
layout(location = 0) in vec2 outTexCoord;
5-
layout(location = 0) out vec4 outColor;
6-
7-
uniform BlurArgs
8-
{
9-
float radius;
10-
int blurType;
11-
float direction;
12-
}
13-
ubo;
14-
uniform sampler2D inTexture;
15-
16-
#define MAX_KERNEL_RADIUS 16384
17-
#define EPS 0.0001
18-
float gaussianWeight(float x, float sigma)
19-
{
20-
return exp(-(x * x) / (2.0 * sigma * sigma));
21-
}
22-
23-
void main()
24-
{
25-
precision highp float;
26-
27-
vec2 texSize = textureSize(inTexture, 0);
28-
vec2 texelSize = 1.0 / texSize;
29-
30-
float sigma = ubo.radius / 3.0;
31-
int radius = int(ubo.radius);
32-
33-
vec4 result = vec4(0.0);
34-
float weightSum = 0.0;
35-
36-
for (int x = -radius; x <= radius; x++)
37-
{
38-
float weight;
39-
switch (ubo.blurType)
40-
{
41-
default:
42-
case 0:
43-
weight = exp(-(x * x) / (2.0 * sigma * sigma));
44-
break;
45-
case 1:
46-
weight = 1.0;
47-
break;
48-
case 2:
49-
weight = 1.0 - (float(abs(x)) / float(radius));
50-
break;
51-
case 3:
52-
weight = 1.0 - smoothstep(0.0, 1.0, abs(x) / radius);
53-
break;
54-
case 4:
55-
weight = 1.0 / (1.0 + (x * x / sigma / sigma));
56-
break;
57-
}
58-
59-
float dir = clamp(ubo.direction, 0.0, 1.0);
60-
vec2 off = outTexCoord + vec2(dir * x, (1 - dir) * x) * texelSize;
61-
// gino: we had to do this otherwise wrong pixels will be fetched
62-
off = clamp(off, vec2(0.0 + texelSize), vec2(1.0 - texelSize));
63-
vec4 sampleColor = texture(inTexture, off);
64-
65-
result += sampleColor * weight;
66-
weightSum += weight;
67-
}
68-
69-
outColor = result / weightSum;
70-
}
4+
#define FRAGMENT_SHADER
5+
#include "core/effects/blur.glsl"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifdef VERTEX_SHADER
2+
#include "basics/vertexgen.glsl"
3+
4+
layout(location = 0) out vec2 outTexCoord;
5+
6+
void main()
7+
{
8+
gl_Position = vec4(vertexgen_quad_ndc(), 0.0, 1.0);
9+
outTexCoord = vertexgen_quad_normal();
10+
}
11+
#endif
12+
13+
#ifdef FRAGMENT_SHADER
14+
layout(location = 0) in vec2 outTexCoord;
15+
layout(location = 0) out vec4 outColor;
16+
17+
uniform BlurArgs
18+
{
19+
float radius;
20+
int blurType;
21+
float direction;
22+
}
23+
ubo;
24+
uniform sampler2D inTexture;
25+
26+
#define MAX_KERNEL_RADIUS 16384
27+
#define EPS 0.0001
28+
float gaussianWeight(float x, float sigma)
29+
{
30+
return exp(-(x * x) / (2.0 * sigma * sigma));
31+
}
32+
33+
void main()
34+
{
35+
precision highp float;
36+
37+
vec2 texSize = textureSize(inTexture, 0);
38+
vec2 texelSize = 1.0 / texSize;
39+
40+
float sigma = ubo.radius / 3.0;
41+
int radius = int(ubo.radius);
42+
43+
vec4 result = vec4(0.0);
44+
float weightSum = 0.0;
45+
46+
for (int x = -radius; x <= radius; x++)
47+
{
48+
float weight;
49+
switch (ubo.blurType)
50+
{
51+
default:
52+
case 0:
53+
weight = exp(-(x * x) / (2.0 * sigma * sigma));
54+
break;
55+
case 1:
56+
weight = 1.0;
57+
break;
58+
case 2:
59+
weight = 1.0 - (float(abs(x)) / float(radius));
60+
break;
61+
case 3:
62+
weight = 1.0 - smoothstep(0.0, 1.0, abs(x) / radius);
63+
break;
64+
case 4:
65+
weight = 1.0 / (1.0 + (x * x / sigma / sigma));
66+
break;
67+
}
68+
69+
float dir = clamp(ubo.direction, 0.0, 1.0);
70+
vec2 off = outTexCoord + vec2(dir * x, (1 - dir) * x) * texelSize;
71+
// gino: we had to do this otherwise wrong pixels will be fetched
72+
off = clamp(off, vec2(0.0 + texelSize), vec2(1.0 - texelSize));
73+
vec4 sampleColor = texture(inTexture, off);
74+
75+
result += sampleColor * weight;
76+
weightSum += weight;
77+
}
78+
79+
outColor = result / weightSum;
80+
}
81+
#endif
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
#version 330 core
22
#extension GL_ARB_separate_shader_objects : enable
33

4-
#include "basics/vertexgen.glsl"
5-
6-
layout(location = 0) out vec2 outTexCoord;
7-
8-
void main()
9-
{
10-
gl_Position = vec4(vertexgen_quad_ndc(), 0.0, 1.0);
11-
outTexCoord = vertexgen_quad_normal();
12-
}
4+
#define VERTEX_SHADER
5+
#include "core/effects/blur.glsl"
Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,5 @@
11
#version 330 core
22
#extension GL_ARB_separate_shader_objects : enable
33

4-
#include "basics/sdf/sdf_rrect.glsl"
5-
6-
layout(location = 0) in vec4 imageColor;
7-
layout(location = 1) in vec2 imagePosition;
8-
layout(location = 2) in vec4 imageRadius;
9-
layout(location = 3) in vec4 imageRectPosition;
10-
layout(location = 4) in float imageFactor;
11-
layout(location = 5) in vec2 imageUv;
12-
layout(location = 6) flat in float imageFillType;
13-
14-
layout(location = 0) out vec4 outColor;
15-
16-
uniform ScreenData
17-
{
18-
float width;
19-
float height;
20-
}
21-
ubo;
22-
uniform sampler2D inTexture;
23-
24-
#define FILLTYPE_FIT 0
25-
#define FILLTYPE_CONTAIN 1
26-
#define FILLTYPE_COVER 2
27-
28-
void main()
29-
{
30-
float dummy = ubo.width + ubo.height;
31-
vec2 rectCenter = geom_rectCenterPos(imageRectPosition);
32-
vec2 halfSize = imageRectPosition.zw / 2.0;
33-
vec2 localPos = imagePosition - rectCenter;
34-
35-
float alpha = sdf_rrect(localPos, halfSize, imageRadius, 0.0, imageFactor);
36-
37-
vec2 imageSize = vec2(textureSize(inTexture, 0));
38-
vec2 rectSize = imageRectPosition.zw;
39-
vec2 uv;
40-
41-
if (int(imageFillType) == FILLTYPE_FIT)
42-
{
43-
uv = imageUv;
44-
}
45-
else
46-
{
47-
float scale = int(imageFillType) == FILLTYPE_CONTAIN ? min(rectSize.x / imageSize.x, rectSize.y / imageSize.y)
48-
: max(rectSize.x / imageSize.x, rectSize.y / imageSize.y);
49-
vec2 scaledImgSize = imageSize * scale;
50-
uv = (imagePosition - rectCenter) / scaledImgSize + 0.5;
51-
if (int(imageFillType) == FILLTYPE_CONTAIN && (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0))
52-
{
53-
alpha = 0.0;
54-
}
55-
}
56-
57-
outColor = imageColor * alpha * texture(inTexture, uv);
58-
}
4+
#define FRAGMENT_SHADER
5+
#include "demiurge/image.glsl"
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifdef VERTEX_SHADER
2+
#include "basics/geometry.glsl"
3+
#include "basics/rotation.glsl"
4+
#include "basics/vertexgen.glsl"
5+
6+
#vertex
7+
8+
layout(location = 0) out vec4 imageColor;
9+
layout(location = 1) out vec2 imagePosition;
10+
layout(location = 2) out vec4 imageRadius;
11+
layout(location = 3) out vec4 imageRectPosition;
12+
layout(location = 4) out float imageFactor;
13+
layout(location = 5) out vec2 imageUv;
14+
layout(location = 6) flat out float imageFillType;
15+
16+
uniform ScreenData
17+
{
18+
float width;
19+
float height;
20+
}
21+
ubo;
22+
23+
void main()
24+
{
25+
vec2 inPosition = vertexgen_quad_normal();
26+
vec2 screenPos = inRectPos.xy - vec2(10) + inPosition.xy * (inRectPos.zw + vec2(20));
27+
vec2 rectCenter = geom_rectCenterPos(inRectPos);
28+
vec3 localPos = vec3(screenPos - rectCenter, 0.0);
29+
30+
gl_Position = vec4(geom_toNdc(rectCenter + rotation_quat(inRectRotation, localPos).xy, ubo.width, ubo.height),
31+
inRectDepth, 1.0);
32+
imageColor = inRectColor;
33+
imagePosition = screenPos;
34+
imageRadius = inRectRadius;
35+
imageRectPosition = inRectPos;
36+
imageFactor = inRectFactor;
37+
imageUv = inPosition;
38+
imageFillType = inFillType;
39+
}
40+
#endif
41+
42+
#ifdef FRAGMENT_SHADER
43+
#include "basics/sdf/sdf_rrect.glsl"
44+
45+
layout(location = 0) in vec4 imageColor;
46+
layout(location = 1) in vec2 imagePosition;
47+
layout(location = 2) in vec4 imageRadius;
48+
layout(location = 3) in vec4 imageRectPosition;
49+
layout(location = 4) in float imageFactor;
50+
layout(location = 5) in vec2 imageUv;
51+
layout(location = 6) flat in float imageFillType;
52+
53+
layout(location = 0) out vec4 outColor;
54+
55+
uniform ScreenData
56+
{
57+
float width;
58+
float height;
59+
}
60+
ubo;
61+
uniform sampler2D inTexture;
62+
63+
#define FILLTYPE_FIT 0
64+
#define FILLTYPE_CONTAIN 1
65+
#define FILLTYPE_COVER 2
66+
67+
void main()
68+
{
69+
float dummy = ubo.width + ubo.height;
70+
vec2 rectCenter = geom_rectCenterPos(imageRectPosition);
71+
vec2 halfSize = imageRectPosition.zw / 2.0;
72+
vec2 localPos = imagePosition - rectCenter;
73+
74+
float alpha = sdf_rrect(localPos, halfSize, imageRadius, 0.0, imageFactor);
75+
76+
vec2 imageSize = vec2(textureSize(inTexture, 0));
77+
vec2 rectSize = imageRectPosition.zw;
78+
vec2 uv;
79+
80+
if (int(imageFillType) == FILLTYPE_FIT)
81+
{
82+
uv = imageUv;
83+
}
84+
else
85+
{
86+
float scale = int(imageFillType) == FILLTYPE_CONTAIN ? min(rectSize.x / imageSize.x, rectSize.y / imageSize.y)
87+
: max(rectSize.x / imageSize.x, rectSize.y / imageSize.y);
88+
vec2 scaledImgSize = imageSize * scale;
89+
uv = (imagePosition - rectCenter) / scaledImgSize + 0.5;
90+
if (int(imageFillType) == FILLTYPE_CONTAIN && (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0))
91+
{
92+
alpha = 0.0;
93+
}
94+
}
95+
96+
outColor = imageColor * alpha * texture(inTexture, uv);
97+
}
98+
#endif
Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
#version 330 core
22
#extension GL_ARB_separate_shader_objects : enable
33

4-
#include "basics/geometry.glsl"
5-
#include "basics/rotation.glsl"
6-
#include "basics/vertexgen.glsl"
7-
8-
#vertex
9-
10-
layout(location = 0) out vec4 imageColor;
11-
layout(location = 1) out vec2 imagePosition;
12-
layout(location = 2) out vec4 imageRadius;
13-
layout(location = 3) out vec4 imageRectPosition;
14-
layout(location = 4) out float imageFactor;
15-
layout(location = 5) out vec2 imageUv;
16-
layout(location = 6) flat out float imageFillType;
17-
18-
uniform ScreenData
19-
{
20-
float width;
21-
float height;
22-
}
23-
ubo;
24-
25-
void main()
26-
{
27-
vec2 inPosition = vertexgen_quad_normal();
28-
vec2 screenPos = inRectPos.xy - vec2(10) + inPosition.xy * (inRectPos.zw + vec2(20));
29-
vec2 rectCenter = geom_rectCenterPos(inRectPos);
30-
vec3 localPos = vec3(screenPos - rectCenter, 0.0);
31-
32-
gl_Position = vec4(geom_toNdc(rectCenter + rotation_quat(inRectRotation, localPos).xy, ubo.width, ubo.height),
33-
inRectDepth, 1.0);
34-
imageColor = inRectColor;
35-
imagePosition = screenPos;
36-
imageRadius = inRectRadius;
37-
imageRectPosition = inRectPos;
38-
imageFactor = inRectFactor;
39-
imageUv = inPosition;
40-
imageFillType = inFillType;
41-
}
4+
#define VERTEX_SHADER
5+
#include "demiurge/image.glsl"

0 commit comments

Comments
 (0)