Add Transparent Lighting Modes for material with option to use non-directional shading

This commit is contained in:
Wojciech Figat
2022-07-14 09:21:09 +02:00
parent 047821f7d2
commit 85f351663b
14 changed files with 254 additions and 52 deletions

View File

@@ -439,7 +439,17 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
options.Macros.Add({ "MATERIAL_REFLECTIONS", Numbers[1] });
options.Macros.Add({ "USE_FOG", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::DisableFog ? 0 : 1] });
if (useForward)
{
options.Macros.Add({ "USE_PIXEL_NORMAL_OFFSET_REFRACTION", Numbers[info.FeaturesFlags & MaterialFeaturesFlags::PixelNormalOffsetRefraction ? 1 : 0] });
switch (info.TransparentLightingMode)
{
case MaterialTransparentLightingMode::Surface:
break;
case MaterialTransparentLightingMode::SurfaceNonDirectional:
options.Macros.Add({ "LIGHTING_NO_DIRECTIONAL", "1" });
break;
}
}
// TODO: don't compile VS_Depth for deferred/forward materials if material doesn't use position offset or masking

View File

@@ -23,13 +23,14 @@ public:
static const Upgrader upgraders[] =
{
{ 18, 19, &Upgrade_18_To_19 },
{ 19, 20, &Upgrade_19_To_20 },
};
setup(upgraders, ARRAY_COUNT(upgraders));
}
private:
// ============================================
// Version 18:
// Versions 18,19,20:
// Designed: 7/24/2019
// Custom Data: Header
// Chunk 0: Material Params
@@ -38,20 +39,46 @@ private:
// Chunk 14: Visject Surface data
// Chunk 15: Source code: ANSI text (encrypted)
// ============================================
// Version 18:
// Designed: 9/13/2018
// Custom Data: Header
// Chunk 0: Material Params
// Chunk 1: Internal SM5 cache
// Chunk 2: Internal SM4 cache
// Chunk 14: Visject Surface data
// Chunk 15: Source code: ANSI text (encrypted)
// ============================================
typedef ShaderStorage::Header Header;
typedef ShaderStorage::Header20 Header20;
typedef ShaderStorage::Header19 Header19;
typedef ShaderStorage::Header18 Header18;
static bool Upgrade_19_To_20(AssetMigrationContext& context)
{
ASSERT(context.Input.SerializedVersion == 19 && context.Output.SerializedVersion == 20);
// Convert header
if (context.Input.CustomData.IsInvalid())
return true;
auto& oldHeader = *(Header19*)context.Input.CustomData.Get();
Header20 newHeader;
Platform::MemoryClear(&newHeader, sizeof(newHeader));
if (context.Input.Header.TypeName == TEXT("FlaxEngine.ParticleEmitter"))
{
newHeader.ParticleEmitter.GraphVersion = oldHeader.ParticleEmitter.GraphVersion;
newHeader.ParticleEmitter.CustomDataSize = oldHeader.ParticleEmitter.CustomDataSize;
}
else if (context.Input.Header.TypeName == TEXT("FlaxEngine.Material"))
{
newHeader.Material.GraphVersion = oldHeader.Material.GraphVersion;
newHeader.Material.Info = oldHeader.Material.Info;
}
else if (context.Input.Header.TypeName == TEXT("FlaxEngine.Shader"))
{
}
else
{
LOG(Warning, "Unknown input asset type.");
return true;
}
context.Output.CustomData.Copy(&newHeader);
// Copy all chunks
return CopyChunks(context);
}
static bool Upgrade_18_To_19(AssetMigrationContext& context)
{
ASSERT(context.Input.SerializedVersion == 18 && context.Output.SerializedVersion == 19);