X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-scene-loader%2Fpublic-api%2Fmaterial-definition.cpp;h=5838da16b0f29a5aa02f67171615db47e5f902a4;hp=3c7a3917015a76ce2dd7bb242a34ab1df40f0f82;hb=59d7a437c93f4864515c64d0aa3eacaebd293db6;hpb=5538e6464abd7f224dcde5de9aeeee6d94177b29 diff --git a/dali-scene-loader/public-api/material-definition.cpp b/dali-scene-loader/public-api/material-definition.cpp index 3c7a391..5838da1 100644 --- a/dali-scene-loader/public-api/material-definition.cpp +++ b/dali-scene-loader/public-api/material-definition.cpp @@ -110,7 +110,9 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const RawData raw; const bool hasTransparency = MaskMatch(mFlags, TRANSPARENCY); - uint32_t numBuffers = mTextureStages.size() + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); + // Why we add additional count here? + uint32_t numBuffers = mTextureStages.size() + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) + : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); if(numBuffers == 0) { return raw; @@ -148,7 +150,7 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); ++iTexture; } - else // single value albedo, albedo-alpha or albedo-metallic + else if(mNeedAlbedoTexture) // single value albedo, albedo-alpha or albedo-metallic { uint32_t bufferSize = 4; uint8_t* buffer = nullptr; @@ -182,7 +184,7 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); ++iTexture; } - else if(createMetallicRoughnessAndNormal) + else if(createMetallicRoughnessAndNormal && mNeedMetallicRoughnessTexture) { // NOTE: we want to set both metallic and roughness to 1.0; dli uses the R & A channels, // glTF2 uses B & G, so we might as well just set all components to 1.0. @@ -196,21 +198,24 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); ++iTexture; } - else if(createMetallicRoughnessAndNormal) + else if(mNeedNormalTexture) { - const auto bufferSize = 3; - uint8_t* buffer = new uint8_t[bufferSize]{0x7f, 0x7f, 0xff}; // normal of (0, 0, 1) - raw.mTextures.push_back({PixelData::New(buffer, bufferSize, 1, 1, Pixel::RGB888, PixelData::DELETE_ARRAY), SINGLE_VALUE_SAMPLER}); - } - else // single-value normal-roughness - { - const auto bufferSize = 4; - uint8_t* buffer = new uint8_t[bufferSize]{0x7f, 0x7f, 0xff, 0xff}; // normal of (0, 0, 1), roughness of 1.0 - raw.mTextures.push_back({PixelData::New(buffer, bufferSize, 1, 1, Pixel::RGBA8888, PixelData::DELETE_ARRAY), SINGLE_VALUE_SAMPLER}); + if(createMetallicRoughnessAndNormal) + { + const auto bufferSize = 3; + uint8_t* buffer = new uint8_t[bufferSize]{0x7f, 0x7f, 0xff}; // normal of (0, 0, 1) + raw.mTextures.push_back({PixelData::New(buffer, bufferSize, 1, 1, Pixel::RGB888, PixelData::DELETE_ARRAY), SINGLE_VALUE_SAMPLER}); + } + else // single-value normal-roughness + { + const auto bufferSize = 4; + uint8_t* buffer = new uint8_t[bufferSize]{0x7f, 0x7f, 0xff, 0xff}; // normal of (0, 0, 1), roughness of 1.0 + raw.mTextures.push_back({PixelData::New(buffer, bufferSize, 1, 1, Pixel::RGBA8888, PixelData::DELETE_ARRAY), SINGLE_VALUE_SAMPLER}); + } } } - // Extra textures. TODO: emissive, occlusion etc. + // Extra textures. if(checkStage(SUBSURFACE)) { raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); @@ -223,6 +228,12 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const ++iTexture; } + if(checkStage(EMISSIVE)) + { + raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); + ++iTexture; + } + return raw; } @@ -251,6 +262,13 @@ TextureSet MaterialDefinition::Load(const EnvironmentDefinition::Vector& environ if(mEnvironmentIdx < environments.size()) { auto& envTextures = environments[mEnvironmentIdx].second; + // If pre-computed brdf texture is defined, set the texture. + if(envTextures.mBrdf) + { + textureSet.SetTexture(n, envTextures.mBrdf); + ++n; + } + if(envTextures.mDiffuse) { textureSet.SetTexture(n, envTextures.mDiffuse); @@ -265,6 +283,7 @@ TextureSet MaterialDefinition::Load(const EnvironmentDefinition::Vector& environ textureSet.SetTexture(n, envTextures.mSpecular); textureSet.SetSampler(n, specularSampler); + ++n; } } else