3D, Textures, Etc - Basic Questions & Theory

General discussion and questions about XNALara go here.

Moderators: ObscureMemories, Runa, Love2Raid

Post Reply
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

3D, Textures, Etc - Basic Questions & Theory

Post by ProtocolX27 »

Here's one not specific to any of the applications. Normals!

In the past I've tried to make modify normals without the best results. What is a recommended way to do so based on an existing diffuse? It'd help if I had a better understanding of the normal composition. Does X Channel represent light horizontal/vertical or is it a combination of things?

Thanks :)
User avatar
thePWA
Porter
Posts: 2416
Joined: Sun Aug 19, 2012 2:27 pm
Custom Rank: JOSHAUAGES v2.0
Location: Earth circa 1999
Contact:

Re: 3D, Textures, Etc - Basic Questions & Theory

Post by thePWA »

I gotta be honest man I know jackshit about normals. All I know is flipping around the channels (red to green or vice versa) and blacking (or whitening) out one channel produces something you can view with xnalara.
Stop! Waitaminute! Fill mah cup with some liquor in it!
FigureSculptor
Posts: 44
Joined: Sun Dec 23, 2012 7:10 am

Re: 3D, Textures, Etc - Basic Questions & Theory

Post by FigureSculptor »

ProtocolX27 wrote:In the past I've tried to make modify normals without the best results. What is a recommended way to do so based on an existing diffuse? It'd help if I had a better understanding of the normal composition. Does X Channel represent light horizontal/vertical or is it a combination of things?

So, this isn't entirely intuitive. A normal map is an image but it's not really an image. Let's take a step back. Bear with me if I'm being too simplistic, but this is conceptually kind of hard and there is probably somebody out there who don't know all this.

Mathematically speaking, a "normal" or "normal vector" is essentially a vector, which is kind of like an imaginary line drawn from the origin to an x,y,z point in space. Vectors represent a direction in 3D space. If you point your finger in any direction, there is a vector that can describe that direction. The "normal vector" defines a direction that is exactly perpendicular to a particular polygon.

http://mathworld.wolfram.com/NormalVector.html

In computer graphics, we usually call this a "face normal" or "polygon normal" because computer graphics generally do operations on a per-vertex or per-pixel basis, not a per-polygon basis. One of the reasons that computers have become able to do such advanced realtime graphics is that all work is now divided up into tiny little chunks that can be operated on in parallel by the GPU. This work is performed by small programs called "shaders". Although there are other types of shaders, pretty much every graphics pipeline features two basic types - vertex shaders (which run once for every vertex in the model being drawn) and fragment shaders - sometimes called pixel shaders - which run once for every pixel in the final image.

In order to take advantage of the GPU, most work has to be broken down so it can be done on either a per-vertex or a per-fragment (pixel) basis. As a result, we tend not to use "face normals". Instead, we use "vertex normals", which are simply the average of the face normals for all the faces that the vertex is a part of. What are these vertex normals used for? Lighting calculations, primarily.

Now, the graphics pipeline is optimized for certain operations. One of those highly optimized operations is moving around texture data. Originally, this was used for texture maps, or what we think of as "diffuse maps" today. Clever artists and programmers started to realize that you could use these images to pass other types of data through the graphics pipeline. Essentially, any data you wanted to get into your fragment shader that could be pre-calculated and stored as an image could be passed into the pipeline disguised as an image. We're now familiar with many of these types of image maps - alpha or transparency maps, specular maps, etc., and many of them can be hand-manipulated using Photoshop fairly intuitively.

Now, what a normal map is, is the pre-calculated normals for a model stored in an image. There's two reasons for doing this. First, normals can be computationally expensive to calculate at runtime, and since they generally don't change during runtime, there's no reason to waste the time doing the calculation. Second, it's possible to cheat and store normal data from a much higher resolution model than the one actually used in-game. Within each pixel of the normal map, the R (red) pixel is used to store the x value of the normal vector to be used in the lighting calculation for that spot on the model, the G (green) pixel holds the y, and the B (Blue) pixel, the z value. The pixel data is mapped to the model and then instead of being drawn as a texture, it is used in the lighting calculation. The end result appears to be a much higher resolution model than is really used.

Since the colors in a vertex map aren't really colors, though they're not easily manipulable the way a transparency, diffuse, or alpha map are. Small adjustments can be made to an existing normal map, but when more extensive modifications are necessary, it's often easier to just re-create a new normal map using techniques similar to what the artists who originally created the model used.

I hope that made sense. It's kind of a conceptually difficult topic.
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

Re: 3D, Textures, Etc - Basic Questions & Theory

Post by ProtocolX27 »

Thanks, Figure Sculptor. Yes that definitely sounds in depth, but that definitely takes care of it being an overview just so I had an understanding of what it actually is. :)

So my theory was almost right that one channel applies to a specific axis. In terms of making a normal, how does the lightness/darkness of a channel correspond to the vector / axis. If I paint the blue channel all black vs all white is that affecting the length of the vector? Or is it more to do with the angle of the vector / how light bounces of it from the axis that it corresponds to.
User avatar
rroca
Posts: 7
Joined: Wed Jun 12, 2013 3:18 pm

Re: 3D, Textures, Etc - Basic Questions & Theory

Post by rroca »

ProtocolX27 wrote:Thanks, Figure Sculptor. Yes that definitely sounds in depth, but that definitely takes care of it being an overview just so I had an understanding of what it actually is. :)

So my theory was almost right that one channel applies to a specific axis. In terms of making a normal, how does the lightness/darkness of a channel correspond to the vector / axis. If I paint the blue channel all black vs all white is that affecting the length of the vector? Or is it more to do with the angle of the vector / how light bounces of it from the axis that it corresponds to.
http://wiki.polycount.com/NormalMap/#RGB_Channels

Really helpful and detailed, you may want to read the whole thing too, it contains plenty of examples :)
Post Reply