From b902a9028563daa733bae149e69021280ea56f45 Mon Sep 17 00:00:00 2001 From: magicwhale <27659755+magicwhale@users.noreply.github.com> Date: Mon, 3 Dec 2018 10:15:47 -0800 Subject: [PATCH] Changed MeshAssimp to dynamically generate materials with filamat (#563) --- samples/CMakeLists.txt | 8 - samples/app/MeshAssimp.cpp | 237 +++++++++++++------ samples/app/MeshAssimp.h | 10 +- samples/materials/gltf2.mat | 70 ------ samples/materials/gltf2DoubleSided.mat | 71 ------ samples/materials/gltf2DoubleSidedMasked.mat | 74 ------ samples/materials/gltf2DoubleSidedTrans.mat | 74 ------ samples/materials/gltf2DoubleSidedUnlit.mat | 62 ----- samples/materials/gltf2Masked.mat | 73 ------ samples/materials/gltf2Trans.mat | 73 ------ samples/materials/gltf2Unlit.mat | 61 ----- 11 files changed, 162 insertions(+), 651 deletions(-) delete mode 100644 samples/materials/gltf2.mat delete mode 100644 samples/materials/gltf2DoubleSided.mat delete mode 100644 samples/materials/gltf2DoubleSidedMasked.mat delete mode 100644 samples/materials/gltf2DoubleSidedTrans.mat delete mode 100644 samples/materials/gltf2DoubleSidedUnlit.mat delete mode 100644 samples/materials/gltf2Masked.mat delete mode 100644 samples/materials/gltf2Trans.mat delete mode 100644 samples/materials/gltf2Unlit.mat diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 8b9e91667f..0cbfa92d97 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -34,14 +34,6 @@ set(MATERIAL_SRCS materials/aiDefaultMat.mat materials/aiDefaultTrans.mat materials/depthVisualizer.mat - materials/gltf2.mat - materials/gltf2DoubleSided.mat - materials/gltf2DoubleSidedMasked.mat - materials/gltf2DoubleSidedTrans.mat - materials/gltf2DoubleSidedUnlit.mat - materials/gltf2Masked.mat - materials/gltf2Trans.mat - materials/gltf2Unlit.mat materials/groundShadow.mat materials/sandboxCloth.mat materials/sandboxLit.mat diff --git a/samples/app/MeshAssimp.cpp b/samples/app/MeshAssimp.cpp index 49fa296152..89e44d660f 100644 --- a/samples/app/MeshAssimp.cpp +++ b/samples/app/MeshAssimp.cpp @@ -53,6 +53,7 @@ #include #include +#include #include "generated/resources/resources.h" @@ -61,6 +62,122 @@ using namespace filamat; using namespace math; using namespace utils; + +enum class AlphaMode : uint8_t { + OPAQUE, + MASKED, + TRANSPARENT +}; + +struct MaterialConfig { + bool doubleSided = false; + bool unlit = false; + bool hasVertexColors; + AlphaMode alphaMode = AlphaMode::OPAQUE; + float maskThreshold = 0.5f; + uint8_t numUVs = 1; + uint8_t baseColorUV = 0; + uint8_t metallicRoughnessUV = 0; + uint8_t emissiveUV = 0; + uint8_t aoUV = 0; + uint8_t normalUV = 0; +}; + +void appendBooleanToBitMask(uint64_t &bitmask, bool b) { + bitmask <<= 1; + bitmask |= b; +} + +uint64_t hashMaterialConfig(MaterialConfig config) { + uint64_t bitmask = 0; + memcpy(&config.maskThreshold, &bitmask, sizeof(config.maskThreshold)); + appendBooleanToBitMask(bitmask, config.doubleSided); + appendBooleanToBitMask(bitmask, config.unlit); + appendBooleanToBitMask(bitmask, config.hasVertexColors); + appendBooleanToBitMask(bitmask, config.alphaMode == AlphaMode::OPAQUE); + appendBooleanToBitMask(bitmask, config.alphaMode == AlphaMode::MASKED); + appendBooleanToBitMask(bitmask, config.alphaMode == AlphaMode::TRANSPARENT); + appendBooleanToBitMask(bitmask, config.numUVs == 1); + appendBooleanToBitMask(bitmask, config.baseColorUV == 0); + appendBooleanToBitMask(bitmask, config.metallicRoughnessUV == 0); + appendBooleanToBitMask(bitmask, config.emissiveUV == 0); + appendBooleanToBitMask(bitmask, config.aoUV == 0); + appendBooleanToBitMask(bitmask, config.normalUV == 0); + return bitmask; +} + +std::string shaderFromConfig(MaterialConfig config) { + std::string shader = R"SHADER( + void material(inout MaterialInputs material) { + )SHADER"; + + if (!config.unlit) { + shader += R"SHADER( + material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; + material.normal.y = -material.normal.y; + )SHADER"; + } + + shader += R"SHADER( + prepareMaterial(material); + material.baseColor = texture(materialParams_baseColorMap, getUV0()); + material.baseColor.rgb *= materialParams.baseColorFactor.xyz; + )SHADER"; + + if (config.alphaMode == AlphaMode::TRANSPARENT) { + shader += R"SHADER( + material.baseColor.rgb *= material.baseColor.a; + )SHADER"; + } + + if (!config.unlit) { + shader += R"SHADER( + material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; + material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; + material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; + material.emissive = texture(materialParams_emissiveMap, getUV0()); + material.emissive.rgb *= materialParams.emissiveFactor.rgb; + )SHADER"; + } + + shader += "}\n"; + return shader; +} + +Material* createMaterialFromConfig(Engine& engine, MaterialConfig config ) { + std::string shader = shaderFromConfig(config); + MaterialBuilder builder = MaterialBuilder() + .name("material") + .material(shader.c_str()) + .doubleSided(config.doubleSided) + .require(VertexAttribute::UV0) + .parameter(MaterialBuilder::SamplerType::SAMPLER_2D, "baseColorMap") + .parameter(MaterialBuilder::UniformType::FLOAT4, "baseColorFactor") + .parameter(MaterialBuilder::SamplerType::SAMPLER_2D, "metallicRoughnessMap") + .parameter(MaterialBuilder::SamplerType::SAMPLER_2D, "aoMap") + .parameter(MaterialBuilder::SamplerType::SAMPLER_2D, "emissiveMap") + .parameter(MaterialBuilder::SamplerType::SAMPLER_2D, "normalMap") + .parameter(MaterialBuilder::UniformType::FLOAT, "metallicFactor") + .parameter(MaterialBuilder::UniformType::FLOAT, "roughnessFactor") + .parameter(MaterialBuilder::UniformType::FLOAT, "normalScale") + .parameter(MaterialBuilder::UniformType::FLOAT, "aoStrength") + .parameter(MaterialBuilder::UniformType::FLOAT3, "emissiveFactor"); + + switch(config.alphaMode) { + case AlphaMode::MASKED : builder.blending(MaterialBuilder::BlendingMode::MASKED); + builder.maskThreshold(config.maskThreshold); + break; + case AlphaMode::TRANSPARENT : builder.blending(MaterialBuilder::BlendingMode::TRANSPARENT); + break; + default : builder.blending(MaterialBuilder::BlendingMode::OPAQUE); + } + + builder.shading(config.unlit ? Shading::UNLIT : Shading::LIT); + + Package pkg = builder.build(); + return Material::Builder().package(pkg.getData(), pkg.getSize()).build(engine); +} + Texture* MeshAssimp::createOneByOneTexture(uint32_t pixel) { uint32_t *textureData = (uint32_t *) malloc(sizeof(uint32_t)); *textureData = pixel; @@ -104,31 +221,6 @@ MeshAssimp::MeshAssimp(Engine& engine) : mEngine(engine) { mDefaultTransparentColorMaterial->setDefaultParameter("baseColor", RgbType::LINEAR, float3{0.8}); mDefaultTransparentColorMaterial->setDefaultParameter("metallic", 0.0f); mDefaultTransparentColorMaterial->setDefaultParameter("roughness", 0.4f); - - mGltfMaterial = Material::Builder() - .package(RESOURCES_GLTF2_DATA, RESOURCES_GLTF2_SIZE) - .build(mEngine); - mGltfMaterialDS = Material::Builder() - .package(RESOURCES_GLTF2DOUBLESIDED_DATA, RESOURCES_GLTF2DOUBLESIDED_SIZE) - .build(mEngine); - mGltfMaterialTrans = Material::Builder() - .package(RESOURCES_GLTF2TRANS_DATA, RESOURCES_GLTF2TRANS_SIZE) - .build(mEngine); - mGltfMaterialDSTrans = Material::Builder() - .package(RESOURCES_GLTF2DOUBLESIDEDTRANS_DATA, RESOURCES_GLTF2DOUBLESIDEDTRANS_SIZE) - .build(mEngine); - mGltfMaterialMasked = Material::Builder() - .package(RESOURCES_GLTF2MASKED_DATA, RESOURCES_GLTF2MASKED_SIZE) - .build(mEngine); - mGltfMaterialDSMasked = Material::Builder() - .package(RESOURCES_GLTF2DOUBLESIDEDMASKED_DATA, RESOURCES_GLTF2DOUBLESIDEDMASKED_SIZE) - .build(mEngine); - mGltfMaterialUnlit = Material::Builder() - .package(RESOURCES_GLTF2UNLIT_DATA, RESOURCES_GLTF2UNLIT_SIZE) - .build(mEngine); - mGltfMaterialDSUnlit = Material::Builder() - .package(RESOURCES_GLTF2DOUBLESIDEDUNLIT_DATA, RESOURCES_GLTF2DOUBLESIDEDUNLIT_SIZE) - .build(mEngine); } MeshAssimp::~MeshAssimp() { @@ -136,17 +228,14 @@ MeshAssimp::~MeshAssimp() { mEngine.destroy(mIndexBuffer); mEngine.destroy(mDefaultColorMaterial); mEngine.destroy(mDefaultTransparentColorMaterial); - mEngine.destroy(mGltfMaterial); - mEngine.destroy(mGltfMaterialDS); - mEngine.destroy(mGltfMaterialTrans); - mEngine.destroy(mGltfMaterialDSTrans); - mEngine.destroy(mGltfMaterialMasked); - mEngine.destroy(mGltfMaterialDSMasked); - mEngine.destroy(mGltfMaterialUnlit); - mEngine.destroy(mGltfMaterialDSUnlit); mEngine.destroy(mDefaultNormalMap); mEngine.destroy(mDefaultMap); + for (auto& item : mGltfMaterialCache) { + auto material = item.second; + mEngine.destroy(material); + } + for (Entity renderable : mRenderables) { mEngine.destroy(renderable); } @@ -277,8 +366,8 @@ TextureSampler::WrapMode aiToFilamentMapMode(aiTextureMapMode mapMode) { } } -TextureSampler::MinFilter aiMinFilterToFilament(unsigned int aiMinFilter){ - switch(aiMinFilter){ +TextureSampler::MinFilter aiMinFilterToFilament(unsigned int aiMinFilter) { + switch(aiMinFilter) { case GL_NEAREST: return TextureSampler::MinFilter::NEAREST; case GL_LINEAR: return TextureSampler::MinFilter::LINEAR; case GL_NEAREST_MIPMAP_NEAREST: return TextureSampler::MinFilter::NEAREST_MIPMAP_NEAREST; @@ -289,8 +378,8 @@ TextureSampler::MinFilter aiMinFilterToFilament(unsigned int aiMinFilter){ } } -TextureSampler::MagFilter aiMagFilterToFilament(unsigned int aiMagFilter){ - switch(aiMagFilter){ +TextureSampler::MagFilter aiMagFilterToFilament(unsigned int aiMagFilter) { + switch(aiMagFilter) { case GL_NEAREST: return TextureSampler::MagFilter::NEAREST; default: return TextureSampler::MagFilter::LINEAR; } @@ -777,49 +866,37 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat aiString normalPath; aiString emissivePath; aiTextureMapMode mapMode[3]; + MaterialConfig matConfig; - bool materialIsDoubleSided = false; - material->Get("$mat.twosided", 0, 0, materialIsDoubleSided); - - bool materialIsUnlit = false; - material->Get(AI_MATKEY_GLTF_UNLIT, materialIsUnlit); + material->Get("$mat.twosided", 0, 0, matConfig.doubleSided); + material->Get(AI_MATKEY_GLTF_UNLIT, matConfig.unlit); aiString alphaMode; - - if (materialIsUnlit) { - if (materialIsDoubleSided){ - outMaterials[materialName] = mGltfMaterialDSUnlit->createInstance(); - } else { - outMaterials[materialName] = mGltfMaterialUnlit->createInstance(); - } - } else if (materialIsDoubleSided) { - material->Get(AI_MATKEY_GLTF_ALPHAMODE, alphaMode); - - if (strcmp(alphaMode.C_Str(), "BLEND") == 0) { - outMaterials[materialName] = mGltfMaterialDSTrans->createInstance(); - } else if (strcmp(alphaMode.C_Str(), "MASK") == 0) { - outMaterials[materialName] = mGltfMaterialDSMasked->createInstance(); - float maskThreshold = 0.5; - material->Get(AI_MATKEY_GLTF_ALPHACUTOFF, maskThreshold); - outMaterials[materialName]->setParameter("maskThreshold", maskThreshold); - } else { - outMaterials[materialName] = mGltfMaterialDS->createInstance(); - } - } else { - material->Get(AI_MATKEY_GLTF_ALPHAMODE, alphaMode); - - if (strcmp(alphaMode.C_Str(), "BLEND") == 0) { - outMaterials[materialName] = mGltfMaterialTrans->createInstance(); - } else if (strcmp(alphaMode.C_Str(), "MASK") == 0) { - outMaterials[materialName] = mGltfMaterialMasked->createInstance(); - float maskThreshold = 0.5; - material->Get(AI_MATKEY_GLTF_ALPHACUTOFF, maskThreshold); - outMaterials[materialName]->setParameter("maskThreshold", maskThreshold); - } else { - outMaterials[materialName] = mGltfMaterial->createInstance(); - } + material->Get(AI_MATKEY_GLTF_ALPHAMODE, alphaMode); + if (strcmp(alphaMode.C_Str(), "BLEND") == 0) { + matConfig.alphaMode = AlphaMode::TRANSPARENT; + } else if (strcmp(alphaMode.C_Str(), "MASK") == 0) { + matConfig.alphaMode = AlphaMode::MASKED; + float maskThreshold = 0.5; + material->Get(AI_MATKEY_GLTF_ALPHACUTOFF, maskThreshold); + matConfig.maskThreshold = maskThreshold; } + uint64_t configHash = hashMaterialConfig(matConfig); + + if (mGltfMaterialCache.find(configHash) == mGltfMaterialCache.end()) { + mGltfMaterialCache[configHash] = createMaterialFromConfig(mEngine, matConfig); + } + + outMaterials[materialName] = mGltfMaterialCache[configHash]->createInstance(); + + // TODO: is there a way to use the same material for multiple mask threshold values? +// if (matConfig.alphaMode == masked) { +// float maskThreshold = 0.5; +// material->Get(AI_MATKEY_GLTF_ALPHACUTOFF, maskThreshold); +// outMaterials[materialName]->setParameter("maskThreshold", maskThreshold); +// } + // Load property values for gltf files aiColor4D baseColorFactor; aiColor3D emissiveFactor; @@ -840,7 +917,8 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat unsigned int magType = 0; material->Get("$tex.mappingfiltermin", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_BASE_COLOR_TEXTURE, minType); material->Get("$tex.mappingfiltermag", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_BASE_COLOR_TEXTURE, magType); - + material->Get("$tex.file.texCoord", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_BASE_COLOR_TEXTURE, + matConfig.baseColorUV); setTextureFromPath(scene, &mEngine, mTextures, baseColorPath, materialName, dirName, mapMode, "baseColorMap", outMaterials, minType, magType); } else { @@ -853,6 +931,8 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat unsigned int magType = 0; material->Get("$tex.mappingfiltermin", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, minType); material->Get("$tex.mappingfiltermag", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, magType); + material->Get("$tex.file.texCoord", AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE, + matConfig.metallicRoughnessUV); setTextureFromPath(scene, &mEngine, mTextures, MRPath, materialName, dirName, mapMode, "metallicRoughnessMap", outMaterials, minType, magType); } else { @@ -862,11 +942,12 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat } if (material->GetTexture(aiTextureType_LIGHTMAP, 0, &AOPath, nullptr, - nullptr, nullptr, nullptr, mapMode) == AI_SUCCESS) { + nullptr, nullptr, nullptr, mapMode) == AI_SUCCESS) { unsigned int minType = 0; unsigned int magType = 0; material->Get("$tex.mappingfiltermin", aiTextureType_LIGHTMAP, 0, minType); material->Get("$tex.mappingfiltermag", aiTextureType_LIGHTMAP, 0, magType); + material->Get("$tex.file.texCoord", aiTextureType_LIGHTMAP, 0, matConfig.aoUV); setTextureFromPath(scene, &mEngine, mTextures, AOPath, materialName, dirName, mapMode, "aoMap", outMaterials, minType, magType); } else { @@ -879,6 +960,7 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat unsigned int magType = 0; material->Get("$tex.mappingfiltermin", aiTextureType_NORMALS, 0, minType); material->Get("$tex.mappingfiltermag", aiTextureType_NORMALS, 0, magType); + material->Get("$tex.file.texCoord", aiTextureType_NORMALS, 0, matConfig.normalUV); setTextureFromPath(scene, &mEngine, mTextures, normalPath, materialName, dirName, mapMode, "normalMap", outMaterials, minType, magType); } else { @@ -891,6 +973,7 @@ void MeshAssimp::processGLTFMaterial(const aiScene* scene, const aiMaterial* mat unsigned int magType = 0; material->Get("$tex.mappingfiltermin", aiTextureType_EMISSIVE, 0, minType); material->Get("$tex.mappingfiltermag", aiTextureType_EMISSIVE, 0, magType); + material->Get("$tex.file.texCoord", aiTextureType_EMISSIVE, 0, matConfig.emissiveUV); setTextureFromPath(scene, &mEngine, mTextures, emissivePath, materialName, dirName, mapMode, "emissiveMap", outMaterials, minType, magType); } else { diff --git a/samples/app/MeshAssimp.h b/samples/app/MeshAssimp.h index 483cc1e85c..9f79dac68b 100644 --- a/samples/app/MeshAssimp.h +++ b/samples/app/MeshAssimp.h @@ -26,6 +26,7 @@ namespace filament { class Renderable; } +#include #include #include @@ -109,14 +110,7 @@ private: filament::Material* mDefaultColorMaterial = nullptr; filament::Material* mDefaultTransparentColorMaterial = nullptr; - filament::Material* mGltfMaterial = nullptr; // Single sided gltf material - filament::Material* mGltfMaterialDS = nullptr; // Double sided gltf material - filament::Material* mGltfMaterialTrans = nullptr; // Transparent gltf material - filament::Material* mGltfMaterialDSTrans = nullptr; // Double sided Transparent gltf material - filament::Material* mGltfMaterialMasked = nullptr; // Transparent gltf material - filament::Material* mGltfMaterialDSMasked = nullptr; // Double sided Transparent gltf material - filament::Material* mGltfMaterialUnlit = nullptr; - filament::Material* mGltfMaterialDSUnlit = nullptr; + mutable std::unordered_map mGltfMaterialCache; filament::Texture* mDefaultMap = nullptr; filament::Texture* mDefaultNormalMap = nullptr; float mDefaultMetallic = 0.0; diff --git a/samples/materials/gltf2.mat b/samples/materials/gltf2.mat deleted file mode 100644 index 531fe32eae..0000000000 --- a/samples/materials/gltf2.mat +++ /dev/null @@ -1,70 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - shadingModel : lit, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2DoubleSided.mat b/samples/materials/gltf2DoubleSided.mat deleted file mode 100644 index a974508dad..0000000000 --- a/samples/materials/gltf2DoubleSided.mat +++ /dev/null @@ -1,71 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - doubleSided : true, - shadingModel : lit, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2DoubleSidedMasked.mat b/samples/materials/gltf2DoubleSidedMasked.mat deleted file mode 100644 index 117117525f..0000000000 --- a/samples/materials/gltf2DoubleSidedMasked.mat +++ /dev/null @@ -1,74 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - shadingModel : lit, - doubleSided : true, - blending : masked, - maskThreshold : 0.5, - transparency : default, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2DoubleSidedTrans.mat b/samples/materials/gltf2DoubleSidedTrans.mat deleted file mode 100644 index 8ab6932f1a..0000000000 --- a/samples/materials/gltf2DoubleSidedTrans.mat +++ /dev/null @@ -1,74 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - shadingModel : lit, - doubleSided : true, - blending : transparent, - transparency : default, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - material.baseColor.rgb *= material.baseColor.a; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2DoubleSidedUnlit.mat b/samples/materials/gltf2DoubleSidedUnlit.mat deleted file mode 100644 index ba17ea3cbf..0000000000 --- a/samples/materials/gltf2DoubleSidedUnlit.mat +++ /dev/null @@ -1,62 +0,0 @@ -material { - name : Unlit, - requires : [ - uv0 - ], - doubleSided : true, - shadingModel : unlit, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - prepareMaterial(material); - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2Masked.mat b/samples/materials/gltf2Masked.mat deleted file mode 100644 index 919e4e27c4..0000000000 --- a/samples/materials/gltf2Masked.mat +++ /dev/null @@ -1,73 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - shadingModel : lit, - blending : masked, - maskThreshold : 0.5, - transparency : default, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2Trans.mat b/samples/materials/gltf2Trans.mat deleted file mode 100644 index 46cea2573e..0000000000 --- a/samples/materials/gltf2Trans.mat +++ /dev/null @@ -1,73 +0,0 @@ -material { - name : Lit, - requires : [ - uv0 - ], - shadingModel : lit, - blending : transparent, - transparency : default, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - material.normal = texture(materialParams_normalMap, getUV0()).xyz * 2.0 - 1.0; - material.normal.y = -material.normal.y; - prepareMaterial(material); - - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - material.baseColor.rgb *= material.baseColor.a; - - material.roughness = materialParams.roughnessFactor * texture(materialParams_metallicRoughnessMap, getUV0()).g; - material.metallic = materialParams.metallicFactor * texture(materialParams_metallicRoughnessMap, getUV0()).b; - material.ambientOcclusion = texture(materialParams_aoMap, getUV0()).r; - material.emissive = texture(materialParams_emissiveMap, getUV0()); - material.emissive.rgb *= materialParams.emissiveFactor.rgb; - } -} \ No newline at end of file diff --git a/samples/materials/gltf2Unlit.mat b/samples/materials/gltf2Unlit.mat deleted file mode 100644 index 87cfb7ba64..0000000000 --- a/samples/materials/gltf2Unlit.mat +++ /dev/null @@ -1,61 +0,0 @@ -material { - name : Unlit, - requires : [ - uv0 - ], - shadingModel : unlit, - parameters : [ - { - type : sampler2d, - name : baseColorMap - }, - { - type : float4, - name : baseColorFactor - }, - { - type : sampler2d, - name : metallicRoughnessMap - }, - { - type : float, - name : metallicFactor - }, - { - type : float, - name : roughnessFactor - }, - { - type : sampler2d, - name : normalMap - }, - { - type : float, - name : normalScale - }, - { - type : sampler2d, - name : aoMap - }, - { - type : float, - name : aoStrength - }, - { - type : sampler2d, - name : emissiveMap - }, - { - type : float3, - name : emissiveFactor - } - ], -} - -fragment { - void material(inout MaterialInputs material) { - prepareMaterial(material); - material.baseColor = texture(materialParams_baseColorMap, getUV0()); - material.baseColor.rgb *= materialParams.baseColorFactor.xyz; - } -} \ No newline at end of file