Ogre::TangentSpaceCalc Class Reference
Core » Math

Class for calculating a tangent space basis. More...

`#include <OgreTangentSpaceCalc.h>`

## Classes

struct | IndexRemap
| Information about a remapped index. More...
struct | Result
| The result of having built a tangent space basis. More...
struct | VertexInfo

## Public Types

typedef list< IndexRemap >::type | IndexRemapList
| List of indexes that were remapped (split vertices). More...
typedef std::pair< size_t, size_t > | VertexSplit
typedef list< VertexSplit >::type | VertexSplits

## Public Member Functions

| TangentSpaceCalc ()
virtual | ~TangentSpaceCalc ()
void | addIndexData (IndexData *i_in, RenderOperation::OperationType opType=RenderOperation::OT_TRIANGLE_LIST)
| Add a set of index data that references the vertex data. More...
Result | build (VertexElementSemantic targetSemantic=VES_TANGENT, unsigned short sourceTexCoordSet=0, unsigned short index=1)
| Build a tangent space basis from the provided data. More...
void | clear ()
| Reset the calculation object. More...
bool | getSplitMirrored () const
| Gets whether or not to split vertices when a mirrored tangent space transition is detected. More...
bool | getSplitRotated () const
| Sets whether or not to split vertices when tangent space rotates more than 90 degrees around a vertex. More...
bool | getStoreParityInW () const
| Gets whether to store tangent space parity in the W of a 4-component tangent or not. More...
void | setSplitMirrored (bool split)
| Sets whether or not to split vertices when a mirrored tangent space transition is detected (matrix parity differs). More...
void | setSplitRotated (bool split)
| Sets whether or not to split vertices when tangent space rotates more than 90 degrees around a vertex. More...
void | setStoreParityInW (bool enabled)
| Sets whether to store tangent space parity in the W of a 4-component tangent or not. More...
void | setVertexData (VertexData *v_in)
| Set the incoming vertex data (which will be modified) More...

## Protected Types

typedef vector< IndexData * >::type | IndexDataList
typedef vector< RenderOperation::OperationType >::type | OpTypeList
typedef vector< VertexInfo >::type | VertexInfoArray

## Protected Member Functions

void | addFaceTangentSpaceToVertices (size_t indexSet, size_t faceIndex, size_t *localVertInd, const Vector3 &faceTsU, const Vector3 &faceTsV, const Vector3 &faceNorm, Result &result)
Real | calculateAngleWeight (size_t v0, size_t v1, size_t v2)
void | calculateFaceTangentSpace (const size_t *vertInd, Vector3 &tsU, Vector3 &tsV, Vector3 &tsN)
| Calculate face tangent space, U and V are weighted by UV area, N is normalised. More...
int | calculateParity (const Vector3 &u, const Vector3 &v, const Vector3 &n)
void | extendBuffers (VertexSplits &splits)
void | insertTangents (Result &res, VertexElementSemantic targetSemantic, unsigned short sourceTexCoordSet, unsigned short index)
void | normaliseVertices ()
void | populateVertexArray (unsigned short sourceTexCoordSet)
void | processFaces (Result &result)
void | remapIndexes (Result &res)
template<typename T >
void | remapIndexes (T *ibuf, size_t indexSet, Result &res)

## Protected Attributes

IndexDataList | mIDataList
OpTypeList | mOpTypes
bool | mSplitMirrored
bool | mSplitRotated
bool | mStoreParityInW
VertexData * | mVData
VertexInfoArray | mVertexArray

## Detailed Description

Class for calculating a tangent space basis.

Definition at line 49 of file OgreTangentSpaceCalc.h.

## Member Typedef Documentation

## IndexDataList

typedef vector<IndexData*>::type Ogre::TangentSpaceCalc::IndexDataList

protected

Definition at line 187 of file OgreTangentSpaceCalc.h.

## IndexRemapList

typedef list<IndexRemap>::type Ogre::TangentSpaceCalc::IndexRemapList

List of indexes that were remapped (split vertices).

Definition at line 72 of file OgreTangentSpaceCalc.h.

## OpTypeList

typedef vector<RenderOperation::OperationType>::type Ogre::TangentSpaceCalc::OpTypeList

protected

Definition at line 188 of file OgreTangentSpaceCalc.h.

## VertexInfoArray

typedef vector<VertexInfo>::type Ogre::TangentSpaceCalc::VertexInfoArray

protected

Definition at line 211 of file OgreTangentSpaceCalc.h.

## VertexSplit

typedef std::pair<size_t, size_t> Ogre::TangentSpaceCalc::VertexSplit

Definition at line 55 of file OgreTangentSpaceCalc.h.

## VertexSplits

typedef list<VertexSplit>::type Ogre::TangentSpaceCalc::VertexSplits

Definition at line 74 of file OgreTangentSpaceCalc.h.

## Constructor & Destructor Documentation

## TangentSpaceCalc()

Ogre::TangentSpaceCalc::TangentSpaceCalc | ( |  | ) |

## ~TangentSpaceCalc()

virtual Ogre::TangentSpaceCalc::~TangentSpaceCalc | ( |  | ) |

virtual

## Member Function Documentation

## addFaceTangentSpaceToVertices()

void Ogre::TangentSpaceCalc::addFaceTangentSpaceToVertices | ( | size_t | indexSet,
|  | size_t | faceIndex,
|  | size_t * | localVertInd,
|  | const Vector3 & | faceTsU,
|  | const Vector3 & | faceTsV,
|  | const Vector3 & | faceNorm,
|  | Result & | result
| ) |  |

protected

## addIndexData()

void Ogre::TangentSpaceCalc::addIndexData | ( | IndexData * | i_in,
|  | RenderOperation::OperationType | opType = `RenderOperation::OT_TRIANGLE_LIST`
| ) |  |

Add a set of index data that references the vertex data.

This might be modified if there are vertex splits.

## build()

Result Ogre::TangentSpaceCalc::build | ( | VertexElementSemantic | targetSemantic = `VES_TANGENT`,
|  | unsigned short | sourceTexCoordSet = `0`,
|  | unsigned short | index = `1`
| ) |  |

Build a tangent space basis from the provided data.

Remarks
  Only indexed triangle lists are allowed. Strips and fans cannot be supported because it may be necessary to split the geometry up to respect deviances in the tangent space basis better.

Parameters

  targetSemantic | The semantic to store the tangents in. Defaults to the explicit tangent binding, but note that this is only usable on more modern hardware (Shader Model 2), so if you need portability with older cards you should change this to a texture coordinate binding instead.
  sourceTexCoordSet | The texture coordinate index which should be used as the source of 2D texture coordinates, with which to calculate the tangents.
  index | The element index, ie the texture coordinate set which should be used to store the 3D coordinates representing a tangent vector per vertex, if targetSemantic is VES_TEXTURE_COORDINATES. If this already exists, it will be overwritten.

Returns
  A structure containing the results of the tangent space build. Vertex data will always be modified but it's also possible that the index data could be adjusted. This happens when mirroring is used on a mesh, which causes the tangent space to be inverted on opposite sides of an edge. This is discontinuous, therefore the vertices have to be split along this edge, resulting in new vertices.

## calculateAngleWeight()

Real Ogre::TangentSpaceCalc::calculateAngleWeight | ( | size_t | v0,
|  | size_t | v1,
|  | size_t | v2
| ) |  |

protected

## calculateFaceTangentSpace()

void Ogre::TangentSpaceCalc::calculateFaceTangentSpace | ( | const size_t * | vertInd,
|  | Vector3 & | tsU,
|  | Vector3 & | tsV,
|  | Vector3 & | tsN
| ) |  |

protected

Calculate face tangent space, U and V are weighted by UV area, N is normalised.

## calculateParity()

int Ogre::TangentSpaceCalc::calculateParity | ( | const Vector3 & | u,
|  | const Vector3 & | v,
|  | const Vector3 & | n
| ) |  |

protected

## clear()

void Ogre::TangentSpaceCalc::clear | ( |  | ) |

Reset the calculation object.

## extendBuffers()

void Ogre::TangentSpaceCalc::extendBuffers | ( | VertexSplits & | splits | ) |

protected

## getSplitMirrored()

bool Ogre::TangentSpaceCalc::getSplitMirrored | ( |  | ) | const

Gets whether or not to split vertices when a mirrored tangent space transition is detected.

Definition at line 136 of file OgreTangentSpaceCalc.h.

## getSplitRotated()

bool Ogre::TangentSpaceCalc::getSplitRotated | ( |  | ) | const

Sets whether or not to split vertices when tangent space rotates more than 90 degrees around a vertex.

Definition at line 156 of file OgreTangentSpaceCalc.h.

References Ogre::VES_TANGENT.

## getStoreParityInW()

bool Ogre::TangentSpaceCalc::getStoreParityInW | ( |  | ) | const

Gets whether to store tangent space parity in the W of a 4-component tangent or not.

Definition at line 115 of file OgreTangentSpaceCalc.h.

## insertTangents()

void Ogre::TangentSpaceCalc::insertTangents | ( | Result & | res,
|  | VertexElementSemantic | targetSemantic,
|  | unsigned short | sourceTexCoordSet,
|  | unsigned short | index
| ) |  |

protected

## normaliseVertices()

void Ogre::TangentSpaceCalc::normaliseVertices | ( |  | ) |

protected

## populateVertexArray()

void Ogre::TangentSpaceCalc::populateVertexArray | ( | unsigned short | sourceTexCoordSet | ) |

protected

## processFaces()

void Ogre::TangentSpaceCalc::processFaces | ( | Result & | result | ) |

protected

## remapIndexes() [1/2]

void Ogre::TangentSpaceCalc::remapIndexes | ( | Result & | res | ) |

protected

## remapIndexes() [2/2]

template<typename T >

void Ogre::TangentSpaceCalc::remapIndexes | ( | T * | ibuf,
|  | size_t | indexSet,
|  | Result & | res
| ) |  |

protected

Definition at line 230 of file OgreTangentSpaceCalc.h.

References Ogre::TangentSpaceCalc::IndexRemap::faceIndex, Ogre::TangentSpaceCalc::Result::indexesRemapped, Ogre::TangentSpaceCalc::IndexRemap::indexSet, and Ogre::TangentSpaceCalc::IndexRemap::splitVertex.

## setSplitMirrored()

void Ogre::TangentSpaceCalc::setSplitMirrored | ( | bool | split | ) |

Sets whether or not to split vertices when a mirrored tangent space transition is detected (matrix parity differs).

Remarks
  This defaults to 'off' because it's the safest option; tangents will be interpolated in all cases even if they don't agree around a vertex, so artefacts will be smoothed out. When you're using art assets of unknown quality this can avoid extra seams on the visible surface. However, if your artists are good, they will be hiding texture seams in folds of the model and thus you can turn this option on, which will prevent the results of those seams from getting smoothed into other areas, which is exactly what you want.

Note
  This option is automatically disabled if you provide any strip or fan based geometry.

Definition at line 131 of file OgreTangentSpaceCalc.h.

## setSplitRotated()

void Ogre::TangentSpaceCalc::setSplitRotated | ( | bool | split | ) |

Sets whether or not to split vertices when tangent space rotates more than 90 degrees around a vertex.

Remarks
  This defaults to 'off' because it's the safest option; tangents will be interpolated in all cases even if they don't agree around a vertex, so artefacts will be smoothed out. When you're using art assets of unknown quality this can avoid extra seams on the visible surface. However, if your artists are good, they will be hiding texture inconsistencies in folds of the model and thus you can turn this option on, which will prevent the results of those seams from getting smoothed into other areas, which is exactly what you want.

Note
  This option is automatically disabled if you provide any strip or fan based geometry.

Definition at line 152 of file OgreTangentSpaceCalc.h.

## setStoreParityInW()

void Ogre::TangentSpaceCalc::setStoreParityInW | ( | bool | enabled | ) |

Sets whether to store tangent space parity in the W of a 4-component tangent or not.

Remarks
  The default element format to use is VET_FLOAT3 which is enough to accurately deal with tangents that do not involve any texture coordinate mirroring. If you wish to allow UV mirroring in your model, you must enable 4-component tangents using this method, and the 'w' co-ordinate will be populated with the parity of the triangle (+1 or -1), which will allow you to generate the bitangent properly.

Parameters

  enabled | true to enable 4-component tangents (default false). If you enable this, you will probably also want to enable mirror splitting (see setSplitMirrored), and your shader must understand how to deal with the parity.

Definition at line 112 of file OgreTangentSpaceCalc.h.

## setVertexData()

void Ogre::TangentSpaceCalc::setVertexData | ( | VertexData * | v_in | ) |

Set the incoming vertex data (which will be modified)

## Member Data Documentation

## mIDataList

IndexDataList Ogre::TangentSpaceCalc::mIDataList

protected

Definition at line 189 of file OgreTangentSpaceCalc.h.

## mOpTypes

OpTypeList Ogre::TangentSpaceCalc::mOpTypes

protected

Definition at line 190 of file OgreTangentSpaceCalc.h.

## mSplitMirrored

bool Ogre::TangentSpaceCalc::mSplitMirrored

protected

Definition at line 191 of file OgreTangentSpaceCalc.h.

## mSplitRotated

bool Ogre::TangentSpaceCalc::mSplitRotated

protected

Definition at line 192 of file OgreTangentSpaceCalc.h.

## mStoreParityInW

bool Ogre::TangentSpaceCalc::mStoreParityInW

protected

Definition at line 193 of file OgreTangentSpaceCalc.h.

## mVData

VertexData* Ogre::TangentSpaceCalc::mVData

protected

Definition at line 186 of file OgreTangentSpaceCalc.h.

## mVertexArray

VertexInfoArray Ogre::TangentSpaceCalc::mVertexArray

protected

Definition at line 212 of file OgreTangentSpaceCalc.h.

The documentation for this class was generated from the following file:

- OgreTangentSpaceCalc.h

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.