TNM084 Procedural Images PDF
Document Details
Uploaded by Deleted User
Linköping University
ISY
Ingemar Ragnemalm
Tags
Summary
This document is a set of lecture notes on procedural images. It covers topics such as random numbers, noise, and splines.
Full Transcript
1(80) Information Coding / Computer Graphics, ISY, LiTH TNM084! Procedural images Ingemar Ragnemalm, ISY 1(80) Information Coding / Computer Graphics, ISY, LiTH Lecture 2...
1(80) Information Coding / Computer Graphics, ISY, LiTH TNM084! Procedural images Ingemar Ragnemalm, ISY 1(80) Information Coding / Computer Graphics, ISY, LiTH Lecture 2 ! Random numbers! ! Splines! ! Noise! ! Filtering noise! ! Perlin noise! ! Simplex noise 2(80)2(80) Information Coding / Computer Graphics, ISY, LiTH ! Lecture questions! ! A few teasers for the rest of the lecture! ! 1. How can you generate random numbers on the GPU?! ! 2. How can a sin() function create random numbers?! ! 3. What function is approximated by cubic spline?! ! 4. What is the advantage with simplex noise over gradient noise? 3(80)3(80) Information Coding / Computer Graphics, ISY, LiTH Random numbers ! Important source of interesting patterns! ! Randomness is chaos?! ! Randomness with structure 4(80)4(80) Information Coding / Computer Graphics, ISY, LiTH What is random? Pick a "random" number - never truly random! ! People never pick the same number twice. Randomness does!! ! Roll a die! ! Is the die fair?! ! But how can we make a computer "roll a die"? 5(80)5(80) Information Coding / Computer Graphics, ISY, LiTH Pseudo-random numbers ! Computers are intrinsically deterministic! ! How can we make randomness?! ! Heat + A/D conversion! ! Pseudo-random number generation 6(80)6(80) Information Coding / Computer Graphics, ISY, LiTH Analog randomness ! Noise in analog inputs are also random numbers!! ! Input from noisy sensor, A/D-conversion.! ! Drawback: The result is not repeatable and dependent of momentary situation, like heat level.! ! The system may stop working a cold day! 7(80)7(80) Information Coding / Computer Graphics, ISY, LiTH PRBS ! Pseudo-random binary sequence! ! Shift bits and do XOR with some bits! ! Creates a chaotic sequence! ! Repeats itself after few or many iterations. 8(80)8(80) Information Coding / Computer Graphics, ISY, LiTH PRBS Needs a "seed", a start value! ! Needs to pick target bits, a "mask"! ! Find ones that create long sequences! ! Special cases with short sequence may occur 9(80)9(80) Information Coding / Computer Graphics, ISY, LiTH PRBS, example 8 bits Sequence of 254 numbers 01000101 1 at end -> XOR with mask 10010000 106 53 82 41 92 46 23 67 105 124 62 31 71 107 125 118 59 85 98 49 80 40 20 10 5 74 37 90 45 94 47 95 103 123 117 114 57 84 42 21 66 33 88 44 22 11 77 110 55 83 97 120 60 30 15 79 111 127 119 115 113 112 56 28 14 7 75 109 126 63 87 99 121 116 58 29 70 35 89 100 50 25 68 34 17 64 32 16 8 4 2 1 72 36 18 9 76 38 19 65 104 52 26 13 78 39 91 101 122 61 86 43 93 102 51 81 96 48 24 12 6 3 73 108 54 27 69 10(80)10(80) Information Coding / Computer Graphics, ISY, LiTH Random library functions ! Pseudo-random number functions are in most run-time libraries! ! High quality random functions, long sequencies! ! rand() and srand() in the standard libraries! ! random() and srandom()! ! Not cryptographically secure; irrelevant for us. 11(80)11(80) Information Coding / Computer Graphics, ISY, LiTH But... ! The random number libraries are generally sequential!! ! Not useable in a shader.! ! Also questioable in the parallel image generation model.! ! In shaders, we need another solution! 12(80)12(80) Information Coding / Computer Graphics, ISY, LiTH Random numbers in GLSL GLSL runs on the GPU! ! Built-in random functions never worked (!)! ! Typical ways to get noise in GLSL:! ! Noise texture, pre-generated noise! ! Feed shader continuously with numbers from host! ! Render to texture! !! Truncated trigonometric numbers! 13(80)13(80) Information Coding / Computer Graphics, ISY, LiTH Noise texture Really pre-generated number in any kind of buffer! ! Easy to do! ! Static! ! Can be used for both static things and some animations (example: snow) 14(80)14(80) Information Coding / Computer Graphics, ISY, LiTH Continous feeding Run random generator on host (CPU)! ! Feed new random numbers every frame! ! Much data traffic! ! Much load on CPU 15(80)15(80) Information Coding / Computer Graphics, ISY, LiTH Generating random sequences on the GPU Run random generator on GPU, in a shader! ! Take a previoius number from a buffer (texture) and generate a new one from that.! ! Initialize by uploading a random texture generated on CPU.! ! Save to a texture(FBO).! ! GPU local - fast! ! Good for randomness that changes over time. 16(80)16(80) Information Coding / Computer Graphics, ISY, LiTH Repeatable randomness Random numbers generated from static seeds! ! Same random number every time.! ! Useful for noise-based images and expandable geometry. 17(80)17(80) Information Coding / Computer Graphics, ISY, LiTH Truncated trigonometric numbers Smart trick with built-in functions! ! M is a number >> 1! ! n = sin(x) * M! ! r = n - (int)n 18(80)18(80) Information Coding / Computer Graphics, ISY, LiTH Plain sin function ! f := sin(x);! ! Nothing random about it 19(80)19(80) Information Coding / Computer Graphics, ISY, LiTH Multiply by 2, take the fraction part f := frac(sin(x) * 2); 20(80)20(80) Information Coding / Computer Graphics, ISY, LiTH But if we multiply by more... f := frac(sin(x) * 10); 21(80)21(80) Information Coding / Computer Graphics, ISY, LiTH...and even more... ! f := frac(sin(x) * 100); 22(80)22(80) Information Coding / Computer Graphics, ISY, LiTH abs() to keep on one side and go high ! f := frac(sin(x) * 100000); 23(80)23(80) Information Coding / Computer Graphics, ISY, LiTH Truncated trigonometric numbers We now have a non-sequential random number generator! Only the pixel position is needed!! ! Just never take steps by π! 24(80)24(80) Information Coding / Computer Graphics, ISY, LiTH Random pixel values Random intensity 25(80)25(80) Information Coding / Computer Graphics, ISY, LiTH Random numbers by permutation polynoms ! Drawback with truncated harmonic functions: The result is implementation dependent!! ! Randomness by truncating an integer-based function using the modulo function.! ! Stefan suggests! ! hash = (34x2 + 10x) mod 289! ! Creates same result on all machines! 26(80)26(80) Information Coding / Computer Graphics, ISY, LiTH Permutation polynoms - usage ! The hash function must be called twice!! ! 2 hash = (34i + 10i) mod 289! ! hash(hash(x)+y);! ! This creates a nice randomness: 27(80)27(80) Information Coding / Computer Graphics, ISY, LiTH More randomness ! See the course book (part 1)!! ! Several more methods, integer and floating point hash functions, much focus on repeatable randomness. 28(80)28(80) Information Coding / Computer Graphics, ISY, LiTH Uses of randomness ! Like above: Random patterns! ! Random geometrical patterns! ! Random movement! ! Random location! ! Random geometry! ! and more... 29(80)29(80) Information Coding / Computer Graphics, ISY, LiTH Random geometrical patterns ! Vary the contents of areas 30(80)30(80) Information Coding / Computer Graphics, ISY, LiTH Random movement ! Vary the speed or direction of moving objects 31(80)31(80) Information Coding / Computer Graphics, ISY, LiTH Random location ! Vary the translation of objects 32(80)32(80) Information Coding / Computer Graphics, ISY, LiTH Random geometry ! Vary parameters of objects 33(80)33(80) Information Coding / Computer Graphics, ISY, LiTH And more! ! Noise functions!! ! White noise! ! Colored noise! ! Perlin noise! ! Voronoi noise! ! ! But for the better ones we need splines: 34(80)34(80)