|
| 1 | + |
| 2 | +#include "UnrealFastNoisePlugin.h" |
| 3 | +#include "UFNNoiseGenerator.h" |
| 4 | +#include "UFNRadialModule.h" |
| 5 | + |
| 6 | +UUFNRadialModule::UUFNRadialModule(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) |
| 7 | +{ |
| 8 | + |
| 9 | +} |
| 10 | + |
| 11 | +float UUFNRadialModule::GetNoise3D(float aX, float aY, float aZ) |
| 12 | +{ |
| 13 | + if (!(inputModule1 && inputModule2)) { |
| 14 | + return 0.0f; |
| 15 | + } |
| 16 | + |
| 17 | + float dist = (origin - FVector(aX, aY, aZ)).Size(); |
| 18 | + |
| 19 | + if (interpType != ESelectInterpType::None) |
| 20 | + { |
| 21 | + // outside falloff |
| 22 | + if (dist > radius + falloff) { |
| 23 | + return inputModule2->GetNoise3D(aX, aY, aZ); |
| 24 | + } |
| 25 | + // inside radius |
| 26 | + else if (dist < radius) { |
| 27 | + return inputModule1->GetNoise3D(aX, aY, aZ); |
| 28 | + } |
| 29 | + // otherwise in the falloff range, so smooth |
| 30 | + else { |
| 31 | + |
| 32 | + switch (interpType) |
| 33 | + { |
| 34 | + case ESelectInterpType::CircularIn: |
| 35 | + return FMath::InterpCircularIn(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 36 | + case ESelectInterpType::CircularInOut: |
| 37 | + return FMath::InterpCircularInOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 38 | + case ESelectInterpType::CircularOut: |
| 39 | + return FMath::InterpCircularOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 40 | + case ESelectInterpType::ExponentialIn: |
| 41 | + return FMath::InterpExpoIn(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 42 | + case ESelectInterpType::ExponentialInOut: |
| 43 | + return FMath::InterpExpoInOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 44 | + case ESelectInterpType::ExponentialOut: |
| 45 | + return FMath::InterpExpoOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 46 | + case ESelectInterpType::SineIn: |
| 47 | + return FMath::InterpSinIn(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 48 | + case ESelectInterpType::SineInOut: |
| 49 | + return FMath::InterpSinInOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 50 | + case ESelectInterpType::SineOut: |
| 51 | + return FMath::InterpSinInOut(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 52 | + case ESelectInterpType::Step: |
| 53 | + return FMath::InterpStep(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff, numSteps); |
| 54 | + case ESelectInterpType::Linear: |
| 55 | + return FMath::Lerp(inputModule1->GetNoise3D(aX, aY, aZ), inputModule2->GetNoise3D(aX, aY, aZ), (dist - radius) / falloff); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + // If there's no interpolation, easy mode |
| 61 | + if (dist > radius) { |
| 62 | + return inputModule1->GetNoise3D(aX, aY, aZ); |
| 63 | + } |
| 64 | + else { |
| 65 | + return inputModule2->GetNoise3D(aX, aY, aZ); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | +} |
| 70 | + |
| 71 | +float UUFNRadialModule::GetNoise2D(float aX, float aY) |
| 72 | +{ |
| 73 | + if (!(inputModule1 && inputModule2)) { |
| 74 | + return 0.0f; |
| 75 | + } |
| 76 | + |
| 77 | + float dist = (FVector2D(aX, aY) - FVector2D(origin.X, origin.Y)).Size(); |
| 78 | + |
| 79 | + if (interpType != ESelectInterpType::None) |
| 80 | + { |
| 81 | + // outside falloff |
| 82 | + if (dist > radius + falloff) { |
| 83 | + return inputModule2->GetNoise2D(aX, aY); |
| 84 | + } |
| 85 | + // inside radius |
| 86 | + else if (dist < radius) { |
| 87 | + return inputModule1->GetNoise2D(aX, aY); |
| 88 | + } |
| 89 | + // otherwise in the falloff range, so smooth |
| 90 | + else { |
| 91 | + |
| 92 | + switch (interpType) |
| 93 | + { |
| 94 | + case ESelectInterpType::CircularIn: |
| 95 | + return FMath::InterpCircularIn(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 96 | + case ESelectInterpType::CircularInOut: |
| 97 | + return FMath::InterpCircularInOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 98 | + case ESelectInterpType::CircularOut: |
| 99 | + return FMath::InterpCircularOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 100 | + case ESelectInterpType::ExponentialIn: |
| 101 | + return FMath::InterpExpoIn(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 102 | + case ESelectInterpType::ExponentialInOut: |
| 103 | + return FMath::InterpExpoInOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 104 | + case ESelectInterpType::ExponentialOut: |
| 105 | + return FMath::InterpExpoOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 106 | + case ESelectInterpType::SineIn: |
| 107 | + return FMath::InterpSinIn(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 108 | + case ESelectInterpType::SineInOut: |
| 109 | + return FMath::InterpSinInOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 110 | + case ESelectInterpType::SineOut: |
| 111 | + return FMath::InterpSinInOut(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 112 | + case ESelectInterpType::Step: |
| 113 | + return FMath::InterpStep(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff, numSteps); |
| 114 | + case ESelectInterpType::Linear: |
| 115 | + return FMath::Lerp(inputModule1->GetNoise2D(aX, aY), inputModule2->GetNoise2D(aX, aY), (dist - radius) / falloff); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + // If there's no interpolation, easy mode |
| 121 | + if (dist > radius) { |
| 122 | + return inputModule1->GetNoise2D(aX, aY); |
| 123 | + } |
| 124 | + else { |
| 125 | + return inputModule2->GetNoise2D(aX, aY); |
| 126 | + } |
| 127 | + |
| 128 | +} |
| 129 | + |
0 commit comments