Math Graph Shader

Hi Everyone,
Not 100% sure if this is the right category, but I wanted to share something I put together a little while ago for graphing math functions in Blender because sometimes it can be handy to actually visualise the transfer function of a shader node instead of its material output

It’s fully procedural and comes with adjustable axis lines and tick marks

Ever wondered what the transfer function of the “Ease” option of the colour ramp looks like?


Math Graph.blend (124.2 KB)

15 Likes

This is so cool! And so badly needed, honestly. I frequently end up checking my shader math visually in wolfram alpha, I am delighted that you’ve made a solution directly in Blender :slight_smile:

Thanks, it originally started as a way to try and debug my attempt at making a more procedural version of the colour ramp (which is now a part of this shader so…).

There’s a lot of neat stuff that can be done with shaders, but it often needs complex math and trying to debug it sometimes is… well, hard.

I did briefly think about how to do 3D graphs, but quickly realised that’d have broken my brain trying to work out how to draw the axis grid lines (which are like 95% of the node setup)

2 Likes

For this reason i wonder if we could have a numeric " viewer " to check equations.
This visual graph is already amazing thank you.

1 Like

While viewing equations is probably out, a numeric output is probably doable, you’d really just need a texture of the digits 0-9 where adding a rounded/truncated 0-9 offsets which part of the UV shows up on a face, then just repeat the tile with 1/10, 1/100, 1/1000 etc. multipliers.

1 Like


hm,i can display 1 digit with a x location of 0.1m shows 1 and at 0.8 m it shows 8 etc.

how to display a comma ? how the node “know” it should be displayed.

As example the output is maybe 3.14 or 5300,6 or 0.000347 etc

how should the node logic look like?

Amazing stuff ! thanks for providing this is really cool

Comma/period placement there would actually be pretty simple. With a few greater than nodes, you could pretty easily figure out the order of magnitude. You’d be bound to a upper limit and lower limit, although when each step of a limit is an order or magnitude, you have a lot of room. You could get from .0001 to 1000 with 9? Greater than nodes, etc

You maybe could post a example?I am not sure how to make a small logic, for every number without a loop.

it’d be using the compare node like “if input between 1x and 10x put comma/decimal point here” and have one of those groups for each power of 10. Catch is, while this shouldn’t be too complex with a fixed decimal point, to get a floating decimal point could become quite complicated.

Could probably have a fixed number of digits, fixed decimal point and an adjustable exponent though, e.g. “0.985x10^7” (use x/10^round(log(x)) to normalise x to between 0 and 1), I mean, does anyone really need 28 significant digits on a shader?. If I remember, I’ll try and have a play after work today

Yes,maybe its better to first find the decimal point,and then if you have the position the calculation its mabye easyer vs the opposite order.Not sure tbh.

Maybe not,as said it would be very handy to have a number viewer to check the values of a equation of a shader,or a quick look what the output of a color channel or vector ect is.Even more if you know you have a equation with a expected output,and you could read out the output would be very helpfull.

here i found this video today,it shows how to make procedural digital numbers.unfortunately it shows only one char at the time without decimal point logic,however the clever use of the coloramp is worth to watch.

edit,i wonder if maybe geometry nodes can help with new options?

By popular demand, I present Math Graph V2 - now with 50% more graph!

Displays 5 significant figured in fixed-point scientific notation. Numbers between 0.0000000000001 and 999990000.0 are supported. Supports a “spinning ticker wheel” style display option as well (although gets a bit jumpy when rolling over from 9 to 0). each digit is modular and so more significant digits can be added after the decimal place or to the exponent if needed.

Math Graph V2.blend (157.7 KB)
(note if the last digit seems off by 1 count, I think it’s to do with floating point rounding errors inside Blender, numbers with power of 2 fractions don’t get rounded)

4 Likes

Wow you did it!
Thanks man.Looks great ,works great.

would it be possible to shift the decimal point,based on the exponent?ofc then you dont have to show the 10xexp.

I guess it would be more complicated the smaller/greater the number gets if more 0s should be displayed

And maybe the plane should be scale down to the top and down height of the numbers,now its 2 m .
edit,i scaled it down to this.Makes only sence if you use the numbers only.for the graph you need ofc the larger plane.you could duplicate the material to have both a small plane number material,and the original graph plane.
numberscale

This would be pretty easy with the “work in progress” SDF texture nodes.

ah yes SDF textures,when they are in the daily builds?

I don’t think there has been a build since D6464 that contained them - Charlie is busy on other projects at the moment.

1 Like

id did something kinda similar some years ago :slight_smile:

This is some extremely usefull thing.
I also if i remember well, put this nodes on blenderkit. Something like math plotter… i don’t really remember.
yours is great @ajmorgan !
I bookmark it !

Happy blending !

1 Like

Just found a bug in the nodes when feeding it exactly 1 or exactly 10, fixed now along with increasing the default text size and adding more digits.

There is also an example of how each node group is linked up to make the counter to make it easier to make other custom counters.

Like how about a custom scene light meter?


Math Graph V3.blend (167.2 KB)

3 Likes

Good stuff, I completely missed your implementation back then

The lightmeter is a amazing idea.
Thats what i meant.This is good example why its very usefull, for many cases to show the values.

Well done.

I made a test with standart view,worldbackround color at rgb 1 and strength 1

the diffuse color set to rgb 0,18 seems correct


then diffuse rgb 1 seems correct

(the follow rgb colors seems correct to,given the explanation at the end,in short
Those weights are typically represented as 0.2126R + 0.7152G + 0.0722*B )

rgb blue 0,0,1 only
lightmeter3
green 0,1,0
lightmeter4
red 1,0,0
lightmeter5

interesting that your meter reads the internal linear light strength not the sRGB view,but since this is shader based it makes sence.
~I know the calc gets the average strength~,but why is the red that different?

rendered with 3.2.0 alpha
with 3.3.0 i get only violet objects with Eevee. Cycles works though.

edit i connected the rgb to bw direct to the shader output,they a different weighted.

here the explanation,its based on normalized luminance
https://blender.stackexchange.com/questions/112525/how-does-cycles-calculate-rgb-to-bw