Files
VoxelForge/Standalone/Compat/UnrealPerlin.cpp
Fr0zkaandClaude Opus 5.5 05f62cff36 standalone: the owner's world outside Unreal -- bit-identical density, D3D11 fly-through viewer
Standalone/ (C++20, MSVC /O2 /arch:AVX2 /fp:precise, Build.ps1): copied density pipeline, op stack,
cave morphology, passages, strate manager/composer, noise, DetSinCos, mesher, clipmap selection,
with a UE compatibility layer (Compat/). Owner data exported once to Standalone/data/owner_world.json
by a default-off explore-commandlet exporter (the only plugin-source change). 25 cm voxels.
Parity: seed 0, 3,436 samples (strate edges, negative/far coords, rooms, tunnels, passages,
landings): bit-identical. Viewer: full 7-level clipmap, per-level toggles 1-7, T = round winding
tunnels (standalone option), N/P seed, F wireframe.
Timing NOT yet a baseline: 515 s for 12,054 tiles (L0 70 s, L6 296 s); the compat TMap/TSet are
vector-backed with linear lookup, which the plugin's caches do not expect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MmSoF64BbRFmk9C3p1VsBJ
2026-10-02 12:14:04 +02:00

65 lines
2.5 KiB
C++

#include "CoreMinimal.h"
#include "UnrealPerlinHelpers.inl"
float FMath::PerlinNoise2D(const FVector2D& Location)
{
using namespace FMathPerlinHelpers;
const float Xfl = FMath::FloorToFloat(static_cast<float>(Location.X));
const float Yfl = FMath::FloorToFloat(static_cast<float>(Location.Y));
const int32 Xi = static_cast<int32>(Xfl) & 255;
const int32 Yi = static_cast<int32>(Yfl) & 255;
const float X = static_cast<float>(Location.X) - Xfl;
const float Y = static_cast<float>(Location.Y) - Yfl;
const float Xm1 = X - 1.0f;
const float Ym1 = Y - 1.0f;
const int32* P = Permutation;
const int32 AA = P[Xi] + Yi;
const int32 AB = AA + 1;
const int32 BA = P[Xi + 1] + Yi;
const int32 BB = BA + 1;
const float U = SmoothCurve(X);
const float V = SmoothCurve(Y);
return FMath::Lerp(
FMath::Lerp(Grad2(P[AA], X, Y), Grad2(P[BA], Xm1, Y), U),
FMath::Lerp(Grad2(P[AB], X, Ym1), Grad2(P[BB], Xm1, Ym1), U),
V);
}
float FMath::PerlinNoise3D(const FVector& Location)
{
using namespace FMathPerlinHelpers;
const float Xfl = FMath::FloorToFloat(static_cast<float>(Location.X));
const float Yfl = FMath::FloorToFloat(static_cast<float>(Location.Y));
const float Zfl = FMath::FloorToFloat(static_cast<float>(Location.Z));
const int32 Xi = static_cast<int32>(Xfl) & 255;
const int32 Yi = static_cast<int32>(Yfl) & 255;
const int32 Zi = static_cast<int32>(Zfl) & 255;
const float X = static_cast<float>(Location.X) - Xfl;
const float Y = static_cast<float>(Location.Y) - Yfl;
const float Z = static_cast<float>(Location.Z) - Zfl;
const float Xm1 = X - 1.0f;
const float Ym1 = Y - 1.0f;
const float Zm1 = Z - 1.0f;
const int32* P = Permutation;
const int32 A = P[Xi] + Yi;
const int32 AA = P[A] + Zi;
const int32 AB = P[A + 1] + Zi;
const int32 B = P[Xi + 1] + Yi;
const int32 BA = P[B] + Zi;
const int32 BB = P[B + 1] + Zi;
const float U = SmoothCurve(X);
const float V = SmoothCurve(Y);
const float W = SmoothCurve(Z);
const float Value = 0.97f * FMath::Lerp(
FMath::Lerp(
FMath::Lerp(Grad3(P[AA], X, Y, Z), Grad3(P[BA], Xm1, Y, Z), U),
FMath::Lerp(Grad3(P[AB], X, Ym1, Z), Grad3(P[BB], Xm1, Ym1, Z), U),
V),
FMath::Lerp(
FMath::Lerp(Grad3(P[AA + 1], X, Y, Zm1), Grad3(P[BA + 1], Xm1, Y, Zm1), U),
FMath::Lerp(Grad3(P[AB + 1], X, Ym1, Zm1), Grad3(P[BB + 1], Xm1, Ym1, Zm1), U),
V),
W);
return FMath::Clamp(Value, -1.0f, 1.0f);
}