Skip to content
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

3D Tiles Styling - add vector support to the built-in functions #4865

Closed
30 tasks done
lilleyse opened this issue Jan 13, 2017 · 6 comments
Closed
30 tasks done

3D Tiles Styling - add vector support to the built-in functions #4865

lilleyse opened this issue Jan 13, 2017 · 6 comments

Comments

@lilleyse
Copy link
Contributor

lilleyse commented Jan 13, 2017

Now that vector types are supported in the styling language (#4759) the built-in functions should support the vec2, vec3, and vec4 types in addition to supporting numbers as they currently do.

Unary functions can accept either a number, vec2, vec3, or vec4. If the type is a vector, the function should be applied to every component of the vector and return the resulting vector. This rule applies to the other functions as well.

  • radians
  • degrees
  • cos
  • sin
  • tan
  • asin
  • acos
  • atan
  • sqrt
  • abs
  • sign
  • floor
  • ceil
  • round
  • exp
  • log
  • exp2
  • log2
  • fract

The function signatures for all these look like:
fract(vecx x)
fract(float x)

For atan and pow, both arguments must be the same type.

  • atan2
  • pow

atan2(float x, float y)
atan2(vecx x, vecx y)

pow(float x, float y)
pow(vecx x, vecx y)

For min and max, the second argument may be a number. Otherwise the types should match.

  • min
  • max

min(float x, float y)
min(vecx x, vecx y)
min(vecx x, float y)

max(float x, float y)
max(vecx x, vecx y)
max(vecx x, float y)

Example: min(vec4(1.0), vec4(2.0)) and min(vec4(1.0), 2.0) are both valid, but min(vec4(1.0), vec3(1.0)) is not

Similar rules for mix and clamp:

  • mix

mix(float x, float y, float a)
mix(vecx x, vecx y, vecx a)
mix(vecx x, vecx y, float a)

  • clamp

clamp(float x, float minVal, float maxVal)
clamp(vecx x, vecx minVal, vecx maxVal)
clamp(vecx x, float minVal, float maxVal)

Below are functions that haven't been added to the styling language yet.

  • length

length(vecx x)
length(float x)

  • distance

distance(vecx x, vecx y)
distance(float x, float y)

  • dot

dot(vecx x, vecx y)
dot(float x, float y)

  • normalize

normalize(vecx x)
normalize(float x) -- always return 1.0

  • cross - this is a special case, ONLY vec3 is supported. Throw a DeveloperError otherwise.

cross(vec3 x, vec3 y)

As usual, this is a good reference: http://www.shaderific.com/glsl-functions/

I'll open a PR for one of these. And then possibly @Dylan-Brown or others can finish it off.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 13, 2017

Please link to this from #3241 (and link future short-term 3D Tiles issues) so we can track our progress.

@lilleyse
Copy link
Contributor Author

Unary functions PR here: #4867

@glee2244
Copy link
Contributor

Hi, I'm working on adding the length and distance functions but couldn't find anything in CesiumMath that support either of those two functions. Are there any other functions in the repo that could possibly help me?

@lilleyse
Copy link
Contributor Author

Look into Cartesian3.length and Cartesian3.distance.

@lilleyse
Copy link
Contributor Author

@glee2244, @Jane-Of-Art, @Dylan-Brown

Just a heads up that length is being implemented here: #5149

@lilleyse
Copy link
Contributor Author

Finished. Thanks @Jane-Of-Art and @glee2244 for the work here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants