Primary and Secondary Requirements due tomorrow dont get snowed into the CIT Collision debugger code should be completely gone You should be working in a different project May still be helpful for hacks including ramp hack ID: 757377
Download Presentation The PPT/PDF document "Lecture 9 Announcements Platformer2" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Lecture 11
AnnouncementsSlide2
Questions?IntroductionSlide3
Lecture
11
Procedural GenerationSlide4
WHITE NOISE
Procedural GenerationSlide5
What is noise?
Randomness
e.g. From 0 to 14 take a random number between 0 and 1
By itself, it is jagged and not usefulSlide6
White Noise
// returns a pseudorandom noise value for a given
seed
#include <random>
f
loat Terrain::noise(float seed) {
std
::
default_random_engine
e(seed);
std
::
uniform_real_distribution
<float> dis(0.0f, 1.0f);
return dis(e);
}Slide7
VALUE NOISE
Procedural GenerationSlide8
Value Noise
Smooth white noise by taking an average of neighbors
Turns white noise into something usefulSlide9
Value Noise
// returns a weighted average of the 9 points around the Vec2i v
float
Terrain::
valueNoise
(
glm
::ivec2
vec
) {
// four corners, each multiplied by 1/16
float corners
= ( noise(vec.x-1, vec.y-1) + noise(vec.x+1, vec.y-1) +
noise(vec.x-1, vec.y+1) + noise(vec.x+1, vec.y+1) ) / 16
// four sides, each multiplied by 1/8
float sides
= ( noise(vec.x-1,
vec.y
) + noise(vec.x+1,
vec.y
) +
noise(
vec.x
, vec.y-1) + noise(
vec.x
, vec.y+1) ) / 8
// center, multiplied by 1/4
float center
= noise(
vec.x
,
vec.y
) / 4
return center + sides + corners
}Slide10
INTERPOLATION
Procedural GenerationSlide11
Interpolation
Most interpolation functions take three arguments.
a
and
b
, the value to interpolate between.
t
, a value between 0 and 1.
When
t
is 0, function returns a
When
t
is 1, function returns
bSlide12
Interpolation
Option 1: linear interpolation
For values
a
and
b
and interpolation parameter
t
:
f = a * (1 - t) + b * tSlide13
Interpolation
Option 2: cosine interpolation
t’ = (1 - cos(t * pi)) / 2
f = a * (1 - t’) + b * t’
Slower, but much smootherSlide14
Interpolation
Option 3: cubic interpolation
t’ = 3t
2
- 2t
3
f = a * (1 - t’) + b * t’
Similar to cosineSlide15
Interpolation
Option 4: Perlin interpolation
t’ = 6t
5
- 15t
4
+ 10t
3
f = a * (1 - t’) + b * t’
Slightly slower than cubic
Super smoothSlide16
Fractional Coordinates
What if our x and y aren’t integers?
Just find the values along the vertices of the unit square and interpolate
x
0
, y
0
x
1
, y
0
x
1
, y
1
x
0
, y
1
x, ySlide17
Fractional Coordinates
// returns the noise interpolated from the four nearest vertices
float
Terrain::
interpolatedNoise
(
glm
::vec2
vec
){
glm
::ivec2
topLeft
=
glm
::ivec2
(
(
int
)
vec.x
, (
int
)
vec.y
);
glm
::ivec2
topRight
=
glm
::ivec2(
(
int
)
vec.x
+ 1, (
int
)
vec.y
);
gl
m
::ivec2
botLeft
=
glm
::ivec2(
(
int
)
vec.x
, (
int
)
vec.y
+ 1);
glm
::ivec2
botRight
=
glm
::ivec2
(
int
)
vec.x
+ 1, (
int
)
vec.y
+ 1);
float dx =
vec.x
– ((
int
)
vec.x
);
float
dy
=
vec.y
– ((
int
)
vec.y
);
float
topNoise
= interpolate(
valueNoise
(
topLeft
),
valueNoise
(
topRight
), dx);
float
botNoise
= interpolate(
valueNoise
(
botLeft
),
valueNoise
(
botRight
), dx);
return interpolate(
topNoise
,
botNoise
,
dy
);
}Slide18
PERLIN NOISE
Procedural GenerationSlide19
Perlin Noise
Named for its creator,
this guy
, Ken Perlin.
It’s a great way to make smooth, natural
noise which can be used to create terrain,
cloud patterns, wood grain, and more!
But you’ll probably use it for terrain…Slide20
Recall: Value Noise
Smooth white noise by taking an average of neighbors
Turns white noise into something usefulSlide21
Perlin Noise
Assign each vertex a pseudorandom gradient
g
lm
::vec2 gradient(
glm
::ivec2
vec
) {
float theta = noise(
vec
) *
2 * M_PI;
return
glm
::vec2(
cos
(theta),
sin
(theta));
}Slide22
Perlin Noise
The noise value of each vertex is the dot product of its gradient and the vertex to the target pointSlide23
Perlin Noise
Interpolate between the noise values of the four vertices (just like for value noise) Slide24
PERLIN NOISE VS VALUE NOISE
Procedural GenerationSlide25
Perlin Noise vs Value Noise
Value noise is easier
Perlin noise has fewer plateausSlide26
ADDING NOISE
Procedural GenerationSlide27
Adding Noise Functions
Freq.
1
2
4
8
Amp.
1
1
/
2
1
/
4
1
/
8
result
Noise
+
+
+
=Slide28
A Good Noise Function
What does our noise function need?
Given an (
x,y
) pair and a seed, returns the same value between 0 and 1 every time
C++ PRNGs
only take
a single seed as an argumentSlide29
A Good Noise Function
Hash the
glm
::ivec2
Returns a single
value that
is unique to each pair
Will return the same
value every
time
Use this number to generate your seedSlide30
Noise
// returns a pseudorandom noise value for a given position
float noise(Vec2i
vec
) {
Random r = new Random();
r.setSeed
(
vec.hashCode
()
);
return
r.nextFloat
();
}Slide31
References
What follows is a lot of pseudocode that contains concepts that we haven’t discussed
Persistence, octaves, etc.
Use this website as a reference for value noise:
https://web.archive.org/web/20160310084426/http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
Also covers an even smoother version of cubic interpolation
Use this website as a reference for Perlin noise:
http://flafla2.github.io/2014/08/09/perlinnoise.html
We stole our Perlin noise pictures from themSlide32
QUESTIONS?
Procedural GenerationSlide33
Lecture 10
Advanced GraphicsSlide34
ParticlesAdvanced GraphicsSlide35
ParticlesWhat is a particle?A particle is a tiny entity that is used in massive quantities to create a visually pleasing effect
Used to model effects like fire, liquids, hair, etc.
Conceptually old—first paper published in 1983Slide36
ParticlesWhat makes particles look good?Fade out or get smaller linearly over their lifespan
Once the particle is completely gone or transparent, it can be removed from the world
Adding some kind of randomness to how they move
Starting position, velocity, acceleration, color, size, shapeSlide37
ParticlesParticles are greatBut they are very slow if not done correctly
Things that make them slow:
It’s a lot of information to tick
It’s a lot of information to draw
There are way too many of them to consider doing collision detection against each otherSlide38
ParticlesWhat shape should my particles be?Sphere?
Too
many vertices
Triangle
Use a texture like this oneRotate the
triangle to
always face the camera
This texture has a black background and no alpha information
Use graphics->
enableBlendTest(Graphics::BLEND_FUNC::ADD)This says take all of the background, and add the color of this particle on top of it
Particles that are denser will appear brighterSlide39
Particle OptimizationsReduce the amount of information in your particles
Vector3 position, Vector3 velocity
maybe some noise values to make them scatter
Less information to tick
Don’t make your particles
GameObjects
Keep them in a separate list so that you can tick and draw them all at once
Binding the particle texture once and then drawing all your particles without unbinding and rebinding the texture is a HUGE improvement
Don’t
collide them with each other
If you must have your particles collide, have them collide only with entities or terrain, not with each otherThis means they also don’t need a shape, so they take up less spaceTick them in your draw loopOnly iterate over them onceDo them on the GPU (see CS 1230 lab)Slide40
Questions?ParticlesSlide41
Lecture 11
Maya and 3D SoftwareSlide42
So you need assets…How will you make them?
Characters, environment assets, etc.
Your engine allows for loading OBJs already, so why not make your own?Slide43
But how do I make them?There are a lot of 3D modeling programs out there to make 3D Assets
Maya, Blender,
Zbrush
Different programs have different benefits
We will focus on how to do basic modeling and shading of assets in Maya
Free for students!!
In general, good for all steps of the asset production process
Download here:
http://www.autodesk.com/education/free-software/mayaSlide44
The Maya GUI
primitives
Attribute editor and channel editor
Outliner
–
can be brought up from Window -> Outliner
Navigation tools
Dropdown menus
**v important**Slide45
ShortcutsLeft click to select objectsRight click and hold to bring up marking menuLeft click + alt to look around
Middle mouse click + alt to pan
W
–
translateE –
rotate
R
–
scale
F to focus on selected object1 – view geometry unsmoothed, 3
– view geometry smoothed, 4 – wireframe views, 5 – shaded view, 6 – shaded display with texture mapsSlide46
ModelinGCreating AssetsSlide47
Basic Modeling OperationsMoving particular edges and verticesExtrudingCombining meshesSlide48
Modeling tipsGeometry likes quadsThese will deform in less unexpected ways when you animate a characterSmoothing cubes vs. using spheres
Soft select
Orthographic views and sketches
Use a mouse for middle click!
SAVE FREQUENTLY for the love of godSlide49
shadingCreating AssetsSlide50
So now I have a gray cubeHow do I make it a colorful cube?UV MappingPlanar mapping –
X, Y, Z
UV Editor
Assigning new materials
Lambert, Blinn
, etc.
HypershadeSlide51
RiggingCreating AssetsSlide52
RiggingIn order to animate a static object, we need to rig it and skin it
Rigging is essentially constructing a working skeleton
Characters usually modeled in the standard “T-pose” to accommodate this process
Skinning is making sure the character mesh moves with the skeletonSlide53
Rigging and Skinning TipsThis takes a hell of a lot of time, so make only a very simple skeleton if you are planning on animating a characterTutorial:
https://www.youtube.com/watch?v=Ah-Jk7d30ks
Save all the time. Do it.Slide54
AnimatingCreating AssetsSlide55
Animations
Animations are made up of
keyframes
, or a transformation paired with a time value
3D animations are created by interpolating between keyframes and transforming the model appropriately
For example, we have a key at t=0 for y=0 and a key at t=2 for y=4, then at t=1 our object should be at y=2Slide56
Animating in MayaSlide57
Animating in MayaSlide58
Animating in MayaSlide59
ResourcesMaya tutorials: https://knowledge.autodesk.com/support/maya/learn-explore/caas/simplecontent/content/maya-tutorials.html
Doing the first few should get you well enough acquainted with the environment/simple modeling
Do a lot of googling!! Oftentimes entering the question into the search bar will get you the answer
There are so many YouTube tutorials out there. They are incredibly useful
Once again SAVE ALL THE TIME. This program can freeze and crash a LOTSlide60
Questions?Creating AssetsSlide61
Lecture 11
Rigged AnimationSlide62
What you’ll need in your engine
Skeleton or Rig class
Define the pose of a character model
Skinning
Deform character model based on position of all joints
Animations
Define keyframes poses
Interpolate pose between key frame poses
(Probably) Parse animation file type (e.g. .
fbx
) to create sequence of keyframe posesSlide63
SkeletonSkeleton represented as a treeEach joint is a node, may or may not have childrenStore transformation at each joint relative to parent joint
Global transformation of a joint = global transformation of parent * local transformation of joint relative to parent
Like CS123
Sceneview
Slide64
Consists of binding a skin (mesh) on top of a skeleton so that the mesh deform realistically when bones moveUseful for many animations
SkinningSlide65
SkinningGiven a set of vertices representing your mesh, and a set of joints or bones:
Determine how much each vertex is affected by each bone
Calculate how the changing bone positions affect the vertices they influence
The first item is something you’ll do while creating content, the last is your engine featureSlide66
Skinning: Vertex WeightsEach vertex will have bone/joint ‘weights’Should sum to 1Each weight determines how much bone affects it
Each vertex can have up to a set number (usually around 3-4) bones that affect it
Assigning weights will be done by hand in a program like MayaSlide67
Skinning: Vertex TransformationNeed to define “rest pose” of the mesh
Where the mesh vertices are when the skeleton is in standard T-pose
Extract the transformation of each vertex relative to associated bones
Next step: when pose changes deform vertices by interpolating transformation relative associated jointsSlide68
Skinning: Vertex TransformationExample: Linear Interpolation
Say we have joints 1 and 2 in the mesh
Let
v
be a vertex with joint weights
0.2
and
0.8
for joints 1 and 2
Let
v1 be the position of vertex v in the coordinate system of joint 1 in the initial mesh poseLet v
2
be the position of vertex
v
in the coordinate system of joint 2 in the initial mesh pose
Let
T
1
be the transformation of joint 1,
T
2
be the transformation of joint 2
v = 0.2 * T
1
* v
1
+ 0.8 * T
2
* v
2
http://scribblethink.org/Work/PSD/SSDtutorial.pdf
Other types of interpolation as well
Dual quaternion is the
most popularSlide69
Skinning: Vertex TransformationProbably want to perform this transformation in a vertex
shader
This way – GPU operates in parallel on all vertices
Need some way of passing skeleton, and vertex weights to the GPUSlide70
AnimationsKeyframesAt time t0, joint j
3
rotation is x
0
At time t1, joint j
3
rotation is x
1
Interpolate between
theseCombination of toolsEx. Joints animate with a function while character is moving, then interpolate back to resting positionSlide71
AnimationsAbstraction: build small animation pieces (ex. ‘swingArms’, ‘bounceTail
’) and combine them for more complex behaviors
Programs like Maya have these features and many more – look for inspiration to make something complexSlide72
AnimationsLoading animations from filesUse assimpIt can load all of the file types into common data structure
https://github.com/assimp/assimp
Slide73
Content Creation
Rigged animation takes good amount work to set up
But if you’re planning on creating content also expect to spend a lot time on making animations that look nice