Use cube map (from asset pack) in hdr example
This commit is contained in:
parent
1dd45a4ddf
commit
89dcddbdca
7 changed files with 21 additions and 54 deletions
|
|
@ -6,35 +6,35 @@ import glob
|
|||
|
||||
APK_NAME = "vulkanHDR"
|
||||
SHADER_DIR = "hdr"
|
||||
ASSETS_MODELS = ["cube.obj", "sphere.obj", "teapot.dae", "torusknot.obj"]
|
||||
ASSETS_TEXTURES = ["hdr_uffizi_bc6uf.DDS", "hrd_uffizi_rgba16_float.dds"]
|
||||
ASSETS_MODELS = ["cube.obj", "sphere.obj", "teapot.dae", "torusknot.obj", "venus.fbx"]
|
||||
ASSETS_TEXTURES = ["hdr/uffizi_cube.ktx"]
|
||||
|
||||
if subprocess.call("ndk-build", shell=True) == 0:
|
||||
if subprocess.call("ndk-build", shell=True) == 0:
|
||||
print("Build successful")
|
||||
|
||||
# Assets
|
||||
os.makedirs("./assets/shaders/base", exist_ok=True)
|
||||
os.makedirs("./assets/shaders/%s" % SHADER_DIR, exist_ok=True)
|
||||
os.makedirs("./assets/textures", exist_ok=True)
|
||||
os.makedirs("./assets/models", exist_ok=True)
|
||||
os.makedirs("./assets/textures/hdr", exist_ok=True)
|
||||
os.makedirs("./assets/models", exist_ok=True)
|
||||
os.makedirs("./res/drawable", exist_ok=True)
|
||||
|
||||
# Shaders
|
||||
# Shaders
|
||||
# Base
|
||||
for file in glob.glob("../../data/shaders/base/*.spv"):
|
||||
shutil.copy(file, "./assets/shaders/base")
|
||||
shutil.copy(file, "./assets/shaders/base")
|
||||
# Sample
|
||||
for file in glob.glob("../../data/shaders/%s/*.spv" %SHADER_DIR):
|
||||
shutil.copy(file, "./assets/shaders/%s" % SHADER_DIR)
|
||||
shutil.copy(file, "./assets/shaders/%s" % SHADER_DIR)
|
||||
# Textures
|
||||
for file in ASSETS_TEXTURES:
|
||||
shutil.copy("../../data/textures/%s" % file, "./assets/textures")
|
||||
shutil.copy("../../data/textures/%s" % file, "./assets/textures/hdr")
|
||||
# Models
|
||||
for file in ASSETS_MODELS:
|
||||
shutil.copy("../../data/models/%s" % file, "./assets/models")
|
||||
|
||||
# Icon
|
||||
shutil.copy("../../android/images/icon.png", "./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:
|
||||
for arg in sys.argv[1:]:
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -3,7 +3,7 @@
|
|||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerEnvMap;
|
||||
layout (binding = 1) uniform samplerCube samplerEnvMap;
|
||||
|
||||
layout (location = 0) in vec3 inUVW;
|
||||
layout (location = 1) in vec3 inPos;
|
||||
|
|
@ -24,13 +24,6 @@ layout (binding = 2) uniform UBO {
|
|||
float exposure;
|
||||
} ubo;
|
||||
|
||||
vec2 envMapEquirect(vec3 normal)
|
||||
{
|
||||
float phi = acos(-normal.y);
|
||||
float theta = atan(-1.0 * normal.x, normal.z) + PI;
|
||||
return vec2(theta / TwoPI, phi / PI);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
|
|
@ -40,7 +33,7 @@ void main()
|
|||
case 0: // Skybox
|
||||
{
|
||||
vec3 normal = normalize(inUVW);
|
||||
color = texture(samplerEnvMap, envMapEquirect(normal));
|
||||
color = texture(samplerEnvMap, normal);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -74,7 +67,7 @@ void main()
|
|||
|
||||
float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14);
|
||||
|
||||
color = texture(samplerEnvMap, envMapEquirect(reflect(-wViewVec, wNormal)));
|
||||
color = texture(samplerEnvMap, reflect(-wViewVec, wNormal));
|
||||
|
||||
color = vec4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0);
|
||||
}
|
||||
|
|
@ -84,7 +77,7 @@ void main()
|
|||
{
|
||||
vec3 wViewVec = mat3(inInvModelView) * normalize(inViewVec);
|
||||
vec3 wNormal = mat3(inInvModelView) * inNormal;
|
||||
color = texture(samplerEnvMap, envMapEquirect(refract(-wViewVec, wNormal, 1.0/1.6)));
|
||||
color = texture(samplerEnvMap, refract(-wViewVec, wNormal, 1.0/1.6));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -28,7 +28,6 @@ out gl_PerVertex
|
|||
void main()
|
||||
{
|
||||
outUVW = inPos;
|
||||
outUVW.x *= -1.0;
|
||||
|
||||
switch(type) {
|
||||
case 0: // Skybox
|
||||
|
|
|
|||
Binary file not shown.
39
hdr/hdr.cpp
39
hdr/hdr.cpp
|
|
@ -1,6 +1,8 @@
|
|||
/*
|
||||
* Vulkan Example - HDR
|
||||
*
|
||||
* Note: Requires the separate (HDR) asset pack (see data/textures/hdr/README.md)
|
||||
*
|
||||
* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de
|
||||
*
|
||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||
|
|
@ -41,7 +43,7 @@ public:
|
|||
});
|
||||
|
||||
struct {
|
||||
vks::Texture2D envmap;
|
||||
vks::TextureCubeMap envmap;
|
||||
} textures;
|
||||
|
||||
struct Models {
|
||||
|
|
@ -601,41 +603,14 @@ public:
|
|||
{
|
||||
// Models
|
||||
models.skybox.loadFromFile(getAssetPath() + "models/cube.obj", vertexLayout, 0.05f, vulkanDevice, queue);
|
||||
std::vector<std::string> filenames = {"sphere.obj", "teapot.dae", "torusknot.obj"};
|
||||
std::vector<std::string> filenames = { "geosphere.obj", "teapot.dae", "torusknot.obj", "venus.fbx" };
|
||||
for (auto file : filenames) {
|
||||
vks::Model model;
|
||||
model.loadFromFile(getAssetPath() + "models/" + file, vertexLayout, 0.05f, vulkanDevice, queue);
|
||||
model.loadFromFile(ASSET_PATH "models/" + file, vertexLayout, 0.05f * (file == "venus.fbx" ? 3.0f : 1.0f), vulkanDevice, queue);
|
||||
models.objects.push_back(model);
|
||||
}
|
||||
|
||||
// Load HDR texture (equirectangular projected)
|
||||
// VK_FORMAT_BC6H_UFLOAT_BLOCK is a compressed 16 bit unsigned floating point format for storing HDR content
|
||||
if (deviceFeatures.textureCompressionBC)
|
||||
{
|
||||
textures.envmap.loadFromFile(getAssetPath() + "textures/hdr_uffizi_bc6uf.DDS", VK_FORMAT_BC6H_UFLOAT_BLOCK, vulkanDevice, queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
textures.envmap.loadFromFile(getAssetPath() + "textures/hrd_uffizi_rgba16_float.dds", VK_FORMAT_R16G16B16A16_SFLOAT, vulkanDevice, queue);
|
||||
}
|
||||
|
||||
// Custom sampler with clamping adress mode
|
||||
vkDestroySampler(device, textures.envmap.sampler, nullptr);
|
||||
VkSamplerCreateInfo sampler{};
|
||||
sampler.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
sampler.magFilter = VK_FILTER_LINEAR;
|
||||
sampler.minFilter = VK_FILTER_LINEAR;
|
||||
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
sampler.addressModeV = sampler.addressModeU;
|
||||
sampler.addressModeW = sampler.addressModeU;
|
||||
sampler.maxLod = (float)textures.envmap.mipLevels;
|
||||
sampler.maxLod = 1.0f;
|
||||
sampler.anisotropyEnable = VK_TRUE;
|
||||
sampler.maxAnisotropy = vulkanDevice->properties.limits.maxSamplerAnisotropy;
|
||||
sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
||||
VK_CHECK_RESULT(vkCreateSampler(vulkanDevice->logicalDevice, &sampler, nullptr, &textures.envmap.sampler));
|
||||
textures.envmap.descriptor.sampler = textures.envmap.sampler;
|
||||
// Load HDR cube map
|
||||
textures.envmap.loadFromFile(getAssetPath() + "textures/hdr/uffizi_cube.ktx", VK_FORMAT_R16G16B16A16_SFLOAT, vulkanDevice, queue);
|
||||
}
|
||||
|
||||
void setupDescriptorPool()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue