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

Added new Color operations #3585

Merged
merged 2 commits into from
Feb 17, 2016
Merged

Added new Color operations #3585

merged 2 commits into from
Feb 17, 2016

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented Feb 16, 2016

Added new functions to Color, including:

  • add - Adds two colors componentwise
  • subtract - Subtracts two colors componentwise
  • multiply - Multiplies two colors componentwise
  • divide - Divide two colors componentwise
  • mod - Mod two colors componentwise
  • multiplyByScalar - Multiply a color by a scalar componentwise
  • divideByScalar - Divide a color by a scalar componentwise

And updated ColorSpec for each of these new functions

@emackey
Copy link
Contributor

emackey commented Feb 16, 2016

I don't normally hear of divide or mod in regards to color. Is there a use case in mind for color division?

More commonly, the opposite (or negative) of a multiply type color operation is called screen or some such, and the formula looks like this:

vec3 result_color = 1.0 - ( (1.0 - color_A) * (1.0 - color_B) );

This is kind of the photo-negative effect of multiply, and is useful for superimposing brighter things on darker things etc.

Also, diff is sometimes useful, it's essentially an absolute-value version of subtract.

Just my $0.02, not saying anyone needs to change the design here, just something to consider.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 16, 2016

@emackey this is for the 3D Tiles styling language where Color is a first-class type just like Number, String, etc. I think it is important that we implement all the sane operators for completeness even if they wouldn't be widely used; think of this like a color that is a vec4 in GLSL.

As for interesting color ideas, feel free post them here: CesiumGS/3d-tiles#2

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 16, 2016

P.S. it would be a killer code sprint project to extend 3D Tiles styling with new color operations...gamma correction...lighten...darken...whatever. We could only put the pragmatic ones in the spec though.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 16, 2016

@ggetz code looks good. Update CHANGES.md.

@ggetz
Copy link
Contributor Author

ggetz commented Feb 17, 2016

Updated.

@pjcozzi
Copy link
Contributor

pjcozzi commented Feb 17, 2016

Thanks @ggetz!

pjcozzi added a commit that referenced this pull request Feb 17, 2016
@pjcozzi pjcozzi merged commit 252c0b0 into CesiumGS:master Feb 17, 2016
@pjcozzi pjcozzi deleted the Color-Operations branch February 17, 2016 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants