Skip to content

Commit b257f68

Browse files
committed
DomainRotatePlane Node
1 parent 6efed6e commit b257f68

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

include/FastNoise/Generators/Modifiers.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,5 +495,46 @@ namespace FastNoise
495495
}
496496
};
497497
#endif
498+
499+
enum class PlaneRotationType
500+
{
501+
ImproveXYPlanes,
502+
ImproveXZPlanes
503+
};
504+
505+
class DomainRotatePlane : public virtual Generator
506+
{
507+
public:
508+
const Metadata& GetMetadata() const override;
509+
510+
void SetSource( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mSource, gen ); }
511+
void SetRotationType( PlaneRotationType type ) { mRotationType = type; }
512+
513+
protected:
514+
GeneratorSource mSource;
515+
PlaneRotationType mRotationType = PlaneRotationType::ImproveXYPlanes;
516+
};
517+
518+
#ifdef FASTNOISE_METADATA
519+
template<>
520+
struct MetadataT<DomainRotatePlane> : MetadataT<Generator>
521+
{
522+
SmartNode<> CreateNode( FastSIMD::FeatureSet ) const override;
523+
524+
MetadataT()
525+
{
526+
groups.push_back( "Domain Modifiers" );
527+
this->AddGeneratorSource( "Source", &DomainRotatePlane::SetSource );
528+
529+
this->AddVariableEnum( "Rotation Type", PlaneRotationType::ImproveXYPlanes, &DomainRotatePlane::SetRotationType, "Improve XY Planes", "Improve XZ Planes" );
530+
531+
description =
532+
"Applies preset rotation to improve noise in specific 3D planes. Faster than DomainRotate.\n"
533+
"This helps reduce axis aligned artifacts in 3D noise for the specified plane.\n"
534+
"For 2D input coordinates a 3rd dimension is added and the noise is optimized for the XY plane\n"
535+
"For 4D input coordinates only the first 3 dimensions are rotated, the 4th dimension is passed through unchanged";
536+
}
537+
};
538+
#endif
498539

499540
}

include/FastNoise/Generators/Modifiers.inl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,63 @@ class FastSIMD::DispatchClass<FastNoise::Abs, SIMD> final : public virtual FastN
299299
return FS::Abs( value );
300300
}
301301
};
302+
303+
template<FastSIMD::FeatureSet SIMD>
304+
class FastSIMD::DispatchClass<FastNoise::DomainRotatePlane, SIMD> final : public virtual FastNoise::DomainRotatePlane, public FastSIMD::DispatchClass<FastNoise::Generator, SIMD>
305+
{
306+
FS_FORCEINLINE void FS_VECTORCALL RotateCoords( PlaneRotationType rotationType, float32v& x, float32v& y, float32v& z ) const
307+
{
308+
float32v newX = x;
309+
float32v newY = y;
310+
float32v newZ = z;
311+
312+
switch( rotationType )
313+
{
314+
case PlaneRotationType::ImproveXYPlanes:
315+
{
316+
float32v xy = x + y;
317+
float32v s2 = xy * float32v( -0.211324865405187f );
318+
newZ = z * float32v( 0.577350269189626f );
319+
newX = x + s2 - newZ;
320+
newY = y + s2 - newZ;
321+
newZ = newZ + xy * float32v( 0.577350269189626f );
322+
}
323+
break;
324+
325+
case PlaneRotationType::ImproveXZPlanes:
326+
{
327+
float32v xz = x + z;
328+
float32v s2 = xz * float32v( -0.211324865405187f );
329+
newY = y * float32v( 0.577350269189626f );
330+
newX = x + s2 - newY;
331+
newZ = z + s2 - newY;
332+
newY = newY + xz * float32v( 0.577350269189626f );
333+
334+
}
335+
break;
336+
}
337+
x = newX;
338+
y = newY;
339+
z = newZ;
340+
}
341+
342+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y ) const
343+
{
344+
float32v z = 0;
345+
RotateCoords( PlaneRotationType::ImproveXYPlanes, x, y, z );
346+
347+
return this->GetSourceValue( mSource, seed, x, y, z );
348+
}
349+
350+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z ) const
351+
{
352+
RotateCoords( mRotationType, x, y, z );
353+
return this->GetSourceValue( mSource, seed, x, y, z );
354+
}
355+
356+
float32v FS_VECTORCALL Gen( int32v seed, float32v x, float32v y, float32v z, float32v w ) const
357+
{
358+
RotateCoords( mRotationType, x, y, z );
359+
return this->GetSourceValue( mSource, seed, x, y, z, w );
360+
}
361+
};

src/FastNoise/FastSIMD_Build.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ FASTNOISE_REGISTER_NODE( AddDimension );
140140
FASTNOISE_REGISTER_NODE( RemoveDimension );
141141

142142
FASTNOISE_REGISTER_NODE( Modulus );
143+
FASTNOISE_REGISTER_NODE( DomainRotatePlane );

src/FastNoise/Metadata.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ constexpr static std::nullptr_t gMetadataVectorSize = nullptr; // Invalid
2121
// Setting these values avoids needless vector resizing and oversizing on startup
2222
// Sadly there is no way to automate this as they fill up as part of static init
2323
template<>
24-
constexpr size_t gMetadataVectorSize<const Metadata*> = 45;
24+
constexpr size_t gMetadataVectorSize<const Metadata*> = 47;
2525
template<>
26-
constexpr size_t gMetadataVectorSize<const char*> = 87;
26+
constexpr size_t gMetadataVectorSize<const char*> = 91;
2727
template<>
28-
constexpr size_t gMetadataVectorSize<Metadata::MemberVariable> = 70;
28+
constexpr size_t gMetadataVectorSize<Metadata::MemberVariable> = 72;
2929
template<>
30-
constexpr size_t gMetadataVectorSize<Metadata::MemberNodeLookup> = 30;
30+
constexpr size_t gMetadataVectorSize<Metadata::MemberNodeLookup> = 32;
3131
template<>
32-
constexpr size_t gMetadataVectorSize<Metadata::MemberHybrid> = 56;
32+
constexpr size_t gMetadataVectorSize<Metadata::MemberHybrid> = 57;
3333

3434
template<typename T>
3535
static std::vector<T>& GetVectorStorage()

0 commit comments

Comments
 (0)