2

This may be odd because as I understand a vector and a scalar cannot be added. However I've found this sample and in line 157 it doing the following operation:

hsv.x + vec3(0.,2./3.,1./3.)

where hsv.x happens to be a float number, the value comes from the mouse X coordinates and well the rest is a vec3.

My question is what is the result of that operation?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Pipo
  • 41
  • 1
  • 7
  • @Rabbid76 Thanks! still, in math operations this isn't possible or am I wrong? this is a particular case for just OpenGL or the same is also for other programming languages? – Pipo Aug 04 '17 at 06:53
  • found this (5.10 page 59): https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.3.30.pdf – Pipo Aug 04 '17 at 06:55
  • It depends more on the specified operator overloads than it does on the language, you can certainly replicate this behavior in C++ and C#. – LJᛃ Aug 04 '17 at 12:11

1 Answers1

5

If you add a scalar to a vector, then the scalar will be add to each component of the vector, because the The OpenGL Shading Language specification (Version 4.6, Chapter 5 Operators and Expressions) says:

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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Thanks! I've just grabbed glsl but I'm not sure if I'm doing it Ok. I've started testing stuff with "shadertoy" and the link I paste above from Khronos.org. Still not sure if that is the right path do you have any recomendations? I've been checking also videos from youtube but i've ended up more confused because in those the shader file is splitted in two files the vertex and fragment shader. – Pipo Aug 05 '17 at 21:09