Search code examples
python-3.xopenglqt3dpyside2

Passing uniform values to into vertex and fragment shaders


How to pass an uniform value into vertex and fragment shaders?

I know that something like that is possible in QMaterial:

self.colorParameter = Qt3DRender.QParameter("color", color)
self.addParameter(self.colorParameter)

Is there any other way?

My goal is to pass some uniform values and change them from time to time.


Solution

  • As @Florian Blume suggested, I am posting my answer:

    class MyMaterial(Qt3DRender.QMaterial):
        def __init__(self, parent):
            super().__init__(parent)
            # some code ...
    
            self.parameter_position = Qt3DRender.QParameter("position", QVector3D(0, 0, 0))
            self.addParameter(self.parameter_position)
    
        def update_position(self, position):
            self.removeParameter(self.parameter_position)
            self.parameter_position.setValue(position)
            self.addParameter(self.parameter_position)