Javascript effect error

Share your Construct 2 effect files

Post » Wed Dec 23, 2015 4:06 pm

Hi, I'm currently trying to make a fast motion blur effect for my game

Here is the fx's file code:
Code: Select all
//////////////////////////////////////////////////////////////////////////
// Motion Blur effect
varying mediump vec2 vTex;
uniform mediump sampler2D samplerFront;
uniform mediump float quality;
uniform mediump float seconds;

function scrUpdater() {
      mediump vec4 front = texture2D(samplerFront, vTex);
        gl_FragColor = front + oldfront*quality/100 ;
    }

void main(void)
{
   if (seconds == 0){
      mediump vec4 front = texture2D(samplerFront, vTex);
        gl_FragColor = front;
   }
   else {
      mediump vec4 oldfront = texture2D(samplerFront, vTex);
      setTimeout(scrUpdater(), 10);
   }
}




When I use it in Construct 2, I get this error:

Image

Can someone help me? :x
Image
B
28
S
6
G
2
Posts: 202
Reputation: 3,131

Post » Wed Dec 23, 2015 4:21 pm

Looks like you are mixing C and JavaScript. 'function' is not a valid keyword, and I don't think setTimeout() is a valid call.
ImageImageImage
B
71
S
20
G
190
Posts: 3,533
Reputation: 108,340

Post » Wed Dec 23, 2015 4:33 pm

What should I put in its place?
I've seen many tutorials like this one: (add in http)://www.w3schools.com/js/js_functions.asp
They all use 'function'.

Also, for the setTimeout() call, it doesn"t give me any error, and I've seen it here:
(add in http)://stackoverflow.com/questions/14226803/javascript-wait-5-seconds-before-executing-next-line
Image
B
28
S
6
G
2
Posts: 202
Reputation: 3,131

Post » Wed Dec 23, 2015 4:54 pm

As far as I know effects use the 'OpenGL Shading Language' not Javascript. So javascript doesn't work here.
B
24
S
3
G
1
Posts: 422
Reputation: 2,107

Post » Wed Dec 23, 2015 5:15 pm

@Asmodean Ah. Well that's a huge mistake I made!
Thank you mate x)

EDIT: Sooooo... I don't have a single chuking idea of how to translate this into OpenGL Shading Language. Can someone help me here?
Image
B
28
S
6
G
2
Posts: 202
Reputation: 3,131

Post » Wed Dec 23, 2015 5:33 pm

Does the following Shader tutorial from gigatron help at all?

https://www.scirra.com/tutorials/4900/shader-toy-to-c2
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
74
Posts: 5,143
Reputation: 52,691

Post » Wed Dec 23, 2015 7:20 pm

Mmh, I managed to get a motion blur to work, however this was absolutely not what I expected...

I expected to get something like that: (https)://www.scirra.com/forum/request-directional-blur_t122854
Or at least like that: (https)://youtu.be/Siud1xP8Veg
Image
B
28
S
6
G
2
Posts: 202
Reputation: 3,131

Post » Thu Dec 24, 2015 11:30 am

*moved to the more appropriate 'Effects' section
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
74
Posts: 5,143
Reputation: 52,691


Return to Effects

Who is online

Users browsing this forum: No registered users and 1 guest