From 30f8500c5d379ab85e5d84f26ae0603b5386992a Mon Sep 17 00:00:00 2001 From: Caner Date: Tue, 9 Dec 2025 14:51:28 +0300 Subject: [PATCH 1/9] Add rendering plugin Added a type for render views Added nodes for converting track to view and for billboard mask rendering --- Plugins/CMakeLists.txt | 1 + Plugins/nosRendering/CMakeLists.txt | 26 +++ .../nosRendering/Config/BillboardMask.nosdef | 63 +++++ Plugins/nosRendering/Config/Rendering.fbs | 38 +++ .../nosRendering/Config/TrackToView.nosdef | 42 ++++ Plugins/nosRendering/Rendering.noscfg | 28 +++ .../nosRendering/Shaders/BillboardMask.frag | 17 ++ .../nosRendering/Shaders/BillboardMask.vert | 39 ++++ Plugins/nosRendering/Source/BillboardMask.cpp | 218 ++++++++++++++++++ Plugins/nosRendering/Source/RenderingMain.cpp | 81 +++++++ Plugins/nosRendering/Source/TrackToView.cpp | 102 ++++++++ 11 files changed, 655 insertions(+) create mode 100644 Plugins/nosRendering/CMakeLists.txt create mode 100644 Plugins/nosRendering/Config/BillboardMask.nosdef create mode 100644 Plugins/nosRendering/Config/Rendering.fbs create mode 100644 Plugins/nosRendering/Config/TrackToView.nosdef create mode 100644 Plugins/nosRendering/Rendering.noscfg create mode 100644 Plugins/nosRendering/Shaders/BillboardMask.frag create mode 100644 Plugins/nosRendering/Shaders/BillboardMask.vert create mode 100644 Plugins/nosRendering/Source/BillboardMask.cpp create mode 100644 Plugins/nosRendering/Source/RenderingMain.cpp create mode 100644 Plugins/nosRendering/Source/TrackToView.cpp diff --git a/Plugins/CMakeLists.txt b/Plugins/CMakeLists.txt index 310b96d2..c0340355 100644 --- a/Plugins/CMakeLists.txt +++ b/Plugins/CMakeLists.txt @@ -41,6 +41,7 @@ endif() add_subdirectory(nosReflect) add_subdirectory(nosStrings) add_subdirectory(nosAnimation) +add_subdirectory(nosRendering) nos_get_targets(PLUGINS_COMMON_EXTERNAL_TARGETS "./External") nos_group_targets("${PLUGINS_COMMON_EXTERNAL_TARGETS}" "External") diff --git a/Plugins/nosRendering/CMakeLists.txt b/Plugins/nosRendering/CMakeLists.txt new file mode 100644 index 00000000..4fe80b1a --- /dev/null +++ b/Plugins/nosRendering/CMakeLists.txt @@ -0,0 +1,26 @@ +set(NOS_VULKAN_NAME "nos.sys.vulkan") +set(NOS_VULKAN_VERSION "6.0") + +set(NOS_TRACK_NAME "nos.track") +set(NOS_TRACK_VERSION "1.9") + +set(MODULE_DEPENDENCIES "${NOS_VULKAN_NAME}-${NOS_VULKAN_VERSION}" "${NOS_TRACK_NAME}-${NOS_TRACK_VERSION}") +set(dep_idx 0) +foreach(module_name_version ${MODULE_DEPENDENCIES}) + # module_name_version: - + string(REPLACE "-" ";" module_name_version ${module_name_version}) + list(GET module_name_version 0 module_name) + list(GET module_name_version 1 module_version) + nos_get_module("${module_name}" "${module_version}" DEP_${dep_idx}) + list(APPEND MODULE_DEPENDENCIES_TARGETS ${DEP_${dep_idx}}) +endforeach() +list(APPEND MODULE_DEPENDENCIES_TARGETS ${NOS_PLUGIN_SDK_TARGET}) + +nos_find_module_path(${NOS_VULKAN_NAME} ${NOS_VULKAN_VERSION} NOS_VULKAN_PATH) + +set(GENERATED_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated") +nos_generate_flatbuffers("${CMAKE_CURRENT_SOURCE_DIR}/Config" "${GENERATED_OUTPUT_DIR}" "cpp" "${NOS_SDK_DIR}/types;${NOS_VULKAN_PATH}" nosRendering_generated) + +list(APPEND MODULE_DEPENDENCIES_TARGETS nosRendering_generated) +set(INCLUDE_FOLDERS "${GENERATED_OUTPUT_DIR}") +nos_add_plugin("nosRendering" "${MODULE_DEPENDENCIES_TARGETS}" "${INCLUDE_FOLDERS}") diff --git a/Plugins/nosRendering/Config/BillboardMask.nosdef b/Plugins/nosRendering/Config/BillboardMask.nosdef new file mode 100644 index 00000000..3ca1f813 --- /dev/null +++ b/Plugins/nosRendering/Config/BillboardMask.nosdef @@ -0,0 +1,63 @@ +{ + "nodes": [ + { + "class_name": "BillboardMask", + "menu_info": { + "category": "Rendering", + "display_name": "Billboard Mask" + }, + "node": { + "contents_type": "Job", + "pins": [ + { + "name": "Position", + "type_name": "nos.fb.vec3", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY" + }, + { + "name": "Size", + "type_name": "nos.fb.vec2", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY", + "data": { + "x": 100.0, + "y": 100.0 + } + }, + { + "name": "RenderView", + "type_name": "nos.rendering.RenderView", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY" + }, + { + "name": "Resolution", + "type_name": "nos.fb.vec2u", + "show_as": "PROPERTY", + "can_show_as": "INPUT_PIN_OR_PROPERTY", + "data": { + "x": 1920, + "y": 1080 + } + }, + { + "name": "OutRenderTarget", + "type_name": "nos.sys.vulkan.Texture", + "show_as": "OUTPUT_PIN", + "can_show_as": "OUTPUT_PIN_OR_PROPERTY" + }, + { + "name": "OutDepth", + "type_name": "nos.sys.vulkan.Texture", + "show_as": "OUTPUT_PIN", + "can_show_as": "OUTPUT_PIN_OR_PROPERTY", + "data": { + "format": "D32_SFLOAT" + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/Plugins/nosRendering/Config/Rendering.fbs b/Plugins/nosRendering/Config/Rendering.fbs new file mode 100644 index 00000000..c014f293 --- /dev/null +++ b/Plugins/nosRendering/Config/Rendering.fbs @@ -0,0 +1,38 @@ +include "Common.fbs"; + +namespace nos.rendering; + + +table PerspectiveProjection +{ + aspect_ratio: float; + fov_x: float; +} + +table OrthographicProjection +{ + width: float; + height: float; +} + +enum ProjectionType : ubyte +{ + Perspective, + Orthographic +} + +table Projection +{ + clip_planes: nos.fb.vec2 (native_inline); + shift: nos.fb.vec2 (native_inline); + projection_type: ProjectionType; + perspective: PerspectiveProjection; + orthographic: OrthographicProjection; +} + +table RenderView +{ + view: nos.fb.mat4(native_inline); + left_handed_projection_matrix: nos.fb.mat4(native_inline); + projection: Projection; +} \ No newline at end of file diff --git a/Plugins/nosRendering/Config/TrackToView.nosdef b/Plugins/nosRendering/Config/TrackToView.nosdef new file mode 100644 index 00000000..ebece214 --- /dev/null +++ b/Plugins/nosRendering/Config/TrackToView.nosdef @@ -0,0 +1,42 @@ +{ + "nodes": [ + { + "class_name": "TrackToView", + "menu_info": { + "category": "Rendering", + "display_name": "Track To View" + }, + "node": { + "contents_type": "Job", + "pins": [ + { + "name": "Track", + "type_name": "nos.track.Track", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY" + }, + { + "name": "AspectRatio", + "type_name": "float", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY", + "data": 1.7777778 + }, + { + "name": "Clip", + "type_name": "nos.fb.vec2", + "show_as": "INPUT_PIN", + "can_show_as": "INPUT_PIN_OR_PROPERTY", + "data": {"x": 0.1, "y": 10000.0} + }, + { + "name": "View", + "type_name": "nos.rendering.RenderView", + "show_as": "OUTPUT_PIN", + "can_show_as": "OUTPUT_PIN_ONLY" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/Plugins/nosRendering/Rendering.noscfg b/Plugins/nosRendering/Rendering.noscfg new file mode 100644 index 00000000..22f7dc2b --- /dev/null +++ b/Plugins/nosRendering/Rendering.noscfg @@ -0,0 +1,28 @@ +{ + "info": { + "id": { + "name": "nos.rendering", + "version": "0.1.0" + }, + "description": "Nodes for rendering operations.", + "display_name": "Rendering", + "category": "Graphics", + "dependencies": [ + { + "name": "nos.sys.vulkan", + "version": "6.0" + }, + { + "name": "nos.track", + "version": "1.9" + } + ] + }, + "custom_types": ["Config/Rendering.fbs"], + "node_definitions": [ + "Config/BillboardMask.nosdef", + "Config/TrackToView.nosdef" + ], + "binary_path": "Binaries/nosRendering", + "associated_nodes": [] +} \ No newline at end of file diff --git a/Plugins/nosRendering/Shaders/BillboardMask.frag b/Plugins/nosRendering/Shaders/BillboardMask.frag new file mode 100644 index 00000000..0ef1938d --- /dev/null +++ b/Plugins/nosRendering/Shaders/BillboardMask.frag @@ -0,0 +1,17 @@ +#version 450 +#extension GL_EXT_scalar_block_layout : enable + +layout(location = 0) in vec2 vertexScreenUv; +layout (location = 1) in vec2 quadUv; +layout(location = 0) out vec4 rt; + +layout (binding = 0, std430) uniform UBO +{ + mat4 MVP; + float AlphaClip; +} ubo; + +void main() +{ + rt = vec4(1.0); +} \ No newline at end of file diff --git a/Plugins/nosRendering/Shaders/BillboardMask.vert b/Plugins/nosRendering/Shaders/BillboardMask.vert new file mode 100644 index 00000000..fbc32bbe --- /dev/null +++ b/Plugins/nosRendering/Shaders/BillboardMask.vert @@ -0,0 +1,39 @@ +#version 450 +#extension GL_EXT_scalar_block_layout : enable + +layout (location = 0) out vec2 outScreenUv; +layout (location = 1) out vec2 outQuadUv; + +layout (binding = 0, std430) uniform UBO +{ + mat4 MVP; + float AlphaClip; +} ubo; + +const vec2 pos[6] = + vec2[6]( + vec2(+1.0, +1.0), + vec2(-1.0, +1.0), + vec2(+1.0, -1.0), + vec2(+1.0, -1.0), + vec2(-1.0, +1.0), + vec2(-1.0, -1.0)); +const vec2 uv[6] = + vec2[6]( + vec2(1.0, 0.0), + vec2(0.0, 0.0), + vec2(1.0, 1.0), + vec2(1.0, 1.0), + vec2(0.0, 0.0), + vec2(0.0, 1.0)); + +void main() +{ + vec4 vertPos = vec4(pos[gl_VertexIndex].x, 0.0, pos[gl_VertexIndex].y, 1.0); + vec4 clipPos = ubo.MVP * vertPos; + vec4 screenPos = clipPos / clipPos.w; + gl_Position = screenPos; + vec2 screenUv = screenPos.xy * 0.5 + 0.5; + outScreenUv = screenUv; + outQuadUv = uv[gl_VertexIndex]; +} \ No newline at end of file diff --git a/Plugins/nosRendering/Source/BillboardMask.cpp b/Plugins/nosRendering/Source/BillboardMask.cpp new file mode 100644 index 00000000..bf53d2dc --- /dev/null +++ b/Plugins/nosRendering/Source/BillboardMask.cpp @@ -0,0 +1,218 @@ +// Copyright MediaZ Teknoloji A.S. All Rights Reserved. + +#include +#include +#include +#include +#include + +namespace nos::rendering +{ +NOS_REGISTER_NAME(BillboardMask) + +NOS_REGISTER_NAME(Position) +NOS_REGISTER_NAME(Size) +NOS_REGISTER_NAME(RenderView) +NOS_REGISTER_NAME(Resolution) +NOS_REGISTER_NAME(OutRenderTarget) +NOS_REGISTER_NAME(OutDepth) + +NOS_REGISTER_NAME(BillboardMask_Pass) + +struct BillboardMask : NodeContext +{ + using NodeContext::NodeContext; + + enum class StatusMessageType + { + FailedToCreateRenderTarget = 1, + FailedToCreateDepthBuffer = 2, + }; + + std::unordered_map ActiveStatusMessages; + + void SerializeAndSendStatusMessages() + { + if (ActiveStatusMessages.size() == 0) + { + ClearNodeStatusMessages(); + return; + } + std::vector messages; + messages.reserve(ActiveStatusMessages.size()); + for (const auto& [type, statusMessage] : ActiveStatusMessages) + { + messages.push_back(statusMessage); + } + SetNodeStatusMessages(messages); + } + + void SetOrAddStatusMessage(StatusMessageType msgType, nos::fb::TNodeStatusMessage message) + { + if (auto it = ActiveStatusMessages.find(msgType); it != ActiveStatusMessages.end()) + { + if (it->second.text == message.text && it->second.type == message.type) + return; + } + ActiveStatusMessages[msgType] = std::move(message); + SerializeAndSendStatusMessages(); + } + + void RemoveStatusMessage(StatusMessageType msgType) + { + if (ActiveStatusMessages.erase(msgType) > 0) + SerializeAndSendStatusMessages(); + } + + nosResult ExecuteNode(nosNodeExecuteParams* params) override + { + NodeExecuteParams pins(params); + TRenderView view = pins.GetPinData(NSN_RenderView); + glm::vec2 size = *pins.GetPinData(NSN_Size); + glm::vec3 position = *pins.GetPinData(NSN_Position); + + nosVec2u resolution = *pins.GetPinData(NSN_Resolution); + + nosResourceShareInfo rt = vkss::DeserializeTextureInfo(pins[NSN_OutRenderTarget].Data->Data); + + if (rt.Info.Texture.Width != resolution.x || rt.Info.Texture.Height != resolution.y) + { + auto newRt = vkss::Resource::Create( + nosTextureInfo{.Width = resolution.x, + .Height = resolution.y, + .Format = NOS_FORMAT_R8_UNORM, + .Filter = NOS_TEXTURE_FILTER_LINEAR, + .Usage = nosImageUsage(NOS_IMAGE_USAGE_SAMPLED | NOS_IMAGE_USAGE_RENDER_TARGET)}, + "Billboard Mask Output"); + if (!newRt) + { + SetOrAddStatusMessage(StatusMessageType::FailedToCreateRenderTarget, + nos::fb::TNodeStatusMessage{ + .text = "Failed to create render target for Billboard Mask node.", + .type = + nos::fb::NodeStatusMessageType::FAILURE, + }); + rt = {}; + } + else + { + SetPinValue(NSN_OutRenderTarget, newRt->ToPinData()); + rt = nosResourceShareInfo(*newRt); + } + } + + nosResourceShareInfo depth = vkss::DeserializeTextureInfo(pins[NSN_OutDepth].Data->Data); + if (depth.Info.Texture.Width != resolution.x || depth.Info.Texture.Height != resolution.y) + { + auto newDepth = vkss::Resource::Create( + nosTextureInfo{.Width = resolution.x, + .Height = resolution.y, + .Format = NOS_FORMAT_R8_UNORM, + .Filter = NOS_TEXTURE_FILTER_LINEAR, + .Usage = nosImageUsage(NOS_IMAGE_USAGE_SAMPLED | NOS_IMAGE_USAGE_RENDER_TARGET)}, + "Billboard Mask Depth"); + if (!newDepth) + { + SetOrAddStatusMessage(StatusMessageType::FailedToCreateRenderTarget, + nos::fb::TNodeStatusMessage{ + .text = "Failed to create render target for Billboard Mask node.", + .type = nos::fb::NodeStatusMessageType::FAILURE, + }); + depth = {}; + } + else + { + SetPinValue(NSN_OutDepth, newDepth->ToPinData()); + depth = nosResourceShareInfo(*newDepth); + } + } + + if (rt.Memory.Handle == 0 || depth.Memory.Handle == 0) + { + return NOS_RESULT_FAILED; + } + + glm::mat4 viewMat = reinterpret_cast(view.view); + glm::mat4 projMat = reinterpret_cast(view.left_handed_projection_matrix); + + glm::mat4 modelMat = glm::mat4(1.0f); + // Face the camera + glm::vec3 cameraPos = glm::vec3(glm::inverse(viewMat)[3]); + cameraPos.z = position.z; + glm::vec3 toCamera = glm::normalize(cameraPos - position); + glm::vec3 up = glm::vec3(0.0f, 0.0f, 1.0f); + glm::vec3 right = glm::normalize(glm::cross(toCamera, up)); + modelMat = glm::translate(modelMat, position); + modelMat[0] = glm::vec4(right, 0.0f); + modelMat[1] = glm::vec4(toCamera, 0.0f); + modelMat[2] = glm::vec4(up, 0.0f); + modelMat = glm::scale(modelMat, glm::vec3(size.x, 1.0f, size.y)); + + glm::mat4 mvp = projMat * viewMat * modelMat; + + auto bindings = std::array{vkss::ShaderBinding(NOS_NAME("MVP"), mvp)}; + + nosDrawCall drawCall{.Bindings = bindings.data(), + .BindingCount = bindings.size(), + .Vertices = nosVertexData{ + .IndexCount = 6, + .DepthFunc = NOS_DEPTH_FUNCTION_LESS, + .DepthWrite = true, + .DepthTest = true, + }}; + + nosRunPass2Params passParams{ + .Key = NSN_BillboardMask_Pass, + .Output = rt, + .DrawCalls = &drawCall, + .DrawCallCount = 1, + .Wireframe = NOS_FALSE, + .Benchmark = 0, + .DoNotClear = false, + .ClearCol = {0.f, 0.f, 0.f, 0.f}, + .DepthAttachment = nosDepthAttachment{.DepthBuffer = depth, .DoNotClear = false, .ClearValue = 1.0f}}; + + auto cmd = vkss::BeginCmd(NOS_NAME("Billboard Mask"), NodeId); + nosVulkan->RunPass2(cmd, &passParams); + nosVulkan->End(cmd, nullptr); + return NOS_RESULT_SUCCESS; + } +}; + +nosResult RegisterBillboardMask(nosNodeFunctions* fn) +{ + NOS_BIND_NODE_CLASS(NSN_BillboardMask, BillboardMask, fn); + + fs::path root = nosEngine.Module->RootFolderPath; + auto vertPath = (root / "Shaders" / "BillboardMask.vert").generic_string(); + auto fragPath = (root / "Shaders" / "BillboardMask.frag").generic_string(); + + // Register shaders + auto billboardMask_Frag = NOS_NAME("BillboardMask_Frag"); + auto billboardMask_Vert = NOS_NAME("BillboardMask_Vert"); + std::array shaders = { + nosShaderInfo{.ShaderName = billboardMask_Frag, + .Source = {.Stage = NOS_SHADER_STAGE_FRAG, .GLSLPath = fragPath.c_str()}, + .AssociatedNodeClassName = NSN_BillboardMask}, + nosShaderInfo{.ShaderName = billboardMask_Vert, + .Source = {.Stage = NOS_SHADER_STAGE_VERT, .GLSLPath = vertPath.c_str()}, + .AssociatedNodeClassName = NSN_BillboardMask}}; + auto ret = nosVulkan->RegisterShaders(shaders.size(), shaders.data()); + if (NOS_RESULT_SUCCESS != ret) + return ret; + + nosPassInfo pass = { + .Key = NSN_BillboardMask_Pass, + .Shader = billboardMask_Frag, + .VertexShader = billboardMask_Vert, + .MultiSample = 1, + .Blend = NOS_BLEND_MODE_ALPHA_BLENDING, + }; + ret = nosVulkan->RegisterPasses(1, &pass); + if (NOS_RESULT_SUCCESS != ret) + return ret; + + return NOS_RESULT_SUCCESS; +} + +} // namespace nos::rendering diff --git a/Plugins/nosRendering/Source/RenderingMain.cpp b/Plugins/nosRendering/Source/RenderingMain.cpp new file mode 100644 index 00000000..c32e3b05 --- /dev/null +++ b/Plugins/nosRendering/Source/RenderingMain.cpp @@ -0,0 +1,81 @@ +// Copyright MediaZ Teknoloji A.S. All Rights Reserved. + +// Includes +#include +#include + +#define NOS_NODES \ + NOS_NODE_OP(TrackToView) \ + NOS_NODE_OP(BillboardMask) + +#define NOS_DEPS NOS_DEP_OP(NOS_VULKAN) + +#define NOS_NAMESPACE nos::rendering + +namespace nos::rendering +{ +struct PluginFunctions : nos::PluginFunctions +{ + nosResult NOSAPI_CALL ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) override; +}; +} // namespace nos::rendering + + + +// Nodos/PluginMain.inl + +NOS_INIT() + +#define NOS_DEP_OP(name) name##_INIT(); + +NOS_DEPS + +#undef NOS_DEP_OP + +#define NOS_DEP_OP(name) name##_IMPORT(); + +NOS_BEGIN_IMPORT_DEPS() +NOS_DEPS +NOS_END_IMPORT_DEPS() + +#undef NOS_DEP_OP + +namespace NOS_NAMESPACE +{ +#define NOS_NODE_OP(name) name, + +enum Nodes : int +{ // CPU nodes + NOS_NODES Count +}; + +#undef NOS_NODE_OP +#define NOS_NODE_OP(name) nosResult Register##name(nosNodeFunctions*); +NOS_NODES + +#undef NOS_NODE_OP + +nosResult NOSAPI_CALL PluginFunctions::ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) +{ + outSize = Nodes::Count; + if (!outFunctions) + return NOS_RESULT_SUCCESS; +#define NOS_NODE_OP(name) \ + case Nodes::name: { \ + auto ret = Register##name(node); \ + if (NOS_RESULT_SUCCESS != ret) \ + return ret; \ + break; \ + } + for (int i = 0; i < Nodes::Count; ++i) + { + auto node = outFunctions[i]; + switch ((Nodes)i) + { + default: break; NOS_NODES + } + } + return NOS_RESULT_SUCCESS; +} +NOS_EXPORT_PLUGIN_FUNCTIONS(PluginFunctions) +} // namespace NOS_NAMESPACE \ No newline at end of file diff --git a/Plugins/nosRendering/Source/TrackToView.cpp b/Plugins/nosRendering/Source/TrackToView.cpp new file mode 100644 index 00000000..77bd7857 --- /dev/null +++ b/Plugins/nosRendering/Source/TrackToView.cpp @@ -0,0 +1,102 @@ +// Copyright MediaZ Teknoloji A.S. All Rights Reserved. + +#include +#include +#include + +#include +#include + +// Inside Nodos/PluginHelpers.hpp +#define NOS_REGISTER_NODE(NodeName) \ + nosResult Register##NodeName(nosNodeFunctions* fn) \ + { \ + NOS_BIND_NODE_CLASS(NOS_NAME(#NodeName), NodeName, fn); \ + return NodeName::OnRegister(); \ + } + +namespace nos::rendering +{ +glm::mat4 MakeView(glm::vec3 pos, glm::vec3 rot) +{ + rot = glm::radians(rot); + auto mat = (glm::mat3)glm::eulerAngleZYX(rot.z, -rot.y, -rot.x); + return glm::lookAtLH(pos, pos + mat[0], mat[2]); +} + +glm::mat4 Perspective(f32 fovx, f32 pixelAspectRatio, glm::vec2 sensorSize, glm::vec2 centerShift, glm::vec2 clipPlanes) +{ + if (glm::vec2(0) == sensorSize) + { + sensorSize = glm::vec2(1); + centerShift = glm::vec2(0); + } + + const f32 X = 1.f / tanf(glm::radians(fovx * 0.5f)); + const f32 Y = -X * (sensorSize.x / sensorSize.y) * pixelAspectRatio; + const auto S = -centerShift / sensorSize; + const f32 Z = clipPlanes.y / (clipPlanes.y - clipPlanes.x); + return glm::mat4(glm::vec4(X, 0, 0, 0), + glm::vec4(0, Y, 0, 0), + glm::vec4(S.x, -S.y, Z, 1.0f), + glm::vec4(0, 0, -clipPlanes.x * Z, 0)); +} + +glm::vec2 CalculateProjectionShift(glm::vec2 sensorSize, glm::vec2 centerShift) +{ + if (centerShift == glm::vec2(0)) + return glm::vec2(0); + if (sensorSize == glm::vec2(0)) + sensorSize = glm::vec2(1); + auto projectionShift = glm::vec2(-centerShift / sensorSize); + projectionShift.y = -projectionShift.y; + return projectionShift; +} + +NOS_REGISTER_NAME(Track) +NOS_REGISTER_NAME(AspectRatio) +NOS_REGISTER_NAME(Clip) +NOS_REGISTER_NAME(View) +struct TrackToView : NodeContext +{ + using NodeContext::NodeContext; + + nosResult ExecuteNode(nosNodeExecuteParams* params) override + { + NodeExecuteParams pins(params); + nos::track::TTrack const& track = pins.GetPinData(NSN_Track); + float aspectRatio = *pins.GetPinData(NSN_AspectRatio); + nos::fb::vec2 clip = *pins.GetPinData(NSN_Clip); + + glm::vec2 sensorSize = reinterpret_cast(track.sensor_size); + glm::vec2 centerShift = reinterpret_cast(track.lens_distortion.center_shift()); + glm::vec2 projShift = CalculateProjectionShift(sensorSize, centerShift); + + TPerspectiveProjection perspectiveProjection{}; + perspectiveProjection.aspect_ratio = aspectRatio; + perspectiveProjection.fov_x = track.fov; + TProjection projection{}; + projection.clip_planes = clip; + projection.shift = reinterpret_cast(projShift); + projection.projection_type = ProjectionType::Perspective; + projection.perspective = std::make_unique(perspectiveProjection); + glm::mat4 viewMatrix = MakeView( + reinterpret_cast(track.location), + reinterpret_cast(track.rotation)); + glm::mat4 projectionMatrix = Perspective( + track.fov, track.pixel_aspect_ratio, sensorSize, centerShift, reinterpret_cast(clip)); + + TRenderView view{}; + view.projection = std::make_unique(projection); + view.view = reinterpret_cast(viewMatrix); + view.left_handed_projection_matrix = reinterpret_cast(projectionMatrix); + SetPinValue(NSN_View, Buffer::From(view)); + return NOS_RESULT_SUCCESS; + } + + static nosResult OnRegister() { return NOS_RESULT_SUCCESS; } +}; + +NOS_REGISTER_NODE(TrackToView) + +} // namespace nos::rendering From 6434d3422695878a5be0a074348905612cff3329 Mon Sep 17 00:00:00 2001 From: Caner Date: Tue, 16 Dec 2025 12:35:20 +0300 Subject: [PATCH 2/9] Move billboard origin to middle bottom to conform with talent rendering --- .../nosRendering/Shaders/BillboardMask.frag | 2 -- .../nosRendering/Shaders/BillboardMask.vert | 21 +++++++------------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Plugins/nosRendering/Shaders/BillboardMask.frag b/Plugins/nosRendering/Shaders/BillboardMask.frag index 0ef1938d..14e87879 100644 --- a/Plugins/nosRendering/Shaders/BillboardMask.frag +++ b/Plugins/nosRendering/Shaders/BillboardMask.frag @@ -1,8 +1,6 @@ #version 450 #extension GL_EXT_scalar_block_layout : enable -layout(location = 0) in vec2 vertexScreenUv; -layout (location = 1) in vec2 quadUv; layout(location = 0) out vec4 rt; layout (binding = 0, std430) uniform UBO diff --git a/Plugins/nosRendering/Shaders/BillboardMask.vert b/Plugins/nosRendering/Shaders/BillboardMask.vert index fbc32bbe..ed127f58 100644 --- a/Plugins/nosRendering/Shaders/BillboardMask.vert +++ b/Plugins/nosRendering/Shaders/BillboardMask.vert @@ -1,9 +1,6 @@ #version 450 #extension GL_EXT_scalar_block_layout : enable -layout (location = 0) out vec2 outScreenUv; -layout (location = 1) out vec2 outQuadUv; - layout (binding = 0, std430) uniform UBO { mat4 MVP; @@ -12,12 +9,12 @@ layout (binding = 0, std430) uniform UBO const vec2 pos[6] = vec2[6]( - vec2(+1.0, +1.0), - vec2(-1.0, +1.0), - vec2(+1.0, -1.0), - vec2(+1.0, -1.0), - vec2(-1.0, +1.0), - vec2(-1.0, -1.0)); + vec2(+0.5, +1.0), + vec2(-0.5, +1.0), + vec2(+0.5, 0.0), + vec2(+0.5, 0.0), + vec2(-0.5, +1.0), + vec2(-0.5, 0.0)); const vec2 uv[6] = vec2[6]( vec2(1.0, 0.0), @@ -31,9 +28,5 @@ void main() { vec4 vertPos = vec4(pos[gl_VertexIndex].x, 0.0, pos[gl_VertexIndex].y, 1.0); vec4 clipPos = ubo.MVP * vertPos; - vec4 screenPos = clipPos / clipPos.w; - gl_Position = screenPos; - vec2 screenUv = screenPos.xy * 0.5 + 0.5; - outScreenUv = screenUv; - outQuadUv = uv[gl_VertexIndex]; + gl_Position = clipPos; } \ No newline at end of file From b6094016a9f8a30ca7afeab8e25861fcbacc0af0 Mon Sep 17 00:00:00 2001 From: Caner Date: Tue, 16 Dec 2025 18:50:46 +0300 Subject: [PATCH 3/9] Rename rendering to graphics --- Plugins/CMakeLists.txt | 2 +- .../CMakeLists.txt | 6 +++--- .../Config/BillboardMask.nosdef | 2 +- .../Config/Graphics.fbs} | 10 ++++++++-- .../Config/TrackToView.nosdef | 2 +- .../Graphics.noscfg} | 10 +++++----- .../Shaders/BillboardMask.frag | 6 ------ .../Shaders/BillboardMask.vert | 1 - .../Source/BillboardMask.cpp | 19 +++++++++++-------- .../Source/GraphicsMain.cpp} | 6 +++--- .../Source/TrackToView.cpp | 6 +++--- 11 files changed, 36 insertions(+), 34 deletions(-) rename Plugins/{nosRendering => nosGraphics}/CMakeLists.txt (85%) rename Plugins/{nosRendering => nosGraphics}/Config/BillboardMask.nosdef (96%) rename Plugins/{nosRendering/Config/Rendering.fbs => nosGraphics/Config/Graphics.fbs} (81%) rename Plugins/{nosRendering => nosGraphics}/Config/TrackToView.nosdef (94%) rename Plugins/{nosRendering/Rendering.noscfg => nosGraphics/Graphics.noscfg} (64%) rename Plugins/{nosRendering => nosGraphics}/Shaders/BillboardMask.frag (60%) rename Plugins/{nosRendering => nosGraphics}/Shaders/BillboardMask.vert (96%) rename Plugins/{nosRendering => nosGraphics}/Source/BillboardMask.cpp (92%) rename Plugins/{nosRendering/Source/RenderingMain.cpp => nosGraphics/Source/GraphicsMain.cpp} (95%) rename Plugins/{nosRendering => nosGraphics}/Source/TrackToView.cpp (97%) diff --git a/Plugins/CMakeLists.txt b/Plugins/CMakeLists.txt index c0340355..589829f7 100644 --- a/Plugins/CMakeLists.txt +++ b/Plugins/CMakeLists.txt @@ -41,7 +41,7 @@ endif() add_subdirectory(nosReflect) add_subdirectory(nosStrings) add_subdirectory(nosAnimation) -add_subdirectory(nosRendering) +add_subdirectory(nosGraphics) nos_get_targets(PLUGINS_COMMON_EXTERNAL_TARGETS "./External") nos_group_targets("${PLUGINS_COMMON_EXTERNAL_TARGETS}" "External") diff --git a/Plugins/nosRendering/CMakeLists.txt b/Plugins/nosGraphics/CMakeLists.txt similarity index 85% rename from Plugins/nosRendering/CMakeLists.txt rename to Plugins/nosGraphics/CMakeLists.txt index 4fe80b1a..19b5d251 100644 --- a/Plugins/nosRendering/CMakeLists.txt +++ b/Plugins/nosGraphics/CMakeLists.txt @@ -19,8 +19,8 @@ list(APPEND MODULE_DEPENDENCIES_TARGETS ${NOS_PLUGIN_SDK_TARGET}) nos_find_module_path(${NOS_VULKAN_NAME} ${NOS_VULKAN_VERSION} NOS_VULKAN_PATH) set(GENERATED_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated") -nos_generate_flatbuffers("${CMAKE_CURRENT_SOURCE_DIR}/Config" "${GENERATED_OUTPUT_DIR}" "cpp" "${NOS_SDK_DIR}/types;${NOS_VULKAN_PATH}" nosRendering_generated) +nos_generate_flatbuffers("${CMAKE_CURRENT_SOURCE_DIR}/Config" "${GENERATED_OUTPUT_DIR}" "cpp" "${NOS_SDK_DIR}/types;${NOS_VULKAN_PATH}" nosGraphics_generated) -list(APPEND MODULE_DEPENDENCIES_TARGETS nosRendering_generated) +list(APPEND MODULE_DEPENDENCIES_TARGETS nosGraphics_generated) set(INCLUDE_FOLDERS "${GENERATED_OUTPUT_DIR}") -nos_add_plugin("nosRendering" "${MODULE_DEPENDENCIES_TARGETS}" "${INCLUDE_FOLDERS}") +nos_add_plugin("nosGraphics" "${MODULE_DEPENDENCIES_TARGETS}" "${INCLUDE_FOLDERS}") \ No newline at end of file diff --git a/Plugins/nosRendering/Config/BillboardMask.nosdef b/Plugins/nosGraphics/Config/BillboardMask.nosdef similarity index 96% rename from Plugins/nosRendering/Config/BillboardMask.nosdef rename to Plugins/nosGraphics/Config/BillboardMask.nosdef index 3ca1f813..46d64907 100644 --- a/Plugins/nosRendering/Config/BillboardMask.nosdef +++ b/Plugins/nosGraphics/Config/BillboardMask.nosdef @@ -27,7 +27,7 @@ }, { "name": "RenderView", - "type_name": "nos.rendering.RenderView", + "type_name": "nos.graphics.RenderView", "show_as": "INPUT_PIN", "can_show_as": "INPUT_PIN_OR_PROPERTY" }, diff --git a/Plugins/nosRendering/Config/Rendering.fbs b/Plugins/nosGraphics/Config/Graphics.fbs similarity index 81% rename from Plugins/nosRendering/Config/Rendering.fbs rename to Plugins/nosGraphics/Config/Graphics.fbs index c014f293..8c3ca8f8 100644 --- a/Plugins/nosRendering/Config/Rendering.fbs +++ b/Plugins/nosGraphics/Config/Graphics.fbs @@ -1,7 +1,6 @@ include "Common.fbs"; -namespace nos.rendering; - +namespace nos.graphics; table PerspectiveProjection { @@ -35,4 +34,11 @@ table RenderView view: nos.fb.mat4(native_inline); left_handed_projection_matrix: nos.fb.mat4(native_inline); projection: Projection; +} + +struct Transform +{ + position: nos.fb.vec3d; + rotation: nos.fb.vec3d; + scale: nos.fb.vec3d; } \ No newline at end of file diff --git a/Plugins/nosRendering/Config/TrackToView.nosdef b/Plugins/nosGraphics/Config/TrackToView.nosdef similarity index 94% rename from Plugins/nosRendering/Config/TrackToView.nosdef rename to Plugins/nosGraphics/Config/TrackToView.nosdef index ebece214..0ee656b8 100644 --- a/Plugins/nosRendering/Config/TrackToView.nosdef +++ b/Plugins/nosGraphics/Config/TrackToView.nosdef @@ -31,7 +31,7 @@ }, { "name": "View", - "type_name": "nos.rendering.RenderView", + "type_name": "nos.graphics.RenderView", "show_as": "OUTPUT_PIN", "can_show_as": "OUTPUT_PIN_ONLY" } diff --git a/Plugins/nosRendering/Rendering.noscfg b/Plugins/nosGraphics/Graphics.noscfg similarity index 64% rename from Plugins/nosRendering/Rendering.noscfg rename to Plugins/nosGraphics/Graphics.noscfg index 22f7dc2b..a472fb07 100644 --- a/Plugins/nosRendering/Rendering.noscfg +++ b/Plugins/nosGraphics/Graphics.noscfg @@ -1,11 +1,11 @@ { "info": { "id": { - "name": "nos.rendering", + "name": "nos.graphics", "version": "0.1.0" }, - "description": "Nodes for rendering operations.", - "display_name": "Rendering", + "description": "Types & Nodes for graphics operations.", + "display_name": "Graphics", "category": "Graphics", "dependencies": [ { @@ -18,11 +18,11 @@ } ] }, - "custom_types": ["Config/Rendering.fbs"], + "custom_types": ["Config/Graphics.fbs"], "node_definitions": [ "Config/BillboardMask.nosdef", "Config/TrackToView.nosdef" ], - "binary_path": "Binaries/nosRendering", + "binary_path": "Binaries/nosGraphics", "associated_nodes": [] } \ No newline at end of file diff --git a/Plugins/nosRendering/Shaders/BillboardMask.frag b/Plugins/nosGraphics/Shaders/BillboardMask.frag similarity index 60% rename from Plugins/nosRendering/Shaders/BillboardMask.frag rename to Plugins/nosGraphics/Shaders/BillboardMask.frag index 14e87879..fe70a464 100644 --- a/Plugins/nosRendering/Shaders/BillboardMask.frag +++ b/Plugins/nosGraphics/Shaders/BillboardMask.frag @@ -3,12 +3,6 @@ layout(location = 0) out vec4 rt; -layout (binding = 0, std430) uniform UBO -{ - mat4 MVP; - float AlphaClip; -} ubo; - void main() { rt = vec4(1.0); diff --git a/Plugins/nosRendering/Shaders/BillboardMask.vert b/Plugins/nosGraphics/Shaders/BillboardMask.vert similarity index 96% rename from Plugins/nosRendering/Shaders/BillboardMask.vert rename to Plugins/nosGraphics/Shaders/BillboardMask.vert index ed127f58..91465cdc 100644 --- a/Plugins/nosRendering/Shaders/BillboardMask.vert +++ b/Plugins/nosGraphics/Shaders/BillboardMask.vert @@ -4,7 +4,6 @@ layout (binding = 0, std430) uniform UBO { mat4 MVP; - float AlphaClip; } ubo; const vec2 pos[6] = diff --git a/Plugins/nosRendering/Source/BillboardMask.cpp b/Plugins/nosGraphics/Source/BillboardMask.cpp similarity index 92% rename from Plugins/nosRendering/Source/BillboardMask.cpp rename to Plugins/nosGraphics/Source/BillboardMask.cpp index bf53d2dc..0b52e065 100644 --- a/Plugins/nosRendering/Source/BillboardMask.cpp +++ b/Plugins/nosGraphics/Source/BillboardMask.cpp @@ -1,12 +1,12 @@ // Copyright MediaZ Teknoloji A.S. All Rights Reserved. #include -#include +#include #include #include #include -namespace nos::rendering +namespace nos::graphics { NOS_REGISTER_NAME(BillboardMask) @@ -98,24 +98,26 @@ struct BillboardMask : NodeContext { SetPinValue(NSN_OutRenderTarget, newRt->ToPinData()); rt = nosResourceShareInfo(*newRt); + RemoveStatusMessage(StatusMessageType::FailedToCreateRenderTarget); } } nosResourceShareInfo depth = vkss::DeserializeTextureInfo(pins[NSN_OutDepth].Data->Data); - if (depth.Info.Texture.Width != resolution.x || depth.Info.Texture.Height != resolution.y) + if (depth.Info.Texture.Width != resolution.x || depth.Info.Texture.Height != resolution.y || + depth.Info.Texture.Format != NOS_FORMAT_D32_SFLOAT) { auto newDepth = vkss::Resource::Create( nosTextureInfo{.Width = resolution.x, .Height = resolution.y, - .Format = NOS_FORMAT_R8_UNORM, + .Format = NOS_FORMAT_D32_SFLOAT, .Filter = NOS_TEXTURE_FILTER_LINEAR, - .Usage = nosImageUsage(NOS_IMAGE_USAGE_SAMPLED | NOS_IMAGE_USAGE_RENDER_TARGET)}, + .Usage = nosImageUsage(NOS_IMAGE_USAGE_SAMPLED | NOS_IMAGE_USAGE_DEPTH_STENCIL)}, "Billboard Mask Depth"); if (!newDepth) { - SetOrAddStatusMessage(StatusMessageType::FailedToCreateRenderTarget, + SetOrAddStatusMessage(StatusMessageType::FailedToCreateDepthBuffer, nos::fb::TNodeStatusMessage{ - .text = "Failed to create render target for Billboard Mask node.", + .text = "Failed to create depth buffer for Billboard Mask node.", .type = nos::fb::NodeStatusMessageType::FAILURE, }); depth = {}; @@ -124,6 +126,7 @@ struct BillboardMask : NodeContext { SetPinValue(NSN_OutDepth, newDepth->ToPinData()); depth = nosResourceShareInfo(*newDepth); + RemoveStatusMessage(StatusMessageType::FailedToCreateDepthBuffer); } } @@ -215,4 +218,4 @@ nosResult RegisterBillboardMask(nosNodeFunctions* fn) return NOS_RESULT_SUCCESS; } -} // namespace nos::rendering +} // namespace nos::graphics diff --git a/Plugins/nosRendering/Source/RenderingMain.cpp b/Plugins/nosGraphics/Source/GraphicsMain.cpp similarity index 95% rename from Plugins/nosRendering/Source/RenderingMain.cpp rename to Plugins/nosGraphics/Source/GraphicsMain.cpp index c32e3b05..4868d9f8 100644 --- a/Plugins/nosRendering/Source/RenderingMain.cpp +++ b/Plugins/nosGraphics/Source/GraphicsMain.cpp @@ -10,15 +10,15 @@ #define NOS_DEPS NOS_DEP_OP(NOS_VULKAN) -#define NOS_NAMESPACE nos::rendering +#define NOS_NAMESPACE nos::graphics -namespace nos::rendering +namespace nos::graphics { struct PluginFunctions : nos::PluginFunctions { nosResult NOSAPI_CALL ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) override; }; -} // namespace nos::rendering +} // namespace nos::graphics diff --git a/Plugins/nosRendering/Source/TrackToView.cpp b/Plugins/nosGraphics/Source/TrackToView.cpp similarity index 97% rename from Plugins/nosRendering/Source/TrackToView.cpp rename to Plugins/nosGraphics/Source/TrackToView.cpp index 77bd7857..d024f611 100644 --- a/Plugins/nosRendering/Source/TrackToView.cpp +++ b/Plugins/nosGraphics/Source/TrackToView.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ return NodeName::OnRegister(); \ } -namespace nos::rendering +namespace nos::graphics { glm::mat4 MakeView(glm::vec3 pos, glm::vec3 rot) { @@ -99,4 +99,4 @@ struct TrackToView : NodeContext NOS_REGISTER_NODE(TrackToView) -} // namespace nos::rendering +} // namespace nos::graphics From bf7d90c05b40c7f275f4356304da40ba21efd415 Mon Sep 17 00:00:00 2001 From: Caner Date: Thu, 18 Dec 2025 16:03:31 +0300 Subject: [PATCH 4/9] Rename shift->center_shift & add todo --- Plugins/nosGraphics/Config/Graphics.fbs | 6 ++++-- Plugins/nosGraphics/Source/TrackToView.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/nosGraphics/Config/Graphics.fbs b/Plugins/nosGraphics/Config/Graphics.fbs index 8c3ca8f8..b0a1b663 100644 --- a/Plugins/nosGraphics/Config/Graphics.fbs +++ b/Plugins/nosGraphics/Config/Graphics.fbs @@ -23,7 +23,7 @@ enum ProjectionType : ubyte table Projection { clip_planes: nos.fb.vec2 (native_inline); - shift: nos.fb.vec2 (native_inline); + center_shift: nos.fb.vec2 (native_inline); projection_type: ProjectionType; perspective: PerspectiveProjection; orthographic: OrthographicProjection; @@ -41,4 +41,6 @@ struct Transform position: nos.fb.vec3d; rotation: nos.fb.vec3d; scale: nos.fb.vec3d; -} \ No newline at end of file +} + +// TODO: Move nos.fb.Transform here too \ No newline at end of file diff --git a/Plugins/nosGraphics/Source/TrackToView.cpp b/Plugins/nosGraphics/Source/TrackToView.cpp index d024f611..a7065e57 100644 --- a/Plugins/nosGraphics/Source/TrackToView.cpp +++ b/Plugins/nosGraphics/Source/TrackToView.cpp @@ -77,7 +77,7 @@ struct TrackToView : NodeContext perspectiveProjection.fov_x = track.fov; TProjection projection{}; projection.clip_planes = clip; - projection.shift = reinterpret_cast(projShift); + projection.center_shift = reinterpret_cast(projShift); projection.projection_type = ProjectionType::Perspective; projection.perspective = std::make_unique(perspectiveProjection); glm::mat4 viewMatrix = MakeView( From f69d2dc5ae06c2139725a31ecde950b445105518 Mon Sep 17 00:00:00 2001 From: Caner Date: Thu, 18 Dec 2025 16:04:39 +0300 Subject: [PATCH 5/9] Fix noscfg indentation --- Plugins/nosGraphics/Graphics.noscfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/nosGraphics/Graphics.noscfg b/Plugins/nosGraphics/Graphics.noscfg index a472fb07..b2ab41e2 100644 --- a/Plugins/nosGraphics/Graphics.noscfg +++ b/Plugins/nosGraphics/Graphics.noscfg @@ -12,13 +12,13 @@ "name": "nos.sys.vulkan", "version": "6.0" }, - { - "name": "nos.track", - "version": "1.9" - } + { + "name": "nos.track", + "version": "1.9" + } ] }, - "custom_types": ["Config/Graphics.fbs"], + "custom_types": [ "Config/Graphics.fbs" ], "node_definitions": [ "Config/BillboardMask.nosdef", "Config/TrackToView.nosdef" From 4f107d831889f9f491ebe0ede0c77fe01f21490e Mon Sep 17 00:00:00 2001 From: Caner Date: Thu, 18 Dec 2025 16:41:50 +0300 Subject: [PATCH 6/9] Mini refactor & get aspect ratio from track directly --- Plugins/nosGraphics/Config/TrackToView.nosdef | 7 ------ .../nosGraphics/Shaders/BillboardMask.vert | 8 ------- Plugins/nosGraphics/Source/BillboardMask.cpp | 1 + Plugins/nosGraphics/Source/TrackToView.cpp | 23 ++++++++----------- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Plugins/nosGraphics/Config/TrackToView.nosdef b/Plugins/nosGraphics/Config/TrackToView.nosdef index 0ee656b8..cea910d4 100644 --- a/Plugins/nosGraphics/Config/TrackToView.nosdef +++ b/Plugins/nosGraphics/Config/TrackToView.nosdef @@ -15,13 +15,6 @@ "show_as": "INPUT_PIN", "can_show_as": "INPUT_PIN_OR_PROPERTY" }, - { - "name": "AspectRatio", - "type_name": "float", - "show_as": "INPUT_PIN", - "can_show_as": "INPUT_PIN_OR_PROPERTY", - "data": 1.7777778 - }, { "name": "Clip", "type_name": "nos.fb.vec2", diff --git a/Plugins/nosGraphics/Shaders/BillboardMask.vert b/Plugins/nosGraphics/Shaders/BillboardMask.vert index 91465cdc..3661846f 100644 --- a/Plugins/nosGraphics/Shaders/BillboardMask.vert +++ b/Plugins/nosGraphics/Shaders/BillboardMask.vert @@ -14,14 +14,6 @@ const vec2 pos[6] = vec2(+0.5, 0.0), vec2(-0.5, +1.0), vec2(-0.5, 0.0)); -const vec2 uv[6] = - vec2[6]( - vec2(1.0, 0.0), - vec2(0.0, 0.0), - vec2(1.0, 1.0), - vec2(1.0, 1.0), - vec2(0.0, 0.0), - vec2(0.0, 1.0)); void main() { diff --git a/Plugins/nosGraphics/Source/BillboardMask.cpp b/Plugins/nosGraphics/Source/BillboardMask.cpp index 0b52e065..ba1952de 100644 --- a/Plugins/nosGraphics/Source/BillboardMask.cpp +++ b/Plugins/nosGraphics/Source/BillboardMask.cpp @@ -149,6 +149,7 @@ struct BillboardMask : NodeContext modelMat[0] = glm::vec4(right, 0.0f); modelMat[1] = glm::vec4(toCamera, 0.0f); modelMat[2] = glm::vec4(up, 0.0f); + // Translation writes to the 4th column, so no need to set it again modelMat = glm::scale(modelMat, glm::vec3(size.x, 1.0f, size.y)); glm::mat4 mvp = projMat * viewMat * modelMat; diff --git a/Plugins/nosGraphics/Source/TrackToView.cpp b/Plugins/nosGraphics/Source/TrackToView.cpp index a7065e57..947cbae7 100644 --- a/Plugins/nosGraphics/Source/TrackToView.cpp +++ b/Plugins/nosGraphics/Source/TrackToView.cpp @@ -24,21 +24,14 @@ glm::mat4 MakeView(glm::vec3 pos, glm::vec3 rot) return glm::lookAtLH(pos, pos + mat[0], mat[2]); } -glm::mat4 Perspective(f32 fovx, f32 pixelAspectRatio, glm::vec2 sensorSize, glm::vec2 centerShift, glm::vec2 clipPlanes) +glm::mat4 Perspective(float fovx, float aspectRatio, glm::vec2 projectionShift, glm::vec2 clipPlanes) { - if (glm::vec2(0) == sensorSize) - { - sensorSize = glm::vec2(1); - centerShift = glm::vec2(0); - } - const f32 X = 1.f / tanf(glm::radians(fovx * 0.5f)); - const f32 Y = -X * (sensorSize.x / sensorSize.y) * pixelAspectRatio; - const auto S = -centerShift / sensorSize; + const f32 Y = -X * aspectRatio; const f32 Z = clipPlanes.y / (clipPlanes.y - clipPlanes.x); return glm::mat4(glm::vec4(X, 0, 0, 0), glm::vec4(0, Y, 0, 0), - glm::vec4(S.x, -S.y, Z, 1.0f), + glm::vec4(projectionShift.x, projectionShift.y, Z, 1.0f), glm::vec4(0, 0, -clipPlanes.x * Z, 0)); } @@ -65,13 +58,16 @@ struct TrackToView : NodeContext { NodeExecuteParams pins(params); nos::track::TTrack const& track = pins.GetPinData(NSN_Track); - float aspectRatio = *pins.GetPinData(NSN_AspectRatio); nos::fb::vec2 clip = *pins.GetPinData(NSN_Clip); glm::vec2 sensorSize = reinterpret_cast(track.sensor_size); glm::vec2 centerShift = reinterpret_cast(track.lens_distortion.center_shift()); glm::vec2 projShift = CalculateProjectionShift(sensorSize, centerShift); - + if (glm::vec2(0) == sensorSize) + { + sensorSize = glm::vec2(1); + } + float aspectRatio = sensorSize.x / sensorSize.y * track.pixel_aspect_ratio; TPerspectiveProjection perspectiveProjection{}; perspectiveProjection.aspect_ratio = aspectRatio; perspectiveProjection.fov_x = track.fov; @@ -83,8 +79,9 @@ struct TrackToView : NodeContext glm::mat4 viewMatrix = MakeView( reinterpret_cast(track.location), reinterpret_cast(track.rotation)); + glm::mat4 projectionMatrix = Perspective( - track.fov, track.pixel_aspect_ratio, sensorSize, centerShift, reinterpret_cast(clip)); + track.fov, aspectRatio, centerShift, reinterpret_cast(clip)); TRenderView view{}; view.projection = std::make_unique(projection); From 38223f6cba0b37a91a679883bc65ef52860b158e Mon Sep 17 00:00:00 2001 From: Caner Date: Thu, 18 Dec 2025 18:40:38 +0300 Subject: [PATCH 7/9] Use standart plugin definitions --- Plugins/nosGraphics/Source/GraphicsMain.cpp | 75 +++++++-------------- Plugins/nosGraphics/Source/TrackToView.cpp | 15 ++--- 2 files changed, 28 insertions(+), 62 deletions(-) diff --git a/Plugins/nosGraphics/Source/GraphicsMain.cpp b/Plugins/nosGraphics/Source/GraphicsMain.cpp index 4868d9f8..04e4064b 100644 --- a/Plugins/nosGraphics/Source/GraphicsMain.cpp +++ b/Plugins/nosGraphics/Source/GraphicsMain.cpp @@ -4,78 +4,49 @@ #include #include -#define NOS_NODES \ - NOS_NODE_OP(TrackToView) \ - NOS_NODE_OP(BillboardMask) - -#define NOS_DEPS NOS_DEP_OP(NOS_VULKAN) - -#define NOS_NAMESPACE nos::graphics - -namespace nos::graphics -{ -struct PluginFunctions : nos::PluginFunctions -{ - nosResult NOSAPI_CALL ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) override; -}; -} // namespace nos::graphics - - - -// Nodos/PluginMain.inl - NOS_INIT() - -#define NOS_DEP_OP(name) name##_INIT(); - -NOS_DEPS - -#undef NOS_DEP_OP - -#define NOS_DEP_OP(name) name##_IMPORT(); +NOS_VULKAN_INIT() NOS_BEGIN_IMPORT_DEPS() -NOS_DEPS +NOS_VULKAN_IMPORT() NOS_END_IMPORT_DEPS() -#undef NOS_DEP_OP - -namespace NOS_NAMESPACE +namespace nos::graphics { -#define NOS_NODE_OP(name) name, - enum Nodes : int { // CPU nodes - NOS_NODES Count + TrackToView, + BillboardMask, + Count }; -#undef NOS_NODE_OP -#define NOS_NODE_OP(name) nosResult Register##name(nosNodeFunctions*); -NOS_NODES - -#undef NOS_NODE_OP +nosResult RegisterTrackToView(nosNodeFunctions*); +nosResult RegisterBillboardMask(nosNodeFunctions*); -nosResult NOSAPI_CALL PluginFunctions::ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) +struct PluginFunctions : nos::PluginFunctions { - outSize = Nodes::Count; - if (!outFunctions) - return NOS_RESULT_SUCCESS; -#define NOS_NODE_OP(name) \ + nosResult NOSAPI_CALL ExportNodeFunctions(size_t& outSize, nosNodeFunctions** outFunctions) + { + outSize = Nodes::Count; + if (!outFunctions) + return NOS_RESULT_SUCCESS; +#define GEN_CASE_NODE(name) \ case Nodes::name: { \ auto ret = Register##name(node); \ if (NOS_RESULT_SUCCESS != ret) \ return ret; \ break; \ } - for (int i = 0; i < Nodes::Count; ++i) - { - auto node = outFunctions[i]; - switch ((Nodes)i) + for (int i = 0; i < Nodes::Count; ++i) { - default: break; NOS_NODES + auto node = outFunctions[i]; + switch ((Nodes)i) + { + default: break; GEN_CASE_NODE(TrackToView) GEN_CASE_NODE(BillboardMask) + } } + return NOS_RESULT_SUCCESS; } - return NOS_RESULT_SUCCESS; -} +}; NOS_EXPORT_PLUGIN_FUNCTIONS(PluginFunctions) } // namespace NOS_NAMESPACE \ No newline at end of file diff --git a/Plugins/nosGraphics/Source/TrackToView.cpp b/Plugins/nosGraphics/Source/TrackToView.cpp index 947cbae7..26b7d359 100644 --- a/Plugins/nosGraphics/Source/TrackToView.cpp +++ b/Plugins/nosGraphics/Source/TrackToView.cpp @@ -7,14 +7,6 @@ #include #include -// Inside Nodos/PluginHelpers.hpp -#define NOS_REGISTER_NODE(NodeName) \ - nosResult Register##NodeName(nosNodeFunctions* fn) \ - { \ - NOS_BIND_NODE_CLASS(NOS_NAME(#NodeName), NodeName, fn); \ - return NodeName::OnRegister(); \ - } - namespace nos::graphics { glm::mat4 MakeView(glm::vec3 pos, glm::vec3 rot) @@ -47,7 +39,6 @@ glm::vec2 CalculateProjectionShift(glm::vec2 sensorSize, glm::vec2 centerShift) } NOS_REGISTER_NAME(Track) -NOS_REGISTER_NAME(AspectRatio) NOS_REGISTER_NAME(Clip) NOS_REGISTER_NAME(View) struct TrackToView : NodeContext @@ -94,6 +85,10 @@ struct TrackToView : NodeContext static nosResult OnRegister() { return NOS_RESULT_SUCCESS; } }; -NOS_REGISTER_NODE(TrackToView) +nosResult RegisterTrackToView(nosNodeFunctions* fn) +{ + NOS_BIND_NODE_CLASS(NOS_NAME("TrackToView"), TrackToView, fn); + return NOS_RESULT_SUCCESS; +} } // namespace nos::graphics From 403f94f138c1ac263066b7a5f344f22976d99798 Mon Sep 17 00:00:00 2001 From: Caner Date: Fri, 19 Dec 2025 16:23:00 +0300 Subject: [PATCH 8/9] Use bigger case Types folder --- Plugins/nosGraphics/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/nosGraphics/CMakeLists.txt b/Plugins/nosGraphics/CMakeLists.txt index 19b5d251..470294fc 100644 --- a/Plugins/nosGraphics/CMakeLists.txt +++ b/Plugins/nosGraphics/CMakeLists.txt @@ -19,7 +19,7 @@ list(APPEND MODULE_DEPENDENCIES_TARGETS ${NOS_PLUGIN_SDK_TARGET}) nos_find_module_path(${NOS_VULKAN_NAME} ${NOS_VULKAN_VERSION} NOS_VULKAN_PATH) set(GENERATED_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated") -nos_generate_flatbuffers("${CMAKE_CURRENT_SOURCE_DIR}/Config" "${GENERATED_OUTPUT_DIR}" "cpp" "${NOS_SDK_DIR}/types;${NOS_VULKAN_PATH}" nosGraphics_generated) +nos_generate_flatbuffers("${CMAKE_CURRENT_SOURCE_DIR}/Config" "${GENERATED_OUTPUT_DIR}" "cpp" "${NOS_SDK_DIR}/Types;${NOS_VULKAN_PATH}" nosGraphics_generated) list(APPEND MODULE_DEPENDENCIES_TARGETS nosGraphics_generated) set(INCLUDE_FOLDERS "${GENERATED_OUTPUT_DIR}") From 261f55448a05842a916dd52f393e7d416153cfac Mon Sep 17 00:00:00 2001 From: Caner Date: Mon, 22 Dec 2025 11:56:36 +0300 Subject: [PATCH 9/9] Renames --- Plugins/nosGraphics/Source/GraphicsMain.cpp | 6 ++++-- Plugins/nosGraphics/Source/TrackToView.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/nosGraphics/Source/GraphicsMain.cpp b/Plugins/nosGraphics/Source/GraphicsMain.cpp index 04e4064b..967a24ef 100644 --- a/Plugins/nosGraphics/Source/GraphicsMain.cpp +++ b/Plugins/nosGraphics/Source/GraphicsMain.cpp @@ -42,11 +42,13 @@ struct PluginFunctions : nos::PluginFunctions auto node = outFunctions[i]; switch ((Nodes)i) { - default: break; GEN_CASE_NODE(TrackToView) GEN_CASE_NODE(BillboardMask) + GEN_CASE_NODE(TrackToView) + GEN_CASE_NODE(BillboardMask) + default: break; } } return NOS_RESULT_SUCCESS; } }; NOS_EXPORT_PLUGIN_FUNCTIONS(PluginFunctions) -} // namespace NOS_NAMESPACE \ No newline at end of file +} // namespace nos::graphics \ No newline at end of file diff --git a/Plugins/nosGraphics/Source/TrackToView.cpp b/Plugins/nosGraphics/Source/TrackToView.cpp index 26b7d359..2c6653b3 100644 --- a/Plugins/nosGraphics/Source/TrackToView.cpp +++ b/Plugins/nosGraphics/Source/TrackToView.cpp @@ -64,7 +64,7 @@ struct TrackToView : NodeContext perspectiveProjection.fov_x = track.fov; TProjection projection{}; projection.clip_planes = clip; - projection.center_shift = reinterpret_cast(projShift); + projection.center_shift = reinterpret_cast(centerShift); projection.projection_type = ProjectionType::Perspective; projection.perspective = std::make_unique(perspectiveProjection); glm::mat4 viewMatrix = MakeView(