Skip to content

Commit

Permalink
- Updated NoiseTexture init extension:
Browse files Browse the repository at this point in the history
  . Rename texture prefix to include a separator -> noise:NoiseTemplate
  . Added Origin property to offset the texture generation (useful for tiling across multiple textures)
  • Loading branch information
iarwain committed Feb 20, 2025
1 parent 937992c commit f949482
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions code/build/template/data/config/ExtensionTemplate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ Mod = path/to/music.mod; NB: Supports: MOD (Protracker), XM
[+noisetex

[GraphicTemplate]
Texture = noise NoiseTemplate; NB: The section defining the noise parameters must exist, even if no parameters are to be defined;
Texture = noise:NoiseTemplate; NB: The section defining the noise parameters must exist, even if no parameters are to be defined;

[NoiseTemplate]
; For parameters reference, check: https://auburn.github.io/FastNoiseLite/
Size = [Vector]; NB: Defaults to (512, 512);
Origin = [Vector]; NB: Offset that can be used for tiling across multiple textures. Defaults to (0, 0);
Type = simplex2|simplex2s|cellular|perlin|cubic|value; NB: Defaults to simplex2;
Seed = [Int]; NB: Defaults to random value;
Frequency = [Float]; NB: Defaults to 0.01;
Type = simplex2|simplex2s|cellular|perlin|cubic|value; NB: Defaults to simplex2;
Fractal = fbm|ridged|pingpong|none; NB: Defaults to none;
Lacunarity = [Float]; NB: Only used when Fractal != none. NB: Defaults to 2.0;
Gain = [Float]; NB: Only used when Fractal != none. NB: Defaults to 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ void orxFASTCALL orxNoiseTexture_Exit();
//! Defines

#define orxNOISETEXTURE_KZ_RESOURCE_TAG "noisetex"
#define orxNOISETEXTURE_KZ_RESOURCE_PREFIX "noise "
#define orxNOISETEXTURE_KZ_RESOURCE_PREFIX "noise:"

#define orxNOISETEXTURE_KZ_CONFIG_SIZE "Size"
#define orxNOISETEXTURE_KZ_CONFIG_ORIGIN "Origin"
#define orxNOISETEXTURE_KZ_CONFIG_TYPE "Type"
#define orxNOISETEXTURE_KZ_CONFIG_SEED "Seed"
#define orxNOISETEXTURE_KZ_CONFIG_FREQUENCY "Frequency"
Expand Down Expand Up @@ -88,6 +89,7 @@ typedef struct NoiseTextureResource
orxS64 s64Size;
orxU32 u32Width;
orxU32 u32Height;
orxVECTOR vOrigin;
fnl_state stState;
orxS32 s32HeaderSize;
orxU8 au8Data[0];
Expand Down Expand Up @@ -162,16 +164,15 @@ static orxSTATUS orxFASTCALL orxNoiseTexture_EventHandler(const orxEVENT *_pstEv
return eResult;
}

[+bundle orxBOOL orxFASTCALL orxBundle_IsProcessing();
]
orxBOOL orxFASTCALL orxBundle_IsProcessing();

// Locate function, returns NULL if it can't handle the storage or if the resource can't be found in this storage
static const orxSTRING orxFASTCALL orxNoiseTexture_Locate(const orxSTRING _zGroup, const orxSTRING _zStorage, const orxSTRING _zName, orxBOOL _bRequireExistence)
{
const orxSTRING zResult = orxNULL;

[+bundle
if(orxBundle_IsProcessing()) {return zResult;}
]

// Is a texture?
if((orxString_Compare(_zStorage, orxRESOURCE_KZ_DEFAULT_STORAGE) == 0)
&& (orxString_Compare(_zGroup, orxTEXTURE_KZ_RESOURCE_GROUP) == 0))
Expand Down Expand Up @@ -253,6 +254,7 @@ static orxHANDLE orxFASTCALL orxNoiseTexture_Open(const orxSTRING _zLocation, or
pstResource->stState = fnlCreateState();
pstResource->s32HeaderSize = s32HeaderSize;
orxMemory_Copy(&(pstResource->au8Data), acHeader, s32HeaderSize);
orxConfig_GetVector(orxNOISETEXTURE_KZ_CONFIG_ORIGIN, &(pstResource->vOrigin));

// Gets seed
pstResource->stState.seed = (orxConfig_HasValue(orxNOISETEXTURE_KZ_CONFIG_SEED) != orxFALSE) ? orxConfig_GetU32(orxNOISETEXTURE_KZ_CONFIG_SEED) : orxMath_GetRandomU32(1, 0xFFFFFFFF);
Expand Down Expand Up @@ -567,7 +569,7 @@ static orxS64 orxFASTCALL orxNoiseTexture_Read(orxHANDLE _hResource, orxS64 _s64
// For all columns
for(i = 0; i < pstResource->u32Width; i++)
{
*(pu8Pixel++) = (orxU8)(255.0f * 0.5f * (1.0f + fnlGetNoise2D(&(pstResource->stState), (float)i, (float)j)));
*(pu8Pixel++) = (orxU8)(255.0f * 0.5f * (1.0f + fnlGetNoise2D(&(pstResource->stState), (float)i + pstResource->vOrigin.fX, (float)j + pstResource->vOrigin.fY)));
}
}

Expand Down

0 comments on commit f949482

Please sign in to comment.