[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 2 KB, 481x133, Graph.png [View same] [iqdb] [saucenao] [google]
6559284 No.6559284 [Reply] [Original]

Hey folks, I heard you guys are super pro with math stuff so I was wondering if I could get some help. I'm a comp sci major working on graphics stuff and was interested in seeing if there's a way to do cel shading without using a look up texture. What I came up with is that graph there <-

I was wonderin, in the domain [0..1] I need a function that is mostly static from 0.0 to A and remains at L, then interpolates from L to H over A to B, then from B to 1.0 remains close to H.

I could very easily do this with branching, but I'm taking it as an exercise in math to work out how to do this as nothing more than a single formula. I'd prefer not just a straight answer but a sort of...push in the right direction for how I'd come to the conclusion and any help would be greatly appreciated. Even something to look up on wikipedia would be awesome.

As a heads up, I've taken a few college level courses in math so go ahead and throw high level stuff at me like integrals and such, I think I can take it.

Again, I promise this isn't homework, though it'd be pretty badass to have a course on shader authoring.

>> No.6559297

1 formula would only be an approximation, you should stick to the piecewise equation for this I think

>> No.6559299

>>6559297

I'm okay with an approximation, I believe I've seen a function that's sorta like the one pictured but instead has a smooth transition n that's what I'm after. Sorta like x^3 but mirrored across the diagonal.

>> No.6559301

>>6559284
>then interpolates from L to H over A to B
Do comp sci people talk like this? what does this mean?

>> No.6559302

>>6559299
I'm not that guy but I guess if you don't really care.

http://en.wikipedia.org/wiki/Sigmoid_function

>> No.6559306

>>6559302

That! That is exactly what I'm looking for! Thank you!

>>6559301
No reason to be rude. You did see the picture, right? :\

>> No.6559323

>>6559302
>>6559306
Is there a reason to use 1/[1+e^(-t)] and not, say, arctan(t)? The wiki page makes it seem like they're all good, but more in-depth comments would be really interesting. Maybe one is computationally more efficient, or one has more natural analytic properties, or something?

>> No.6559326

>>6559323

From what I'm seeing, tanh(x) = (e^x - e^-x) / (e^x + e^-x), so 1/(1 + e^-t) would have less operations in it. However, the curve isn't quite exactly the same, the tanh one is just a bit tighter. I'm sure you could change that a bit with some tweaking but how they are by default that's what I see.

>> No.6559330

>>6559323

The ones in the graph all have the property that they tend to 1/-1 at inf/-inf, their only difference is the speed at which they converge. You'd likely want one that converges decently fast for your example so something like x/(1+abs(x)) would not at all do.

>> No.6559331

>>6559323
Oh, here we go:

http://en.wikipedia.org/wiki/Logistic_function

``The logistic function is the solution of the simple first-order non-linear differential equation:

f'(x) = f(x)*(1-f(x))

"

which corresponds to vaguely exponential growth when f(x) is close to 0, so that 1-f(x) is close to 1, and so that f'(x) = f(x)*(1-f(x)) is close to f(x), and a limiting factor (1-f(x)) that symbolizes the population being f(x) less efficient at reproducing as the population approaches its maximum of 1.

I actually remember this being mentioned briefly in diff. eq. 1, with more variables, but it's the same graph up to some scaling and translating.

>> No.6559333

>>6559330

Do note that while scaling each function does allow you to change a few things it won't change the inherent speed of convergence.

>> No.6559335

This one is super neato too

http://en.wikipedia.org/wiki/Gudermannian_function