diff --git a/android/deferredshadows/AndroidManifest.xml b/android/deferredshadows/AndroidManifest.xml
index 753f649e..7bead55f 100644
--- a/android/deferredshadows/AndroidManifest.xml
+++ b/android/deferredshadows/AndroidManifest.xml
@@ -15,6 +15,7 @@
android:label="Deferredshadows"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
+ android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden">
diff --git a/android/deferredshadows/build.bat b/android/deferredshadows/build.bat
deleted file mode 100644
index 6246ff46..00000000
--- a/android/deferredshadows/build.bat
+++ /dev/null
@@ -1,30 +0,0 @@
-cd jni
-call ndk-build
-if %ERRORLEVEL% EQU 0 (
- echo ndk-build has failed, build cancelled
- cd..
-
- mkdir "assets\shaders\base"
- xcopy "..\..\data\shaders\base\*.spv" "assets\shaders\base" /Y
-
- mkdir "assets\shaders\deferredshadows"
- xcopy "..\..\data\shaders\deferredshadows\*.spv" "assets\shaders\deferredshadows" /Y
-
- mkdir "assets\models\armor"
- xcopy "..\..\data\models\armor\*.*" "assets\models\armor" /Y
-
- mkdir "assets\textures"
- xcopy "..\..\data\textures\pattern_57_diffuse_bc3.ktx" "assets\textures" /Y
- xcopy "..\..\data\textures\pattern_57_normal_bc3.ktx" "assets\textures" /Y
-
- mkdir "assets\models"
- xcopy "..\..\data\models\openbox.dae" "assets\models" /Y
-
- mkdir "res\drawable"
- xcopy "..\..\android\images\icon.png" "res\drawable" /Y
-
- call ant debug -Dout.final.file=vulkanDeferredshadows.apk
-) ELSE (
- echo error : ndk-build failed with errors!
- cd..
-)
diff --git a/android/deferredshadows/build.py b/android/deferredshadows/build.py
new file mode 100644
index 00000000..5821bc35
--- /dev/null
+++ b/android/deferredshadows/build.py
@@ -0,0 +1,58 @@
+import os
+import shutil
+import subprocess
+import sys
+import glob
+
+APK_NAME = "vulkanDeferredshadows"
+SHADER_DIR = "deferredshadows"
+ASSETS_MODELS = ["openbox.dae"]
+ASSETS_TEXTURES = ["stonefloor02_color_astc_8x8_unorm.ktx", "stonefloor02_color_bc3_unorm.ktx", "stonefloor02_normal_astc_8x8_unorm.ktx", "stonefloor02_normal_bc3_unorm.ktx", "stonefloor02_color_etc2_unorm.ktx", "stonefloor02_normal_etc2_unorm.ktx"]
+
+if subprocess.call("ndk-build", shell=True) == 0:
+ print("Build successful")
+
+ # Assets
+ if not os.path.exists("./assets"):
+ os.makedirs("./assets")
+
+ # Shaders
+ # Base
+ if not os.path.exists("./assets/shaders/base"):
+ os.makedirs("./assets/shaders/base")
+ for file in glob.glob("../../data/shaders/base/*.spv"):
+ shutil.copy(file, "./assets/shaders/base")
+ # Sample
+ if not os.path.exists("./assets/shaders/%s" % SHADER_DIR):
+ os.makedirs("./assets/shaders/%s" % SHADER_DIR)
+ for file in glob.glob("../../data/shaders/%s/*.spv" %SHADER_DIR):
+ shutil.copy(file, "./assets/shaders/%s" % SHADER_DIR)
+ # Textures and model
+ if not os.path.exists("./assets/models/armor/"):
+ os.makedirs("./assets/models/armor/")
+ for file in glob.glob("../../data/models/armor/*.*"):
+ shutil.copy(file, "./assets/models/armor")
+ # Textures from base
+ if not os.path.exists("./assets/textures"):
+ os.makedirs("./assets/textures")
+ for file in ASSETS_TEXTURES:
+ shutil.copy("../../data/textures/%s" % file, "./assets/textures")
+ if not os.path.exists("./assets/models"):
+ os.makedirs("./assets/models")
+ for file in ASSETS_MODELS:
+ shutil.copy("../../data/models/%s" % file, "./assets/models")
+
+ # Icon
+ if not os.path.exists("./res/drawable"):
+ os.makedirs("./res/drawable")
+ shutil.copy("../../android/images/icon.png", "./res/drawable")
+
+ if subprocess.call("ant debug -Dout.final.file=%s.apk" % APK_NAME, shell=True) == 0:
+ if len(sys.argv) > 1:
+ if sys.argv[1] == "-deploy":
+ if subprocess.call("adb install -r %s.apk" % APK_NAME, shell=True) != 0:
+ print("Could not deploy to device!")
+ else:
+ print("Error during build process!")
+else:
+ print("Error building project!")
diff --git a/data/textures/stonefloor02_color_astc_8x8_unorm.ktx b/data/textures/stonefloor02_color_astc_8x8_unorm.ktx
new file mode 100644
index 00000000..5c953c7a
Binary files /dev/null and b/data/textures/stonefloor02_color_astc_8x8_unorm.ktx differ
diff --git a/data/textures/stonefloor02_color_bc3_unorm.ktx b/data/textures/stonefloor02_color_bc3_unorm.ktx
new file mode 100644
index 00000000..f9b03033
Binary files /dev/null and b/data/textures/stonefloor02_color_bc3_unorm.ktx differ
diff --git a/data/textures/stonefloor02_color_etc2_unorm.ktx b/data/textures/stonefloor02_color_etc2_unorm.ktx
new file mode 100644
index 00000000..80dd0e43
Binary files /dev/null and b/data/textures/stonefloor02_color_etc2_unorm.ktx differ
diff --git a/data/textures/stonefloor02_normal_astc_8x8_unorm.ktx b/data/textures/stonefloor02_normal_astc_8x8_unorm.ktx
new file mode 100644
index 00000000..19bd9a4d
Binary files /dev/null and b/data/textures/stonefloor02_normal_astc_8x8_unorm.ktx differ
diff --git a/data/textures/stonefloor02_normal_bc3_unorm.ktx b/data/textures/stonefloor02_normal_bc3_unorm.ktx
new file mode 100644
index 00000000..fca0470f
Binary files /dev/null and b/data/textures/stonefloor02_normal_bc3_unorm.ktx differ
diff --git a/data/textures/stonefloor02_normal_etc2_unorm.ktx b/data/textures/stonefloor02_normal_etc2_unorm.ktx
new file mode 100644
index 00000000..cec16fe8
Binary files /dev/null and b/data/textures/stonefloor02_normal_etc2_unorm.ktx differ
diff --git a/deferredshadows/deferredshadows.cpp b/deferredshadows/deferredshadows.cpp
index 7ce6556e..6e3a63fb 100644
--- a/deferredshadows/deferredshadows.cpp
+++ b/deferredshadows/deferredshadows.cpp
@@ -184,8 +184,6 @@ public:
camera.setPerspective(60.0f, (float)width / (float)height, zNear, zFar);
timerSpeed *= 0.25f;
paused = true;
- // Device features to be enabled for this example
- enabledFeatures.geometryShader = VK_TRUE;
}
~VulkanExample()
@@ -232,6 +230,18 @@ public:
vkDestroySemaphore(device, offscreenSemaphore, nullptr);
}
+ // Enable physical device features required for this example
+ virtual void getEnabledFeatures()
+ {
+ // Geometry shader support is required for writing to multiple shadow map layers in one single pass
+ if (deviceFeatures.geometryShader) {
+ enabledFeatures.geometryShader = VK_TRUE;
+ }
+ else {
+ vks::tools::exitFatal("Selected GPU does not support geometry shaders!", "Feature not supported");
+ }
+ }
+
// Prepare a layered shadow map with each layer containing depth from a light's point of view
// The shadow mapping pass uses geometry shader instancing to output the scene from the different
// light sources' point of view to the layers of the depth attachment in one single pass
@@ -417,10 +427,30 @@ public:
modelCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f);
models.background.loadFromFile(getAssetPath() + "models/openbox.dae", vertexLayout, &modelCreateInfo, vulkanDevice, queue);
- textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/colormap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
- textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
- textures.background.colorMap.loadFromFile(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
- textures.background.normalMap.loadFromFile(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
+ // Textures
+ std::string texFormatSuffix;
+ VkFormat texFormat;
+ // Get supported compressed texture format
+ if (vulkanDevice->features.textureCompressionBC) {
+ texFormatSuffix = "_bc3_unorm";
+ texFormat = VK_FORMAT_BC3_UNORM_BLOCK;
+ }
+ else if (vulkanDevice->features.textureCompressionASTC_LDR) {
+ texFormatSuffix = "_astc_8x8_unorm";
+ texFormat = VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
+ }
+ else if (vulkanDevice->features.textureCompressionETC2) {
+ texFormatSuffix = "_etc2_unorm";
+ texFormat = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
+ }
+ else {
+ vks::tools::exitFatal("Device does not support any compressed texture format!", "Error");
+ }
+
+ textures.model.colorMap.loadFromFile(getAssetPath() + "models/armor/color" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue);
+ textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normal" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue);
+ textures.background.colorMap.loadFromFile(getAssetPath() + "textures/stonefloor02_color" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue);
+ textures.background.normalMap.loadFromFile(getAssetPath() + "textures/stonefloor02_normal" + texFormatSuffix + ".ktx", texFormat, vulkanDevice, queue);
}
void reBuildCommandBuffers()
@@ -914,8 +944,8 @@ public:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen));
// Shadow mapping pipeline
- // The shadow mapping pipeline uses geometry shader instancing (invoctations layout modifier) to output
- // shadow maps for multiple lights sources into the different shadiw map layers in one single render pass
+ // The shadow mapping pipeline uses geometry shader instancing (invocations layout modifier) to output
+ // shadow maps for multiple lights sources into the different shadow map layers in one single render pass
std::array shadowStages;
shadowStages[0] = loadShader(getAssetPath() + "shaders/deferredshadows/shadow.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shadowStages[1] = loadShader(getAssetPath() + "shaders/deferredshadows/shadow.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);