I’m starting to dig into the wonderful world of shaders, and one thing that i find real hard is lighting, especially because of all the math behind it. I was wondering if it possible to use the ofLight objects to create light inside of the shaders where i can make vertex transformations and apply materials. I have tried this but the shaders seems to cancel the ofLight, probably because I’m not passing the light information to the shader. Is there any way to do this? If so can give me some advice or point me to an example?
Really appreciate any help.
I think this feature will be in OF 9.0. You can get light data, by calling ofGetLightsData() and pass it to the shader. And then you will be be able to call predefined functions, like ofPointLight inside your shader to calculate lighting for you. I wrote ofxUbo, which will make it a lot easier to pass light and matrerial data over to shaders (without it you will have a million setUniform calls!). I will update the examples to use the new programmable lights api as soon as OF 9.0 is released.
But for now I think you still have do the calculations manually.
@arturo, did you add the feature where users can call lighting functions from their shaders? I know you added a “shader include system” can you add the light and material structs to shaders as well. Thanks
Thanks a lot for the clarifications. Good to know that this feature is going to be available in the 9.0 version. Also going to have a look in ofxUbo it seems to be a pretty efficient way to pass data into the shaders.