Could anyone explain this math?

Recommended Posts

	vec3 i  = floor(v + dot(v, C.yyy));


v is a vector and add to a dot product of v and some other vector with y,y,y

the right part results in a scalar, how can a vector add to a scalar gives another vector?

	"vec4 permute(vec4 x) {",
"return mod289(((x * 34.0) + 1.0) * x);",
"}",


Also this, x of type vector4 is expanded 34 times should result in another vector4, how on earth can you add one to a vector4?

Update:

Does he mean to add one to a vector piecewise?

Thanks

Jack

Edited by lucky6969b

Share on other sites
1 hour ago, lucky6969b said:

the right part results in a scalar, how can a vector add to a scalar gives another vector?

While your thought is true in common mathematical understanding, it is just a question of definition for computer languages. In GLSL, for example, adding a scalar to a vector is possible; it just builds a vector where all components are set to the scalar and then performs a vector addition.

GLSL specification, chapter "Operators and Expressions", section "Expressions", says:

Quote

...
One operand is a scalar, and the other is a vector or matrix. In this case, the scalar operation is applied independently to each component of the vector or matrix, resulting in the same size vector or matrix.
...

Edited by haegarr

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• 10
• 17
• 9
• 14
• 41
• Forum Statistics

• Total Topics
631067
• Total Posts
2997734
×