Download presentation
Presentation is loading. Please wait.
Published byYesenia Blay Modified over 10 years ago
1
CSE3AGT – Zones Portals and Anti-Portals, Fog and Ray Tracing Paul Taylor 2010
2
Zones, Portals and Anti-Portals With Pictures!
3
Zones Air-tight areas of your level that constitute different areas. http://www.hourences.com/book/tutorialszoni ng.htm
4
Portals These are the windows between your Zones You can either think of zones as airtight areas, or pretend to fill them with water
5
A more effective Zone / Portal combination
6
Occlusion Planes A newer advance in pre-rendering occlusion – This was one of the key technologies that enabled large open-world games to be created A plane which is inserted into any object which is large enough to be a ‘good’ occluder
7
The Bigger the Better!
8
Remember what occluders do
9
Get Creative! Don’t forget your ceilings and floors! You should keep your visible occluders down to only like 3 or 4
10
Fog is your friend!
11
Bonuses Much shorter Z-Depth Required before culling Heavy Fog can be used in situations of high complexity Even on a ‘Sunny Clear Day’ with huge draw- distances, fog can be used to stop pop-in
12
Negatives More code in your shaders Easily offset by the savings in polygons Some extra possible issues with artefacts Fatter Vertices
13
How? Two Main Methods: Vertex Based Fog - Cheaper Table Based Fog (Pixel Fog) - Expensive Important Attributes Distance (range / plane) Drop Off (Very similar to lighting!) Z or W based
14
Vertex Fog Functions in a similar way to Per Vertex Colours, or Per Vertex Lighting Fog values are interpolated across polygons based on Vertex Values All the usual per-vertex problems apply here too!
15
Plane Based Fog
16
Range Ranged based fog has a start and an end – Vertices before the FogStart are unfogged, Vertices after FogEnd are Completely obscured – A function is used to interpolate from FogStart to FogEnd Simplest: Linear Interpolation More complex: Eg: Exponential, quadratic, etc.
17
Range Based Fog
18
Linear Fog
19
Exponential Fog (2 types) D = distance from viewpoint Density = Variable from 0.0 to 1.0 The second equation has a steeper gradient through the middle section http://msdn.microsoft.com/en- us/library/bb173401%28VS.85%29.aspx
20
Exponential Fog Curves Linear Fog
21
Vertex Based Fog Limitations
22
Polygon based Fog & Non Z Objects Fail!
23
A Tessellation Solution
24
Z-Fog The most basic Pixel Fog is Z-Fog (Depth-Fog) Things that can go wrong: Tilting on the Y axis results in: http://cs.gmu.edu/~jchen/cs662/fog.pdf
25
Why does it happen? Side View of the previous slide
26
How can we solve it? We could Fix the rotation on the Y axis Or we could calculate the true distance from eye to each pixel. It just so happens that we can get this value for free (Processing wise, we will need an extra float per vertex)
27
W-Fog (The DX9 Way) What is W? How do we make sure W exists? Both these matrices will work perfectly as an XYZ projection matrix. Below will create a W = Z * S. not exactly helpful. Above will Incorrect Projection Matrix for Accurate W Based Fog Correct Projection Matrix for Accurate W based Fog
28
W-Fog the DX10 Way W Fog is easy, we already use world coordinates for vertices in our lighting, so we can just add a float to pass the eye-vertex distance to the pixel shader
29
Newest Fog Technologies Technical Innovations to reduce your visibility! If you want to be ‘at the front’ you need to be looking for papers from Google Scholar! – Take each idea you like, figure out how it’s done, then figure out what you could do better! The following is from the latest build of the UDK
30
Exponential Height Fog New kind of global fog with density that decreases with height Never creates a hard line (unlike standard fog); supports one layer Can specify both "towards the light" and "away from the light" colours Rendering cost similar to two layers of constant density height fog Can now use different colours for the hemisphere facing the light and vice versa
31
Constant Density Height Fog
32
Exponential Height Fog http://udn.epicgames.com/Three/rsrc/Three/C ontentBlog/1ExpResized.jpg
33
Pipelines are for Chumps Raycasting and Raytracing
34
Ray Casting Definition Time There are two definitions of Ray Casting The Old and the New The old was related to 3D games back in the Wolfenstein / Doom 1 Era. Where gameplay was on a 2D platform The New definition is: – Non Recursive Ray Tracing
35
Ray Tracing http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_1_Introduction.shtml Glass Ball
36
Rays from the Sun or from the Screen Rays could be programmed to work in either direction We choose from the screen to the Light – Only X x Y Pixels to trace From the Light we would need to emulate Millions of Rays to find the few thousand that reach the screen
37
Our Rays
38
Center of Projection (0,0)
39
Viewport (0,0) Screen Clipping Planes
40
Into World Coordinates (0,0) Screen Clipping Planes
41
Getting Each Initial Ray Origin = (0,0,0) Direction = ScreenX,screenY, zMin – ScreenX, ScreenY are the float locations of each pixel in projected world coordinates – zMin is the plane on which the screen exists
42
Surface Materials Surfaces must have their Material Properties set – Diffuse, Reflective, Emissive, and Colour need to be considered
43
For Each Pixel (the main Raytrace loop) For each pixel { Construct ray from camera through pixel Find first primitive hit by ray Determine colour at intersection point Draw colour to pixel Buffer }
44
Intersections The simplest way is to loop through all your primitives (All Polygons) – If the Polygon Normal DOT RayDirection(Cos Theta) < 0 // Face is opposite to Ray Ignore – Now we can Intersect the Ray with the Polygon – Or Intersect the Ray with the Polygons Plane
45
Ray / Polygon Intersection p0, p1 and p2 are verts of the triangle point(u,v) = (1-u-v)*p0 + u*p1 + v*p2 U > 0 V > 0 U + V <= 1.0
46
Line Representation point(t) = p + t * d t is any point on the line p is a known point on the line D is the direction vector Combined: p + t * d = (1-u-v) * p0 + u * p1 + v * p2 A Point on the line (p + t * d) which Is part of the triangle [(1-u-v) * p0 + u * p1 + v * p2]
47
http://www.lighthouse3d.com/opengl/maths/index.php?raytriint
48
Intersections Suck! http://local.wasp.uwa.edu.au/~pbourke/geom etry/planeline/ http://local.wasp.uwa.edu.au/~pbourke/geom etry/planeline/ http://www.netcomuk.co.uk/~jenolive/vect18 c.html http://www.netcomuk.co.uk/~jenolive/vect18 c.html http://softsurfer.com/Archive/algorithm_0104 /algorithm_0104B.htm#Line- Plane%20Intersection http://softsurfer.com/Archive/algorithm_0104 /algorithm_0104B.htm#Line- Plane%20Intersection http://members.tripod.com/~Paul_Kirby/vect or/Vplanelineint.html http://members.tripod.com/~Paul_Kirby/vect or/Vplanelineint.html
49
Intersecting a Plane A point on the Plane = p1 Plane Normal = n. Ray = p(t) = e + td P(t) = Point on Ray E = Origin D = Direction Vector t = [(P1 – e). n]/ d.n
50
World / Object Coordiantes We need to translate the Ray into Object Coordinates / Vice Versa to get this to work Ray = p(t) = e + td Ray = Inv (Object->World)e + t Inv (Object- >World)d
51
After Finding the Intersecting Plane You need a simple way to check for a hit or miss If your Object has a bounding box this can be achieved through a line check
52
Miss Conditions
54
Hit Conditions
55
For Other Shaped Flat Polygons An Even Number of Intersections with the Outside of the Polygon means a Miss An Odd Number of Intersections means a Hit
56
Task List for Ray Casting 1)Create a vector for each Pixel on the screen a)From the Origin of the Camera Matrix (0,0,0) b)That intersects with a Pixel in the screen 2)Use this Vector to create a trace through the World a)From the Zmin to the Zmax Clipping Volume b)UnProjected into World Coordinates 3)Intersect the trace with every object in the world
57
4)When the ray hits an Object we need to check how the pixel should be lit a)Check if the Ray has a direct view to each of the lights in the scene b)calculate the input from each light. c)Color the pixel based on the lighting and surface properties
58
One extra task for Ray Casting After Intersection Calculate the reflective Vector – Dot Product of Ray and Surface Normal Then cast a new Ray – This continues in a recursive fashion untill: A ray heads off into the universe A ray hits a light We reach our maximum recursion level
59
How we would like to be able to calculate light
60
Conservation of Energy A Physics-Based Approach to Lighting – Surfaces will absorb some light, and reflect some light – Any surfaces may also be light emitting – Creating a large simultaneous equation can solve the light distribution (I mean LARGE) – The light leaving a point is the sum of the light emitted + the sum of all reflected light
61
Don’t Scream (loudly)
62
The Rendering Equation http://en.wikipedia.org/wiki/Rendering_equation Light Leaving Point X in direction Light Emitted by Point X in direction Integral over the Input Hemisphere Bidirectional reflective function (BDRF) in the direction from direction ’ Light toward Point X from direction ’ Attenuation of inward light related to incidence angle
63
The Monte Carlo Method Repeated Random Sampling Deterministic Algorithms may be unfeasibly complex (light)
64
Metropolis Light Transport A directed approach to simplifying the BDRF Still considered a Monte Carlo Method It directs the randomness considering more samples from directions with a higher impact on the point being assessed
65
BDRF Tracing http://graphics.stanford.edu/papers/metro/
66
Metropolis Light Transport http://graphics.stanford.edu/papers/metro/
67
Radiosity Simplifying the Rendering Equation by making all surfaces perfectly diffuse reflectors This simplifies the BDRF function
68
Ray Tracing and the GPU
69
Adios Larrabee! http://www.thinq.co.uk/news/2010/5/26/inte l-abandons-discrete-graphics/ http://www.thinq.co.uk/news/2010/5/26/inte l-abandons-discrete-graphics/
70
DIY CUDA (An Introduction to it!) Stolen From NVIDIA_CUDA_Tutorial_No_NDA_Apr08.pdf
87
*GTX 260 : 192 CUDA Cores
94
Perhaps a better example This shows the scalability of CUDA arrays
104
CUDA References to get you going http://llpanorama.wordpress.com/cuda- tutorial/ http://llpanorama.wordpress.com/cuda- tutorial/ http://users.ece.gatech.edu/~lanterma/mpg0 8/ http://users.ece.gatech.edu/~lanterma/mpg0 8/
105
The main CUDA point: Compute Shaders follow the same logic You’ll need to be epic with compute shaders to be highly desirable in industry It’ll give you massive credibility in Cluster Software development – A lot of clusters are moving toward GPU horsepower High Performance Computing = – Technical Proficiency – Lots of cash – Games Related Knowledge gives you an extreme edge over other parallel programmers
106
DIY Farming by Bungie http://www.bungie.net/images/Inside/publica tions/presentations/Life_on_the_Bungie_Far m.pptx http://www.bungie.net/images/Inside/publica tions/presentations/Life_on_the_Bungie_Far m.pptx
107
References http://developer.nvidia.com/object/Implemen ting_Fog_Direct3D.html http://developer.nvidia.com/object/Implemen ting_Fog_Direct3D.html http://www.hourences.com/book/tutorialszo ning.htm http://www.hourences.com/book/tutorialszo ning.htm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.