pplux / px

Single header C++ Libraries for Thread Scheduling, Rendering, and so on...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set_uniforms usage example

NukeBird opened this issue · comments

Can someone show me how to set custom uniforms?
I didn't find any example for the set_uniforms function

commented

Mmm... you are right, we need to add an example... There is no way to declare custom uniforms, but there is a variable length uniform called u_data, defined as vec4 u_data[N]; The trick here is to emulate a "uniform block" by having only one uniform to define the pipeline state.

The benefit is the ability to map C structures to that array of vec4 in the shader, like bgfx IBL example here:
https://github.com/bkaradzic/bgfx/blob/master/examples/18-ibl/uniforms.sh#L6
https://github.com/bkaradzic/bgfx/blob/master/examples/18-ibl/ibl.cpp#L48

I do need to add an example explaining this, but for the time being that was the idea. You need to declare a vec4 u_data[N] in your shader and that should represent all your data. If you need something more specific or have other requirements I can consider other alternatives.

@pplux hm... So set_uniforms takes vec4[N] to fill vec4 u_data[N]? Every call completely changes u_data?

commented

Yep, right now it does change the whole uniform "blob", the size is up to you, so you can use more or less data (only in multiples of vec4, remember)

If you need more granularity I can consider changing px_render to accept more than one u_data... but The point was to make the API very simple and it can not be simpler than just one big uniform data per pipeline. But again, I can think of something if you have a proper use case for it.

commented

Re-open it if you need further support with it, maybe I will add several user-uniform blobs in the future for better granularity, but right now I think is ok.