# Week 5
- Lecture: Introducing UV texturing and texturing pipeline.
- Presentations: team based progress report.
- Tutorial: UV unwrapping.
- Making: Shading, texturing, and UV unwrapping.
- Advanced topic: PBR
- Hands on studio: team discussion & making.
- Assignment: Continuously work on your process report.
_____________________________________
# Pipeline: export & import assets to game engines
## Maya to Game Engine
### References
- [Maya 2018 online Help](http://help.autodesk.com/view/MAYAUL/2018/ENU//)
- [Unreal Engine 4 Documentation](https://docs.unrealengine.com/latest/INT/)
- [Unity Manual: Importing Objects](https://docs.unity3d.com/Manual/ImportingModelFiles.html)
- [Unity Manual: Supported Model file formats](https://docs.unity3d.com/Manual/3D-formats.html)
- Art of Maya [pdf link](http://web.cse.ohio-state.edu/~parent/classes/682/MAYA/art_of_maya.pdf): P. 81~85: Interactive 3D.
- Book: Rigging for Games by Eyal Assaf, 2015: based on using Maya and Unity.
## Unreal Engine
Unreal Engine is the world’s most open and advanced real-time 3D creation platform. Continously evolving to serve not only its original purpose as a state-of-the-art games engine, today it gives creators across industries the freedom and control to deliver cutting-edge content, interactive experiences, and immersive virtual worlds.
- description by [Unreal Engine.](https://www.unrealengine.com/en-US/)
The Unreal Engine is a game engine developed by Epic Games, first showcased in the 1998 first-person shooter game Unreal. Although primarily developed for first-person shooters, it has been successfully used in a variety of other genres, including stealth, MMORPGs, and other RPGs. With its code written in C++, the Unreal Engine features a high degree of portability and is a tool used by many game developers today.
The current release is Unreal Engine 4, designed for Microsoft's DirectX 11 and 12 (for Microsoft Windows, Xbox One, Windows RT); OpenGL (for OS X, Linux, PlayStation 4, iOS, Android, Ouya and Windows XP); and JavaScript/WebGL (for HTML5 Web browsers).
- [Wikipedia.](https://en.wikipedia.org/wiki/Unreal_Engine)
-----------
### Demo
- [Enterprise Summer Sizzle Reel 2019 | Unreal Engine](https://www.youtube.com/watch?v=iDqGtPHAecc&list=PLZlv_N0_O1gYfw89JtRX0bTb_YbxHOXwz)
- [NASA: Building the ISS in Unreal Engine](https://www.youtube.com/watch?v=WuyHqsjv-EY): The International Space Station is a unique place – a convergence of science, technology and human innovation that demonstrates new technologies and makes research breakthroughs not possible on Earth - [Nasa](https://www.nasa.gov/mission_pages/station/main/onthestation/facts_and_figures.html)
- [VR Editor - GDC 2016](https://www.youtube.com/watch?v=1VVr2vMVdjc): Epic's Mike Fricker and Nick Donaldson show the VR Editor, the full Unreal Editor running in VR mode, using Oculus Touch controls. The VR Editor is available now with Oculus and Vive support.
- [Procedural Nature Pack (UE4)](https://www.youtube.com/watch?v=gut5ermayK4)
- [GDC 2016 State of Unreal: Hellblade Live Performance & Real-Time Animation, Unreal Engine 4](https://www.youtube.com/watch?v=JbQSpfWUs4I)
__________________
## Import modeling & animation assets from Maya
![unreal01](img/lab/unreal.png)
![unreal02](img/lab/unreal01.png)
## File format to use: OBJ or FBX
### Obj
OBJ has it’s origins with Alias Wavefront, a simple data-format that represents 3D geometry — namely, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices.
- [Comparison I between OBJ & FBX](http://aecobjects.com/2014/10/which_format_is_better/)
- [Comparison II between OBJ & FBX](http://www.reallusion.com/iclone/help/3DXchange5/Pipeline/05_Export/The_Comparison_of_OBJ_FBX.htm)
### FBX
FBX is a file format owned and developed by Autodesk. It is used to provide interoperability between digital content creation applications such as Autodesk MotionBuilder, Autodesk Maya, and Autodesk 3ds Max. Autodesk MotionBuilder software supports FBX natively, while Autodesk Maya and Autodesk 3ds Max software include FBX plug-ins.
Unreal Engine features an FBX import pipeline which allows simple transfer of content from any number of digital content creation applications that support the format.
The advantages of the Unreal FBX Importer over other importing methods are:
- Static Mesh, Skeletal Mesh, animation, and morph targets in a single file format.
- Multiple assets/content can be contained in a single file.
- Import of multiple LODs and Morphs/Blendshapes in one import operation.
- Materials and textures imported with and applied to meshes.
- [FBX Content Pipeline in Unreal Engine 4](https://docs.unrealengine.com/latest/INT/Engine/Content/FBX/index.html)
## When you make assets in Maya
- If it is static, you can save it as obj and import to the content browser in Unreal.
You need to import textures and build the material in the material editor in Unreal. Your object should have UV texture coordinates assigned.
- If it has rigs and animation, save it as FBX. You still need to import textures separately and your objects should have UV texture coordinates too.
## FBX exporter in Maya
- You can export as FBX directly.
- Or you can use the game exporter as below, under File menu:
![exporter](img/lab/exporter.png)
- In the Unreal UI, you will see this window to import FBX. Check some parameters:
![importer](img/lab/importer.png)
____________________________________
## Expanded topic: Substance Painter
### What is Substance Painter?
Substance Painter is a powerful 3D painting tool.
The main purpose of Substance Painter is to texture models. Its advanced masking and procedural texturing tools allow you to make textures that are much harder to achieve in purely 2D programs like Photoshop.
Before you get into Substance Painter you first need a polygonal model that has been properly UV unwrapped. This 3D asset would be imported and used as the surface/object to paint on.
### Download Substance Painter
You can create an account to access to the application with a 1 year free student license.
- [Substance Painter webpage](https://www.substance3d.com/products/substance-painter/)
- [Substance education license](https://www.substance3d.com/education/)
### Where to start
In the course below from Substance Academy, you can take a project based approach to learn Substance Painter.
- [GETTING STARTED WITH SUBSTANCE PAINTER 2018](https://academy.substance3d.com/courses/getting-started-with-substance-painter-2018/youtube-IGGQl9kVB1M)
____________________________________
## Advanced topic: PBR - physically based rendering
### THE THEORY OF PHYSICALLY-BASED RENDERING AND SHADING
from THE PBR GUIDE BY ALLEGORITHMIC.
Light is a complex phenomenon as it can exhibit properties of both a wave and a particle. As a result, different models have been created to describe its behavior.
As texture artists, we are interested in the ray model of light as it describes the interaction of light and matter. Understanding how light rays interact with surface matter is important because our job is to create textures that describe a surface. The textures and materials we author interact with light in our virtual worlds. The more we understand how light behaves, the better our textures will look.
In this guide, we will discuss the theory behind the physics of physically based rendering (PBR) models. We will start by examining the behavior of light rays and work up to defining the key characteristics of PBR.
- [THE PBR GUIDE BY ALLEGORITHMIC - PART 1](https://academy.substance3d.com/courses/the-pbr-guide-part-1): Click the link to read the guide.
___________________________________
# UV texturing
>UV stands for the horizontal (U) and vertical (V) coordinates of the 2D coordinate map space that is applied to a 3D object.
UVs are 2D representations of a 3D object. There can be a problem with wrapping a 2D image (a texture) around a 3D object. UV mapping helps with this problem: UVs are directly related to vertices on a polygon and NURBS, but the UVs cannot be manipulated in 3D space; they are tied to a 2D coordinate plane and edited in a **UV editor**.
> UVs are like a “where” — they are a coordinate system across the surface of polygons (think latitude and longitude across a globe).
> Understanding what UVs are and being able to manipulate them is incredibly powerful and allows any image to define the surface of a 3D form. ***Unfortunately, this power to manipulate UV is not a trivial task and can be very counterintuitive.***
![tex_01](img/maya/UVMapping.png)
The application of a texture in the UV space related to its effect in 3D. CC BY-SA 3.0 [wikipedia](https://en.wikipedia.org/wiki/UV_mapping)
![tex_02](img/maya/Cube_Representative_UV_Unwrapping.png)
A representation of the UV mapping of a cube. The flattened cube net may then be textured to texture the cube. CC BY-SA 3.0 [wikipedia](https://en.wikipedia.org/wiki/UV_mapping)
## Video
- [The Basics Of UV Mapping by The Guerrilla CG Project](https://vimeo.com/5017993)
- [“On the Run” Creative Process - Part One by the Rusted Pixel](https://vimeo.com/120644464)
________________________
## Create UVs for polygon surfaces (Modeling // UV /)
### Using different mapping methods and check the UV Texture Editor.
![uv01](img/maya/shading/texturing/uv.png)
### Example of a 3D human model with the UV map.
![uv01](img/maya/shading/texturing/uv01.png)
(a) Planar, (b) cylindrical, (c) spherical, and (d) automatic mapping of a human model.
![uv02](img/maya/shading/texturing/uv02.png)
## UV texture map
### A human head model with a uniform UV map and a nonuniform UV map.
![uv03](img/maya/shading/texturing/uv03.png)
### Examples of UV texture mapping
![3dp01](img/maya/shading/texturing/texs.png)
### The bumps and folds of a sculpture are roughed in with the 3D Paint tool
![3dp](img/maya/shading/texturing/3dpaint.png)
_____________________
## UV Texture editor
3D software uses u- and v-coordinates to determine how textures should be applied to 3D objects. **UV mapping** refers to the process of determining these coordinates for polygon objects. **UV layout** is a term that refers to the 2D configuration of the UVs on a surface. In the **UV Texture Editor**, u-coordinates are plotted along the horizontal axis, and v-coordinates are plotted along the vertical axis. **UV maps** act as a guide for the placement of images.
**NURBS surfaces have implicit UVs; this means that the coordinates are built into the parameterization of the surface. UV texture coordinates do not have to be created for NURBS surfaces; only polygon and subdivision surfaces require mapped UVs.**
## Reference
[Maya 2018 online Help](http://help.autodesk.com/view/MAYAUL/2018/ENU//)
- Art of Maya [pdf link](http://web.cse.ohio-state.edu/~parent/classes/682/MAYA/art_of_maya.pdf)
- [Maya 2018 UV editor overview](http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-73BF7546-3BF2-44F3-9192-15A024CEC173)
- [Maya 2018: UV Toolkit Review, 13:27](https://www.youtube.com/watch?v=4gT3XAbOiV0)
- [UV mapping tips](http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-1CEF8A5B-1051-40F1-ACFE-F29AD066F56F)
- [Layout UV shells](http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-21CFF911-9C21-4019-B676-766ACA3BC889)
- [UV projection](http://help.autodesk.com/view/MAYAUL/2018/ENU//index.html?guid=GUID-B7E73748-5F8E-4E66-BE88-DF3C2A3DF438)
- [Displaying and Selecting UVs](http://help.autodesk.com/view/MAYAUL/2018/ENU//index.html?guid=GUID-764C4EB5-7050-477B-B866-76FE86758E7D)
### Further reading
- [OpenGL Cube Map Texturing tutorial from NVIDIA, 1999](http://www.nvidia.com/object/cube_map_ogl_tutorial.html)
## UV Practice
![texturing](img/donut.png)
Left image from Richard Singh. Right rendering image using Maya with Arnold renderer.
### Dice
- [Forward and Back Dice Template](https://www.earlylearninghq.org.uk/numeracy-resources/counting-games/forward-and-back-dice-template/)
![tex](https://www.earlylearninghq.org.uk/wp-content/uploads/2015/01/Forward-and-back-dice-prev.jpg)
![tex](https://i.pinimg.com/236x/20/e4/f6/20e4f61196f156f6195afa59143dea81--hardwood-tile-engineered-hardwood.jpg)
![texturing](img/dice1.png)
![texturing](img/dice2.png)
- [Coin Dice Template (UK)](https://www.earlylearninghq.org.uk/numeracy-resources/coins/coin-dice-uk/) ![tex](https://www.earlylearninghq.org.uk/wp-content/uploads/2017/01/Coin-dice-prev.jpg)
![texturing](img/dice01.png)
![texturing](img/dice02.png)
### Box texturing
![tex](http://media.moddb.com/images/members/1/400/399748/skin_box.jpg)
![texturing](img/box.png)
Rendered with Arnold renderer.
![texturing](img/box1.png)
Rendered with TURTLE renderer.
## Low poly barrel
- [Barrel Low Poly by terentiy from TurboSquid](https://www.turbosquid.com/FullPreview/Index.cfm/ID/1040707)
- [Barrel Low Poly by KurtCV from TurboSquid](https://www.turbosquid.com/FullPreview/Index.cfm/ID/794977)
![barrel](img/barrel01.png)
![barrel](img/barrel02.png)
____________________________
## Practice: Lego texturing
You can download the lego OBJ file [here](obj/lego.obj)
![uv01](img/maya/character/uv01.png)
- You can download this Lego uv texture from [LEGO Universe Wiki](http://legouniverse.wikia.com/wiki/File:Torsos_NPC_VandaDarkflame_I5.png) is a fandom games community.
Content is available under CC-BY-SA.
- [Custom Minifig Textures](http://nexusadventures.wikia.com/wiki/User_blog:Ferfature/Custom_Minifig_Textures)
### Preparation
- Assign one material because we will work all UVs into a single texture coordinate.
- Assign the texture from the color attribute.
- Change the workspace to the UV editing mode.
### Planar UV mapping
- Let's apply planar uv mapping for each part and move the uv shells to proper parts.
- Then from a camera view, select the face which has a texture from the Lego geometry and apply **Select / Convert Selection / To Edge Perimeter.**
![uv02](img/maya/character/uv02.png)
- Move to the UV texture editor and apply UV Edtor / Polygon / Cut UV Edges.
![uv03](img/maya/character/uv03.png)
- In the UV texture editor, choose Shell from the component mode, and select & move around to find the cut shell.
![uv04](img/maya/character/uv04.png)
- Move the shell and select UV from the component mode and move UVs to map the texture to the UV layout.
- Repeat the same process to the head, body, belt, and legs.
![uv05](img/maya/character/uv05.png)
- For the arms, which have more geometry faces, you can select a few faces and use Select / Grow or Shrink and other commands to make the selection processes efficient.
![uv06](img/maya/character/uv06.png)
![uv07](img/maya/character/uv07.png)
## Rendering check
![lego](img/lego_a.png)
Rendering image using Arnold renderer. Using Arnold material and lights.
![lego](img/lego_t.png)
Rendering image using TURTLE renderer. Using Maya material and lights.
### Reference for TURTLE
Turtle is a sophisticated baking plug-in for Autodesk® Maya® software used for lighting and content creation in next-gen game development. [Autodesk: Turtle](https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/ENU/123112/files/turtle-html.html)
- [Turtle manual.pdf](http://download.autodesk.com/us/support/files/turtlemanualrelease.pdf)
It is installed with Maya (starting version 2014).
Turtle lets you:
- Create stunning global illumination for game levels
- Bake illumination into texture maps, vertex maps, or point clouds.
- Bake occlusion and normal maps from detailed models to low-polygon models.
______________________________
## Lego related reference
- [Lego Man 3D Minifig Reference
by Quandtum](http://quandtum.deviantart.com/art/Lego-Man-3D-Minifig-Reference-145171513)
- [Anatomy Of A Lego Minifig](http://wtf.thebizzare.com/offbeat/uncategorized/anatomy-of-a-lego-minifig/)
- [LEGO-Textures: Textures scanned from real LEGO bricks!](https://github.com/rioforce/LEGO-Textures)
- [CgTrader](https://www.cgtrader.com/3d-models/sport-hobby/toy/lego-man-collection-10-characters)
- [LEGO HEAD DECALS](http://fantasticpixcool.com/lego+head+decals)
- [Base Lego Model](https://3docean.net/item/base-lego-model/8762731)
- [Lego Minifig 3D Model](https://www.creativecrash.com/3d-model/lego-minifig-3d-model)
___________________________________
# Action items
- Check out [Maya Texturing from 3D Modeling & Animation class note](https://jiharu.github.io/intm3d/week07.html) for more description about UV texturing.
- Check the [Lynda.com: Creating Game Environments in Maya and Photoshop with Adam Crespi](https://www.lynda.com/MyPlaylist/Watch/14973311/110453?autoplay=true)