[of-dev] ofxShader addon

Pierre Proske pierre at digitalstar.net
Sun Jul 11 11:19:08 PDT 2010


The shader manager I'm using was based on a Windows version of 
dynamically updated shader code. I have a Linux version working with 
inotify (http://en.wikipedia.org/wiki/Inotify) which watches a directory 
for changes.
I've got windows equivalent code but haven't testted it yet. On OSX I 
think kqueue might be able to be used for the same thing (monitoring 
file changes).

Basically you watch a directory. Perhaps this could be the data dir and 
then you just look for changes to .vert and .frag files, even if they 
are a directory lower down.
At the moment I'm using the base shader filenames in the manager to 
compare which file have changed. With multiple directories you could 
have multiple files of the same name, which could get messy. Or perhaps 
you could watch for the absolute path names of shaders in the watched 
dir...but I haven't tried this yet.

Basically the syntax is this:

.h file:

ofxShaderManager shaderManager;

.cpp file:

(in setup)
shaderManager.loadShader('blur');
shaderManager.loadShader("test.vert","blue.frag");
shaderManager.startup();

(in update)
shaderManager.update();

(in draw)
shaderManager.shaders[0].setShaderActive("true");

The latter could optionally be shaderManager.shaders["blur"] (although 
haven't implemented this yet), but the test.vert/blue.frag combo would 
have to be referenced as shaderManager.shaders[1]

You don't actually need the startup() or update() to use the 
shaders...but without these calls they won't update dynamically.



On 11/07/10 18:15, Kyle McDonald wrote:
> Pierre, if you have changes to ofxShader, want to merge now, or before 
> the branch?
>
> Once ofxShader is on github, I'll take it off here:
>
> http://code.google.com/p/kyle/source/browse/#svn/trunk/openframeworks/addons/ofxShader/src 
>
>
> ofxShaderManager sounds great :) Why do they need to be in /data? Can 
> ofxShaderManager watch for updates on a per-file basis rather than a 
> per-folder basis? i.e., if you tell it to use some specific shader 
> file, can't it just watch that file?
>
> That said, the version in my google code does go:
>
> string ofxShader::loadShaderText(string filename) {
>         ifstream file;
>         file.open(ofToDataPath(filename).c_str());
> ...
> }
>
> Which obviously isn't a guarantee, but it's an encouragement.
>
> Kyle
>
> Golan Levin wrote:
>> how about data/shaders/ ? :)
>>
>> On Sun, Jul 11, 2010 at 10:35 AM, Pierre Proske 
>> <pierre at digitalstar.net <mailto:pierre at digitalstar.net>> wrote:
>>
>>     OK that sounds great....
>>     looking forward to working off the git versions...
>>
>>     The only issue with the manager class is that you need to tell it
>>     which directory to monitor for updates. If this is just the /data
>>     dir, it's not a problem. But if people keep their shaders elsewhere,
>>     you then need to coordinate with the ofxShader where that dir is,
>>     and that's where the problems arise, because the manager needs to
>>     share this path info.
>>
>>     Anyway I'll get an example up soon just to start with.
>>
>>     p.
>>
>>
>>     On 11/07/10 14:55, Zachary Lieberman wrote:
>>
>>
>>
>>         greetings,
>>
>>         ofxShader will be part of the core in 007, same with 
>> ofxFboTexture.
>>
>>         As for a manager class, can you write something that works
>>         against the current ofxShader?
>>
>>         We'll start a branch in github for 007 dev and get both the
>>         latest FBO and latest shader stuff up, so that we all can know
>>         where to find the latest, and if you want to work with it or
>>         push it in different directions, you can work off the git.
>>
>>         take care,
>>         zach
>>
>>
>>
>>
>>
>>
>>         On Sun, Jul 11, 2010 at 4:54 AM, Pierre Proske
>> <pierre at digitalstar.net <mailto:pierre at digitalstar.net>
>> <mailto:pierre at digitalstar.net <mailto:pierre at digitalstar.net>>>
>>         wrote:
>>
>>            I was just reading this post:
>>            http://www.openframeworks.cc/forum/viewtopic.php?f=12&t=4256
>> <http://www.openframeworks.cc/forum/viewtopic.php?f=12&t=4256>
>> <http://www.openframeworks.cc/forum/viewtopic.php?f=12&t=4256
>> <http://www.openframeworks.cc/forum/viewtopic.php?f=12&t=4256>>
>>
>>            and I saw that Kyle has done a little work on
>>            ofxShader....something which I was planning to do (well, I've
>>         made
>>            my own changes).
>>
>>            My question is, in the light of the addons refresh - is 
>> ofxShader
>>            going to be integrated into the core? Otherwise, where 
>> will the
>>            latest version be kept (I'm worried its going to turn into
>>         another
>>            ofxFBO with multiple versions).
>>
>>            My interest is because, firstly, the addon needed a bit of an
>>            update, and secondly, I've made a basic framework for an
>>            ofxShaderManager addon, that keeps track of all currently 
>> loaded
>>            shaders and also monitors the shader directory, so that if 
>> you
>>            make a change to a shader text file, it notices the changes,
>>            recompiles the shaders and links the program anew. This 
>> enables
>>            you to make changes to the shader while the app is 
>> running, which
>>            saves a lot of time. I thought I could build on top of 
>> ofxShader,
>>            but I think I will need to re-write parts of it to 
>> accomodate a
>>            global shader path, a little like the ofDataPath. If it 
>> gets too
>>            complicated, I might just make a new ofxShader2, but I'd 
>> like to
>>            avoid that if possible.
>>            _______________________________________________
>>            of-dev mailing list
>>            of-dev at dev.openframeworks.cc
>> <mailto:of-dev at dev.openframeworks.cc>
>> <mailto:of-dev at dev.openframeworks.cc
>> <mailto:of-dev at dev.openframeworks.cc>>
>>
>>                   
>> http://dev.openframeworks.cc/listinfo.cgi/of-dev-openframeworks.cc
>>
>>
>>
>>         _______________________________________________
>>         of-dev mailing list
>>         of-dev at dev.openframeworks.cc 
>> <mailto:of-dev at dev.openframeworks.cc>
>>         
>> http://dev.openframeworks.cc/listinfo.cgi/of-dev-openframeworks.cc
>>
>>
>>
>>     --     http://www.digitalstar.net
>>
>>
>>     _______________________________________________
>>     of-dev mailing list
>>     of-dev at dev.openframeworks.cc <mailto:of-dev at dev.openframeworks.cc>
>>     http://dev.openframeworks.cc/listinfo.cgi/of-dev-openframeworks.cc
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> of-dev mailing list
>> of-dev at dev.openframeworks.cc
>> http://dev.openframeworks.cc/listinfo.cgi/of-dev-openframeworks.cc
> _______________________________________________
> of-dev mailing list
> of-dev at dev.openframeworks.cc
> http://dev.openframeworks.cc/listinfo.cgi/of-dev-openframeworks.cc
>


-- 
http://www.digitalstar.net




More information about the of-dev mailing list