How do you pass by reference in a GLSL shader?
You can mark an attribute as inout
in the function signature, and that will make the attribute effectively "pass by reference"
For example,
void doSomething( vec3 trans, inout mat4 mat )
Here mat
is "passed by reference", trans
is passed by value.
mat
must be writeable (ie not a uniform attribute)
All parameters are “pass by value” by default. You can change this behavior using these “parameter qualifiers”:
in: “pass by value”; if the parameter’s value is changed in the function, the actual parameter from the calling statement is unchanged.
out: “pass by reference”; the parameter is not initialized when the function is called; any changes in the parameter’s value changes the actual parameter from the calling statement.
inout: the parameter’s value is initialized by the calling statement and any changes made by the function change the actual parameter from the calling statement.
So if you don't want to make a copy, you should use out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With