Lighting parameters in Qt3D in 5.5 Alpha
Kaznix last edited by
I'm experimenting with Qt3D and looking to add some lighting to a forward rendered scene. What I would like to do is to create a lighting manager, which supports a number of lights, and have these lighting settings propagate to any descendent Qt3D::QNode of the lighting manager. Essentially, the lighting manager monitors its lights and updates QParameter() objects for shader variables (such as light position and colour). However, the scene and material system don't seem to easily support this.
My understanding is that only QMaterial, QTechnique and QEffect support QParameter children. This means that every material I instantiate needs to have lighting QParameters. This might be OK if I can share materials and have a small number of materials or share parameter objects. I've tried sharing materialshad some crashes, but I haven't looked into the cause in much detail yet.
I'm really trying to avoid updating lighting parameters in each material for each object. With hundreds to thousands of objects, this just seems a really inefficent way of doing things.
I'm left with investigating one of the following approaches.
- Revisit sharing materials, and update lighting parameters on each lighting related material.
- Share QParameter instances across lighting related materials.
- Find a way to get the backend renderer to instantiate shader parameters and bindings when it processed the lighting manager and keep these bindings for all children in the scene.
Can anyone comment on the viability these approaches, or provide alternatives which limit the number of parameter updates as lights move or change?
Thanks in advance.
Kaznix last edited by
Upon further investigation, I've found a few interesting things, which means I can nearly do things the way I want to.
- QMaterial is a QComponent which has a "shareable" property, thus materials can be shared.
- I can instantiate the QParameters for lights in the light cache, then set these values only my materials.
- QShaderData seems to be intended to provide shader configuration for entity instances.
The second point is a little awkward as the light cache destroys its parameters, then its children. Qt3D then tries to clone all the children as they are deleted, but some of these are materials referring back to the deleted parameters. For now I'm walking the hierarchy and unbinding the shared parameters.
While QShaderData seems intended to provide per entity configuration of shader parameters (e.g., object tint colour), I'm yet to workout how to use it correctly. This would allow me to share materials and possibly even propagate shared lighting parameter values. Since I can't work out the correct usage, for now I'm cloning materials to configure per entity shader parameters, but sharing the underlying QEffect.
Hopefully the full release of Qt3D will clear up QShaderData usage.
Hi and welcome to devnet,
To talk about your findings and Qt3D's design, you should write to the development mailing list. You'll find there Qt3D developers/maintainers (this forum is more user oriented)