From cf77eb8544975f501c62f627a01d08addf24d243 Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 20 Feb 2026 18:50:13 -0500 Subject: [PATCH] Created MaskedRainbow material in unreal --- .claude/settings.local.json | 5 +- .../Materials/M_MaskedRainbow.uasset | 3 ++ Content/StaticMeshes/SM_RainbowCube.uasset | 3 ++ Shaders/RainbowColors.ush | 50 +++++++++++++++++++ Source/Integration/Integration.Build.cs | 5 +- Source/Integration/Integration.cpp | 6 +++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 Content/StarterContent/Materials/M_MaskedRainbow.uasset create mode 100644 Content/StaticMeshes/SM_RainbowCube.uasset create mode 100644 Shaders/RainbowColors.ush diff --git a/.claude/settings.local.json b/.claude/settings.local.json index cdcd3d8f..1dbecc56 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -8,7 +8,10 @@ "Bash(clangd:*)", "Bash(clangd-16:*)", "Bash(ssh jyelon-office \"clangd --version 2>/dev/null || clangd-16 --version 2>/dev/null || clangd-18 --version 2>/dev/null || ls /usr/bin/clangd*\")", - "Bash(git check-ignore:*)" + "Bash(git check-ignore:*)", + "Bash(ls:*)", + "WebFetch(domain:ikrima.dev)", + "WebFetch(domain:indxzero.github.io)" ], "deny": [ "Bash(git commit *)", diff --git a/Content/StarterContent/Materials/M_MaskedRainbow.uasset b/Content/StarterContent/Materials/M_MaskedRainbow.uasset new file mode 100644 index 00000000..4f500b92 --- /dev/null +++ b/Content/StarterContent/Materials/M_MaskedRainbow.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7d86fb186b74a617e95132901bc0b85f3a50e782fa42711348a73fd818ac711 +size 15203 diff --git a/Content/StaticMeshes/SM_RainbowCube.uasset b/Content/StaticMeshes/SM_RainbowCube.uasset new file mode 100644 index 00000000..f022fb63 --- /dev/null +++ b/Content/StaticMeshes/SM_RainbowCube.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abe17a13dd1066bc8c1a55c348dabc19ae83016a9058eff441961b2e3b454e6d +size 19989 diff --git a/Shaders/RainbowColors.ush b/Shaders/RainbowColors.ush new file mode 100644 index 00000000..6f6e85ab --- /dev/null +++ b/Shaders/RainbowColors.ush @@ -0,0 +1,50 @@ +#pragma once + +static const int RainbowColorsSize = 16; +static const float3 RainbowColors[RainbowColorsSize] = { + float3(1.00, 0.05, 0.05), // 0 red + float3(0.45, 0.00, 0.00), // 1 dark red + float3(1.00, 0.20, 0.00), // 2 orange + float3(0.20, 0.05, 0.01), // 3 dark orange (brown) + float3(1.00, 1.00, 0.00), // 4 yellow + float3(0.35, 0.45, 0.00), // 5 olive + float3(0.00, 1.00, 0.00), // 6 green + float3(0.00, 0.30, 0.00), // 7 dark green + float3(0.00, 1.00, 1.00), // 10 cyan + float3(0.00, 0.40, 0.40), // 11 dark cyan + float3(0.00, 0.00, 1.00), // 8 blue + float3(0.00, 0.00, 0.25), // 9 dark blue + float3(0.25, 0.00, 1.00), // 12 purple + float3(0.10, 0.00, 0.25), // 13 dark purple + float3(1.00, 0.05, 1.00), // 14 pink + float3(0.45, 0.00, 0.25) // 15 dark pink +}; + +// Given a color index, find the associated color. +// If NColors is 8 or less, skips the "dark" colors. +// If NColors is 4 or less, skips 3 out of 4 colors. +// +float3 RainbowColorLookup(int coloridx, int ncolors) +{ + if (ncolors <= 8) coloridx *= 2; + if (ncolors <= 4) coloridx *= 2; + + float3 color = float3(1,1,1); + if (coloridx < RainbowColorsSize) color = RainbowColors[coloridx]; + return color; +} + +// Create a striped rainbow pattern. The pattern has ncolors +// color bands, separated by thin white lines. Using the mask, +// which is a bitmask, you can turn any band to black. +// +float3 MaskedRainbowPattern(float texcoord, int ncolors, int mask) +{ + float bandPos = texcoord * ncolors; + int coloridx = (int)floor(fmod(bandPos, ncolors)); + float3 color = RainbowColorLookup(coloridx, ncolors); + if (mask & (1 << coloridx)) color = float3(0, 0, 0); + float edge = frac(bandPos); + if ((edge <= 0.1) || (edge >= 0.9)) color = float3(1, 1, 1); + return color; +} diff --git a/Source/Integration/Integration.Build.cs b/Source/Integration/Integration.Build.cs index 41a28f7e..9ddb568e 100644 --- a/Source/Integration/Integration.Build.cs +++ b/Source/Integration/Integration.Build.cs @@ -8,7 +8,7 @@ public class Integration : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", @@ -18,7 +18,8 @@ public class Integration : ModuleRules "Networking", "EnhancedInput", "UMG", - "CommonUI" + "CommonUI", + "RenderCore" }); PrivateDependencyModuleNames.AddRange(new string[] { diff --git a/Source/Integration/Integration.cpp b/Source/Integration/Integration.cpp index e5df9503..44d9d40e 100644 --- a/Source/Integration/Integration.cpp +++ b/Source/Integration/Integration.cpp @@ -3,6 +3,9 @@ #include "Integration.h" #include "Common.h" #include "Modules/ModuleManager.h" +#include "Interfaces/IPluginManager.h" +#include "Misc/Paths.h" +#include "ShaderCore.h" #if WITH_EDITOR #include "Engine/Blueprint.h" @@ -17,6 +20,9 @@ IMPLEMENT_PRIMARY_GAME_MODULE(FlxIntegrationModuleImpl, Integration, "Integratio void FlxIntegrationModuleImpl::StartupModule() { + FString ShaderDir = FPaths::Combine(FPaths::ProjectDir(), TEXT("Shaders")); + AddShaderSourceDirectoryMapping(TEXT("/Project/Integration"), ShaderDir); + #if WITH_EDITOR OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddRaw( this, &FlxIntegrationModuleImpl::OnAssetSaved);