[C3][Effects] Skend converted

For discussion and help with the Construct 3 Plugin SDK

Post » Wed Jan 10, 2018 7:51 am

This one is for bilgekaan

Converted over skend effect.

Skend.c3addon

Result below.
Image
SkendTest.c3p

New effect (modified version of Skend):
SkendPow.c3addon
Also includes parameter to adjust the exponent of the skew variation (originally started at 2.0 for the Skend effect, higher makes the base skew less, lower makes the base skew more.)
SkendPowTest.c3p

@bilgekaan let me know if it works for you.

[Changes needed to make the effect work are in subsequent posts.]
Last edited by Mikal on Sat Jan 13, 2018 1:45 am, edited 3 times in total.
B
63
S
28
G
19
Posts: 186
Reputation: 14,584

Post » Wed Jan 10, 2018 11:42 am

@Mika It's working now. Thank you!
B
76
S
38
G
52
Posts: 504
Reputation: 32,292

Post » Wed Jan 10, 2018 4:47 pm

Hi, I'm interested in using this fx, but reading the c2 thread it appears it doesn't work when exported? Is this correct for c3?

Effects like seamless screw up when exported as it doesnt take into consideration that construct bundles images into sprite sheets. Something similar could be happening with Skend.


Thanks.
B
14
S
4
G
1
Posts: 81
Reputation: 1,143

Post » Wed Jan 10, 2018 8:16 pm

@Mikal could you post the capx aswell please :D !
Image
B
45
S
23
G
13
Posts: 355
Reputation: 11,641

Post » Wed Jan 10, 2018 10:40 pm

Added SkendTest.c3p to original post for @LaurenceBedford

@m00npunk - good question, not sure, I'll leave that as an exercise for the reader. It seems like if there was a concern, you could pad your sprite that you are skending, so the shader would not touch other sprite data in a sprite sheet. The simple SkendTest does work with Remote Preview on an IPhone with Safari.
B
63
S
28
G
19
Posts: 186
Reputation: 14,584

Post » Thu Jan 11, 2018 7:44 pm

@Mikal That's weird. It looks like this in my template.

Image

I think it tries to skew whole sprite sheet as @mOOnpunk mentioned.
B
76
S
38
G
52
Posts: 504
Reputation: 32,292

Post » Fri Jan 12, 2018 3:40 am

bilgekaan wrote:@Mikal That's weird. It looks like this in my template.

I think it tries to skew whole sprite sheet as @mOOnpunk mentioned.


@bilgekaan that looks pretty strange, can you share your *.c3p project, so I can try it also and take a look? It also does not appear to 'Skend' the way I expect (where the amount changing depends on Y coord of the texel/sprite.) Instead, it looks like the entire image is shifting.

If you use the SkendTest.c3p project I posted above, do you see the same issue?
B
63
S
28
G
19
Posts: 186
Reputation: 14,584

Post » Fri Jan 12, 2018 5:39 am

Ok, I see the same error when I add more sprites. Hmmm, let's see if there are some new C3 effect uniforms that can adjust for this.
B
63
S
28
G
19
Posts: 186
Reputation: 14,584

Post » Fri Jan 12, 2018 7:10 am

I am not sure why the behavior is different between C3 and C2, but in C3 the wrong skend behavior shows up when there are more sprites in the project (and when sprites are packed into some large textures.) To resolve this I normalized the delta x offset based on srcStart/SrcEnd and also switched back to pixelSize.y. See comments in the effect.fx code below.

I updated the c3addon in the OP with this new version, @bilgekaan please try it again.

I tried a few tests with a different number of other sprites and checked for how the textures were packed using the chrome debugger, the effect worked across a few cases, but watch for the skend effect changing as you change the number of sprite objects (not instances) and size of the sprite source texture (animation).

Also the more you skend, you may need to 'pad' in your original texture or you'll get clipping and perhaps sampling neighboring textures in the case of packed textures.

Here's the new code:
Code: Select all
/////////////////////////////////////////////////////////
// Skend effect
varying mediump vec2 vTex;
uniform lowp sampler2D samplerFront;

uniform lowp float pixelWidth;
uniform lowp float pixelHeight;
uniform lowp float Skend;
uniform mediump vec2 pixelSize;
uniform mediump vec2 srcEnd;
uniform mediump vec2 srcStart;
uniform mediump vec2 srcOriginStart;
uniform mediump vec2 srcOriginEnd;
uniform mediump vec2 layoutStart;
uniform mediump vec2 layoutEnd;

void main(void)
{   
   mediump vec2 tex = vTex;
   mediump vec2 texOffset = tex - srcStart;
   
   // Original from C2 effect, did not work with sprite packing in C3 and pixelHeight did not seem to work
   // tex.y -= (pixelHeight*Skend)*pow(tex.x,2.0);
   // Instead, calculate the normalised position n of vTex in the foreground rectangle and use that for Skend amount
   mediump vec2 n = (vTex - srcOriginStart) / (srcOriginEnd - srcOriginStart);
   tex.y -= (pixelSize.y*Skend)*pow(n.x,2.0);
      
   gl_FragColor = texture2D(samplerFront,tex);
}
B
63
S
28
G
19
Posts: 186
Reputation: 14,584

Post » Fri Jan 12, 2018 9:25 pm

@Mikal It still bends the whole sprite sheet that the grass sprite belongs but this version is usable if we create more blank space in the grass sprite. Thank you!
B
76
S
38
G
52
Posts: 504
Reputation: 32,292

Next

Return to Plugin SDK

Who is online

Users browsing this forum: No registered users and 0 guests