Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions editor/Assets/Importers/GltfImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public IReadOnlyList<ImporterSetting> GetSettings() {
AssetTypeRegistry.ByExtension(".tnode")!,
AssetTypeRegistry.ByExtension(".ktx2")!,
AssetTypeRegistry.ByExtension(".tmat")!,
AssetTypeRegistry.ByExtension(".tanim")!
AssetTypeRegistry.ByExtension(".tanim")!,
AssetTypeRegistry.ByExtension(".tskel")!
];

/// <summary>
Expand Down Expand Up @@ -165,8 +166,10 @@ public async Task<IReadOnlyList<string>> Import(
: [];
var materials = m_settings.ImportMaterials ? byExtension.GetValueOrDefault(".tmat") ?? [] : [];
var animations = m_settings.ImportAnimations ? byExtension.GetValueOrDefault(".tanim") ?? [] : [];
// Skeletons import even with animations off since BoneAttachments and skinned meshes need them
var skeletons = byExtension.GetValueOrDefault(".tskel") ?? [];
var scenes = m_settings.GeneratePrefab ? byExtension.GetValueOrDefault(".json") ?? [] : [];
var totalItems = meshes.Count + textures.Count * 10 + materials.Count + animations.Count +
var totalItems = meshes.Count + textures.Count * 10 + materials.Count + animations.Count + skeletons.Count +
scenes.Count * 2; // *2: patch + create
var doneItems = 0;

Expand Down Expand Up @@ -301,6 +304,23 @@ void ReportProgress() {
}
}

var skeletonUids = new Dictionary<string, string>();
foreach (var sk in skeletons) {
var skeletonName = Path.GetFileNameWithoutExtension(sk.Name);
var destPath = Path.Combine(destDir, skeletonName + ".tskel");
var uid = UidGenerator.Generate();
skeletonUids[skeletonName] = uid;

log($"Skeleton {skeletonName}");
File.Copy(sk.FullName, destPath, true);
var header = new MetaHeader
{ Uid = uid, Type = AssetTypeRegistry.ByExtension(".tskel")!.Type, Source = ctx.SourceVirtualPath };
MetaFile.Write(destPath, header, m_settings.ToSection());
importedUids.Add(uid);
doneItems++;
ReportProgress();
}

if (!ctx.IsStaging) AssetDatabase.RebuildAssetDatabase();

// Scenes
Expand All @@ -320,15 +340,19 @@ void PatchNode(JsonNode node) {
if (p["material"] is { } matNode &&
materialUids.TryGetValue(matNode.GetValue<string>(), out var matUid))
p["material"] = matUid;
if (p["skin_animation"] is { } skinAnimNode &&
animationUids.TryGetValue(skinAnimNode.GetValue<string>(), out var skinAnimUid))
p["skin_animation"] = skinAnimUid;
}
} else if (nodeType == "toast::AnimationPlayer") {
} else if (nodeType is "toast::AnimationPlayer" or "toast::SkeletalNode") {
var p = node["params"]?.AsObject();
if (p != null && p["animation"] is { } animNode &&
animationUids.TryGetValue(animNode.GetValue<string>(), out var animUid))
p["animation"] = animUid;
if (p?["skeleton"] is { } skeletonNode &&
skeletonUids.TryGetValue(skeletonNode.GetValue<string>(), out var skeletonUid))
p["skeleton"] = skeletonUid;
// Clips skipped by Import Animations have no UID and drop out of the list
if (p?["clips"] is JsonArray clipNames)
p["clips"] = new JsonArray(clipNames
.Select(c => animationUids.TryGetValue(c!.GetValue<string>(), out var clipUid) ? clipUid : null)
.Where(clipUid => clipUid != null)
.Select(clipUid => (JsonNode)JsonValue.Create(clipUid)!)
.ToArray());
}

if (node["children"] is not JsonArray children) return;
Expand Down
18 changes: 18 additions & 0 deletions editor/Assets/Types/SkeletonAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Lucide.Avalonia;

namespace editor.Assets.Types;

public sealed class SkeletonAsset : BaseAsset {
public override string Type => "skeleton";
public override string Extension => ".tskel";
public override string DisplayName => "Skeleton";
public override string ChipText => "SKEL";
public override string ChipColor => "Purple";
public override LucideIconKind Icon => LucideIconKind.Bone;
public override bool CanBeCreated => false;
public override string Category => "Visual";
public override bool HasThumbnail => false;
public override bool CanBeEdited => false;
public override string EditorTool => "";
public override string SchemaPath => "";
}
6 changes: 3 additions & 3 deletions editor/Editors/PaletteView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,17 @@
Grid.Column="0"
Classes="lbl compact-text"
Text="IOR" />
<elements:DragFloatBox Grid.Row="7"
<elements:DragFloatBox Grid.Row="5"
Grid.Column="1"
Value="{Binding Ior, Mode=TwoWay}"
Minimum="1"
Maximum="3.55" Classes="compact-field" />

<TextBlock Grid.Row="7"
Grid.Column="0"
Classes="lbl compact-text"
Classes="lbl-text"
Text="Max emissive" />
<elements:DragFloatBox Grid.Row="5"
<elements:DragFloatBox Grid.Row="7"
Grid.Column="1"
Value="{Binding MaxEmissive, Mode=TwoWay}"
Minimum="0" Classes="compact-field" />
Expand Down
19 changes: 19 additions & 0 deletions editor/Workspace/InspectorModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ public FieldVM(FieldInfo info) {
}
}

if (!info.IsArray && info.FieldType == "string_t" && ReflectionDatabase.HasAttr(info.Attributes, "Options")) {
Kind = WidgetKind.Enum;
HasDynamicOptions = true;
}

var isColor = ReflectionDatabase.HasAttr(info.Attributes, "Color");
if (isColor && !info.IsArray) {
if (info.FieldType == "vec3_t") Kind = WidgetKind.Color3;
Expand Down Expand Up @@ -483,6 +488,20 @@ internal FieldVM(
_ => 0
};
public ObservableCollection<string> EnumOptions { get; } = [];

public bool HasDynamicOptions { get; }

public void ApplyEngineOptions(IReadOnlyList<string> options) {
if (!HasDynamicOptions || EnumOptions.SequenceEqual(options, StringComparer.Ordinal)) return;
EnumOptions.Clear();
m_enumLabelToValue.Clear();
m_enumValueToLabel.Clear();
foreach (var option in options) {
EnumOptions.Add(option);
m_enumLabelToValue[option] = option;
m_enumValueToLabel[option] = option;
}
}
internal string EngineValue => ToEngineString();
public IAsyncCanExecuteCommand PasteCommand => m_pasteCommand ??= new InspectorPasteCommand(
component => m_clipboardHost?.PasteFieldAsync(this, ClipboardComponent(component)) ?? Task.CompletedTask,
Expand Down
1 change: 1 addition & 0 deletions editor/Workspace/InspectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public InspectorViewModel(HierarchyViewModel? follow) {

foreach (var p in e.Parameters) {
if (!m_fieldByParam.TryGetValue(p.Name, out var vm)) continue;
vm.ApplyEngineOptions(p.Options);
// don't clobber a value the user is actively editing
if ((DateTime.UtcNow - vm.LastEdit).TotalMilliseconds < 250) continue;
vm.ApplyEngineString(p.Value);
Expand Down
17 changes: 14 additions & 3 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ target_link_libraries(toast_engine
Vulkan::Vulkan
KTX::ktx
unofficial::VulkanMemoryAllocator-Hpp::VulkanMemoryAllocator-Hpp
slang::gfx slang::slang protobuf::libprotobuf tinysplinecxx::tinysplinecxx
slang::slang protobuf::libprotobuf-lite tinysplinecxx::tinysplinecxx
LZ4::lz4
unofficial::sqlite3::sqlite3
toast_pack
$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:imgui::imgui>
RmlUi::RmlUi
RmlUi::Core
cpptrace::cpptrace
$<$<CONFIG:Debug>:${EXTERNAL_LIBS_DEBUG}>
$<$<NOT:$<CONFIG:Debug>>:${EXTERNAL_LIBS_RELEASE}>
Expand Down Expand Up @@ -163,6 +163,15 @@ target_compile_definitions(toast_engine PUBLIC
GLM_FORCE_INTRINSICS
)

option(TOAST_PROFILE_LOCKS "Show contended mutexes in Tracy, every lock sends events while a profiler is connected" ON)
# A header and not a define since it changes engine type layouts and game projects never see engine defines
set(_toast_build_config_dir "${CMAKE_CURRENT_BINARY_DIR}/build_config/$<CONFIG>")
file(GENERATE
OUTPUT "${_toast_build_config_dir}/toast/build_config.hpp"
CONTENT "#pragma once\n$<$<AND:$<CONFIG:Debug,RelWithDebInfo>,$<BOOL:${TOAST_PROFILE_LOCKS}>>:#define TOAST_PROFILE_LOCKS\n>"
)
target_include_directories(toast_engine PUBLIC "${_toast_build_config_dir}")

# Replaces global operator new and delete so Tracy lists every heap allocation, only active where Tracy is
option(TOAST_TRACK_HEAP "Report C++ heap allocations to Tracy" ON)
# 0 records no callstack, around 8 to 16 shows who allocates but slows allocation heavy code down a lot
Expand All @@ -172,7 +181,7 @@ target_compile_definitions(toast_engine PRIVATE
TOAST_HEAP_CALLSTACK_DEPTH=${TOAST_HEAP_CALLSTACK_DEPTH}
)

# Keep Slang's Debug profile for Linux builds that retain C++ debug information.
# Linux builds with C++ debug info keep the Slang Debug profile
target_compile_definitions(toast_engine PRIVATE
$<$<AND:$<PLATFORM_ID:Linux>,$<CONFIG:RelWithDebInfo>>:TOAST_SLANG_DEBUG_DEFAULT>
)
Expand Down Expand Up @@ -252,6 +261,7 @@ list(GET _tinyspline_include_list 0 _tinyspline_include)
add_custom_command(TARGET toast_engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf "${TOAST_ENGINE_OUTPUT_ROOT}/include" "${TOAST_ENGINE_OUTPUT_ROOT}/ffi"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/include" "${TOAST_ENGINE_OUTPUT_ROOT}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_toast_build_config_dir}/toast/build_config.hpp" "${TOAST_ENGINE_OUTPUT_ROOT}/include/toast/build_config.hpp"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/ffi" "${TOAST_ENGINE_OUTPUT_ROOT}/ffi"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/.clang-format" "${TOAST_ENGINE_OUTPUT_ROOT}/.clang-format"
# Generated reflection headers
Expand Down Expand Up @@ -286,6 +296,7 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets")
)
endif ()


if (WIN32)
add_custom_command(TARGET toast_engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:toast_engine> "${TOAST_ENGINE_BIN_DIR}"
Expand Down
79 changes: 60 additions & 19 deletions engine/assets/shaders/bloom.slang
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ Sampler2D gSource;
[[vk::binding(1,0)]]
Sampler2D gSceneColor;

[[vk::binding(2,0)]]
Sampler2D gGlassBackdrop;

[[vk::binding(3,0)]]
Sampler2D gGlassMask;

float3 bloomSource(float2 uv)
{
float m = gGlassMask.Sample(uv).r;
return lerp(gSource.Sample(uv).rgb, gGlassBackdrop.Sample(uv).rgb, m);
}

typedef FullscreenVSOutput VSOutput;

[shader("vertex")]
Expand All @@ -48,7 +60,7 @@ float3 applyThreshold(float3 color)
}

// Not an entry point or Slang would promote the uniform parameter into a second push block
float4 fragmentDownsample(VSOutput input, uniform bool applyKaris) : SV_Target0
float4 fragmentDownsampleLoop(VSOutput input) : SV_Target0
{
float2 texel = gParams.inverseSourceSize;
float2 uv = input.uv;
Expand Down Expand Up @@ -78,36 +90,65 @@ float4 fragmentDownsample(VSOutput input, uniform bool applyKaris) : SV_Target0
float3 group4 = (e + f + h + i) * 0.25;

float3 result;
if (applyKaris)
{
float w0 = 1.0 / (1.0 + luminance(group0));
float w1 = 1.0 / (1.0 + luminance(group1));
float w2 = 1.0 / (1.0 + luminance(group2));
float w3 = 1.0 / (1.0 + luminance(group3));
float w4 = 1.0 / (1.0 + luminance(group4));
float total = w0 * 0.5 + (w1 + w2 + w3 + w4) * 0.125;
result = (group0 * w0 * 0.5 + (group1 * w1 + group2 * w2 + group3 * w3 + group4 * w4) * 0.125) / max(total, 1e-4);

result = applyThreshold(result);
}
else
{
result = group0 * 0.5 + (group1 + group2 + group3 + group4) * 0.125;
}
result = group0 * 0.5 + (group1 + group2 + group3 + group4) * 0.125;

return float4(result, 1.0);
}

float4 fragmentDownsampleStart(VSOutput input) : SV_Target0
{
float2 texel = gParams.inverseSourceSize;
float2 uv = input.uv;

// Interleaved so the texture queue never throttles and live registers stay low
float3 j = bloomSource(uv + float2(-1.0, 1.0) * texel).rgb;
float3 k = bloomSource(uv + float2( 1.0, 1.0) * texel).rgb;
float3 l = bloomSource(uv + float2(-1.0,-1.0) * texel).rgb;
float3 m = bloomSource(uv + float2( 1.0,-1.0) * texel).rgb;
float3 group0 = (j + k + l + m) * 0.25;

float3 e = bloomSource(uv).rgb;
float3 b = bloomSource(uv + float2( 0.0, 2.0) * texel).rgb;
float3 d = bloomSource(uv + float2(-2.0, 0.0) * texel).rgb;
float3 a = bloomSource(uv + float2(-2.0, 2.0) * texel).rgb;
float3 group1 = (a + b + d + e) * 0.25;

float3 c = bloomSource(uv + float2( 2.0, 2.0) * texel).rgb;
float3 f = bloomSource(uv + float2( 2.0, 0.0) * texel).rgb;
float3 group2 = (b + c + e + f) * 0.25;

float3 g = bloomSource(uv + float2(-2.0,-2.0) * texel).rgb;
float3 h = bloomSource(uv + float2( 0.0,-2.0) * texel).rgb;
float3 group3 = (d + e + g + h) * 0.25;

float3 i = bloomSource(uv + float2( 2.0,-2.0) * texel).rgb;
float3 group4 = (e + f + h + i) * 0.25;

float3 result;

float w0 = 1.0 / (1.0 + luminance(group0));
float w1 = 1.0 / (1.0 + luminance(group1));
float w2 = 1.0 / (1.0 + luminance(group2));
float w3 = 1.0 / (1.0 + luminance(group3));
float w4 = 1.0 / (1.0 + luminance(group4));
float total = w0 * 0.5 + (w1 + w2 + w3 + w4) * 0.125;
result = (group0 * w0 * 0.5 + (group1 * w1 + group2 * w2 + group3 * w3 + group4 * w4) * 0.125) / max(total, 1e-4);

result = applyThreshold(result);

return float4(result, 1.0);
}

[shader("fragment")]
float4 fragmentDownsampleFirst(VSOutput input) : SV_Target0
{
return fragmentDownsample(input, true);
return fragmentDownsampleStart(input);
}

[shader("fragment")]
float4 fragmentDownsampleNext(VSOutput input) : SV_Target0
{
return fragmentDownsample(input, false);
return fragmentDownsampleLoop(input);
}

[shader("fragment")]
Expand Down
2 changes: 2 additions & 0 deletions engine/assets/shaders/debris_draw.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Opaque debris into the voxel G-buffer and glass debris blended forward like voxel glass
import voxel_gbuffer;
import lighting;
import gi_sample;
import glass_common;

struct PushConstants {
Expand Down Expand Up @@ -221,6 +222,7 @@ GlassShade shadeDebrisGlass(VSOutput input) {
surface.viewSpaceZ = mul(gCamera.view, float4(input.worldPosition, 1.0)).z;
surface.pixel = input.position.xy;

gGiGathered = giCheap(input.worldPosition, normal);
GlassShade shade;
const ShadingResult lit = shadeSurfaceLighting(surface);
if (lit.isDebugView) {
Expand Down
Loading
Loading