Fixing image leak and computeDiffuse in Wavefront shading
This commit is contained in:
parent
2eb9b6e522
commit
e56201ef1d
25 changed files with 141 additions and 77 deletions
|
|
@ -380,15 +380,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,6 +406,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -313,15 +313,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -339,6 +340,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -334,15 +334,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,6 +361,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -334,15 +334,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,6 +361,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -337,15 +337,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,6 +364,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -334,15 +334,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,6 +361,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ extern std::vector<std::string> defaultSearchPaths;
|
||||||
#include "nvvk/pipeline_vk.hpp"
|
#include "nvvk/pipeline_vk.hpp"
|
||||||
#include "nvvk/renderpasses_vk.hpp"
|
#include "nvvk/renderpasses_vk.hpp"
|
||||||
#include "nvvk/shaders_vk.hpp"
|
#include "nvvk/shaders_vk.hpp"
|
||||||
|
#include "nvh/nvprint.hpp"
|
||||||
|
|
||||||
#include "shaders/binding.glsl"
|
#include "shaders/binding.glsl"
|
||||||
|
|
||||||
|
|
@ -205,7 +206,11 @@ void HelloVulkan::loadScene(const std::string& filename)
|
||||||
std::string warn, error;
|
std::string warn, error;
|
||||||
|
|
||||||
if(!tcontext.LoadASCIIFromFile(&tmodel, &error, &warn, filename))
|
if(!tcontext.LoadASCIIFromFile(&tmodel, &error, &warn, filename))
|
||||||
|
{
|
||||||
assert(!"Error while loading scene");
|
assert(!"Error while loading scene");
|
||||||
|
}
|
||||||
|
LOGW(warn.c_str());
|
||||||
|
LOGE(error.c_str());
|
||||||
|
|
||||||
|
|
||||||
m_gltfScene.importMaterials(tmodel);
|
m_gltfScene.importMaterials(tmodel);
|
||||||
|
|
@ -286,31 +291,42 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf, tinygltf:
|
||||||
samplerCreateInfo.setMaxLod(FLT_MAX);
|
samplerCreateInfo.setMaxLod(FLT_MAX);
|
||||||
vk::Format format = vk::Format::eR8G8B8A8Srgb;
|
vk::Format format = vk::Format::eR8G8B8A8Srgb;
|
||||||
|
|
||||||
if(gltfModel.images.empty())
|
auto addDefaultTexture = [this]() {
|
||||||
{
|
|
||||||
// Make dummy image(1,1), needed as we cannot have an empty array
|
// Make dummy image(1,1), needed as we cannot have an empty array
|
||||||
nvvk::ScopeCommandBuffer cmdBuf(m_device, m_graphicsQueueIndex);
|
nvvk::ScopeCommandBuffer cmdBuf(m_device, m_graphicsQueueIndex);
|
||||||
std::array<uint8_t, 4> white = {255, 255, 255, 255};
|
std::array<uint8_t, 4> white = {255, 255, 255, 255};
|
||||||
m_textures.emplace_back(m_alloc.createTexture(
|
m_textures.emplace_back(m_alloc.createTexture(
|
||||||
cmdBuf, 4, white.data(), nvvk::makeImage2DCreateInfo(vk::Extent2D{1, 1}), {}));
|
cmdBuf, 4, white.data(), nvvk::makeImage2DCreateInfo(vk::Extent2D{1, 1}), {}));
|
||||||
m_debug.setObjectName(m_textures[0].image, "dummy");
|
m_debug.setObjectName(m_textures.back().image, "dummy");
|
||||||
|
};
|
||||||
|
|
||||||
|
if(gltfModel.images.empty())
|
||||||
|
{
|
||||||
|
addDefaultTexture();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_textures.resize(gltfModel.images.size());
|
m_textures.reserve(gltfModel.images.size());
|
||||||
for(size_t i = 0; i < gltfModel.images.size(); i++)
|
for(size_t i = 0; i < gltfModel.images.size(); i++)
|
||||||
{
|
{
|
||||||
auto& gltfimage = gltfModel.images[i];
|
auto& gltfimage = gltfModel.images[i];
|
||||||
void* buffer = &gltfimage.image[0];
|
void* buffer = &gltfimage.image[0];
|
||||||
VkDeviceSize bufferSize = gltfimage.image.size();
|
VkDeviceSize bufferSize = gltfimage.image.size();
|
||||||
auto imgSize = vk::Extent2D(gltfimage.width, gltfimage.height);
|
auto imgSize = vk::Extent2D(gltfimage.width, gltfimage.height);
|
||||||
|
|
||||||
|
if(bufferSize == 0 || gltfimage.width == -1 || gltfimage.height == -1)
|
||||||
|
{
|
||||||
|
addDefaultTexture();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
vk::ImageCreateInfo imageCreateInfo =
|
vk::ImageCreateInfo imageCreateInfo =
|
||||||
nvvk::makeImage2DCreateInfo(imgSize, format, vkIU::eSampled, true);
|
nvvk::makeImage2DCreateInfo(imgSize, format, vkIU::eSampled, true);
|
||||||
|
|
||||||
nvvk::Image image = m_alloc.createImage(cmdBuf, bufferSize, buffer, imageCreateInfo);
|
nvvk::Image image = m_alloc.createImage(cmdBuf, bufferSize, buffer, imageCreateInfo);
|
||||||
nvvk::cmdGenerateMipmaps(cmdBuf, image.image, format, imgSize, imageCreateInfo.mipLevels);
|
nvvk::cmdGenerateMipmaps(cmdBuf, image.image, format, imgSize, imageCreateInfo.mipLevels);
|
||||||
vk::ImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo);
|
vk::ImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo);
|
||||||
m_textures[i] = m_alloc.createTexture(image, ivInfo, samplerCreateInfo);
|
m_textures.emplace_back(m_alloc.createTexture(image, ivInfo, samplerCreateInfo));
|
||||||
|
|
||||||
m_debug.setObjectName(m_textures[i].image, std::string("Txt" + std::to_string(i)).c_str());
|
m_debug.setObjectName(m_textures[i].image, std::string("Txt" + std::to_string(i)).c_str());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -350,15 +350,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,6 +376,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -344,15 +344,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,6 +371,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -334,15 +334,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,6 +361,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -338,15 +338,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -364,6 +365,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -342,15 +342,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,6 +368,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
|
|
@ -334,15 +334,16 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
o << "media/textures/" << texture;
|
o << "media/textures/" << texture;
|
||||||
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
std::string txtFile = nvh::findFile(o.str(), defaultSearchPaths);
|
||||||
|
|
||||||
stbi_uc* pixels =
|
stbi_uc* stbi_pixels = stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||||
stbi_load(txtFile.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
|
||||||
|
|
||||||
|
std::array<stbi_uc, 4> color{255u, 0u, 255u, 255u};
|
||||||
|
|
||||||
|
stbi_uc* pixels = stbi_pixels;
|
||||||
// Handle failure
|
// Handle failure
|
||||||
if(!pixels)
|
if(!stbi_pixels)
|
||||||
{
|
{
|
||||||
texWidth = texHeight = 1;
|
texWidth = texHeight = 1;
|
||||||
texChannels = 4;
|
texChannels = 4;
|
||||||
std::array<uint8_t, 4> color{255u, 0u, 255u, 255u};
|
|
||||||
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
pixels = reinterpret_cast<stbi_uc*>(color.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,6 +361,8 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
|
||||||
|
|
||||||
m_textures.push_back(texture);
|
m_textures.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stbi_image_free(stbi_pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ vec3 computeDiffuse(WaveFrontMaterial mat, vec3 lightDir, vec3 normal)
|
||||||
float dotNL = max(dot(normal, lightDir), 0.0);
|
float dotNL = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 c = mat.diffuse * dotNL;
|
vec3 c = mat.diffuse * dotNL;
|
||||||
if(mat.illum >= 1)
|
if(mat.illum >= 1)
|
||||||
return c + mat.ambient;
|
c += mat.ambient;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
vec3 computeSpecular(WaveFrontMaterial mat, vec3 viewDir, vec3 lightDir, vec3 normal)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue