Presentation is loading. Please wait.

Presentation is loading. Please wait.

67535: Computer Games Programming Week 2: Randomness: Perlin noise and Fractals Lighting: Phong-Blinn-Giraud; HDR Tutorial: Phong lighting in a fragment.

Similar presentations


Presentation on theme: "67535: Computer Games Programming Week 2: Randomness: Perlin noise and Fractals Lighting: Phong-Blinn-Giraud; HDR Tutorial: Phong lighting in a fragment."— Presentation transcript:

1 67535: Computer Games Programming Week 2: Randomness: Perlin noise and Fractals Lighting: Phong-Blinn-Giraud; HDR Tutorial: Phong lighting in a fragment shader

2 Noise

3 Noise and Procedural Modeling Create interest through difference Hide repeating patterns and artefacts from other generation methods (e.g. faulting) Can be used as a basis function for fractals Noise is like salt: adds flavour to procedural content

4 Noise can be used for everything Animation Textures Audio AI Crowd simulations Particle effects Any type of geometry

5 White Noise vs. Gradient Noise White noise is ok for subtle offsets Not smooth enough at small scale Not random enough at large scale

6 Perlin Noise Developed in early eighties by Ken Perlin for the movie “Tron” Gives a band-limited pseudo-random noise value for any given point in 1D 2D or 3D VERY fast to compute, still hard to beat the original implementation (1980’s) Invariant under rotation and translation Largely isotropic

7 Perlin Noise Scalar point field 1D, 2D, 3D, 4D …nD Must meet certain criteria to be a gradient noise Bandlimited Reproducible function Set range (usually –1 to 1) Stationary and Isotropic

8 Perlin Noise A gradient noise - uses a set of pseudo-random gradients at regularly spaced points and interpolate between (blending function) Overview:  Space divided into regular lattice  One pseudo-random wavelet per lattice point (or per side of cubical cell)  Scalar value of function = Sum of wavelets

9 Wavelets Wavelet:  a function which drops off to zero outside a given radius (one cell)  Integrates to zero (meaning it has positive and negative regions that balance each other out)  Has a value of zero at its centre  Has some randomly chosen gradient at its centre

10 Perlin Noise 1D Idea consistent in all dimensions, easily visualized in 1D Associate a pseudo-random gradient (slope) with each integer in 1D Notice at the int the gradient value is 0 Slopes are random

11 Perlin Noise 1D For any point on the line (non integer values) the value is the interpolation between the two closest values Interpolation is NOT linear Interpolation requires a continuous blending function No need to sum because 1D will only have one blend for any input value

12 Perlin Noise 2D This same approach can easily be extended to higher dimensions Now a grid rather than a line Each integer point now has a 2D gradient Noise value is computed from 4 closest points on the grid

13 Perlin Noise 2D For 2D (and higher dimensions), we need to sum up the contributions of each wavelet. Still use the blending function (spline) For 2D use a bilinear interpolation First interpolate in the x, then in the y using the results from the x Easily extends to 3D, 4D, …, nD

14 Note on Picking Gradients Don’t have to be the ones described here In 3D, for example, can be the corners of the cubic cell Or the midpoints of the cubic lines Just need to be evenly distributed over all directions, and have enough sample points

15 Perlin Noise Algorithm Summary Compute which cubical “cell” we are in Compute the wavelet centred on each of the surrounding sides of the cube Sum the wavelets Look at Procedural Modelling book and the Gustavson’s paper for implementation details

16 Fractals “A geometrically complex object, the complexity of which arises through a repetition of scale”. A simple way of generating extreme complexity Can be treated entirely heuristically, no need to understand the underlying maths Experimentation is a simple matter of changing parameters that alter the end result

17 Basis Function Fractals rely on repetition over scale Something must be repeated Technically anything can be used, but it is better if it’s: Controllable Self Similar Deterministic Easy to calculate

18 Fractals Use a variant of Perlin noise (absolute value, squared, etc) as a basis function How the basis function is rescaled and combined (through addition, multiplication, subtraction) determines the properties of the fractal Octaves indicate the dimensionality and fractional values can be extremely useful for continuous level of detail schemes

19 Perlin-based fractal Scale, add, repeat Good for clouds, water, soft terrain Can be a more detailed replacement for general noise (but also more expensive)

20 Clouds Add dimension to animate over time

21 Fractal terrain Resembles realistic rocky mountainous terrain Can produce infinite landscapes Can produce small detailed landscapes or massive ones

22 Multifractals Extends on homogenous fractals and blends two or more fractal functions together to create objects that exhibit a blend of features For example change the blend ratio over the height of the basis function to give sharp mountains, but soft hills and lowlands

23 Reading on Procedural Content Generation Games Programming Gems 1 & 2 Texturing and Modelling : A Procedural Approach Perlin: http://www.noisemachine.com/talk1/index.html http://http.developer.nvidia.com/GPUGems2/gpugems2_cha pter26.html Musgrave: http://www.ypoart.com/downloads/Musgrave.htm http://pcg.wikidot.com/ http://www.pandromeda.com/ http://www.planetside.co.uk/terragen/ algorithmicbotany.org/papers/abop/abop.pdf‎

24 Lighting

25 Lighting: real world Photons / lightwaves hitting atoms Reflection; refraction; interference; absorption…

26 Lighting: human perception Much simpler that the real world Limited to visible spectrum Separated into three colours (trichromaticity) Many real light effects are dismissed in favour of world constancy

27 Object shading Shading is a strong cue to object shape and material, and thus object identity NB: shape and identity can be derived not only from shading, but also from: Occlusion, relative size, eye focus, eyes’ convergence, relation to known objects, motion, viewer self-motion… Not all these can be modelled easily A shading model needs to give just enough cues to be effective and efficient, not to be realistic

28 Non-photorealistic rendering Note that shading does not have to be realistic to work e.g. Gooch NPR, based on technical illustration styles Pass 1: scene is rendered in white-hot-cold colour scheme based on angle between View and Normal Pass 2: edges are highlighted in Black

29 Phong and Phong-Blinn shading model Very simple computationally Just about good enough for practical purposes Does not look cool enough

30 Phong Bui-tuong (1975) The most common reflection model in CG An acceptable compromise between simplicity and accuracy Largely empirical Local reflection model – does not handle global effects of light reflecting between surfaces

31 “Standard” Lighting Model Three different models of lighting – Ambient term to approximate light arriving via other surfaces – Diffuse component for the amount of incoming light reflected equally in all directions – Specular component for the amount of light reflected in a mirror-like fashion …linearly combined

32 Lighting Formula This is very simple approximation, Particularly good for uniform materials such as plastic or metal – That’s why early CG images look like plastic and metal

33 Phong Lighting model I = A intensity * A colour + D intensity * D colour * N. L + S intensity * S colour *(R(V,N). V) n Lightsource properties: L, A intensity, D intensity, S intensity Material properties: A colour, D colour, S colour, n Shape property: N Camera position: V

34 Simplification I: Blinn Calculating R for every vertex is expensive Let H = (L + V) / |L+V| R V ≈ N H, especially (R V) a ≈ (N H) b For directional lights, H does not depend on object

35 Simplification II: Gouraud Evaluate the lighting model per vertex, then interpolate for surface fragments

36 Complication I: Ward Specular highlight is caused by a randomly faceted surface The distribution of facet normals defines the shape of the highlight e.g. Ward anisotropic distibution models asymmetrical facets

37 NB: Lighting space Face normals, light direction and camera positions must be in the same space In order to get the normals correctly specified in world or view space, we would multiply by world or view matrix – This does not preserve scaling – Need to use inverse-transposed world or view matrix – In most practical cases, inverse-transpose is equal to the matrix

38 HDR

39 Dynamic Range Dynamic range is the ratio between the largest and smallest possible values of a changeable quantity DR of an image is the ratio of brightness of the lightest and the darkest pixel; a measure of image contrast DR of a display is a ratio of brightness of the lightest and the darkest image the display can produce (full black to full white) DR of human eye at any given time: 1:10,000; overall (with accommodation): 1:1,000,000 DR of a good digital camera: 1:10,000 DR of an LCD display: 1:500 to 1:1,000 DR of a RGB colour space: 1:256

40 Resolution How many different levels are there between the minimum and the maximum value? Display: 256 gray levels Human perception: JND (Just Noticeable Difference) is much smaller and varies non-linearly depending on intensity, colour, overall luminance etc.

41 HDR imaging (digital photography)

42

43 HDR rendering Light calculations are done in high resolution and dynamic range – Float: DR of 1:65,536 Resulting brightness value of a pixel is translated to display DR as late as possible (i.e. pixel shader at the last stage of post- processing) Non-linear mapping functions (e.g. Sigmoids) Local tone-mapping (preserving local contrast)

44 HDR benefits


Download ppt "67535: Computer Games Programming Week 2: Randomness: Perlin noise and Fractals Lighting: Phong-Blinn-Giraud; HDR Tutorial: Phong lighting in a fragment."

Similar presentations


Ads by Google