Xesenix

How to pass vectors and colors to filters uniforms

Recommended Posts

var Colorize = function (game) {
    Phaser.Filter.call(this, game);
    this.uniforms.uColor= { type: '3f', value: { r: 0.5, g: 0.5, b: 0.5} };

    this.fragmentSrc = [

        "precision mediump float;",
        "uniform float     uColor;",

        "void main(void) {",
            "gl_FragColor.r = uColor.r;",
            "gl_FragColor.g = uColor.g;",
            "gl_FragColor.b = uColor.b;",
            "gl_FragColor.a = 1.0;",
        "}"
    ];

};

 

It works if i pass each color channel as separate value but i can find combination of type and data structure that would do the same in single object

Share this post


Link to post
Share on other sites
uniforms.example1 = { type: '1f', value: 1.0 };
uniforms.example2 = { type: '2f', value: { x: 0.0, y: 0.0 }};
uniforms.example3 = { type: '3f', value: { x: 0.0, y: 0.0, z: 0.0 }};

fragmentSrc = [

    "precision mediump float;",

    "uniform float     example1;",
    "uniform vec2      example2;",
    "uniform vec3      example3;",

    ...

Like this :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.