Skip to content

Commit

Permalink
Specular AA working
Browse files Browse the repository at this point in the history
* Fixed and cleaned up various include conflicts/issues
  • Loading branch information
Benjamin Glatzel committed May 29, 2017
1 parent 74ca429 commit 1114805
Show file tree
Hide file tree
Showing 75 changed files with 284 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
// limitations under the License.

// Precompiled header file
#define FBXSDK_NAMESPACE_USING 1
#include "stdafx_assets.h"
#include "stdafx.h"
#include "stdafx_vulkan.h"

// FBX
#define FBXSDK_NAMESPACE_USING 1
#undef snprintf
#include "fbxsdk.h"

// Helper
#include "IntrinsicAssetManagementHelperFbx.h"

namespace Intrinsic
{
namespace AssetManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

// Precompiled header file
#include "stdafx_assets.h"
#include "stdafx.h"
#include "stdafx_vulkan.h"

using namespace Intrinsic::Renderer::Vulkan::Resources;
Expand Down Expand Up @@ -136,6 +135,34 @@ void ImporterTexture::importNormalMapTextureFromFile(
".dds");
ImageRef imgRef =
createTexture(fileName, Renderer::Vulkan::Format::kBC1RGBUNorm);

// Calc. avg. normal length for specular AA
float avgNormalLength = 1.0f;
{
_INTR_STRING texturePath = "media/textures/" + fileName + ".dds";

gli::texture2d normalTexture =
gli::texture2d(gli::load(texturePath.c_str()));
gli::texture2d normalTexDec =
gli::convert(normalTexture, gli::FORMAT_RGB32_SFLOAT_PACK32);

glm::vec3 avgNormal = glm::vec3(0.0f);
for (int32_t y = 0u; y < normalTexDec.extent().y; ++y)
{
for (int32_t x = 0u; x < normalTexDec.extent().x; ++x)
{
const gli::vec3 normal = gli::normalize(
normalTexDec.load<gli::vec3>(gli::extent2d(x, y), 0u) * 2.0f -
1.0f);

avgNormal += normal;
}
}

avgNormal /= normalTexDec.extent().x * normalTexDec.extent().y;
avgNormalLength = glm::length(avgNormal);
}
ImageManager::_descAvgNormLength(imgRef) = avgNormalLength;
}

// <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

// Precompiled header file
#include "stdafx_assets.h"
#include "stdafx.h"
#include "stdafx_vulkan.h"

namespace Intrinsic
Expand Down
11 changes: 3 additions & 8 deletions IntrinsicAssetManagement/src/stdafx_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@

#pragma once

// Defines
#define _INTR_MAX_ASSET_COUNT 4096u

// FBX
#undef snprintf
#include "fbxsdk.h"

// Core related includes
#include "stdafx.h"

// Defines
#define _INTR_MAX_ASSET_COUNT 4096u

// Asset Management related includes
#include "IntrinsicAssetManagementHelperFbx.h"
#include "IntrinsicAssetManagementResourcesAsset.h"
#include "IntrinsicAssetManagementImporterFbx.h"
#include "IntrinsicAssetManagementImporterTexture.h"
3 changes: 3 additions & 0 deletions IntrinsicCore/src/IntrinsicCoreApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// Precompiled header file
#include "stdafx.h"
#include <cmath>

// Renderer includes
#include "IntrinsicRendererVulkanRenderSystem.h"
Expand Down Expand Up @@ -42,6 +43,8 @@ bool Application::_running = true;

void Application::init(void* p_PlatformHandle, void* p_PlatformWindow)
{
std::isnan(1234.0f);

// Init. physics
Physics::System::init();

Expand Down
5 changes: 2 additions & 3 deletions IntrinsicCore/src/IntrinsicCoreComponentsRigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ void RigidBodyManager::updateActorsFromNodes(
physx::PxRigidDynamic* rigidDynamic = actor->isRigidDynamic();
physx::PxRigidStatic* rigidStatic = actor->isRigidStatic();

if (rigidDynamic &&
rigidDynamic->getRigidBodyFlags().isSet(
physx::PxRigidBodyFlag::eKINEMATIC))
if (rigidDynamic && rigidDynamic->getRigidBodyFlags().isSet(
physx::PxRigidBodyFlag::eKINEMATIC))
{
// Update kinematic target
const physx::PxTransform transform =
Expand Down
21 changes: 11 additions & 10 deletions IntrinsicCore/src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
#include "windows.h"
#endif // _WIN32

// GLM and GLI related includes
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_ENABLE_EXPERIMENTAL

#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <gli/gli.hpp>

// Tinydir
#include "tinydir/tinydir.h"

Expand Down Expand Up @@ -62,16 +73,6 @@
#include <cmath>
#include <thread>

// GLM related includes
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_ENABLE_EXPERIMENTAL

#include "glm/glm.hpp"
#include "glm/gtc/quaternion.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtx/quaternion.hpp"
#include "glm/gtx/rotate_vector.hpp"

// Core related includes
#include "IntrinsicCoreVersion.h"
#include "IntrinsicCorePrerequisites.h"
Expand Down
2 changes: 2 additions & 0 deletions IntrinsicEd/src/IntrinsicEdManagerWindowAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ void IntrinsicEdManagerWindowAsset::onCompileQueuedAssets()
Vulkan::Resources::ComputeCallManager::_activeRefs);
Vulkan::Resources::ComputeCallManager::createResources(
Vulkan::Resources::ComputeCallManager::_activeRefs);
Vulkan::Resources::MaterialManager::createResources(
Vulkan::Resources::MaterialManager::_activeRefs);

_assetsToRecompile.clear();
}
Expand Down
3 changes: 0 additions & 3 deletions IntrinsicEd/src/IntrinsicEdNodeViewTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "stdafx_editor.h"
#include "stdafx.h"

// Lib. includes
#include "gli.hpp"

// Helpers
void expandAllParents(QTreeWidgetItem* p_Item)
{
Expand Down
6 changes: 3 additions & 3 deletions IntrinsicEd/src/stdafx_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

#pragma once

// Core related includes
#include "stdafx.h"

// Qt related includes
#include <QtWidgets>
#include <QtWidgets/QMainWindow>

// Core related includes
#include "stdafx.h"

// ->Ed related includes
#include "IntrinsicEdViewport.h"
#include "IntrinsicEd.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "stdafx_vulkan.h"
#include "stdafx.h"

// Lib. includes
#include <gli/gli.hpp>

namespace Intrinsic
{
namespace Renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ImageData : Dod::Resources::ResourceDataBase
descMipLevelCount.resize(_INTR_MAX_IMAGE_COUNT);
descFileName.resize(_INTR_MAX_IMAGE_COUNT);
descMemoryPoolType.resize(_INTR_MAX_IMAGE_COUNT);
descAvgNormLength.resize(_INTR_MAX_IMAGE_COUNT);

vkImage.resize(_INTR_MAX_IMAGE_COUNT);
vkImageView.resize(_INTR_MAX_IMAGE_COUNT);
Expand All @@ -56,6 +57,7 @@ struct ImageData : Dod::Resources::ResourceDataBase
_INTR_ARRAY(uint32_t) descArrayLayerCount;
_INTR_ARRAY(uint32_t) descMipLevelCount;
_INTR_ARRAY(_INTR_STRING) descFileName;
_INTR_ARRAY(float) descAvgNormLength;

// Resources
_INTR_ARRAY(VkImage) vkImage;
Expand Down Expand Up @@ -89,6 +91,7 @@ struct ImageManager
_descArrayLayerCount(p_Ref) = 1u;
_descMipLevelCount(p_Ref) = 1u;
_descFileName(p_Ref) = "";
_descAvgNormLength(p_Ref) = 1.0f;
}

_INTR_INLINE static void destroyImage(ImageRef p_Ref)
Expand Down Expand Up @@ -120,9 +123,14 @@ struct ImageManager
p_Document.GetAllocator());
p_Properties.AddMember("fileName",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc,
_N(Image), "string",
_N(Image), _N(string),
_descFileName(p_Ref), true, false),
p_Document.GetAllocator());
p_Properties.AddMember(
"avgNormLength",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(Image), _N(float),
_descAvgNormLength(p_Ref), true, false),
p_Document.GetAllocator());
}

_INTR_INLINE static void initFromDescriptor(ImageRef p_Ref,
Expand All @@ -141,6 +149,9 @@ struct ImageManager
if (p_Properties.HasMember("fileName"))
_descFileName(p_Ref) =
JsonHelper::readPropertyString(p_Properties["fileName"]);
if (p_Properties.HasMember("avgNormLength"))
_descAvgNormLength(p_Ref) =
JsonHelper::readPropertyFloat(p_Properties["avgNormLength"]);
}

// <-
Expand Down Expand Up @@ -359,6 +370,10 @@ struct ImageManager
{
return _data.descFileName[p_Ref._id];
}
_INTR_INLINE static float& _descAvgNormLength(ImageRef p_Ref)
{
return _data.descAvgNormLength[p_Ref._id];
}

// GPU resources
_INTR_INLINE static VkImage& _vkImage(ImageRef p_Ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "stdafx_vulkan.h"
#include "stdafx.h"

// Lib. includes
#include <gli/gli.hpp>

namespace Intrinsic
{
namespace Renderer
Expand Down Expand Up @@ -105,33 +102,10 @@ void MaterialManager::createResources(const MaterialRefArray& p_Materiales)
ImageManager::_getResourceByName(_descNormalTextureName(matRef));

float avgNormalLength = 1.0f;
// if (normalRef.isValid())
//{
// _INTR_STRING texturePath =
// "media/textures/" + ImageManager::_descFileName(normalRef);

// gli::texture2d normalTexture =
// gli::texture2d(gli::load(texturePath.c_str()));
// gli::texture2d normalTexDec =
// gli::convert(normalTexture, gli::FORMAT_RGB32_SFLOAT_PACK32);

// glm::vec3 avgNormal = glm::vec3(0.0f);
// for (int32_t y = 0u; y < normalTexDec.extent().y; ++y)
// {
// for (int32_t x = 0u; x < normalTexDec.extent().x; ++x)
// {
// const gli::vec3 normal =
// gli::normalize(normalTexDec.load<gli::vec3>(
// gli::extent2d(x, y), 0u)) *
// 2.0f -
// 1.0f;
// avgNormal += normal;
// }
// }

// avgNormal /= normalTexDec.extent().x * normalTexDec.extent().y;
// avgNormalLength = glm::length(avgNormal);
//}
if (normalRef.isValid())
{
avgNormalLength = ImageManager::_descAvgNormLength(normalRef);
}

// Update material pass flags
{
Expand Down
2 changes: 1 addition & 1 deletion app/assets/shaders/gbuffer_water.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void main()
gbuffer.normal = normalize(TBN * (normal.xyz * 2.0 - 1.0));
gbuffer.metalMask = metalRoughness.x;
gbuffer.specular = 0.0;
gbuffer.roughness = metalRoughness.y;
gbuffer.roughness = adjustRoughness(metalRoughness.y, uboPerMaterial.data1.x);
gbuffer.materialBufferIdx = uboPerMaterial.data0.x;
gbuffer.emissive = 0.0;
gbuffer.occlusion = 1.0;
Expand Down
8 changes: 0 additions & 8 deletions app/managers/assets/blue_noise.asset.json

This file was deleted.

3 changes: 2 additions & 1 deletion app/managers/images/Moss_01.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Moss_01",
"imageType": 1,
"imageFormat": 10,
"fileName": "Moss_01.dds"
"fileName": "Moss_01.dds",
"avgNormLength": 1.0
}
}
3 changes: 2 additions & 1 deletion app/managers/images/Moss_01_NRM.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Moss_01_NRM",
"imageType": 1,
"imageFormat": 7,
"fileName": "Moss_01_NRM.dds"
"fileName": "Moss_01_NRM.dds",
"avgNormLength": 0.7670081853866577
}
}
3 changes: 2 additions & 1 deletion app/managers/images/Moss_01_PBR.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Moss_01_PBR",
"imageType": 1,
"imageFormat": 7,
"fileName": "Moss_01_PBR.dds"
"fileName": "Moss_01_PBR.dds",
"avgNormLength": 1.0
}
}
3 changes: 2 additions & 1 deletion app/managers/images/Prop_Atlas_01.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Prop_Atlas_01",
"imageType": 1,
"imageFormat": 10,
"fileName": "Prop_Atlas_01.dds"
"fileName": "Prop_Atlas_01.dds",
"avgNormLength": 1.0
}
}
3 changes: 2 additions & 1 deletion app/managers/images/Prop_Atlas_01_NRM.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Prop_Atlas_01_NRM",
"imageType": 1,
"imageFormat": 7,
"fileName": "Prop_Atlas_01_NRM.dds"
"fileName": "Prop_Atlas_01_NRM.dds",
"avgNormLength": 0.9487378001213074
}
}
3 changes: 2 additions & 1 deletion app/managers/images/Prop_Atlas_01_PBR.image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Prop_Atlas_01_PBR",
"imageType": 1,
"imageFormat": 7,
"fileName": "Prop_Atlas_01_PBR.dds"
"fileName": "Prop_Atlas_01_PBR.dds",
"avgNormLength": 1.0
}
}
Loading

0 comments on commit 1114805

Please sign in to comment.