HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TextureBaker< Renderer, ShaderGen > Class Template Reference

#include <TextureBaker.h>

+ Inheritance diagram for TextureBaker< Renderer, ShaderGen >:

Classes

class  BakedConstant
 
class  BakedImage
 

Public Member Functions

void setExtension (const string &extension)
 Set the file extension for baked textures. More...
 
const stringgetExtension () const
 Return the file extension for baked textures. More...
 
void setColorSpace (const string &colorSpace)
 
const stringgetColorSpace () const
 Return the color space in which color textures are encoded. More...
 
void setDistanceUnit (const string &unitSpace)
 Set the distance unit to which textures are baked. Defaults to meters. More...
 
const stringgetDistanceUnit () const
 Return the distance unit to which textures are baked. More...
 
void setAverageImages (bool enable)
 Set whether images should be averaged to generate constants. Defaults to false. More...
 
bool getAverageImages () const
 Return whether images should be averaged to generate constants. More...
 
void setOptimizeConstants (bool enable)
 Set whether uniform textures should be stored as constants. Defaults to true. More...
 
bool getOptimizeConstants () const
 Return whether uniform textures should be stored as constants. More...
 
void setOutputImagePath (const FilePath &outputImagePath)
 
const FilePathgetOutputImagePath ()
 Get the current output location for baked texture images. More...
 
void setBakedGraphName (const string &name)
 Set the name of the baked graph element. More...
 
const stringgetBakedGraphName () const
 Return the name of the baked graph element. More...
 
void setBakedGeomInfoName (const string &name)
 Set the name of the baked geometry info element. More...
 
const stringgetBakedGeomInfoName () const
 Return the name of the baked geometry info element. More...
 
const stringgetTextureFilenameTemplate () const
 Get the texture filename template. More...
 
void setTextureFilenameTemplate (const string &filenameTemplate)
 Set the texture filename template. More...
 
void setFilenameTemplateVarOverride (const string &key, const string &value)
 Set texFilenameOverrides if template variable exists. More...
 
void setOutputStream (std::ostream *outputStream)
 Set the output stream for reporting progress and warnings. Defaults to std::cout. More...
 
std::ostream * getOutputStream () const
 Return the output stream for reporting progress and warnings. More...
 
void setHashImageNames (bool enable)
 
bool getHashImageNames () const
 Return whether automatic baked texture resolution is set. More...
 
void setTextureSpaceMin (const Vector2 &min)
 Set the minimum texcoords used in texture baking. Defaults to 0, 0. More...
 
Vector2 getTextureSpaceMin () const
 Return the minimum texcoords used in texture baking. More...
 
void setTextureSpaceMax (const Vector2 &max)
 Set the maximum texcoords used in texture baking. Defaults to 1, 1. More...
 
Vector2 getTextureSpaceMax () const
 Return the maximum texcoords used in texture baking. More...
 
void setupUnitSystem (DocumentPtr unitDefinitions)
 Set up the unit definitions to be used in baking. More...
 
void bakeShaderInputs (NodePtr material, NodePtr shader, GenContext &context, const string &udim=EMPTY_STRING)
 Bake textures for all graph inputs of the given shader. More...
 
void bakeGraphOutput (OutputPtr output, GenContext &context, const StringMap &filenameTemplateMap)
 Bake a texture for the given graph output. More...
 
void optimizeBakedTextures (NodePtr shader)
 Optimize baked textures before writing. More...
 
DocumentPtr bakeMaterialToDoc (DocumentPtr doc, const FileSearchPath &searchPath, const string &materialPath, const StringVec &udimSet, std::string &documentName)
 Bake material to document in memory and write baked textures to disk. More...
 
void bakeAllMaterials (DocumentPtr doc, const FileSearchPath &searchPath, const FilePath &outputFileName)
 
void writeDocumentPerMaterial (bool value)
 
string getValueStringFromColor (const Color4 &color, const string &type)
 

Protected Types

using BakedImageVec = vector< BakedImage >
 
using BakedImageMap = std::unordered_map< OutputPtr, BakedImageVec >
 
using BakedConstantMap = std::unordered_map< OutputPtr, BakedConstant >
 

Protected Member Functions

 TextureBaker (unsigned int width, unsigned int height, Image::BaseType baseType, bool flipSavedImage)
 
StringMap initializeFileTemplateMap (InputPtr input, NodePtr shader, const string &udim=EMPTY_STRING)
 
size_t findVarInTemplate (const string &filename, const string &var, size_t start=0)
 
FilePath generateTextureFilename (const StringMap &fileTemplateMap)
 
DocumentPtr generateNewDocumentFromShader (NodePtr shader, const StringVec &udimSet)
 
bool writeBakedImage (const BakedImage &baked, ImagePtr image)
 

Protected Attributes

string _extension
 
string _colorSpace
 
string _distanceUnit
 
bool _averageImages
 
bool _optimizeConstants
 
FilePath _outputImagePath
 
string _bakedGraphName
 
string _bakedGeomInfoName
 
string _textureFilenameTemplate
 
std::ostream * _outputStream
 
bool _hashImageNames
 
Vector2 _textureSpaceMin
 
Vector2 _textureSpaceMax
 
ShaderGeneratorPtr _generator
 
ConstNodePtr _material
 
ImagePtr _frameCaptureImage
 
BakedImageMap _bakedImageMap
 
BakedConstantMap _bakedConstantMap
 
StringSet _permittedOverrides
 
StringMap _texTemplateOverrides
 
StringMap _bakedInputMap
 
std::unordered_map< string,
NodePtr
_worldSpaceNodes
 
bool _flipSavedImage
 
bool _writeDocumentPerMaterial
 
DocumentPtr _bakedTextureDoc
 

Detailed Description

template<typename Renderer, typename ShaderGen>
class TextureBaker< Renderer, ShaderGen >

A helper class for baking procedural material content to textures. TODO: Add support for graphs containing geometric nodes such as position and normal.

Definition at line 31 of file TextureBaker.h.

Member Typedef Documentation

template<typename Renderer, typename ShaderGen>
using TextureBaker< Renderer, ShaderGen >::BakedConstantMap = std::unordered_map<OutputPtr, BakedConstant>
protected

Definition at line 253 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
using TextureBaker< Renderer, ShaderGen >::BakedImageMap = std::unordered_map<OutputPtr, BakedImageVec>
protected

Definition at line 252 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
using TextureBaker< Renderer, ShaderGen >::BakedImageVec = vector<BakedImage>
protected

Definition at line 251 of file TextureBaker.h.

Constructor & Destructor Documentation

template<typename Renderer , typename ShaderGen >
TextureBaker< Renderer, ShaderGen >::TextureBaker ( unsigned int  width,
unsigned int  height,
Image::BaseType  baseType,
bool  flipSavedImage 
)
protected

Definition at line 49 of file TextureBaker.inl.

Member Function Documentation

template<typename Renderer , typename ShaderGen >
void TextureBaker< Renderer, ShaderGen >::bakeAllMaterials ( DocumentPtr  doc,
const FileSearchPath searchPath,
const FilePath outputFileName 
)

Bake materials in the given document and write them to disk. If multiple documents are written, then the given output filename will be used as a template.

Definition at line 552 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
void TextureBaker< Renderer, ShaderGen >::bakeGraphOutput ( OutputPtr  output,
GenContext context,
const StringMap filenameTemplateMap 
)

Bake a texture for the given graph output.

Definition at line 218 of file TextureBaker.inl.

template<typename Renderer, typename ShaderGen>
DocumentPtr TextureBaker< Renderer, ShaderGen >::bakeMaterialToDoc ( DocumentPtr  doc,
const FileSearchPath searchPath,
const string materialPath,
const StringVec udimSet,
std::string documentName 
)

Bake material to document in memory and write baked textures to disk.

Definition at line 484 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
void TextureBaker< Renderer, ShaderGen >::bakeShaderInputs ( NodePtr  material,
NodePtr  shader,
GenContext context,
const string udim = EMPTY_STRING 
)

Bake textures for all graph inputs of the given shader.

Definition at line 178 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
size_t TextureBaker< Renderer, ShaderGen >::findVarInTemplate ( const string filename,
const string var,
size_t  start = 0 
)
protected

Definition at line 101 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
DocumentPtr TextureBaker< Renderer, ShaderGen >::generateNewDocumentFromShader ( NodePtr  shader,
const StringVec udimSet 
)
protected

Definition at line 321 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
FilePath TextureBaker< Renderer, ShaderGen >::generateTextureFilename ( const StringMap fileTemplateMap)
protected

Definition at line 116 of file TextureBaker.inl.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::getAverageImages ( ) const
inline

Return whether images should be averaged to generate constants.

Definition at line 82 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getBakedGeomInfoName ( ) const
inline

Return the name of the baked geometry info element.

Definition at line 131 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getBakedGraphName ( ) const
inline

Return the name of the baked graph element.

Definition at line 119 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getColorSpace ( ) const
inline

Return the color space in which color textures are encoded.

Definition at line 58 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getDistanceUnit ( ) const
inline

Return the distance unit to which textures are baked.

Definition at line 70 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getExtension ( ) const
inline

Return the file extension for baked textures.

Definition at line 41 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::getHashImageNames ( ) const
inline

Return whether automatic baked texture resolution is set.

Definition at line 179 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::getOptimizeConstants ( ) const
inline

Return whether uniform textures should be stored as constants.

Definition at line 94 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const FilePath& TextureBaker< Renderer, ShaderGen >::getOutputImagePath ( )
inline

Get the current output location for baked texture images.

Definition at line 107 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
std::ostream* TextureBaker< Renderer, ShaderGen >::getOutputStream ( ) const
inline

Return the output stream for reporting progress and warnings.

Definition at line 165 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
const string& TextureBaker< Renderer, ShaderGen >::getTextureFilenameTemplate ( ) const
inline

Get the texture filename template.

Definition at line 137 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
Vector2 TextureBaker< Renderer, ShaderGen >::getTextureSpaceMax ( ) const
inline

Return the maximum texcoords used in texture baking.

Definition at line 203 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
Vector2 TextureBaker< Renderer, ShaderGen >::getTextureSpaceMin ( ) const
inline

Return the minimum texcoords used in texture baking.

Definition at line 191 of file TextureBaker.h.

template<typename Renderer , typename ShaderGen >
string TextureBaker< Renderer, ShaderGen >::getValueStringFromColor ( const Color4 color,
const string type 
)

Definition at line 27 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
StringMap TextureBaker< Renderer, ShaderGen >::initializeFileTemplateMap ( InputPtr  input,
NodePtr  shader,
const string udim = EMPTY_STRING 
)
protected

Definition at line 142 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
void TextureBaker< Renderer, ShaderGen >::optimizeBakedTextures ( NodePtr  shader)

Optimize baked textures before writing.

Definition at line 259 of file TextureBaker.inl.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setAverageImages ( bool  enable)
inline

Set whether images should be averaged to generate constants. Defaults to false.

Definition at line 76 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setBakedGeomInfoName ( const string name)
inline

Set the name of the baked geometry info element.

Definition at line 125 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setBakedGraphName ( const string name)
inline

Set the name of the baked graph element.

Definition at line 113 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setColorSpace ( const string colorSpace)
inline

Set the color space in which color textures are encoded.

By default, this color space is srgb_texture, and color inputs are automatically transformed to this space by the baker. If another color space is set, then the input graph is responsible for transforming colors to this space.

Definition at line 52 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setDistanceUnit ( const string unitSpace)
inline

Set the distance unit to which textures are baked. Defaults to meters.

Definition at line 64 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setExtension ( const string extension)
inline

Set the file extension for baked textures.

Definition at line 35 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setFilenameTemplateVarOverride ( const string key,
const string value 
)
inline

Set texFilenameOverrides if template variable exists.

Definition at line 150 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setHashImageNames ( bool  enable)
inline

Set whether to create a short name for baked images by hashing the baked image filenames This is useful for file systems which may have a maximum limit on filename size. By default names are not hashed.

Definition at line 173 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setOptimizeConstants ( bool  enable)
inline

Set whether uniform textures should be stored as constants. Defaults to true.

Definition at line 88 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setOutputImagePath ( const FilePath outputImagePath)
inline

Set the output location for baked texture images. Defaults to the root folder of the destination material.

Definition at line 101 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setOutputStream ( std::ostream *  outputStream)
inline

Set the output stream for reporting progress and warnings. Defaults to std::cout.

Definition at line 159 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setTextureFilenameTemplate ( const string filenameTemplate)
inline

Set the texture filename template.

Definition at line 143 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setTextureSpaceMax ( const Vector2 max)
inline

Set the maximum texcoords used in texture baking. Defaults to 1, 1.

Definition at line 197 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::setTextureSpaceMin ( const Vector2 min)
inline

Set the minimum texcoords used in texture baking. Defaults to 0, 0.

Definition at line 185 of file TextureBaker.h.

template<typename Renderer , typename ShaderGen >
void TextureBaker< Renderer, ShaderGen >::setupUnitSystem ( DocumentPtr  unitDefinitions)

Set up the unit definitions to be used in baking.

Definition at line 629 of file TextureBaker.inl.

template<typename Renderer , typename ShaderGen >
bool TextureBaker< Renderer, ShaderGen >::writeBakedImage ( const BakedImage baked,
ImagePtr  image 
)
protected

Definition at line 158 of file TextureBaker.inl.

template<typename Renderer, typename ShaderGen>
void TextureBaker< Renderer, ShaderGen >::writeDocumentPerMaterial ( bool  value)
inline

Set whether to write a separate document per material when calling bakeAllMaterials. By default separate documents are written.

Definition at line 230 of file TextureBaker.h.

Member Data Documentation

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::_averageImages
protected

Definition at line 277 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
BakedConstantMap TextureBaker< Renderer, ShaderGen >::_bakedConstantMap
protected

Definition at line 292 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_bakedGeomInfoName
protected

Definition at line 281 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_bakedGraphName
protected

Definition at line 280 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
BakedImageMap TextureBaker< Renderer, ShaderGen >::_bakedImageMap
protected

Definition at line 291 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
StringMap TextureBaker< Renderer, ShaderGen >::_bakedInputMap
protected

Definition at line 295 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
DocumentPtr TextureBaker< Renderer, ShaderGen >::_bakedTextureDoc
protected

Definition at line 302 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_colorSpace
protected

Definition at line 275 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_distanceUnit
protected

Definition at line 276 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_extension
protected

Definition at line 274 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::_flipSavedImage
protected

Definition at line 299 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
ImagePtr TextureBaker< Renderer, ShaderGen >::_frameCaptureImage
protected

Definition at line 290 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
ShaderGeneratorPtr TextureBaker< Renderer, ShaderGen >::_generator
protected

Definition at line 288 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::_hashImageNames
protected

Definition at line 284 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
ConstNodePtr TextureBaker< Renderer, ShaderGen >::_material
protected

Definition at line 289 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::_optimizeConstants
protected

Definition at line 278 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
FilePath TextureBaker< Renderer, ShaderGen >::_outputImagePath
protected

Definition at line 279 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
std::ostream* TextureBaker< Renderer, ShaderGen >::_outputStream
protected

Definition at line 283 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
StringSet TextureBaker< Renderer, ShaderGen >::_permittedOverrides
protected

Definition at line 293 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
StringMap TextureBaker< Renderer, ShaderGen >::_texTemplateOverrides
protected

Definition at line 294 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
string TextureBaker< Renderer, ShaderGen >::_textureFilenameTemplate
protected

Definition at line 282 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
Vector2 TextureBaker< Renderer, ShaderGen >::_textureSpaceMax
protected

Definition at line 286 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
Vector2 TextureBaker< Renderer, ShaderGen >::_textureSpaceMin
protected

Definition at line 285 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
std::unordered_map<string, NodePtr> TextureBaker< Renderer, ShaderGen >::_worldSpaceNodes
protected

Definition at line 297 of file TextureBaker.h.

template<typename Renderer, typename ShaderGen>
bool TextureBaker< Renderer, ShaderGen >::_writeDocumentPerMaterial
protected

Definition at line 301 of file TextureBaker.h.


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