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

More unary fns for 3d-tiles #4775

Merged
merged 32 commits into from
Jan 13, 2017
Merged

More unary fns for 3d-tiles #4775

merged 32 commits into from
Jan 13, 2017

Conversation

leesafini
Copy link
Contributor

For #4604

Implements within 3D-Tiles:

  • sign(x)
  • floor(x)
  • ceil(x)
  • round(x)
  • exp(x)
  • log(x)
  • exp2(x)
  • log2(x)
  • fract(x)

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, 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.
  • Apparently JavaScript doesn't have a build-in function for exp2 either, so I've added this to CesiumMath as well
  • I keep getting shader failures for round. Still working on this, but let me know if you can see any glaring problems.

@leesafini
Copy link
Contributor Author

@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?

@leesafini leesafini changed the title Unaryfns More unary fns for 3d-tiles Dec 20, 2016
@lilleyse
Copy link
Contributor

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.

Copy link
Contributor

@lilleyse lilleyse left a 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"
});
Copy link
Contributor

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).

Copy link
Contributor

@lilleyse lilleyse Jan 12, 2017

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,
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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
Copy link
Contributor

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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 2, 2017

The only thing is I'm not sure if exp2 and fract belong in CesiumMath, but I'm open to other opinions.

Perhaps just keep them local and not expose them to keep the surface area of the Cesium API down.

@lilleyse
Copy link
Contributor

lilleyse commented Jan 9, 2017

@leesafini is this ready to review? #4759 was merged recently so there are a few merge conflicts.

@leesafini
Copy link
Contributor Author

@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.

@lilleyse
Copy link
Contributor

lilleyse commented Jan 9, 2017

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)';
Copy link
Contributor

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)';

Copy link
Contributor Author

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!

@leesafini
Copy link
Contributor Author

@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...

@leesafini
Copy link
Contributor Author

@lilleyse Made the changes you suggested for round, now definitely ready to view

Copy link
Contributor

@lilleyse lilleyse left a 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"
});
Copy link
Contributor

@lilleyse lilleyse Jan 12, 2017

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,
Copy link
Contributor

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) {
Copy link
Contributor

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,
Copy link
Contributor

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.

@leesafini
Copy link
Contributor Author

@lilleyse Good to review.

@lilleyse
Copy link
Contributor

Awesome, thanks for finishing this up @leesafini.

@lilleyse lilleyse merged commit 69fcd93 into CesiumGS:3d-tiles Jan 13, 2017
@lilleyse
Copy link
Contributor

Also don't worry about the spec changes, I'll add those.

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

Successfully merging this pull request may close these issues.

3 participants