-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
More unary fns for 3d-tiles #4775
Conversation
…iles' into unaryfns
vertex shader for round still won't compile - not sure why
JavaScript apparently doesn't have exp2 function?
@lilleyse This is telling me I have conflicts in ExpressionSpec, but it seems fine when I look through it myself. How can I tell where the conflict is? |
I see some merge conflicts when merging the latest 3d-tiles into this branch. They also appear if you click the Resolve conflicts button. Though it looks like most of the conflicts are pretty simple to fix. |
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 great! The tests are really solid.
The only thing is I'm not sure if exp2
and fract
belong in CesiumMath
, but I'm open to other opinions.
addStyle('Sign', { | ||
color : "color() * sign(${temperature})", | ||
pointSize : "5" | ||
}); |
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.
Since temperature
is always positive this style won't look very special. One idea could be using the sign of the ${POSITIONS} values (like the tests below).
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.
Just a reminder about this comment. fract
sort of applies here too. Even just sign(${temperature} - 0.5)
may be sufficient.
sign : Math.sign, | ||
floor : Math.floor, | ||
ceil : Math.ceil, | ||
round : Math.round, |
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.
It turns out that round
isn't supported in GLSL ES 1.0.
In Node.prototype.getShaderExpression
you will need to add a special case for it - you can substitute round
with floor(left + 0.5).
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.
I'm having a lot of trouble with this. Currently getting Vertex shader failed to compile. Compile log: ERROR: 0:8: '0.5' : syntax error
but it's saying the error is in files I'm pretty sure I've never modified.
Not really sure if I'm approaching this in the right way, anyway - I added in the special case for round
and had to remove it from the unary functions, and in doing so had to add in a case for it in parseCall like I had done before the data-driven approach was implemented.
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.
I think round
can be treated like the other unary fns in that section. Only the shader area needs to have the special case.
ceil : Math.ceil, | ||
round : Math.round, | ||
exp : Math.exp, | ||
exp2 : CesiumMath.exp2, |
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.
I don't think exp2 is essential to add to CesiumMath
. Instead create a function in Expression.js
for exp2
and reference that in the unaryFunctions
list.
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.
Similarly I would do the same thing for fract
.
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.
@pjcozzi What do you think here?
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.
Agreed, #4775 (comment)
exp2 : CesiumMath.exp2, | ||
log : Math.log, | ||
log2 : Math.log2, | ||
fract : CesiumMath.fract |
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.
I've done the basic, where fract(x) when x < 0 outputs x - floor(x). This means that the output of fract(-2.25) would be 0.75. If there's another way you would prefer this to be handled, please let me know.
This is the way GLSL does it, so that's good.
Perhaps just keep them local and not expose them to keep the surface area of the Cesium API down. |
@leesafini is this ready to review? #4759 was merged recently so there are a few merge conflicts. |
@lilleyse Sorry, not ready yet! Having issues with how to call fract and exp2 from within Expression. Today's my birthday, so I've had a slow weekend with progress. |
Ok thanks for the heads up, and happy birthday! |
@@ -1184,6 +1223,8 @@ define([ | |||
return 'bool(' + left + ')'; | |||
} else if (value === 'Number') { | |||
return 'float(' + left + ')'; | |||
} else if (value === 'round') { | |||
return 'floor(' + left + '0.5)'; |
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.
Try 'floor(' + left + ' + 0.5)';
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.
Hahaha oof, that fixed it. Sorry!
@lilleyse pretty sure this is ready to view, but the conflicts it's telling me need to be resolved are just the changes I've made in this branch... |
@lilleyse Made the changes you suggested for |
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.
I fixed the merge conflict - it was definitely a weird one...
Besides my comments, there are also a couple test failures.
addStyle('Sign', { | ||
color : "color() * sign(${temperature})", | ||
pointSize : "5" | ||
}); |
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.
Just a reminder about this comment. fract
sort of applies here too. Even just sign(${temperature} - 0.5)
may be sufficient.
@@ -104,7 +104,16 @@ define([ | |||
asin : Math.asin, | |||
atan : Math.atan, | |||
radians : CesiumMath.toRadians, | |||
degrees : CesiumMath.toDegrees | |||
degrees : CesiumMath.toDegrees, | |||
sign : Math.sign, |
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.
Use CesiumMath.sign
instead. Looking here Math.sign
isn't supported in all browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign.
@@ -1404,6 +1413,14 @@ define([ | |||
return expressions; | |||
} | |||
|
|||
function fract(number) { |
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.
Place these functions closer to the top, maybe right before var binaryFunctions = {
.
exp : Math.exp, | ||
exp2 : exp2, | ||
log : Math.log, | ||
log2 : Math.log2, |
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.
It turns out this is also not supported for IE. log2
will also need to be a local function which can use CesiumMath.logBase
.
@lilleyse Good to review. |
Awesome, thanks for finishing this up @leesafini. |
Also don't worry about the spec changes, I'll add those. |
For #4604
Implements within 3D-Tiles:
A few notes:
fract
has been added to CesiumMath. According to the Wikipedia page for fractional parts, there are a couple of ways of handling negative inputs. I've done the basic, wherefract(x)
whenx < 0
outputsx - floor(x)
. This means that the output offract(-2.25)
would be0.75
. If there's another way you would prefer this to be handled, please let me know.exp2
either, so I've added this to CesiumMath as wellround
. Still working on this, but let me know if you can see any glaring problems.