How to get node material block output value

Is there any way that we can take the node material calculation result out from the node material editor?

Sorry, not sure I understand the question. Node Material Editor produces node materials, essentially shader programs; what is a node material calculation result?

Let me update the question, I see there is input and output in each block, I know this value is keep changing, but is there way we can get the output value

It’s not possible to inspect these shaders as they’re running, if that’s what you mean. The only real way to get values out of a shader is through the output, which ultimately will be a rendered texture. You can see the output of individual steps by converting the output to a color, and connecting that to the output, thereby disconnecting all subsequent parts of the pipeline. That output can be hard to interpret, but it’s really the only way I know of to get intermediate values out of a running shader. Shaders run in a completely different environment from most code, and consequently debugging them can be very tricky.

What I need is all just math calculation, I wonder if I can change the node material editor blocks logic into code (not just generate code using node material) I need apply the same logic to mesh

That’s probably the right thing to do. Compute shaders are quite tricky and specialized, so unless what you’re doing is quite unusual, doing it on the CPU using normal code is almost certainly the most straightforward approach. Best of luck!

Thank you, if you know what’s the babylon API corresponding to Remap block in node material?

And I also know node material multiply it’s inputs, do you have any idea what this multiply means in code?

Can you post a link to what you’re trying to adapt? I think there’s a lot of missing context here.

Something like this, if it is possible to change this logic into code? I have no idea how I can do that?
image

You can get the shader code for the block from the console if that’s what you’re after? :slight_smile:

2 Likes

So, I believe this is a very typical value scaling operation. The arithmetic to do what you’ve screenshotted is pretty much as follows:

const remap = function (input, sourceMin, sourceMax, targetMin, targetMax) {
    return (input - sourceMin) / (sourceMax - sourceMin) * (targetMax - targetMin) + targetMin;
};

const clamp = function (input, minValue, maxValue) {
    return Math.min(maxValue, Math.max(minValue, input));
};

It sounds like you might be a little out of depth on the math. Depending on what you’re trying to do, it might be most helpful to check out some dedicated math for games resources. Stuff like that may have more targeted explanations for the arithmetic pieces than you’d find in the Babylon docs, which are principally focused on Babylon itself. If you’re not looking to go that deep, Blake’s suggestion to look at the code in the console is also a great idea. Hope this helps, and best of luck!

2 Likes

Ah, I see, I’m really new to all of this, I have no background of math for this at all, so this may look like an odd question to you, thank you for the link!

2 Likes

Gotcha, makes sense. The kind of math needed to get off the ground with 3D development isn’t complicated, but it can be difficult to figure out where to approach it from. I still recommend checking out that link I posted before, but if you have no math background at all, it might be a little overwhelming. I wrote a Playground doing some basic “procedural animations,” moving meshes with arithmetic over frames. As an addition to looking things up, it might be helpful to visualize things by changing the code in this Playground and seeing how it makes things move differently.

Simple Procedural Animation with Arithmetic | Babylon.js Playground (babylonjs.com)

Again, hope this helps, and best of luck!

2 Likes