Skip to content

Commit

Permalink
gles fixes done
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Nov 16, 2024
1 parent 76f381d commit 2eda931
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
39 changes: 16 additions & 23 deletions armorpaint/shaders/dilate_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,46 @@ in vec2 tex_coord;
out vec4 frag_color;

#ifdef ESSL
#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = t[](
#define CONST_ARRAY_END() );
const vec2 offsets[8] = vec2[](
vec2(-1.0, 0.0), vec2( 1.0, 0.0), vec2( 0.0, 1.0), vec2( 0.0, -1.0),
vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0), vec2(-1.0, -1.0)
);
#else
#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = {
#define CONST_ARRAY_END() };
const vec2 offsets[8] = {
vec2(-1.0, 0.0), vec2( 1.0, 0.0), vec2( 0.0, 1.0), vec2( 0.0, -1.0),
vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0), vec2(-1.0, -1.0)
};
#endif

CONST_ARRAY_BEGIN(vec2, offsets, 8)
vec2(-1.0, 0.0),
vec2( 1.0, 0.0),
vec2( 0.0, 1.0),
vec2( 0.0, -1.0),
vec2(-1.0, 1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0),
vec2(-1.0, -1.0)
CONST_ARRAY_END()

void main() {
// Based on https://shaderbits.com/blog/uv-dilation by Ryan Brucks
vec2 size = textureSize(tex, 0).xy;
vec2 size = vec2(textureSize(tex, 0).xy);
vec2 texel_size = vec2(1.0, 1.0) / size;
float min_dist = 10000000.0;
ivec2 coord = ivec2(tex_coord * size);
float mask = texelFetch(texdilate, coord, 0).r;
if (mask > 0) discard;
if (mask > 0.0) discard;

frag_color = texelFetch(tex, coord, 0);
int i = 0;
while (i < dilate_radius) {
while (i < int(dilate_radius)) {
i++;
int j = 0;
while (j < 8) {
vec2 cur_uv = tex_coord + offsets[j] * texel_size * i;
vec2 cur_uv = tex_coord + offsets[j] * texel_size * vec2(i, i);
coord = ivec2(cur_uv * size);
float offset_mask = texelFetch(texdilate, coord, 0).r;
vec4 offset_col = texelFetch(tex, coord, 0);

if (offset_mask != 0) {
if (offset_mask != 0.0) {
float cur_dist = length(tex_coord - cur_uv);
if (cur_dist < min_dist) {
vec2 project_uv = cur_uv + offsets[j] * texel_size * i * 0.25;
vec2 project_uv = cur_uv + offsets[j] * texel_size * vec2(i, i) * vec2(0.25, 0.25);
vec4 direction = textureLod(tex, project_uv, 0.0);
min_dist = cur_dist;
if (direction.x != 0 || direction.y != 0 || direction.z != 0) {
if (direction.x != 0.0 || direction.y != 0.0 || direction.z != 0.0) {
vec4 delta = offset_col - direction;
frag_color = offset_col + delta * 4;
frag_color = offset_col + delta * vec4(4.0, 4.0, 4.0, 4.0);
}
else {
frag_color = offset_col;
Expand Down
23 changes: 6 additions & 17 deletions base/shaders/ssao_blur_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@ in vec2 tex_coord;
out float frag_color;

#ifdef ESSL
#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = t[](
#define CONST_ARRAY_END() );
const float blur_weights[10] = float[](
0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535
);
#else
#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = {
#define CONST_ARRAY_END() };
const float blur_weights[10] = {
0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535
};
#endif

CONST_ARRAY_BEGIN(float, blur_weights, 10)
0.132572,
0.125472,
0.106373,
0.08078,
0.05495,
0.033482,
0.018275,
0.008934,
0.003912,
0.001535
CONST_ARRAY_END()

const float discard_threshold = 0.95;

void main() {
Expand Down

0 comments on commit 2eda931

Please sign in to comment.