Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @lunoland's modification of code provided by Shadertoy users hornet and TomF (see shadertoy.com/view/4t2SDh)
- // Generate a uniformly distributed random coordinate between (0, 0) and (1, 1); you can use UVs as input.
- float2 random_coord(float2 input) {
- return frac(sin(dot(input + frac(_Time.y) * 0.07, float2(12.9898, 78.233))) * 43758.5453);
- }
- // Take the resulting color you get from randomly sampling a pre-calculated blue noise texture and remap it to a
- // triangle-shaped distribution in the range of [-0.5, 1.5].
- half4 tri_dist(half4 input) {
- input = input * 2 - 1;
- half4 result = original * rsqrt(abs(input));
- result = max(-1, result); // Handle the NaN that results from 0 * rsqrt(0)
- return result - sign(input) + 0.5;
- }
- // In your fragment shader, you can add some noise to the final color like so:
- sampler2D _NoiseTex; // Add this texture in the properties block and assign it a pre-calculated blue noise texture (16x16 works fine) from http://momentsingraphics.de/Media/BlueNoise/FreeBlueNoiseTextures.zip
- half4 frag (v2f input) : SV_Target {
- // ...whatever operations you do to get your final color go here
- // Sample the pre-calculated blue noise texture at random, and then remap the resulting color to the triangular distribution
- half4 noise = tri_dist( tex2D(_NoiseTex, rand(input.uv)) ) / 255; // add 2 bits of triangularly distributed noise (1 / 255 = 1 bit, 1.5 - -0.5 = 2)
- return color + noise;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement