How to use viewOrigin and scrollPos to fix Effects?

Share your Construct 2 effect files

Post » Sat Dec 31, 2016 7:25 pm

I need to fix the hexagonal pixellate effect- when the screen scroll, the effect doesn't take this into account so the effect goes crazy when the screen scrolls.
I need help figuring out how to apply either the viewOrigin or the scrollPos to compensate for the scrolling.
I imagine I'd have to add something like mod(scrollPos,scale) to some value, but it isn't clear to me where exactly, or which value, etc..
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Sat Dec 31, 2016 9:04 pm

I thought it might be easier to edit the Pixellate effect instead of the Hexagonal, but I still can't seem to figure it out.


Code: Select all
/////////////////////////////////////////////////////////
// Pixellate effect
varying mediump vec2 vTex;
uniform lowp sampler2D samplerFront;

uniform mediump float pixelWidth;
uniform mediump float pixelHeight;

uniform mediump float tilesize;
uniform mediump vec2 scrollPos;


void main(void)
{
   mediump vec2 tilecount = vec2((1.0 / pixelWidth) / tilesize, (1.0 / pixelHeight) / tilesize);
   mediump vec2 tile = vec2(1.0 / tilecount.x, 1.0 / tilecount.y);
   mediump vec2 halftile = tile / 2.0;
   
   mediump vec2 offset = mod(scrollPos,tilesize);
   offset.x = pixelWidth*offset.x;
   offset.y = pixelHeight*offset.y;
   
   mediump vec2 tex = floor((vTex-offset) / tile) * tile + halftile;
   
   gl_FragColor = texture2D(samplerFront, tex);
}
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Sun Jan 01, 2017 6:45 pm

@Prominent
Can you send .capx with the problem .. then i can look what's wrong .
B
67
S
24
G
29
Posts: 827
Reputation: 22,677

Post » Sun Jan 01, 2017 7:02 pm

@Gigatron , https://1drv.ms/u/s!AhHSZHEulqh_gXNbRY9jc_ihjpvv
There's an example of the issue.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Sun Jan 01, 2017 9:38 pm

@ Prominent

Please try this code , it must working in this case ...
Good luck ;

Code: Select all
/////////////////////////////////////////////////////////
// Pixellate effect
#ifdef GL_ES
precision mediump float;
#endif
 
varying mediump vec2 vTex;
uniform mediump sampler2D samplerFront;
uniform mediump float pixelWidth;
uniform mediump float pixelHeight;
 
vec2 iResolution = vec2( 1./pixelWidth, 1./pixelHeight);

#define PIXEL_SIZE 32.0

void main()  {
   vec2 uv = vTex;
   
    float plx = pixelWidth * PIXEL_SIZE  ;
    float ply = pixelHeight * PIXEL_SIZE  ;
   
    float xx = plx * (PIXEL_SIZE / iResolution.x);
    float yy = ply * (PIXEL_SIZE/ iResolution.y);
   
    uv.x = xx * floor(uv.x / xx);
    uv.y = yy * floor(uv.y / yy);
   
    gl_FragColor = texture2D(samplerFront, uv);
}


*****
If it's work for you then you can replace :
#define PIXEL_SIZE 32.0 with : uniform float PIXEL_SIZE to acces this variable from .xml file and C2 editor
B
67
S
24
G
29
Posts: 827
Reputation: 22,677

Post » Sun Jan 01, 2017 11:19 pm

@Gigatron , that doesn't fix the issue. It still gets messed up when scrolling. The pixelated effect needs to pan with the scroll position.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Tue Jan 03, 2017 4:08 pm

@Prominent
Yes i understand ... i must move texture inside quad(Vtex) to do what you want.. added for my todo list...
B
67
S
24
G
29
Posts: 827
Reputation: 22,677


Return to Effects

Who is online

Users browsing this forum: No registered users and 2 guests