How to generate a random number for every each fragment of a fullscreen render pass

Hi,

i am trying to achieve a very basic screen FX: i just want to overlay a noise texture generated with the randomrange() method over the current screen. Thus, attempting to mimmick the film grain as if the image was recorded with a physical camera.

I know the maths behind the “overlay” blend mode and how to generate the randomrange number between 0 and 1.

The problem arises because if plug in the output of the overlay operation to the fragment color. My randomrange number is only generated once so when i run the game the screen flashes over time. It is working but it is applying the same randomnumber to every fragment of the same rendered image.

I dont know how to tell the fragment program to pick one different value per screen (x,y) coordinates.

I ll attach here a screen shot of my shadergraph configuration:

i have tried 2 options:

  • (1) use a SimpleNoise texture (I, ideally, would like to avoid this)
  • (2) create a custom function and code two loops, one per dimension, generating the noise and pluging it in to the base color fragment input.

I am sure, there should have to be a “simpler” and easier way of doing such a light operation.

Thanks.

Hi, just in case anyone is looking at this question and finds the trouble difficult to sort it out.
I just came up with this solution, which is based on:

  • (1) one custom noise function that depends on two parameters (x and y) and a third one using the Seed parameter
  • (2) it is important to make the noise dependant on these two dimensions so we can make it dependant on UV input from the texture. We use the UV (that range from 0 to 1) and multiply each dimension by the total amount of pixels in that direction (as stated by the Screen width and Screen height values)

The rest is just make the seed depend on Time variable with graduation by a divisor factor that we call here the “inverse of speed”. The greater the speed, the slower the noise variation is.

Thanks for reading.

Regards,
JC