[Bf-python] Fastest way for RenderEngine to return combined rgba + z

Asbjørn lordcrc at gmail.com
Sat Aug 24 00:22:00 CEST 2013


On 23.08.2013 15:05, Bram de Greve wrote:
> This surely looks interesting. I've been looking for something like this
> for my own little toy-raytracer (liar.bramz.net).
> For this you implemented a C extension module that's loaded in Blender
> as part of your add-on?

Yes, pylux is a binary python module (called "pylux"). It's implemented 
almost exclusively using Boost.Python, the only direct Python C stuff is 
the buffer things I added now.

The source code is available under the GPL license here:
https://bitbucket.org/luxrender/lux/src/tip/python?at=default

The buffer specific code is here:
https://bitbucket.org/luxrender/lux/src/0c11e6bf3765c26d16039cb8c4dd59a6886d6013/python/pycontext.h?at=default#cl-234

This object wraps the buffer stuff, and is used in 
PyContex::blenderCombinedDepthBuffers().

The Blender python plugin code is here:
https://bitbucket.org/luxrender/luxblend25/src/9beea7f187d76b432c15505e322ccc556cb37a6b/src/luxrender/outputs/__init__.py?at=default#cl-115

In essence it's just

result = render_engine.begin_result(0, 0, xres, yres)

pb, zb = pylux.blenderCombinedDepthBuffers() # get buffer objects
result.layers.foreach_set("rect", pb) # rgba pixels
result.layers[0].passes.foreach_set("rect", zb) # zbuffer

render_engine.end_result(result)

So far we only support this for a single layer with a single pass.

Please note that this was the very first time I've done anything Python 
C api stuff, and also the very first time I've done anything non-trivial 
with Boost.Python (I did not write the initial pylux code), so there's 
probably some silly stuff in there :)

Just ask if you have any questions.

Cheers
- Asbjørn



More information about the Bf-python mailing list