10
$\begingroup$

I've got a pretty complicated node tree which isn't behaving exactly as I'd like. I'm pretty sure I've made some mistakes in my math nodes..

I'm interested in the output values of the math nodes. The best solution I've currently got is hooking the up to a color ramp, an emission shader, and rendering them on something.

Question: Is it possible to query the output value of math nodes, directly in the node editor? It'd be great to not have to render and deduce the values by their color.

$\endgroup$
  • $\begingroup$ I guess that you talk about the material node tree editor? $\endgroup$ – WorldSEnder May 24 '14 at 17:43
  • $\begingroup$ Yep, that's the one.. $\endgroup$ – ajwood May 24 '14 at 18:14
7
$\begingroup$

You should activate the plugin "Node Wrangler" (it's awesome). Beside offering many Shortcuts and hotskeys it also offers to view every? possible output. To enable it open File > User Preferences...Ctrl+Alt+U and go to the Addons section. Search for "Node Wrangler":

Enable Node Wrangler

Next you can go into your node editor and Ctrl+Shift+Left Mouse-click on the output node of your choice. It should have created a Viewer-node that is linked between the selected node and the Material Output.

Add Viewer Node

You can now view the output from the node in any 3d-Viewport after switching to Viewport-Shading Rendered. To render faster you can switch to Object-Local-view. Just select the object you want to view and press Numpad /. This will temporarily disable all other objects and speed up the preview rendering. (If you don't have a Numpad, the setting can be found under View > View Global/Local)

Switch to Rendered Mode

Note: This plugin also offers much functionality. Just press Ctrl+Space in the Node Editor to see it for yourself.

$\endgroup$
  • $\begingroup$ This definitely makes my current debugging strategy easier.. but I'd really like to be able to see the values as text. $\endgroup$ – ajwood May 24 '14 at 23:36
  • $\begingroup$ as text? You mean something like (0.8, 0.3, 0.5, 0.3) for an rgba value? $\endgroup$ – WorldSEnder May 24 '14 at 23:52
  • $\begingroup$ Yeah.. I suppose it doesn't make sense if there is UV stuff or texturing going on.. however I've got values that are constant across the whole surface, and I don't know exactly what those values are. $\endgroup$ – ajwood May 24 '14 at 23:57
  • $\begingroup$ Hm, I think, because Graphics is about the visuals you don't need to worry too much about the exact values. After all, it should look good. It was something I couldn't do at all, in the beginning but now, after ~2 years, I don't think that mathematical correctness is something Visuals need. Btw, you can always Render the image and then use a color-picker to get the exact values $\endgroup$ – WorldSEnder May 25 '14 at 0:03
  • 2
    $\begingroup$ @ajwood By clicking on the image in the image editor/viewer after rendering, you can see the value. Screenshot of a use case. $\endgroup$ – gandalf3 May 27 '14 at 23:29
9
$\begingroup$

You could use a tiny OSL script to print the values calculated by the math nodes:

shader Inspector(float input=0,output color debug=0)
{
  debug = input;
  printf("%f" , debug );
}

The printf will print the input values to the console window.

You need to wire the output otherwise it wouldn't be evaluated (optimizer)

enter image description here

In order to use OSL scripts you need to:

  • Tick Open Shading Language in the render settings
  • Set Render device to CPU (GPU can't handle script nodes)

See What is wrong with this OSL shader?

For more tips on debugging osl see also this blog

$\endgroup$
  • $\begingroup$ I've tried doing this but I am not familiar with coding at all. Do I need to enter a command to get the actual value printed in the console? When compiling it nothing gets printed. $\endgroup$ – Eranekao Feb 27 '16 at 17:31
  • $\begingroup$ @VilkoL Simply paste the code snippet in a text editor and select the filename in a script node. Note that OSL must be enabled first and is only available when device is set to CPU the render setings. $\endgroup$ – stacker Feb 27 '16 at 20:49
  • $\begingroup$ Yes I already did that but what is the trigger to make it print the value? Having it connected and hitting the refresh button on the script node doesn't print anything in the console. And yes, it is connected to the material output via an emission shader. What am I missing? $\endgroup$ – Eranekao Feb 27 '16 at 20:56
  • $\begingroup$ Cycles render would trigger the print statement from the 'shader' , Using this on a material would create huge console output. Perhaps it is better if you could ask another question and describe what you want to find out. $\endgroup$ – stacker Feb 27 '16 at 21:31
  • $\begingroup$ Maybe I'm not being clear enough, sorry if this is the case. What I am trying to achieve is exactly what is asked in this question: to view the output from a math node within a material. When I said that it is connected to the material output via emission shader, I meant that I did the setup as provided in your picture above so it doesn't get ignored (optimizer), except with a simple emission shader rather than a diffuse mix. I did a render but still nothing is printed in the console. Are we talking about the same console? I'm talking about the window called "python console". $\endgroup$ – Eranekao Feb 28 '16 at 3:30
1
$\begingroup$

If the printf command doesn't print to the console, then the node is probably optimized away. To avoid this, you have to start blender from the console with a special setting.

In Windows you have to set the OSL_OPTIONS optimize to 0, e.g. open a command prompt in blender directory and type:

set OSL_OPTIONS=optimize=0
blender.exe

In Blender recompile your script.

This is only for debugging because it slows down the rendering!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.