5
$\begingroup$

In the node editor, I am looking for a way to get a random number (in [0,1)) per ray. The object info node's random output just gives a random number per object, the number never changes. I am looking for a way to get a new number every time the shader is sampled.

I am aware of this question, however that is not quite what I am looking for.

$\endgroup$
5
  • $\begingroup$ Just curious.. What do you want this for? $\endgroup$
    – gandalf3
    Commented Jul 11, 2015 at 0:50
  • $\begingroup$ try combining some ray outputs with some math to produce some thing that seems random. outputs like ray length,view vector and camera_uv coordinates... $\endgroup$
    – Chebhou
    Commented Jul 11, 2015 at 1:15
  • $\begingroup$ @Chebhou The problem is that I need it to give me a different value every time I sample the shader, even in the same spot. To get a static random value I could use a noise texture with a huge scale. $\endgroup$
    – PGmath
    Commented Jul 11, 2015 at 1:18
  • 1
    $\begingroup$ @PGmath Oh I see , i don't think there's a variable related to the sample number AFAIK , check if OSL can provide such a thing $\endgroup$
    – Chebhou
    Commented Jul 11, 2015 at 1:22
  • $\begingroup$ @gandalf3 Well, the thing that brought it to mind at the moment was trying to more properly roughen a fake glossy reflection. (Blurring does work mostly but I was looking for another way.) But I have wished there was such a feature in the past though for other reasons, mostly having to do with various tricks to speed up render times/reduce noise. $\endgroup$
    – PGmath
    Commented Jul 11, 2015 at 20:39

2 Answers 2

4
$\begingroup$

There's enough randomness in the Position from the Geometry node. It will almost never be exactly the same for two samples, but you have to apply a hash function to convert it to a random number in the [0,1) range.

The simplest solution would be to use a Voronoi or Noise Texture node with a very large Scale.

Another solution is to make your own hash function using math nodes, replicating for example this GLSL code.

$\endgroup$
0
$\begingroup$

I think you have to combine as many inputs as possible for Noise texture with big scale: window coordinates, per-object random, object local and global coordinates, normal vector, frame number, etc, to get higher enthropy, and maybe this way you will get something close to what you want.

$\endgroup$
8
  • $\begingroup$ I don't think this will work, I need a new random number per sample, i.e. every time the surface is sampled a new number is generated. $\endgroup$
    – PGmath
    Commented Jul 11, 2015 at 20:37
  • $\begingroup$ Ok, I understand. I mean, you have to gather many possible input factors where at least some can change between frames, inside pixel, etc, to get high enough enthropy for one noise texture with pretty big scale, so every ray will meet new value. Also I forget about one more thing: make seed driver-controlled and put random function there to get random rays for every frame and even render launch link. BTW: I tried to use this driver in shader - didn't work. $\endgroup$ Commented Jul 11, 2015 at 20:51
  • $\begingroup$ I'm not quite sure what you mean, but I think I mostly get it. But I'm not really interested in frames/animation, what I am looking for is something that will give me a new number every time a surface is sampled, within a frame. $\endgroup$
    – PGmath
    Commented Jul 12, 2015 at 13:36
  • $\begingroup$ BTW, A sample is where cycles shoots a ray from the camera at a pixel and it bounces through the scene to determine what color that pixel should be. $\endgroup$
    – PGmath
    Commented Jul 12, 2015 at 13:38
  • $\begingroup$ Of course. When you put on surface very fine-grain noise, then every ray will get own random value, combine it with that random-seed driver and all rays became more random every time you render even same single frame. $\endgroup$ Commented Jul 12, 2015 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .