SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2011, 2012, 2013, 2014
XNA Game Development
L05 – Texturing
that appears in a video game needs to be textured; this includes everything from plants
to people. If things aren’t textured well, your game just won’t look right.
Texturing
• What’s it?!
Textures are images applied to surfaces that are created using primitive objects
Texturing
• What’s it?!
Textures are images applied to surfaces that are created using primitive objects
XNA is Perfect at Texturing
textures can be colored, filtered, blended,
and transformed at run time!
Texturing
• What’s it?!
Textures are images applied to surfaces that are created using primitive objects
textures can be colored, filtered, blended,
and transformed at run time!
XNA is Perfect at Texturing
XNA supports:
.bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga image formats for textures
Texturing
• UV Coordinates
– 2D World
• a texture is a two-dimensional object that is mapped onto a 2D polygon
– 3D World
• a texture is a two-dimensional object that is mapped onto a 3D polygon
Texturing
• UV Coordinates
Texturing
• Vertex Types for Textures
Texturing
• Vertex Types for Textures
– VertexPositionColorTexture
– VertexPositionNormalTexture
– VertexPositionTexture
Texturing
• VertexPositionColorTexture
– This format allows you to apply image textures to your primitive shapes, and you can even
shade your images with color.
– For example, with this vertex type you could draw a rectangle with an image texture and then
you could show it again with a different shade of color!
VertexPositionColorTexture vertex = new
VertexPositionColorTexture(Vector3 position, Color color, Vector2 uv);
Texturing
• VertexPositionNormalTexture
– This format allows you to add textures to your primitive objects. The normal data enables
lighting for this textured format.
VertexPositionNormalTexture vertex = new
VertexPositionNormalTexture(Vector3 position, Vector3 normal, Vector2 uv);
Texturing
• VertexPositionTexture
– This format only permits storage of position and texture data.
– It may be useful if you don’t need lighting and were concerned about saving space or
improving performance for large amounts of vertices.
VertexPositionTexture vertex = new
VertexPositionTexture(Vector3 position, Vector2 uv);
Texturing
• TRANSPARENT TEXTURES
Texturing
• TRANSPARENT TEXTURES
Texturing
• TRANSPARENT TEXTURES
Texturing
• TRANSPARENT TEXTURES
Texturing
• TRANSPARENT TEXTURES
An alpha channel can be used to “mask” all pixels of a specific color in an image. Alpha
data is stored in the last color byte of a pixel after the red, green, and blue bytes.
When alpha blending is enabled in your XNA code and the alpha channel is active,
transparency is achieved for the pixels where the alpha setting is set to 0.
New “Alpha” Channel!
Texturing
• TRANSPARENT TEXTURES
An alpha channel can be used to “mask” all pixels of a specific color in an image. Alpha
data is stored in the last color byte of a pixel after the red, green, and blue bytes.
When alpha blending is enabled in your XNA code and the alpha channel is active,
transparency is achieved for the pixels where the alpha setting is set to 0.
New “Alpha” Channel!
Texturing
• Texture Coloring “Shaders”
– Microsoft Book, Chapter 9, Page 119
• Texture Example (Learning XNA 3.0 “O’Riley” , P:205)
A Simple Texture Sample
Texturing
• Loading Textures through content manager
Texture2D texture = Content.Load<Texture2D>("ImagesimageName");
Texturing
• Let’s make a texture in a 3D world!
VertexPositionTexture[] verts;
Texturing
• LoadContent()
verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0));
verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0));
verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1));
verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));
Texturing
• LoadContent()
verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0));
verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0));
verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1));
verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));
Texturing
• LoadContent()
verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0));
verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0));
verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1));
verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));
0,0 1,0
0,1 1,1
texture = Content.Load<Texture2D>(@"arrow");
Texturing
• Draw()
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world;
effect.View = view;
effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
0,0 1,0
0,1 1,1
Texturing
• Draw()
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world;
effect.View = view;
effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
0,0 1,0
0,1 1,1
Texturing
• Draw()
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world;
effect.View = view;
effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
Texturing
Texturing
• Draw()
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world;
effect.View = view;
effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 1);
}
Texturing
Texturing
• Now, How can we fix the black area?!
Texturing
• Now, How can we fix the black area?!
Texturing
• Now, How can we fix the black area?!
Texturing
• 1st , Make sure that the image supports transperancy “.png”
Texturing
• 2nd, We should tell the GraphicsDevice to blend the image for us
Texturing
• Alpha Channel!
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
• Cool!
• “App1-Texturing”
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texturing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = world; effect.View = view; effect.Projection = projection;
effect.Texture = texture;
effect.TextureEnabled = true;
BlendState originalState = GraphicsDevice.BlendState;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}
GraphicsDevice.BlendState = originalState;
base.Draw(gameTime);
}
Texture Tiling
Texturing
• TEXTURE TILING
Texturing
Tiling is a very simple effect that creates a
repeating pattern of an image on the
surface of a primitive object.
Texturing
• TEXTURE TILING
Texturing
• TEXTURE TILING
Using a small image to cover a large surface makes tiling a useful way
to increase the performance of your textures and decrease the size of
your image files.
Texture Tiling
• In Load Content
// Right Top
verts[0] = new VertexPositionTexture(
new Vector3(-1, 1, 0), new Vector2(10, 0));
// Left Top
verts[1] = new VertexPositionTexture(
new Vector3(1, 1, 0), new Vector2(1, 0));
// Right Bottom
verts[2] = new VertexPositionTexture(
new Vector3(-1, -1, 0), new Vector2(10, 10));
// Left Bottom
verts[3] = new VertexPositionTexture(
new Vector3(1, -1, 0), new Vector2(1, 10));
Texture Tiling
Texture Tiling
Still something wrong!
If the texture rotates, the back of the texture is not drawn!
Why?! And how to fix this?
Texture Tiling
• Fixing the culling
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
RasterizerState currentRasterizerState =
GraphicsDevice.RasterizerState;
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
// … our code
GraphicsDevice.RasterizerState = currentRasterizerState;
base.Draw(gameTime);
}
Texture Tiling
• Fixing the culling
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
RasterizerState currentRasterizerState =
GraphicsDevice.RasterizerState;
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
// … our code
GraphicsDevice.RasterizerState = currentRasterizerState;
base.Draw(gameTime);
}
Billboarding
Billboarding
• Billboarding “Microsoft Book – Page 129”
Billboarding
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
Billboarding
• The math
Billboarding
• Atan2(y,x) Vs Atan(y/x)
Billboarding
• Atan2(y,x) Vs Atan(y/x)
Read more at http://en.wikipedia.org/wiki/Atan2/
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
rotationY = Matrix.CreateRotationY(GetViewerAngle());
Billboarding
float GetViewerAngle()
{
// use camera look direction to get
// rotation angle about Y
float x = cam.view.X - cam.position.X;
float z = cam.view.Z - cam.position.Z;
return (float)Math.Atan2(x, z) + MathHelper.Pi;
}
rotationY = Matrix.CreateRotationY(GetViewerAngle());

Contenu connexe

Tendances

Super Resolution in Digital Image processing
Super Resolution in Digital Image processingSuper Resolution in Digital Image processing
Super Resolution in Digital Image processingRamrao Desai
 
Adaptive Median Filters
Adaptive Median FiltersAdaptive Median Filters
Adaptive Median FiltersAmnaakhaan
 
Digital image processing short quesstion answers
Digital image processing short quesstion answersDigital image processing short quesstion answers
Digital image processing short quesstion answersAteeq Zada
 
SinGAN for Image Denoising
SinGAN for Image DenoisingSinGAN for Image Denoising
SinGAN for Image DenoisingKhalilBergaoui
 
Image Degradation & Resoration
Image Degradation & ResorationImage Degradation & Resoration
Image Degradation & ResorationSanjay Saha
 
Image Acquisition and Representation
Image Acquisition and RepresentationImage Acquisition and Representation
Image Acquisition and RepresentationAmnaakhaan
 
Labview with dwt for denoising the blurred biometric images
Labview with dwt for denoising the blurred biometric imagesLabview with dwt for denoising the blurred biometric images
Labview with dwt for denoising the blurred biometric imagesijcsa
 
Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Varun Ojha
 
3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slidesBHAGYAPRASADBUGGE
 
Fractal Image Compression By Range Block Classification
Fractal Image Compression By Range Block ClassificationFractal Image Compression By Range Block Classification
Fractal Image Compression By Range Block ClassificationIRJET Journal
 
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'Seldon
 
SinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural ImageSinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural ImageJishnu P
 
Digital image processing img smoothning
Digital image processing img smoothningDigital image processing img smoothning
Digital image processing img smoothningVinay Gupta
 
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...Koteswar Rao Jerripothula
 

Tendances (20)

1873 1878
1873 18781873 1878
1873 1878
 
Super Resolution in Digital Image processing
Super Resolution in Digital Image processingSuper Resolution in Digital Image processing
Super Resolution in Digital Image processing
 
F0533134
F0533134F0533134
F0533134
 
Adaptive Median Filters
Adaptive Median FiltersAdaptive Median Filters
Adaptive Median Filters
 
Digital image processing short quesstion answers
Digital image processing short quesstion answersDigital image processing short quesstion answers
Digital image processing short quesstion answers
 
SinGAN for Image Denoising
SinGAN for Image DenoisingSinGAN for Image Denoising
SinGAN for Image Denoising
 
Image Degradation & Resoration
Image Degradation & ResorationImage Degradation & Resoration
Image Degradation & Resoration
 
Ijebea14 283
Ijebea14 283Ijebea14 283
Ijebea14 283
 
Image Acquisition and Representation
Image Acquisition and RepresentationImage Acquisition and Representation
Image Acquisition and Representation
 
Bh044365368
Bh044365368Bh044365368
Bh044365368
 
Image restoration
Image restorationImage restoration
Image restoration
 
Labview with dwt for denoising the blurred biometric images
Labview with dwt for denoising the blurred biometric imagesLabview with dwt for denoising the blurred biometric images
Labview with dwt for denoising the blurred biometric images
 
Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)Chapter 1 introduction (Image Processing)
Chapter 1 introduction (Image Processing)
 
3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides
 
Fractal Image Compression By Range Block Classification
Fractal Image Compression By Range Block ClassificationFractal Image Compression By Range Block Classification
Fractal Image Compression By Range Block Classification
 
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'
Tensorflow London 13: Zbigniew Wojna 'Deep Learning for Big Scale 2D Imagery'
 
SinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural ImageSinGAN - Learning a Generative Model from a Single Natural Image
SinGAN - Learning a Generative Model from a Single Natural Image
 
Digital image processing img smoothning
Digital image processing img smoothningDigital image processing img smoothning
Digital image processing img smoothning
 
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...
[PDF] Automatic Image Co-segmentation Using Geometric Mean Saliency (Top 10% ...
 
20100822 computervision veksler
20100822 computervision veksler20100822 computervision veksler
20100822 computervision veksler
 

Similaire à XNA L05–Texturing

CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture MappingMark Kilgard
 
Anatomy of a Texture Fetch
Anatomy of a Texture FetchAnatomy of a Texture Fetch
Anatomy of a Texture FetchMark Kilgard
 
Demystifying Neural Style Transfer
Demystifying Neural Style TransferDemystifying Neural Style Transfer
Demystifying Neural Style TransferSEMINARGROOT
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf AtlantaJanie Clayton
 
Generating super resolution images using transformers
Generating super resolution images using transformersGenerating super resolution images using transformers
Generating super resolution images using transformersNEERAJ BAGHEL
 
GFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ESGFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ESPrabindh Sundareson
 
Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)basisspace
 
DPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingDPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingMrLawler
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturingSardar Alam
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter NotesJanie Clayton
 
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014Mary Chan
 
Texture mapping in_opengl
Texture mapping in_openglTexture mapping in_opengl
Texture mapping in_openglManas Nayak
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014Jarosław Pleskot
 
Texture By Priyanka Chauhan
Texture By Priyanka ChauhanTexture By Priyanka Chauhan
Texture By Priyanka ChauhanPriyanka Chauhan
 
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effectsナム-Nam Nguyễn
 
Overview of Convolutional Neural Networks
Overview of Convolutional Neural NetworksOverview of Convolutional Neural Networks
Overview of Convolutional Neural Networksananth
 

Similaire à XNA L05–Texturing (20)

CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 
Anatomy of a Texture Fetch
Anatomy of a Texture FetchAnatomy of a Texture Fetch
Anatomy of a Texture Fetch
 
8thlightu3
8thlightu38thlightu3
8thlightu3
 
Demystifying Neural Style Transfer
Demystifying Neural Style TransferDemystifying Neural Style Transfer
Demystifying Neural Style Transfer
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta
 
Extreme dxt compression
Extreme dxt compressionExtreme dxt compression
Extreme dxt compression
 
Generating super resolution images using transformers
Generating super resolution images using transformersGenerating super resolution images using transformers
Generating super resolution images using transformers
 
GFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ESGFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ES
 
Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)
 
DPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingDPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture Mapping
 
Texturemapping
TexturemappingTexturemapping
Texturemapping
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturing
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
 
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
 
Texture mapping in_opengl
Texture mapping in_openglTexture mapping in_opengl
Texture mapping in_opengl
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014
 
Texture By Priyanka Chauhan
Texture By Priyanka ChauhanTexture By Priyanka Chauhan
Texture By Priyanka Chauhan
 
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
 
Overview of Convolutional Neural Networks
Overview of Convolutional Neural NetworksOverview of Convolutional Neural Networks
Overview of Convolutional Neural Networks
 

Plus de Mohammad Shaker

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian GraduateMohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyMohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesMohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - ColorMohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - TypographyMohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingMohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and ThreadingMohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsMohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and GamingMohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / ParseMohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesMohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and AdaptersMohammad Shaker
 

Plus de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Dernier

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

XNA L05–Texturing

  • 1. Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L05 – Texturing
  • 2. that appears in a video game needs to be textured; this includes everything from plants to people. If things aren’t textured well, your game just won’t look right.
  • 3. Texturing • What’s it?! Textures are images applied to surfaces that are created using primitive objects
  • 4. Texturing • What’s it?! Textures are images applied to surfaces that are created using primitive objects XNA is Perfect at Texturing textures can be colored, filtered, blended, and transformed at run time!
  • 5. Texturing • What’s it?! Textures are images applied to surfaces that are created using primitive objects textures can be colored, filtered, blended, and transformed at run time! XNA is Perfect at Texturing XNA supports: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga image formats for textures
  • 6. Texturing • UV Coordinates – 2D World • a texture is a two-dimensional object that is mapped onto a 2D polygon – 3D World • a texture is a two-dimensional object that is mapped onto a 3D polygon
  • 9. Texturing • Vertex Types for Textures – VertexPositionColorTexture – VertexPositionNormalTexture – VertexPositionTexture
  • 10. Texturing • VertexPositionColorTexture – This format allows you to apply image textures to your primitive shapes, and you can even shade your images with color. – For example, with this vertex type you could draw a rectangle with an image texture and then you could show it again with a different shade of color! VertexPositionColorTexture vertex = new VertexPositionColorTexture(Vector3 position, Color color, Vector2 uv);
  • 11. Texturing • VertexPositionNormalTexture – This format allows you to add textures to your primitive objects. The normal data enables lighting for this textured format. VertexPositionNormalTexture vertex = new VertexPositionNormalTexture(Vector3 position, Vector3 normal, Vector2 uv);
  • 12. Texturing • VertexPositionTexture – This format only permits storage of position and texture data. – It may be useful if you don’t need lighting and were concerned about saving space or improving performance for large amounts of vertices. VertexPositionTexture vertex = new VertexPositionTexture(Vector3 position, Vector2 uv);
  • 17. Texturing • TRANSPARENT TEXTURES An alpha channel can be used to “mask” all pixels of a specific color in an image. Alpha data is stored in the last color byte of a pixel after the red, green, and blue bytes. When alpha blending is enabled in your XNA code and the alpha channel is active, transparency is achieved for the pixels where the alpha setting is set to 0. New “Alpha” Channel!
  • 18. Texturing • TRANSPARENT TEXTURES An alpha channel can be used to “mask” all pixels of a specific color in an image. Alpha data is stored in the last color byte of a pixel after the red, green, and blue bytes. When alpha blending is enabled in your XNA code and the alpha channel is active, transparency is achieved for the pixels where the alpha setting is set to 0. New “Alpha” Channel!
  • 19. Texturing • Texture Coloring “Shaders” – Microsoft Book, Chapter 9, Page 119 • Texture Example (Learning XNA 3.0 “O’Riley” , P:205)
  • 21. Texturing • Loading Textures through content manager Texture2D texture = Content.Load<Texture2D>("ImagesimageName");
  • 22. Texturing • Let’s make a texture in a 3D world! VertexPositionTexture[] verts;
  • 23. Texturing • LoadContent() verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)); verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)); verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)); verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));
  • 24. Texturing • LoadContent() verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)); verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)); verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)); verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1));
  • 25. Texturing • LoadContent() verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)); verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)); verts[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)); verts[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1)); 0,0 1,0 0,1 1,1 texture = Content.Load<Texture2D>(@"arrow");
  • 26. Texturing • Draw() GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } 0,0 1,0 0,1 1,1
  • 27. Texturing • Draw() GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } 0,0 1,0 0,1 1,1
  • 28.
  • 29. Texturing • Draw() GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); }
  • 31. Texturing • Draw() GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 1); }
  • 33. Texturing • Now, How can we fix the black area?!
  • 34. Texturing • Now, How can we fix the black area?!
  • 35. Texturing • Now, How can we fix the black area?!
  • 36. Texturing • 1st , Make sure that the image supports transperancy “.png”
  • 37. Texturing • 2nd, We should tell the GraphicsDevice to blend the image for us
  • 39. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 41. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 42. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 43. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 44. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 45. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 46. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 47. Texturing protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); BasicEffect effect = new BasicEffect(GraphicsDevice); effect.World = world; effect.View = view; effect.Projection = projection; effect.Texture = texture; effect.TextureEnabled = true; BlendState originalState = GraphicsDevice.BlendState; GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleStrip, verts, 0, 2); } GraphicsDevice.BlendState = originalState; base.Draw(gameTime); }
  • 50. Texturing Tiling is a very simple effect that creates a repeating pattern of an image on the surface of a primitive object.
  • 52. Texturing • TEXTURE TILING Using a small image to cover a large surface makes tiling a useful way to increase the performance of your textures and decrease the size of your image files.
  • 53. Texture Tiling • In Load Content // Right Top verts[0] = new VertexPositionTexture( new Vector3(-1, 1, 0), new Vector2(10, 0)); // Left Top verts[1] = new VertexPositionTexture( new Vector3(1, 1, 0), new Vector2(1, 0)); // Right Bottom verts[2] = new VertexPositionTexture( new Vector3(-1, -1, 0), new Vector2(10, 10)); // Left Bottom verts[3] = new VertexPositionTexture( new Vector3(1, -1, 0), new Vector2(1, 10));
  • 55. Texture Tiling Still something wrong! If the texture rotates, the back of the texture is not drawn! Why?! And how to fix this?
  • 56. Texture Tiling • Fixing the culling protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); RasterizerState currentRasterizerState = GraphicsDevice.RasterizerState; GraphicsDevice.RasterizerState = RasterizerState.CullNone; // … our code GraphicsDevice.RasterizerState = currentRasterizerState; base.Draw(gameTime); }
  • 57. Texture Tiling • Fixing the culling protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); RasterizerState currentRasterizerState = GraphicsDevice.RasterizerState; GraphicsDevice.RasterizerState = RasterizerState.CullNone; // … our code GraphicsDevice.RasterizerState = currentRasterizerState; base.Draw(gameTime); }
  • 61. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; }
  • 62. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; }
  • 63. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; }
  • 64. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; }
  • 65. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; }
  • 68. Billboarding • Atan2(y,x) Vs Atan(y/x) Read more at http://en.wikipedia.org/wiki/Atan2/
  • 69. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; } rotationY = Matrix.CreateRotationY(GetViewerAngle());
  • 70. Billboarding float GetViewerAngle() { // use camera look direction to get // rotation angle about Y float x = cam.view.X - cam.position.X; float z = cam.view.Z - cam.position.Z; return (float)Math.Atan2(x, z) + MathHelper.Pi; } rotationY = Matrix.CreateRotationY(GetViewerAngle());