Skip to content

Commit

Permalink
Correctly handle albedo textures as SRGB and...
Browse files Browse the repository at this point in the history
* Added an option to compile all textures or all meshes in the asset
manager window
* Wrong handling of lighting in the pre combine pass
  • Loading branch information
begla committed May 15, 2017
1 parent 9807e9d commit 13dddd9
Show file tree
Hide file tree
Showing 54 changed files with 183 additions and 124 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json eol=lf
Original file line number Diff line number Diff line change
Expand Up @@ -84,60 +84,44 @@ ImageRef createTexture(const _INTR_STRING& p_TextureName,
return imageRef;
}

void updateDrawCalls(ImageRef p_ImageRef)
{
_INTR_ARRAY(DrawCallRef) drawCallsToUpdate;

const uint32_t activeResourceCount =
DrawCallManager::getActiveResourceCount();

for (uint32_t dcIdx = 0u; dcIdx < activeResourceCount; ++dcIdx)
{
DrawCallRef dcRef = DrawCallManager::getActiveResourceAtIndex(dcIdx);

_INTR_ARRAY(BindingInfo)& bindInfos =
DrawCallManager::_descBindInfos(dcRef);

for (uint32_t biIdx = 0u; biIdx < (uint32_t)bindInfos.size(); ++biIdx)
{
BindingInfo& bindInfo = bindInfos[biIdx];
// <-

if (bindInfo.resource == p_ImageRef)
{
drawCallsToUpdate.push_back(dcRef);
break;
}
}
}
void ImporterTexture::importColorTextureFromFile(const _INTR_STRING& p_FilePath)
{
_INTR_STRING fileName, extension;
StringUtil::extractFileNameAndExtension(p_FilePath, fileName, extension);

DrawCallManager::destroyResources(drawCallsToUpdate);
DrawCallManager::createResources(drawCallsToUpdate);
compressTexture("-bc1 " + p_FilePath + " " + mediaPath + "/" + fileName +
".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC1RGBUNorm);
}

void ImporterTexture::importTextureFromFile(const _INTR_STRING& p_FilePath)
// <-

void ImporterTexture::importAlebdoTextureFromFile(
const _INTR_STRING& p_FilePath)
{
_INTR_STRING fileName, extension;
StringUtil::extractFileNameAndExtension(p_FilePath, fileName, extension);

compressTexture("-bc1 " + p_FilePath + " " + mediaPath + "/" + fileName +
".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC1RGBUNorm);
updateDrawCalls(imgRef);
createTexture(fileName, Renderer::Vulkan::Format::kBC1RGBSrgb);
}

// <-

void ImporterTexture::importAlphaTextureFromFile(const _INTR_STRING& p_FilePath)
void ImporterTexture::importAlebdoAlphaTextureFromFile(
const _INTR_STRING& p_FilePath)
{
_INTR_STRING fileName, extension;
StringUtil::extractFileNameAndExtension(p_FilePath, fileName, extension);

compressTexture("-bc2 " + p_FilePath + " " + mediaPath + "/" + fileName +
".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC2UNorm);
updateDrawCalls(imgRef);
ImageRef imgRef = createTexture(fileName, Renderer::Vulkan::Format::kBC2Srgb);
}

// <-
Expand All @@ -152,7 +136,6 @@ void ImporterTexture::importNormalMapTextureFromFile(
".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC1RGBUNorm);
updateDrawCalls(imgRef);
}

// <-
Expand All @@ -165,7 +148,6 @@ void ImporterTexture::importHdrCubemapFromFile(const _INTR_STRING& p_FilePath)
copyFile(p_FilePath, mediaPath + "/" + fileName + ".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC6UFloat);
updateDrawCalls(imgRef);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ struct ImporterTexture
static void init();
static void destroy();

static void importTextureFromFile(const _INTR_STRING& p_FilePath);
static void importAlphaTextureFromFile(const _INTR_STRING& p_FilePath);
static void importColorTextureFromFile(const _INTR_STRING& p_FilePath);
static void importAlebdoTextureFromFile(const _INTR_STRING& p_FilePath);
static void importAlebdoAlphaTextureFromFile(const _INTR_STRING& p_FilePath);
static void importNormalMapTextureFromFile(const _INTR_STRING& p_FilePath);
static void importHdrCubemapFromFile(const _INTR_STRING& p_FilePath);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,32 @@ void AssetManager::compileAssets(AssetRefArray& p_Refs)
Renderer::Vulkan::Resources::MaterialManager::saveToMultipleFiles(
"managers/materials/", ".material.json");
}
else if (_descAssetType(assetRef) == AssetType::kColorTexture)
else if (_descAssetType(assetRef) == AssetType::kLinearColorTexture)
{
ImporterTexture::init();
ImporterTexture::importTextureFromFile(
ImporterTexture::importColorTextureFromFile(
Settings::Manager::_assetTexturePath + "/" +
_descAssetFileName(assetRef));
ImporterTexture::destroy();

Renderer::Vulkan::Resources::ImageManager::saveToMultipleFiles(
"managers/images/", ".image.json");
}
else if (_descAssetType(assetRef) == AssetType::kAlphaTexture)
else if (_descAssetType(assetRef) == AssetType::kAlbedoTexture)
{
ImporterTexture::init();
ImporterTexture::importAlphaTextureFromFile(
ImporterTexture::importAlebdoAlphaTextureFromFile(
Settings::Manager::_assetTexturePath + "/" +
_descAssetFileName(assetRef));
ImporterTexture::destroy();

Renderer::Vulkan::Resources::ImageManager::saveToMultipleFiles(
"managers/images/", ".image.json");
}
else if (_descAssetType(assetRef) == AssetType::kAlbedoAlphaTexture)
{
ImporterTexture::init();
ImporterTexture::importAlebdoAlphaTextureFromFile(
Settings::Manager::_assetTexturePath + "/" +
_descAssetFileName(assetRef));
ImporterTexture::destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ enum Enum
{
kNone,
kMesh,
kColorTexture,
kAlphaTexture,
kAlbedoTexture,
kAlbedoAlphaTexture,
kLinearColorTexture,
kNormalTexture,
kHdrTexture
kHdrTexture,

kCount,
kTexturesBegin = kAlbedoTexture,
kTexturesEnd = kHdrTexture
};
}

Expand Down Expand Up @@ -100,11 +105,11 @@ struct AssetManager
p_Document.GetAllocator());
p_Properties.AddMember(
"assetType",
_INTR_CREATE_PROP_ENUM(
p_Document, p_GenerateDesc, _N(Asset), _N(enum),
_descAssetType(p_Ref),
"None,Mesh,ColorTexture,AlphaTexture,NormalTexture,HdrTexture",
false, false),
_INTR_CREATE_PROP_ENUM(p_Document, p_GenerateDesc, _N(Asset), _N(enum),
_descAssetType(p_Ref),
"None,Mesh,AlbedoTexture,AlbedoAlphaTexture,"
"LinearColorTexture,NormalTexture,HDRTexture",
false, false),
p_Document.GetAllocator());
}

Expand Down
99 changes: 78 additions & 21 deletions IntrinsicEd/src/IntrinsicEdManagerWindowAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ IntrinsicEdManagerWindowAsset::IntrinsicEdManagerWindowAsset(QWidget* parent)
QObject::connect(&_assetRecompileTimer, SIGNAL(timeout()),
SLOT(onCompileQueuedAssets()));

_assetRecompileTimer.setSingleShot(true);
_assetRecompileTimer.setInterval(16);
_assetRecompileTimer.start();

onPopulateResourceTree();
}
Expand Down Expand Up @@ -97,15 +98,10 @@ void IntrinsicEdManagerWindowAsset::onPopulateResourceTree()
{
meshes->addChild(item);
}
else if (
AssetManager::_descAssetType(assetEntry) ==
Intrinsic::AssetManagement::Resources::AssetType::kColorTexture ||
AssetManager::_descAssetType(assetEntry) ==
Intrinsic::AssetManagement::Resources::AssetType::kAlphaTexture ||
AssetManager::_descAssetType(assetEntry) ==
Intrinsic::AssetManagement::Resources::AssetType::kNormalTexture ||
AssetManager::_descAssetType(assetEntry) ==
Intrinsic::AssetManagement::Resources::AssetType::kHdrTexture)
else if (AssetManager::_descAssetType(assetEntry) >=
AssetType::kTexturesBegin &&
AssetManager::_descAssetType(assetEntry) <=
AssetType::kTexturesEnd)
{
textures->addChild(item);
}
Expand Down Expand Up @@ -139,6 +135,26 @@ void IntrinsicEdManagerWindowAsset::initContextMenu(QMenu* p_ContextMenu)
QObject::connect(compileAsset, SIGNAL(triggered()), this,
SLOT(onCompileAsset()));
}
else if (currIt->text(0u) == "Textures")
{
p_ContextMenu->addSeparator();

QAction* compileAsset =
new QAction(QIcon(":/Icons/asset"), "Compile All Textures", this);
p_ContextMenu->addAction(compileAsset);
QObject::connect(compileAsset, SIGNAL(triggered()), this,
SLOT(onCompileAllTextures()));
}
else if (currIt->text(0u) == "Meshes")
{
p_ContextMenu->addSeparator();

QAction* compileAsset =
new QAction(QIcon(":/Icons/asset"), "Compile All Meshes", this);
p_ContextMenu->addAction(compileAsset);
QObject::connect(compileAsset, SIGNAL(triggered()), this,
SLOT(onCompileAllMeshes()));
}
}

void IntrinsicEdManagerWindowAsset::onCompileAsset()
Expand All @@ -152,15 +168,48 @@ void IntrinsicEdManagerWindowAsset::onCompileAsset()
resource) == _assetsToRecompile.end())
{
_assetsToRecompile.push_back(resource);
_assetRecompileTimer.start(100);
}
}
}

void IntrinsicEdManagerWindowAsset::onCompileAllTextures()
{
for (uint32_t i = 0u; i < AssetManager::getActiveResourceCount(); ++i)
{
AssetRef ref = AssetManager::getActiveResourceAtIndex(i);

if (AssetManager::_descAssetType(ref) >= AssetType::kTexturesBegin &&
AssetManager::_descAssetType(ref) <= AssetType::kTexturesEnd)
{
if (std::find(_assetsToRecompile.begin(), _assetsToRecompile.end(),
ref) == _assetsToRecompile.end())
{
_assetsToRecompile.push_back(ref);
}
}
}
}

void IntrinsicEdManagerWindowAsset::onCompileAllMeshes()
{
for (uint32_t i = 0u; i < AssetManager::getActiveResourceCount(); ++i)
{
AssetRef ref = AssetManager::getActiveResourceAtIndex(i);

if (AssetManager::_descAssetType(ref) == AssetType::kMesh)
{
if (std::find(_assetsToRecompile.begin(), _assetsToRecompile.end(),
ref) == _assetsToRecompile.end())
{
_assetsToRecompile.push_back(ref);
}
}
}
}

void IntrinsicEdManagerWindowAsset::onAssetChanged(const QString& p_FileName)
{
// Recompile assets

for (uint32_t i = 0u; i < AssetManager::getActiveResourceCount(); ++i)
{
AssetRef assetRef = AssetManager::getActiveResourceAtIndex(i);
Expand All @@ -178,8 +227,6 @@ void IntrinsicEdManagerWindowAsset::onAssetChanged(const QString& p_FileName)
}
}
}

_assetRecompileTimer.start(1000);
}

void IntrinsicEdManagerWindowAsset::onResourceTreePopulated()
Expand All @@ -199,10 +246,8 @@ void IntrinsicEdManagerWindowAsset::onResourceTreePopulated()
QString(Settings::Manager::_assetMeshPath.c_str()) + "/" +
AssetManager::_descAssetFileName(ref).c_str());
}
else if (AssetManager::_descAssetType(ref) == AssetType::kColorTexture ||
AssetManager::_descAssetType(ref) == AssetType::kAlphaTexture ||
AssetManager::_descAssetType(ref) == AssetType::kHdrTexture ||
AssetManager::_descAssetType(ref) == AssetType::kNormalTexture)
else if (AssetManager::_descAssetType(ref) >= AssetType::kTexturesBegin &&
AssetManager::_descAssetType(ref) <= AssetType::kTexturesEnd)
{
_assetChangeWatch->addPath(
QString(Settings::Manager::_assetTexturePath.c_str()) + "/" +
Expand All @@ -215,9 +260,21 @@ void IntrinsicEdManagerWindowAsset::onCompileQueuedAssets()
{
Intrinsic::AssetManagement::Resources::AssetManager::compileAssets(
_assetsToRecompile);
_assetsToRecompile.clear();

onResourceTreePopulated();
if (!_assetsToRecompile.empty())
{
// TODO: Update only the assets which are affected by a changed asset
Vulkan::Resources::DrawCallManager::destroyResources(
Vulkan::Resources::DrawCallManager::_activeRefs);
Vulkan::Resources::DrawCallManager::createResources(
Vulkan::Resources::DrawCallManager::_activeRefs);
Vulkan::Resources::ComputeCallManager::destroyResources(
Vulkan::Resources::ComputeCallManager::_activeRefs);
Vulkan::Resources::ComputeCallManager::createResources(
Vulkan::Resources::ComputeCallManager::_activeRefs);

_assetsToRecompile.clear();
}
}

void IntrinsicEdManagerWindowAsset::dragEnterEvent(QDragEnterEvent* event)
Expand Down Expand Up @@ -254,7 +311,7 @@ void IntrinsicEdManagerWindowAsset::dropEvent(QDropEvent* event)
}
else if (extension == ".TGA" || extension == ".tga")
{
assetType = AssetType::kColorTexture;
assetType = AssetType::kAlbedoTexture;
}

if (assetType != AssetType::kNone)
Expand Down
2 changes: 2 additions & 0 deletions IntrinsicEd/src/IntrinsicEdManagerWindowAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public slots:
void onAssetChanged(const QString& p_FileName);
void onResourceTreePopulated();
void onCompileAsset();
void onCompileAllTextures();
void onCompileAllMeshes();
void onCompileQueuedAssets();

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void RenderSystem::initOrUpdateVkSwapChain()
{
colorAttachmentView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
colorAttachmentView.pNext = nullptr;
colorAttachmentView.format = VK_FORMAT_B8G8R8A8_SRGB;
colorAttachmentView.format = surfaceFormatToUse;
colorAttachmentView.components.r = VK_COMPONENT_SWIZZLE_R;
colorAttachmentView.components.g = VK_COMPONENT_SWIZZLE_G;
colorAttachmentView.components.b = VK_COMPONENT_SWIZZLE_B;
Expand Down
Loading

0 comments on commit 13dddd9

Please sign in to comment.