Sign in to follow this  
cachopixi

global shader uniforms (ie. u_time)

Recommended Posts

Is there a way to globally set the values of certain uniforms, so they don't need to be set on a per shader basis? ie.:

uniform vec2 u_resolution;
uniform float u_time;

It seems to be it might be inconvenient to have to update every shader each when we change resolution, or to update the time

Thanks!

Share this post


Link to post
Share on other sites

Two-part answer

u_resolution

u_resolution is actually part of filter uniforms that depend on temporary pow2-sized texture. In v5 its available under another name for all filters.
https://github.com/pixijs/pixi.js/wiki/v4-Creating-Filters

v5: http://pixijs.download/dev/docs/PIXI.Filter.html

working on new docs: https://github.com/pixijs/pixi.js/pull/5555

one of latest filter-related threads

u_time

In v5 its possible to add stuff to global uniforms. Related code: https://github.com/pixijs/pixi.js/search?q=globalUniforms&unscoped_q=globalUniforms

Maybe you can put something in "renderer.globalUniforms" before you create the shader.

I did not test this approach so I do not know additional actions are required for it. You have to guess and debug.

 

Share this post


Link to post
Share on other sites

Thanks for your reply!

I'm using version 4.8.7 which I got from npm. Is version 5 ready to use already?

Even after checking the docs I don't understand how u_resolution is already defined, as I don't seem to be there unless I define it. Is there any sample code I can check?

>u_resolution is actually part of filter uniforms that depend on temporary pow2-sized texture

does this mean it only works for pow2-sized textures?

 

Share this post


Link to post
Share on other sites

Look, I specified in  https://github.com/pixijs/pixi.js/pull/5555 that we have 5 different spaces for coordinates. Its hell. There is u_resolution (sometimes called `dimensions`) that is needed for conversion between some of them, and it has special name in v5, but in v4 you have to add a hack to "Filter.apply" method to use it.

The problem is discussed so many times that I really dont have time to discuss it right now unless you have a demo for me to fix. All that links I posted should help you to make your case, then I can help you to fix it :)

"container.filterArea = renderer.screen" makes everything significantly easier, because all normalized coords are in screen, maybe that helps you.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.