Merge remote-tracking branch 'origin/master' into 1.9

This commit is contained in:
Wojtek Figat
2024-08-05 20:00:39 +02:00
52 changed files with 983 additions and 131 deletions

View File

@@ -179,7 +179,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathd.IsOne(X * X + Y * Y);
public bool IsNormalized => Mathd.Abs((X * X + Y * Y) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -234,7 +234,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathd.IsOne(X * X + Y * Y + Z * Z);
public bool IsNormalized => Mathd.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f;
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.

View File

@@ -220,7 +220,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathd.IsOne(X * X + Y * Y + Z * Z + W * W);
public bool IsNormalized => Mathd.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -184,7 +184,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathf.IsOne(X * X + Y * Y);
public bool IsNormalized => Mathf.Abs((X * X + Y * Y) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -228,7 +228,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z);
public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f;
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.

View File

@@ -202,7 +202,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z + W * W);
public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -163,7 +163,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z + W * W);
public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f;
/// <summary>
/// Gets the euler angle (pitch, yaw, roll) in degrees.

View File

@@ -107,7 +107,7 @@ public:
/// </summary>
bool IsNormalized() const
{
return Math::IsOne(X * X + Y * Y + Z * Z + W * W);
return Math::Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f;
}
/// <summary>

View File

@@ -207,7 +207,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathr.IsOne(X * X + Y * Y);
public bool IsNormalized => Mathr.Abs((X * X + Y * Y) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -105,7 +105,7 @@ public:
// Gets a value indicting whether this instance is normalized.
bool IsNormalized() const
{
return Math::IsOne(X * X + Y * Y);
return Math::Abs((X * X + Y * Y) - 1.0f) < 1e-4f;
}
// Gets a value indicting whether this vector is zero.

View File

@@ -256,7 +256,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathr.IsOne(X * X + Y * Y + Z * Z);
public bool IsNormalized => Mathr.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f;
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.

View File

@@ -136,7 +136,7 @@ public:
// Gets a value indicting whether this instance is normalized.
bool IsNormalized() const
{
return Math::IsOne(X * X + Y * Y + Z * Z);
return Math::Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f;
}
// Gets a value indicting whether this vector is zero.

View File

@@ -258,7 +258,7 @@ namespace FlaxEngine
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized => Mathr.IsOne(X * X + Y * Y + Z * Z + W * W);
public bool IsNormalized => Mathr.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f;
/// <summary>
/// Gets a value indicting whether this vector is zero

View File

@@ -944,6 +944,12 @@ void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount, bo
}
}
void DebugDraw::DrawActorsTree(Actor* actor)
{
Function<bool(Actor*)> function = &DrawActorsTreeWalk;
actor->TreeExecute(function);
}
void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest)
{
ASSERT(direction.IsNormalized());

View File

@@ -67,6 +67,12 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
/// <param name="drawScenes">True if draw all debug shapes from scenes too or false if draw just from specified actor list.</param>
API_FUNCTION() static void DrawActors(Actor** selectedActors, int32 selectedActorsCount, bool drawScenes);
/// <summary>
/// Draws the debug shapes for the given actor and the actor's children
/// </summary>
/// /// <param name="actor">The actor to start drawing at.</param>
API_FUNCTION() static void DrawActorsTree(Actor* actor);
/// <summary>
/// Draws the lines axis from direction.
/// </summary>

View File

@@ -195,6 +195,12 @@ int32 Engine::Main(const Char* cmdLine)
// Use the same time for all ticks to improve synchronization
const double time = Platform::GetTimeSeconds();
// Update application (will gather data and other platform related events)
{
PROFILE_CPU_NAMED("Platform.Tick");
Platform::Tick();
}
// Update game logic
if (Time::OnBeginUpdate(time))
{
@@ -302,12 +308,6 @@ void Engine::OnUpdate()
UpdateCount++;
// Update application (will gather data and other platform related events)
{
PROFILE_CPU_NAMED("Platform.Tick");
Platform::Tick();
}
const auto mainWindow = MainWindow;
#if !USE_EDITOR

View File

@@ -39,7 +39,11 @@ void ForwardMaterialShader::Bind(BindParameters& params)
// Setup features
if ((_info.FeaturesFlags & MaterialFeaturesFlags::GlobalIllumination) != MaterialFeaturesFlags::None)
{
GlobalIlluminationFeature::Bind(params, cb, srv);
if ((_info.FeaturesFlags & MaterialFeaturesFlags::ScreenSpaceReflections) != MaterialFeaturesFlags::None)
SDFReflectionsFeature::Bind(params, cb, srv);
}
ForwardShadingFeature::Bind(params, cb, srv);
// Setup parameters

View File

@@ -10,7 +10,7 @@
/// <summary>
/// Current materials shader version.
/// </summary>
#define MATERIAL_GRAPH_VERSION 168
#define MATERIAL_GRAPH_VERSION 169
class Material;
class GPUShader;

View File

@@ -5,6 +5,7 @@
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/ShadowsPass.h"
#include "Engine/Renderer/GlobalSignDistanceFieldPass.h"
#if USE_EDITOR
#include "Engine/Renderer/Lightmaps.h"
#endif
@@ -188,6 +189,58 @@ bool GlobalIlluminationFeature::Bind(MaterialShader::BindParameters& params, Spa
return useGI;
}
bool SDFReflectionsFeature::Bind(MaterialShader::BindParameters& params, Span<byte>& cb, int32& srv)
{
auto& data = *(Data*)cb.Get();
ASSERT_LOW_LAYER(cb.Length() >= sizeof(Data));
bool useSDFReflections = false;
if (EnumHasAnyFlags(params.RenderContext.View.Flags, ViewFlags::Reflections))
{
switch (params.RenderContext.List->Settings.ScreenSpaceReflections.TraceMode)
{
case ReflectionsTraceMode::SoftwareTracing:
{
GlobalSignDistanceFieldPass::BindingData bindingDataSDF;
GlobalSurfaceAtlasPass::BindingData bindingDataSurfaceAtlas;
if (!GlobalSignDistanceFieldPass::Instance()->Get(params.RenderContext.Buffers, bindingDataSDF) &&
!GlobalSurfaceAtlasPass::Instance()->Get(params.RenderContext.Buffers, bindingDataSurfaceAtlas))
{
useSDFReflections = true;
// Bind SDF and Surface Atlas data
data.GlobalSDF = bindingDataSDF.Constants;
data.GlobalSurfaceAtlas = bindingDataSurfaceAtlas.Constants;
params.GPUContext->BindSR(srv + 0, bindingDataSDF.Texture ? bindingDataSDF.Texture->ViewVolume() : nullptr);
params.GPUContext->BindSR(srv + 1, bindingDataSDF.TextureMip ? bindingDataSDF.TextureMip->ViewVolume() : nullptr);
params.GPUContext->BindSR(srv + 2, bindingDataSurfaceAtlas.Chunks ? bindingDataSurfaceAtlas.Chunks->View() : nullptr);
params.GPUContext->BindSR(srv + 3, bindingDataSurfaceAtlas.CulledObjects ? bindingDataSurfaceAtlas.CulledObjects->View() : nullptr);
params.GPUContext->BindSR(srv + 4, bindingDataSurfaceAtlas.Objects ? bindingDataSurfaceAtlas.Objects->View() : nullptr);
params.GPUContext->BindSR(srv + 5, bindingDataSurfaceAtlas.AtlasDepth->View());
params.GPUContext->BindSR(srv + 6, bindingDataSurfaceAtlas.AtlasLighting->View());
}
break;
}
}
}
if (!useSDFReflections)
{
// Unbind SRVs to prevent issues
data.GlobalSDF.CascadesCount = 0;
params.GPUContext->UnBindSR(srv + 0);
params.GPUContext->UnBindSR(srv + 1);
params.GPUContext->UnBindSR(srv + 2);
params.GPUContext->UnBindSR(srv + 3);
params.GPUContext->UnBindSR(srv + 4);
params.GPUContext->UnBindSR(srv + 5);
params.GPUContext->UnBindSR(srv + 6);
}
cb = Span<byte>(cb.Get() + sizeof(Data), cb.Length() - sizeof(Data));
srv += SRVs;
return useSDFReflections;
}
#if USE_EDITOR
void ForwardShadingFeature::Generate(GeneratorData& data)
@@ -215,6 +268,11 @@ void GlobalIlluminationFeature::Generate(GeneratorData& data)
data.Template = TEXT("Features/GlobalIllumination.hlsl");
}
void SDFReflectionsFeature::Generate(GeneratorData& data)
{
data.Template = TEXT("Features/SDFReflections.hlsl");
}
void DistortionFeature::Generate(GeneratorData& data)
{
data.Template = TEXT("Features/Distortion.hlsl");

View File

@@ -6,6 +6,8 @@
#include "Engine/Core/Math/Rectangle.h"
#include "Engine/Core/Types/Span.h"
#include "Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.h"
#include "Engine/Renderer/GlobalSignDistanceFieldPass.h"
#include "Engine/Renderer/GI/GlobalSurfaceAtlasPass.h"
// Material shader features are plugin-based functionalities that are reusable between different material domains.
struct MaterialShaderFeature
@@ -85,6 +87,25 @@ struct GlobalIlluminationFeature : MaterialShaderFeature
#endif
};
// Material shader feature that adds SDF Reflections feature (software reflections).
struct SDFReflectionsFeature : MaterialShaderFeature
{
enum { SRVs = 7 };
PACK_STRUCT(struct Data
{
GlobalSignDistanceFieldPass::ConstantsData GlobalSDF;
GlobalSurfaceAtlasPass::ConstantsData GlobalSurfaceAtlas;
});
static bool Bind(MaterialShader::BindParameters& params, Span<byte>& cb, int32& srv);
#if USE_EDITOR
static void Generate(GeneratorData& data);
#endif
};
// Material shader feature that adds distortion vectors rendering pass.
struct DistortionFeature : MaterialShaderFeature
{

View File

@@ -38,7 +38,7 @@ API_STRUCT() struct HingeJointDrive
/// <summary>
/// Target velocity of the joint.
/// </summary>
API_FIELD(Attributes="Limit(0)") float Velocity = 0.0f;
API_FIELD() float Velocity = 0.0f;
/// <summary>
/// Maximum torque the drive is allowed to apply.

View File

@@ -2923,7 +2923,7 @@ int32 LinuxPlatform::CreateProcess(CreateProcessSettings& settings)
LOG(Info, "Working directory: {0}", settings.WorkingDirectory);
}
const bool captureStdOut = settings.LogOutput || settings.SaveOutput;
const String cmdLine = settings.FileName + TEXT(" ") + settings.Arguments;
const String cmdLine = String::Format(TEXT("\"{0}\" {1}"), settings.FileName, settings.Arguments);
int fildes[2];
int32 returnCode = 0;

View File

@@ -670,6 +670,17 @@ void GlobalSurfaceAtlasPass::Dispose()
_shader = nullptr;
}
bool GlobalSurfaceAtlasPass::Get(const RenderBuffers* buffers, BindingData& result)
{
auto* surfaceAtlasData = buffers ? buffers->FindCustomBuffer<GlobalSurfaceAtlasCustomBuffer>(TEXT("GlobalSurfaceAtlas")) : nullptr;
if (surfaceAtlasData && surfaceAtlasData->LastFrameUsed + 1 >= Engine::FrameCount) // Allow to use Surface Atlas from the previous frame (not used currently)
{
result = surfaceAtlasData->Result;
return false;
}
return true;
}
void GlobalSurfaceAtlasPass::OnCollectDrawCalls(RenderContextBatch& renderContextBatch)
{
// Check if Global Surface Atlas will be used this frame

View File

@@ -61,6 +61,14 @@ private:
void* _currentActorObject;
public:
/// <summary>
/// Gets the Global Surface Atlas (only if enabled in Graphics Settings).
/// </summary>
/// <param name="buffers">The rendering context buffers.</param>
/// <param name="result">The result Global Surface Atlas data for binding to the shaders.</param>
/// <returns>True if there is no valid Global Surface Atlas rendered during this frame, otherwise false.</returns>
bool Get(const RenderBuffers* buffers, BindingData& result);
/// <summary>
/// Calls drawing scene objects in async early in the frame.
/// </summary>

View File

@@ -386,6 +386,7 @@ void RenderList::RunCustomPostFxPass(GPUContext* context, RenderContext& renderC
Swap(input, output);
}
context->ResetRenderTarget();
context->ResetSR();
}
}
}

View File

@@ -689,51 +689,41 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
// World Triplanar Texture
case 16:
{
// Get input boxes
auto textureBox = node->GetBox(0);
auto scaleBox = node->GetBox(1);
auto blendBox = node->GetBox(2);
if (!textureBox->HasConnection())
{
// No texture to sample
value = Value::Zero;
break;
}
if (!CanUseSample(_treeType))
{
// Must sample texture in pixel shader
value = Value::Zero;
break;
}
const bool canUseSample = CanUseSample(_treeType);
const auto texture = eatBox(textureBox->GetParent<Node>(), textureBox->FirstConnection());
const auto scale = tryGetValue(scaleBox, node->Values[0]).AsFloat3();
const auto scale = tryGetValue(scaleBox, node->Values[0]).AsFloat4();
const auto blend = tryGetValue(blendBox, node->Values[1]).AsFloat();
auto result = writeLocal(Value::InitForZero(ValueType::Float4), node);
const String triplanarTexture = String::Format(TEXT(
" {{\n"
" float3 worldPos = input.WorldPosition.xyz * ({1} * 0.001f);\n"
" float3 normal = abs(input.TBN[2]);\n"
" normal = pow(normal, {2});\n"
" normal = normal / (normal.x + normal.y + normal.z);\n"
" {3} += {0}.Sample(SamplerLinearWrap, worldPos.yz) * normal.x;\n"
" {3} += {0}.Sample(SamplerLinearWrap, worldPos.xz) * normal.y;\n"
" {3} += {0}.Sample(SamplerLinearWrap, worldPos.xy) * normal.z;\n"
" {3} += {0}.{4}(SamplerLinearWrap, worldPos.yz{5}) * normal.x;\n"
" {3} += {0}.{4}(SamplerLinearWrap, worldPos.xz{5}) * normal.y;\n"
" {3} += {0}.{4}(SamplerLinearWrap, worldPos.xy{5}) * normal.z;\n"
" }}\n"
),
texture.Value, // {0}
scale.Value, // {1}
blend.Value, // {2}
result.Value // {3}
result.Value, // {3}
canUseSample ? TEXT("Sample") : TEXT("SampleLevel"), // {4}
canUseSample ? TEXT("") : TEXT(", 0") // {5}
);
_writer.Write(*triplanarTexture);
value = result;
break;
}
// Get Lightmap UV
case 18:
@@ -748,9 +738,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
"#endif\n"
"}}\n"
), output.Value);
_writer.Write(*lightmapUV);
value = output;
break;
}

View File

@@ -188,40 +188,46 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
{
case MaterialDomain::Surface:
if (materialInfo.TessellationMode != TessellationMethod::None)
ADD_FEATURE(TessellationFeature);
ADD_FEATURE(TessellationFeature);
if (materialInfo.BlendMode == MaterialBlendMode::Opaque)
ADD_FEATURE(MotionVectorsFeature);
ADD_FEATURE(MotionVectorsFeature);
if (materialInfo.BlendMode == MaterialBlendMode::Opaque)
ADD_FEATURE(LightmapFeature);
ADD_FEATURE(LightmapFeature);
if (materialInfo.BlendMode == MaterialBlendMode::Opaque)
ADD_FEATURE(DeferredShadingFeature);
ADD_FEATURE(DeferredShadingFeature);
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == MaterialFeaturesFlags::None)
ADD_FEATURE(DistortionFeature);
ADD_FEATURE(DistortionFeature);
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::GlobalIllumination))
ADD_FEATURE(GlobalIlluminationFeature);
{
ADD_FEATURE(GlobalIlluminationFeature);
// SDF Reflections is only valid when both GI and SSR is enabled
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::ScreenSpaceReflections))
ADD_FEATURE(SDFReflectionsFeature);
}
if (materialInfo.BlendMode != MaterialBlendMode::Opaque)
ADD_FEATURE(ForwardShadingFeature);
ADD_FEATURE(ForwardShadingFeature);
break;
case MaterialDomain::Terrain:
if (materialInfo.TessellationMode != TessellationMethod::None)
ADD_FEATURE(TessellationFeature);
ADD_FEATURE(TessellationFeature);
ADD_FEATURE(LightmapFeature);
ADD_FEATURE(DeferredShadingFeature);
break;
case MaterialDomain::Particle:
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == MaterialFeaturesFlags::None)
ADD_FEATURE(DistortionFeature);
ADD_FEATURE(DistortionFeature);
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::GlobalIllumination))
ADD_FEATURE(GlobalIlluminationFeature);
ADD_FEATURE(GlobalIlluminationFeature);
ADD_FEATURE(ForwardShadingFeature);
break;
case MaterialDomain::Deformable:
if (materialInfo.TessellationMode != TessellationMethod::None)
ADD_FEATURE(TessellationFeature);
ADD_FEATURE(TessellationFeature);
if (materialInfo.BlendMode == MaterialBlendMode::Opaque)
ADD_FEATURE(DeferredShadingFeature);
ADD_FEATURE(DeferredShadingFeature);
if (materialInfo.BlendMode != MaterialBlendMode::Opaque)
ADD_FEATURE(ForwardShadingFeature);
ADD_FEATURE(ForwardShadingFeature);
break;
default:
break;
@@ -708,7 +714,7 @@ void MaterialGenerator::ProcessGroupMath(Box* box, Node* node, Value& value)
{
switch (node->TypeID)
{
// Vector Transform
// Vector Transform
case 30:
{
// Get input vector