0

I have a driver in my input nodes which works fine. It just outputs a random value.

enter image description here

But...it will only be executed once.

If i do something like in this screenshot, the x coordinate will be evaluated for every x, right? or am i missing here something?

But my driver value will be executed only once and for all x/y/z values it will be that constant value...can i somehow change this that my driver will be executed for every coordinate as the "less than" node does this?

This is in my driver:

enter image description here

import bpy
import random

two sample functions

def rand(f,t): """ Simple function call:

        invert(val)
"""
print("executed")
return random.uniform(f,t)



Add functions defined in this script into the drivers namespace.

bpy.app.driver_namespace["rand"] = rand

Chris
  • 59,454
  • 6
  • 30
  • 84
  • 1
    Hello ! Not sure what's in your driver but if it's "just" outputting a random value, you might want to use a White Noise texture https://blender.stackexchange.com/a/213316/86891 with a Map Range node afterwards – Gorgious Oct 08 '21 at 06:57
  • thanks! that was i was looking for. So for me it seems that way, that shader nodes calculates all values once except the ones which has the coordinates as inputs (which makes sense in an optimizing way). So my problem could probably be solved if i had the coordinates as inputs for my driver... ;) – Chris Oct 08 '21 at 07:35

1 Answers1

2

To get any value per X, the value must be some function of X. X is not accessible at the time the driver is evaluated.

For a (discontinuous) random 0-1 per X, you could use X as the coordinate to look up into 1D White Noise:

enter image description here

If you want the value to be random (per X, per Frame), you could use 2D noise:

enter image description here

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • thanks Robin, unfortunately i want to be able to have a random number per texture x coordinate. But i couldn't figure out how to get texture coordinates into my driver...but yes, i understand, this works with white noise, but not with my driver ;) – Chris Oct 08 '21 at 07:41
  • but if you know how i get the texture coordinate in my driver i would be very interested.... – Chris Oct 08 '21 at 07:42
  • @Chris Ahh.. if, by texture coordinate, you mean UV coordinate, plug in 'UV' instead of 'Object' from the first node. (or, if from a particular non-active UV map then use the UV Map input node). – Robin Betts Oct 08 '21 at 07:47
  • 1
    sorry, looks like i did not make it clear. Yes i meant UV coordinate, but i meant my driver...how can i get the uv coordinate in my driver? – Chris Oct 08 '21 at 07:54
  • @Chris you would have, somehow, to associate something with UV, before render-time. What is your desired end-effect? – Robin Betts Oct 08 '21 at 07:58
  • this was just a "i am curious"-question. How i could do that. Thank you! – Chris Oct 08 '21 at 08:04