Skip to content

Instantly share code, notes, and snippets.

@peted70
Created June 4, 2018 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peted70/1c02c88fbba39c4d1d5b1a0159d024de to your computer and use it in GitHub Desktop.
Save peted70/1c02c88fbba39c4d1d5b1a0159d024de to your computer and use it in GitHub Desktop.
void MeshNode::CompileAndLoadPixelShader()
{
// Create a shader descriptor which we can use to either find the shader in the
// shader cache or create and add it.
// The hash used for lookup is generated from the shader name and defines passed
// when it is compiled
ShaderDescriptor descriptor("pbrpixel.hlsl", DevResources());
auto textures = _material->Textures();
// Allocate the defines map...
int count = textures.size();
// Iterate through all textures and set them as shader resources...
int idx = 0;
for (auto txItr = textures.begin(); txItr != textures.end(); ++txItr)
{
auto textureWrapper = txItr->second;
auto type = textureWrapper->Type();
const char *define = defineLookup[type];
descriptor.AddDefine(define);
idx++;
}
// Lookup and return or create the shader if necessary
m_pixelShaderWrapper = ShaderCache<PixelShaderWrapper>::Instance().FindOrCreateShader(descriptor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment