Skip to content

Conversation

@SpellDigger
Copy link

fixes #2235

@BoySanic BoySanic moved this to Easy to Review in PRs to review Nov 8, 2025
Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also adjust the value range to actually use the full spectrum of values, otherwise if there are 10 values, it will only ever use the first 5 of them.

@SpellDigger
Copy link
Author

yea idk man the issue said for colors below 5 it said nothing about more and i absolutely do not understand the math is doing to do what u want (also i gtg)

@IntegratedQuantum
Copy link
Member

Well, clamping would also add a heavy bias for less than 5.

@IntegratedQuantum IntegratedQuantum moved this from Easy to Review to WIP/not ready for review in PRs to review Nov 10, 2025
after many tries and blind guesses this is the current progress
@SpellDigger
Copy link
Author

ok after many tries, blind guesses and almost crashing out i got to this point

but my current issue now is the fact the tools look bad at 5 colors but nice at 10
{67E94989-AA5A-4BD5-B7D3-A8C1DD2169BF}
{57432F91-8853-423A-885E-47D92E7C3CB9}
{7B7E6565-70EC-4A6B-8F82-AA554A11294D}
{1C6BEC72-D406-411F-94B1-84D5C0FC471C}

@SpellDigger
Copy link
Author

(ignore the gold zon im gonna clean it up if this is good enough)

@IntegratedQuantum
Copy link
Member

You should be able to make something that looks the same as before for 5 colors.

@SpellDigger
Copy link
Author

ill try editing it a bit then since i have time

@SpellDigger
Copy link
Author

SpellDigger commented Nov 11, 2025

oh i think i was just casting not enough* light this seems to be the same as before
{74873EB0-7CA6-4F28-844A-4D2F945A1ED1}
while working for more gradients
{6BA4D616-B27A-4FFA-A6AA-6C680867EF69}
ill clean up gold zon and commit

@SpellDigger
Copy link
Author

(forgot to remove the floor from mid)

(otherwise it goofs up the gradient when it has a decimal value)
@SpellDigger
Copy link
Author

nvm im stupid i forgot i needed that to even out the center colors

@SpellDigger
Copy link
Author

ok should be ready for merge

const mid = @as(f32, @floatFromInt(material.colorPalette.len - 1))/2.0;
const lightScale = mid/2;
const lightVal = (lightTL*2.0 + lightTR)/6.0*lightScale;
var light = @as(i32, @intFromFloat(@round(@floor(mid) - lightVal)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it flooring the mid? To me it seems like this would add a bias when the number of colors is even.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the floor the shading is just messed up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image please

light = @max(@min(light, 4), 0);
const mid = @as(f32, @floatFromInt(material.colorPalette.len - 1))/2.0;
const lightScale = mid/2;
const lightVal = (lightTL*2.0 + lightTR)/6.0*lightScale;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two magic values here (6.0 should be 3.0, and the /2 in the line above), if you can't find a good name for them, please at least combine them into a single /4.

Copy link
Author

@SpellDigger SpellDigger Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sherlock how do u want me to combine them then
/3.0 x mid breaks the math in general
/(3.0 x mid) breaks when theres 10 gradients

complaining about magic numbers here is just angers me, because those magic numbers are the exact leftovers u left me to work with and figure out what are they there for

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because the original code was bad, doesn't give you permission to make things worse.

What I'd suggest is lightScale = mid/4.0 and lightVal = (...)/3.0*... that way we only have one purely magic number instead of two.

Ideally of course you'd get rid of both magic numbers, but I think that would require a larger rewrite of the math, which doesn't seem like a good idea right now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what? this doesnt get rid of any magic numbers unless ur telling me to get rid of the /2 at mid (which is not a magic number cuz its pretty obvious by name im getting the mid point here) but that completly breaks the math

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /3.0 is less magic because it's clearly part of an interpolation between two numbers.

@H41ogen
Copy link
Contributor

H41ogen commented Nov 27, 2025

is this abandoned?

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

Labels

None yet

Projects

Status: WIP/not ready for review

Development

Successfully merging this pull request may close these issues.

Specifying less than 5 colors for tool materials crashes the game

3 participants