-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector types: vec2, vec3, vec4 #166
Conversation
What does this mean
Do we need a If not, in the GLSL world, these would be separate types so I suppose they should not have implicit conversion and instead should require explicit construction ( |
* `vec4(vec3, Number)` - initialize with a `vec3` and number | ||
* `vec4(Number, vec3)` - initialize with a `vec3` and number | ||
|
||
`vec2` components may be accessed with `.x`, `.y` and `[0]`, `[1]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is in the vec4 section. Either create a new section here or move some of these sentences to be in the right vector type section just above.
|
||
Vectors support the following binary operators by performing component-wise operations: `===`, `==`, `!==`, `!=`, `+`, `-`, `*`, `/`, and `%`. For example `vec4(1.0) === vec4(1.0)` is true since the x, y, z, and w components are equal. This is not the same behavior as a JavaScript `Object`, where, for example, reference equality would be used. Operators are essentially overloaded for `vec2`, `vec3`, and `vec4`. | ||
|
||
Operations between vectors of different types will not evaluate component-wise, but instead will evaluate as JavaScript objects. For example `vec2(1.0) === vec3(1.0)` is false and `vec2(1.0) * vec4(1.0)` is `NaN`. See the [Conversions](#conversions) section for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awkward. Can we do better?
vec2(1.0) === vec3(1.0)
What does this do in GLSL? Based on the constructor overloads, is one converted to the other?
Instead of returning false
/NaN
for these examples, is it reasonable to implement if these are type mismatch errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLSL will not compile with that, you need to cast explicitly.
Equality checks could be made to work without too much trouble, the multiply would be harder (is the result vec2 or vec4?). Originally all this would work if vec2
, vec3
, and vec4
were treated as the same vec4
type, but I thought the point of moving away from that was to prevent expressions like these from working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, is it reasonable to implement if these are type mismatch errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think I misunderstood your comment.
It shouldn't be hard to detect type mismatch errors in the JS backend, as usual it's more difficult in the GLSL backend, but still possible to just catch a shader failure and throw a generic type mismatch error (as talked about offline).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let's go with the type mismatch.
Just those comments. |
Expressions like
This shouldn't be too hard to implement.
I think its nice to have a color type in case we want to add special functions on colors. At the moment though its nearly the same as a |
I think the right thing to do is to use If we need color-specific functions, they would just be stand alone functions, not member functions. GLSL is a pretty good example of getting good milage out of using As simple as possible, but no more simple. |
The code update is not too bad at all. This approach sounds good with me too, more flexible. |
Great, let's do it! |
I opened a PR for handling colors as vec4. CesiumGS/cesium#4849 I'll also have a PR for checking type mismatching. |
@lilleyse given CesiumGS/cesium#4867, is this ready to finish? |
…ctors, and add .r accessors to vectors
This is ready for another look. The new changes describe colors in terms of vectors. There will be a separate PR for type mismatching since that affects pretty much everything including vectors.
I'm going to open a PR soon for the built-in math functions, and in that PR it will support vector types. |
Looks great! |
For #2
#138 will build off this.
Cesium implementation: CesiumGS/cesium#4759
To Do: