Jump to content

Passing and using Uint8Array in fragment shader?


Darker
 Share

Recommended Posts

I kept searching the internets and I found this demo, which is exactly what I need - define a color pallete, a list of pixels, width and height and render it:

 

http://jsfiddle.net/greggman/cvADG/

 

The problem is this demo uses raw WebGL+some helper functions. I would like to go with Pixi.JS approach, which is better readable:

function CustomFilter(fragmentSource){    PIXI.AbstractFilter.call(this,        // vertex shader        null,        // fragment shader        fragmentSource,        // set the uniforms        {            pixels : {type : '???', value : new Uint8Array(100)},            colors : {type : '???', value : new Uint8Array(6)},            width  : {type : 'int', value : 10},            height : {type : 'int', value : 10},        }    );}

The problem is I don't know the following two things for start:

 

  1.  What type name should I use for Uint8Array? And what type name will that be in GLSL?
  2. How do I read the array values? How do I know at which pixel offset am I located, so that I know which one should I render?

Also there are other concerns, like:

 

  1. How do I notify Pixi that an array offset has changed?
Link to comment
Share on other sites

Actually I think I wanna use the array is a texture - which is 2Dshader I guess? This would allow me to access the elements through float offsets so that, if properly implemented, the game field would be easily scalable.

Yup, that is the correct way to do it. Unfortunately there is no easy data texture support in filters right now. It is something we plan to add though.

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...