Added ETC2 and ASTC texture variants (Refs #174)

This commit is contained in:
saschawillems 2017-03-11 11:39:05 +01:00
parent 3af19a1041
commit cddbebddea
10 changed files with 97 additions and 38 deletions

View file

@ -15,6 +15,7 @@
android:label="Deferredshadows" android:label="Deferredshadows"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden"> android:configChanges="orientation|screenSize|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="vulkanDeferredshadows" /> <meta-data android:name="android.app.lib_name" android:value="vulkanDeferredshadows" />
<intent-filter> <intent-filter>

View file

@ -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..
)

View file

@ -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!")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -184,8 +184,6 @@ public:
camera.setPerspective(60.0f, (float)width / (float)height, zNear, zFar); camera.setPerspective(60.0f, (float)width / (float)height, zNear, zFar);
timerSpeed *= 0.25f; timerSpeed *= 0.25f;
paused = true; paused = true;
// Device features to be enabled for this example
enabledFeatures.geometryShader = VK_TRUE;
} }
~VulkanExample() ~VulkanExample()
@ -232,6 +230,18 @@ public:
vkDestroySemaphore(device, offscreenSemaphore, nullptr); 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 // 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 // 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 // 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); modelCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f);
models.background.loadFromFile(getAssetPath() + "models/openbox.dae", vertexLayout, &modelCreateInfo, vulkanDevice, queue); 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
textures.model.normalMap.loadFromFile(getAssetPath() + "models/armor/normalmap.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); std::string texFormatSuffix;
textures.background.colorMap.loadFromFile(getAssetPath() + "textures/pattern_57_diffuse_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); VkFormat texFormat;
textures.background.normalMap.loadFromFile(getAssetPath() + "textures/pattern_57_normal_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); // 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() void reBuildCommandBuffers()
@ -914,8 +944,8 @@ public:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen));
// Shadow mapping pipeline // Shadow mapping pipeline
// The shadow mapping pipeline uses geometry shader instancing (invoctations layout modifier) to output // The shadow mapping pipeline uses geometry shader instancing (invocations layout modifier) to output
// shadow maps for multiple lights sources into the different shadiw map layers in one single render pass // shadow maps for multiple lights sources into the different shadow map layers in one single render pass
std::array<VkPipelineShaderStageCreateInfo, 3> shadowStages; std::array<VkPipelineShaderStageCreateInfo, 3> shadowStages;
shadowStages[0] = loadShader(getAssetPath() + "shaders/deferredshadows/shadow.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); 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); shadowStages[1] = loadShader(getAssetPath() + "shaders/deferredshadows/shadow.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);