Skip to content

Commit 492874d

Browse files
handle the CCW/CW flip when instance matrix is LH
1 parent 82726cb commit 492874d

3 files changed

Lines changed: 16 additions & 50 deletions

File tree

include/nbl/asset/ICPUScene.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ class ICPUScene final : public IAsset, public IScene
186186

187187
virtual inline instance_flags_t getInstanceFlags(const uint32_t instanceIx, const ICPUMorphTargets::index_t targetIx)
188188
{
189+
core::bitflag retval = instance_flags_t::TRIANGLE_FACING_CULL_DISABLE_BIT;
190+
// you probably want this
191+
if (hlsl::determinant(hlsl::math::linalg::truncate<3,3>(getTransform(instanceIx,targetIx)))<0.f)
192+
retval |= instance_flags_t::TRIANGLE_FLIP_FACING_BIT;
189193
// TODO: could derive from the material table if we want FORCE_OPAQUE_BIT or FORCE_NO_OPAQUE_BIT but its a whole instance thing
190-
return instance_flags_t::TRIANGLE_FACING_CULL_DISABLE_BIT;
194+
return retval.value;
191195
}
192196

193197
virtual inline uint32_t getInstanceIndex(const uint32_t instanceIx, const ICPUMorphTargets::index_t targetIx) {return instanceIx;}

include/nbl/ext/MitsubaLoader/CMitsubaLoader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class CMitsubaLoader final : public asset::ISceneLoader
4848
virtual ~CMitsubaLoader() = default;
4949

5050
#if 0
51-
void cacheTexture(SContext& ctx, uint32_t hierarchyLevel, const CElementTexture* texture, const CMitsubaMaterialCompilerFrontend::E_IMAGE_VIEW_SEMANTIC semantic);
52-
5351
template <typename Iter>
5452
core::smart_refctd_ptr<asset::ICPUDescriptorSet> createDS0(const SContext& _ctx, asset::ICPUPipelineLayout* _layout, const asset::material_compiler::CMaterialCompilerGLSLBackendCommon::result_t& _compResult, Iter meshBegin, Iter meshEnd);
5553
#endif

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ namespace ext::MitsubaLoader
2929
{
3030

3131
#if 0 // old material compiler
32-
_NBL_STATIC_INLINE_CONSTEXPR const char* FRAGMENT_SHADER_DEFINITIONS =
33-
R"(
34-
vec3 nbl_glsl_MC_getNormalizedWorldSpaceV()
35-
{
36-
vec3 campos = ....;
37-
return normalize(campos - WorldPos);
38-
}
39-
vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
40-
{
41-
return normalize(Normal);
42-
}
43-
44-
mat2x3 nbl_glsl_perturbNormal_dPdSomething()
45-
{
46-
return mat2x3(dFdx(WorldPos),dFdy(WorldPos));
47-
}
48-
mat2 nbl_glsl_perturbNormal_dUVdSomething()
49-
{
50-
return mat2(dFdx(UV),dFdy(UV));
51-
}
52-
)";
5332
_NBL_STATIC_INLINE_CONSTEXPR const char* FRAGMENT_SHADER_IMPL = R"(
5433
#ifndef _NBL_BSDF_COS_EVAL_DEFINED_
5534
#define _NBL_BSDF_COS_EVAL_DEFINED_
@@ -104,19 +83,6 @@ void main()
10483
}
10584
#endif
10685
)";
107-
static core::smart_refctd_ptr<asset::ICPUSpecializedShader> createFragmentShader(const asset::material_compiler::CMaterialCompilerGLSLBackendCommon::result_t& _mcRes, size_t _VTstorageViewCount)
108-
{
109-
std::string source =
110-
FRAGMENT_SHADER_PROLOGUE +
111-
_mcRes.fragmentShaderSource_declarations +
112-
FRAGMENT_SHADER_INPUT_OUTPUT +
113-
"#include <nbl/builtin/glsl/ext/MitsubaLoader/material_compiler_compatibility.glsl/" + std::to_string(_VTstorageViewCount) + ">" +
114-
FRAGMENT_SHADER_DEFINITIONS +
115-
_mcRes.fragmentShaderSource +
116-
FRAGMENT_SHADER_IMPL;
117-
118-
return createSpecShader(source.c_str(), asset::ISpecializedShader::ESS_FRAGMENT);
119-
}
12086
// TODO: move to IAssetLoader
12187
static core::smart_refctd_ptr<asset::ICPUImage> createDerivMap(SContext& ctx, asset::ICPUImage* _heightMap, const ICPUSampler::SParams& _samplerParams, bool fromNormalMap)
12288
{
@@ -142,11 +108,8 @@ static core::smart_refctd_ptr<asset::ICPUImage> createDerivMap(SContext& ctx, as
142108

143109
return derivmap_img;
144110
}
145-
static core::smart_refctd_ptr<asset::ICPUImage> createSingleChannelImage(const asset::ICPUImage* _img, const asset::ICPUImageView::SComponentMapping::E_SWIZZLE srcChannel)
146-
{
147-
// deprecated will be expressed in Material Compiler Frontend AST as a swizzle
148-
}
149111
#endif
112+
150113
constexpr auto LoggerError = system::ILogger::ELL_ERROR;
151114

152115
bool CMitsubaLoader::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const
@@ -216,7 +179,7 @@ void SContext::writeDot3File(system::ISystem* system, const system::path& filepa
216179
}
217180
if (!file)
218181
{
219-
inner.params.logger.log("Failed to Open \"%s\" for writing",system::ILogger::ELL_ERROR,filepath.c_str());
182+
inner.params.logger.log("Failed to Open \"%s\" for writing",LoggerError,filepath.c_str());
220183
return;
221184
}
222185
auto str = printer();
@@ -304,7 +267,7 @@ SAssetBundle CMitsubaLoader::loadAsset(system::IFile* _file, const IAssetLoader:
304267
instances.resize(index+1,true);
305268
instances.getMorphTargets()[index] = core::smart_refctd_ptr<ICPUMorphTargets>(const_cast<ICPUMorphTargets*>(targets.get()));
306269
if (shape->transform.matrix[3]!=float32_t4(0,0,0,1))
307-
_params.logger.log("Shape with id %s has Non-Affine transformation matrix, last row is not 0,0,0,1!",system::ILogger::ELL_ERROR,shape->id.c_str());
270+
_params.logger.log("Shape with id %s has Non-Affine transformation matrix, last row is not 0,0,0,1!",LoggerError,shape->id.c_str());
308271
instances.getInitialTransforms()[index] = shape->getTransform();
309272
//
310273
const core::string debugName = shape->id.empty() ? std::format("0x{:x}",ptrdiff_t(shape)):shape->id;
@@ -426,7 +389,7 @@ auto SContext::getMaterial(
426389
auto logger = inner.params.logger;
427390
if (!success)
428391
{
429-
logger.log("Failed to add Material for %s",system::ILogger::ELL_ERROR,debugName.c_str());
392+
logger.log("Failed to add Material for %s",LoggerError,debugName.c_str());
430393
return {};
431394
}
432395
else if (debugFileWriter)
@@ -509,10 +472,10 @@ parameter_t SContext::getTexture(const CElementTexture* const rootTex, hlsl::flo
509472
transform[1][2] = bitmap.voffset;
510473
}
511474
else
512-
inner.params.logger.log("Failed to load bitmap texture for %p with id %s",system::ILogger::ELL_ERROR,tex,tex ? tex->id.c_str():"");
475+
inner.params.logger.log("Failed to load bitmap texture for %p with id %s",LoggerError,tex,tex ? tex->id.c_str():"");
513476
}
514477
else
515-
inner.params.logger.log("Failed to unroll texture scale for %p with id %s",system::ILogger::ELL_ERROR,rootTex,rootTex ? rootTex->id.c_str():"");
478+
inner.params.logger.log("Failed to unroll texture scale for %p with id %s",LoggerError,rootTex,rootTex ? rootTex->id.c_str():"");
516479
if (!retval.view) // set a clear error value
517480
retval.scale = std::numeric_limits<decltype(retval.scale)>::signaling_NaN();
518481
return retval;
@@ -623,7 +586,7 @@ auto SContext::genProfile(const CElementEmissionProfile* profile) -> frontend_ir
623586
iesMeta = meta->selfCast<const CIESProfileMetadata>();
624587
if (!iesMeta)
625588
{
626-
inner.params.logger.log("Could Load Emission Profile from \"%s\" or its not an IES profile!",system::ILogger::ELL_ERROR,profile->filename);
589+
inner.params.logger.log("Could Load Emission Profile from \"%s\" or its not an IES profile!",LoggerError,profile->filename);
627590
return retval;
628591
}
629592
assert(assetLoaded.getAssetType()==IAsset::ET_IMAGE_VIEW);
@@ -952,7 +915,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
952915
auto logger = inner.params.logger;
953916
if (!success)
954917
{
955-
logger.log("Failed to add Material for %s",system::ILogger::ELL_ERROR,debugName.c_str());
918+
logger.log("Failed to add Material for %s",LoggerError,debugName.c_str());
956919
return {};
957920
}
958921
else if (debugFileWriter)
@@ -1100,7 +1063,7 @@ auto SContext::loadShapeGroup(const CElementShape* shape) -> SContext::shape_ass
11001063

11011064
auto collection = core::make_smart_refctd_ptr<ICPUGeometryCollection>();
11021065
if (!collection)
1103-
inner.params.logger.log("Failed to create an ICPUGeometryCollection for Shape Group",system::ILogger::ELL_ERROR);
1066+
inner.params.logger.log("Failed to create an ICPUGeometryCollection for Shape Group",LoggerError);
11041067
else
11051068
{
11061069
auto* geometries = collection->getGeometries();
@@ -1302,6 +1265,7 @@ auto SContext::loadBasicShape(const CElementShape* shape) -> SContext::shape_ass
13021265
addGeometry({.geometry=creator->createDisk(1.f,64)});
13031266
break;
13041267
case CElementShape::Type::OBJ:
1268+
assert(false);
13051269
#if 0 // TODO: Arek
13061270
mesh = loadModel(shape->obj.filename);
13071271
flipNormals = flipNormals!=shape->obj.flipNormals;
@@ -1363,7 +1327,7 @@ auto SContext::loadBasicShape(const CElementShape* shape) -> SContext::shape_ass
13631327
// handle fail
13641328
if (pGeometries->empty())
13651329
{
1366-
inner.params.logger.log("Failed to Load/Create Basic non-Instanced Shape with id %s",system::ILogger::ELL_ERROR,shape->id.c_str());
1330+
inner.params.logger.log("Failed to Load/Create Basic non-Instanced Shape with id %s",LoggerError,shape->id.c_str());
13671331
return nullptr;
13681332
}
13691333

0 commit comments

Comments
 (0)