Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you pass a matrix by reference in a GLSL shader?

Tags:

glsl

How do you pass by reference in a GLSL shader?

like image 584
bobobobo Avatar asked Nov 29 '12 19:11

bobobobo


2 Answers

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)

like image 126
bobobobo Avatar answered Nov 15 '22 15:11

bobobobo


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

like image 2
Aditya Singh Rathore Avatar answered Nov 15 '22 14:11

Aditya Singh Rathore