+ 2

assignment in GLSL

How to assign one of the vector or matrix members in to float number?(in opengl Shading Language) I'm going to do something like this: vec3 A=vec3(0.0,1.0,1.0) float B=First component of A

4th Mar 2021, 6:21 PM
Mehran
Mehran - avatar
3 Respuestas
+ 2
I'm not sure if you're asking how to pass a vector or matrix from your main application's code to GLSL programs or doing math operations in GLSL using vectors and matrices. I'll explain how to pass the vector or matrix. If you're trying to pass a vector or matrix from RAM and CPU code to make it available in your vertex shader in GLSL, you have a few options. attribute uniform The first step you should take is using a uniform since attributes are more complex. Attributes is where you pass something like an array and your vertex shader looks at only 1 element from that array at a time. A uniform is almost as simple as a global variable that can be accessed from your application programming language like c++ and your GLSL. A uniform is also accessible from your fragment shader.
4th Mar 2021, 6:37 PM
Josh Greig
Josh Greig - avatar
+ 2
The question-poster wrote, "Josh Greig I know that. I'm going to do something like this: vec3 A=vec3(0.0,1.0,1.0) float B=First component of A" Response: That clears it up. That snippet wasn't in the original question until you edited it in. This is what you want: vec3 A=vec3(0.0,1.0,1.0) float B=A.x; A.r and A.x are two names for the same first element. A.x is what I'd use unless A was representing a colour.
4th Mar 2021, 7:32 PM
Josh Greig
Josh Greig - avatar
+ 1
Josh Greig I know that. I'm going to do something like this: vec3 A=vec3(0.0,1.0,1.0) float B=First component of A
4th Mar 2021, 7:02 PM
Mehran
Mehran - avatar