Grain

Function
Adds grain to an image. Used to simulate film grain for 3D rendered elements.

This node has been entirely rewritten for 2.32, giving you complete per-channel control over size, density, softness, etc. The controls are explained below, with visual examples after the parameter list.

One thing to note is that if you have a RGB channel image, there will be no grain if you hit obeyAlpha, as there is an alpha value of 0.

In general, when there is a parameter, followed by the same parameter on a per-channel basis, the first one acts as a multiplier on the channel parameters. For example, a density of .5 will multiply r,g,bDensity by .5.

Parameters
Type
Defaults
Function
size, r,g,bSize
float
1 Overall size of the grain. size is a multiplier on r,g,bSize. You can have sizes less than 1.
density, r,g,bDensity
float
.8 The density of the grain. 1 means maximum density. density is a multiplier on r,g,bDensity.
seed
float
time The random seed for the grain
filmResponse
float
-1 The valid range is theoretically infinite, but practically is -1 and 1. -1 is typical of standard film, with grain applied to the entire range except the brightest whites, and black is the most affected. 1 is the inverse of that, withholding grain from the darks, with most grain on the whites. Default is -1.
lGain, r,g,bGain
float
.5, .5, rGain, rGain The overall luminance of the grain.
r,g,bBias
float
0 This can be used to shift the grain emphasis up or down in luminance.
r,g,bLowOffset
float
0 From the midpoint of the Gain, ths will squeeze the darker grain areas. This is good to adjust when the highlights are good, but you need to modify the darker grains.
r,g,bHighOffset
float
0 From the midpoint of the Gain, this will squeeze the brighter grain areas.
aspect
float
1 The grain aspect ratio. An aspect of 2 will stretch it twice as wide.
softness, r,g,bSoftness
float
0 A value above 0 will soften the grain. A value below 0 will sharpen the grain. The global softness is an additive factor, so it will be added to the values of the per-channel parameters.
obeyAlpha
int
0 This will only place grain in the alpha channel when turned on. If you have a RGB image, there will be no grain if this is turned on, as your alpha is 0.

Example:

In these illustrations, we have placed a Ramp, the Grain node, and a PlotScanline to analyze the image. Since we have a black-to-white Ramp, we get a linear line from left to right when there is no grain applied.


filmResponse, Gain: Adding the Grain node introduces noise, disturbing the line. Notice that there is more noise (grain) near the lower, dark area of the plotscanline. This is due to the filmResponse of -1, which concentrates grain on the lower areas. The second image is a result of increasing the lGain (or r,g,bGain on a per-channel basis), increasing both the overall range of the grain, making it both lighter and darker simultaneously:



Bias, Offset. The following two images show the result of modifying the Bias and Gain. In the first image, I have moved the rBias (I am only looking at the Red channel) down to -.5. This shifts the grain downwards from the diagonal line, making it darker. This will effect both the lighter grain (the dots above the original diagonal line) and the darker grain (the dots below the original diagonal line). To adjust only the lighter or darker grains, use the offset sliders. The second image shows a rLowOffset of .5, squeezing just the darker grains, leaving only lighter grains.


softness: The first image is the standard softness. The second image has a softness of 10. The third image has a softness of -10.

 


Synopsis

image Grain( 
  image In, 
  float size, 
  float density, 
  float seed, 
  float filmResponse, 
  float lGain, 
  float rGain,          
  float gGain,
  float bGain,
  float rSize,
  float gSize,
  float bSize,
  float rDensity,
  float gDensity,
  float bDensity,
  float aspect,
  float rBias,
  float rLowOffset,
  float rHighOffset,
  float gBias,
  float gLowOffset,
  float gHighOffset,
  float bBias,
  float bLowOffset,
  float bHighOffset,
  float softness,
  float rSoftness,
  float gSoftness,
  float bSoftness,
  int obeyAlpha
);


Script

image = Grain( 
  image, 
  size, 
  density, 
  seed, 
  filmResponse, 
  lGain, rGain, gGain, bGain,
  rSize, gSize, bSize,
  rDensity, gDensity, bDensity,
  aspect,
  rBias, rLowOffset, rHighOffset,
  gBias, gLowOffset, gHighOffset,
  bBias, bLowOffset, bHighOffset,
  softness, rSoftness, gSoftness, bSoftness,
  obeyAlpha

);

Command Line

shake -grain size density seed etc...