67 #ifndef _graphicsproceduralcrackmodifier_cpp
68 #define _graphicsproceduralcrackmodifier_cpp
70 #include "Graphics/Procedural/Texture/crackmodifier.h"
72 #include "MathTools/mathtools.h"
81 CrackColour(1.0,1.0,1.0,1.0),
103 MathTools::MersenneTwisterGenerator32 NumGen(this->
GeneratorSeed);
110 if( NormalsWidth < TargetWidth || NormalsHeight < TargetHeight ) {
116 for(
Whole CurrCrack = 0 ; CurrCrack < this->
CrackCount ; ++CurrCrack )
118 Real X =
static_cast<Real>( NumGen.GenerateScaledReal() ) * static_cast<Real>( TargetWidth );
119 Real Y =
static_cast<Real>( NumGen.GenerateScaledReal() ) * static_cast<Real>( TargetHeight );
120 Real Angle = MathTools::GetTwoPi() *
static_cast<Real>( NumGen.GenerateScaledReal() );
127 NormalLength = ( NormalLength > 0 ) ? MathTools::Sqrt(NormalLength) : 0;
128 PixelCount = std::min<Whole>(
static_cast<Whole>( PixelCount * NormalLength * NormalLength / 8.0 ), static_cast<Whole>( this->
CrackLength ) );
130 PixelCount =
static_cast<Whole>( PixelCount * (
static_cast<Real>( NumGen.GenerateScaledReal() ) * 2.0 ) );
133 while( --PixelCount >= 0 )
135 Angle +=
static_cast<Real>( this->
CrackVariation ) / 256.0 * ( 2.0 * ( static_cast<Real>( NumGen.GenerateScaledReal() ) - 1.0 ) );
137 X = X + MathTools::Cos( Angle );
138 Y = Y + MathTools::Sin( Angle );
139 if( static_cast<Whole>(X) >= TargetWidth || static_cast<Whole>(Y) >= TargetHeight )
144 if( Normal.
X == 0.0 ) {
145 if( Normal.
Y > 0.0 ) {
146 Angle = MathTools::GetPi();
148 Angle = MathTools::GetTwoPi();
150 }
else if( Normal.
X < 0 ) {
151 Angle = MathTools::ATan( Normal.
Y / Normal.
X ) + 1.5 * MathTools::GetPi();
152 }
else if( Normal.
Y < 0 ) {
153 Angle = MathTools::ATan( Normal.
Y / Normal.
X ) + 2.5 * MathTools::GetPi();
155 Angle = MathTools::ATan( Normal.
Y / Normal.
X ) + MathTools::GetHalfPi();
158 NormalLength = ( NormalLength > 0 ) ? MathTools::Sqrt(NormalLength) : 0;
159 if( NormalLength < ( 255.0 - NormalsPixel.
AlphaChannel * 255.0 ) / 4.0 ) {
169 Real cy2, cy1, cx2, cx1;
172 cy2 = ( X - MathTools::Floor(X) ) * ( Y - MathTools::Floor(Y) );
173 cy1 = ( Y - MathTools::Floor(Y) ) * ( MathTools::Ceil(X) - X );
174 cx2 = ( X - MathTools::Floor(X) ) * ( MathTools::Ceil(Y) - Y );
175 cx1 = 1 - ( cx2 + cy1 + cy2 );
176 NextX = std::min( static_cast<Whole>(X) + 1, TargetWidth );
177 NextY = std::min( static_cast<Whole>(Y) + 1, TargetHeight );
179 x1 = Buffer.
GetPixel( static_cast<Whole>(X), static_cast<Whole>(Y) );
180 y1 = Buffer.
GetPixel( static_cast<Whole>(X), NextY );
181 x2 = Buffer.
GetPixel( NextX, static_cast<Whole>(Y) );
182 y2 = Buffer.
GetPixel( NextX, NextY );
194 TempBuffer.
SetPixel( static_cast<Whole>(X), static_cast<Whole>(Y), x1 );
195 TempBuffer.
SetPixel( static_cast<Whole>(X), NextY, y1 );
196 TempBuffer.
SetPixel( NextX, static_cast<Whole>(Y), x2 );
197 TempBuffer.
SetPixel( NextX, NextY, y2 );
202 TempBuffer.
SetPixel( static_cast<Whole>(X), static_cast<Whole>(Y), Buffer.
GetPixel( static_cast<Whole>(X), static_cast<Whole>(Y) ) + this->
CrackColour );
218 {
return "CrackModifier"; }
ColourChannelType & GetPixel(const Whole X, const Whole Y, const UInt16 Component)
Gets access to the pixel at the specified position in this buffer. the X or Y location go beyond the ...
UInt8 CrackVariation
Determines the amount of "stutter" to the cracks normal curve (or non-curve depending on the paramete...
virtual String GetName() const
Gets the name of this modifier.
CrackModifier & SetCrackLengthMode(const LengthMode Length)
Sets any additional configuration for the length of the cracks.
CrackModifier & SetColour(const ColourValue &Colour)
Sets the colour of the generated cracks.
virtual ~CrackModifier()
Class destructor.
Whole GetWidth() const
Get the pixel width of this texture.
QualityMode CrackQualityMode
The mode in which the colours at or near the crack are to be determined. See QualityMode enum for mor...
The modifier will generate the pixel length of a crack between the configured value and a value large...
uint8_t UInt8
An 8-bit unsigned integer.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
CrackModifier & SetCrackQualityMode(const QualityMode Quality)
Sets any additional configuration for the colour/sampling of the crack colour.
CrackModifier & SetCrackCount(const Whole Count)
Sets how many cracks to create.
CrackModifier & SetNormalsTexture(TextureBuffer *Normals)
Sets the normals texture to use for generating cracks.
CrackModifier & SetCrackVariation(const UInt8 Variation)
Sets the amount of wobble or stutter to the cracks that are created.
float Real
A Datatype used to represent a real floating point number.
Real GreenChannel
Value from 0.0 to 1.0 representing the amount of green present in the colour. 1.0 if very green...
Real Y
Coordinate on the Y vector.
Whole CrackCount
The number of cracks to generate.
Real X
Coordinate on the X vector.
This is used to represent a point on a 2 dimentional area, such as a screen.
UInt8 CrackLength
The pixel length of the cracks to be generated.
Real AlphaChannel
Value from 0.0 to 1.0 representing the transparency of the colours. 1.0 is opaque and 0...
TextureBuffer * NormalsTexture
The parameter image to pull normals the cracks are to move along from. Alpha channel and colours may ...
Real SquaredLength() const
Gets the length of this vector squared.
Whole GeneratorSeed
The seed for the random number generator used to place the cracks.
void SetValues(const Real Red, const Real Green, const Real Blue, const Real Alpha)
Sets each of the colour channels.
CrackModifier & SetCrackLength(const UInt8 Length)
Sets the length of each crack that is created. May not be used verbatim.
The modifier will randomize the pixel length of the cracks between zero and double the configured len...
LengthMode
An enum used to set how the length of each generated crack is to be determined.
virtual void Modify(TextureBuffer &Buffer)
Alters the generated pixels in a TextureBuffer.
CrackModifier()
Blank constructor.
A convenience buffer that stores pixel colour values of a texture to be generated.
Attempts to blend the colours of all surrounding pixels for a more smooth appearance.
The bulk of the engine components go in this namspace.
LengthMode CrackLengthMode
The mode in which the final length of each crack is determined. See LengthMode enum for more details...
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Combines the colours from the image being modified and the configured crack colour.
Whole GetHeight() const
Get the pixel height of this texture.
void SetPixel(const Whole X, const Whole Y, const ColourValue &Colour)
Set colour of a specified pixel using a ColourValue. the X or Y location go beyond the set size of th...
A modifier that will generate random coloured lines on a texture.
Real RedChannel
Value from 0.0 to 1.0 representing the amount of red present in the colour. 1.0 if very red...
ColourValue CrackColour
The base colour to give to the pixels forming the cracks.
CrackModifier & SetGeneratorSeed(const Whole Seed)
Sets the seed for the random number generator used to determine crack starting positions.
std::string String
A datatype used to a series of characters.
void SetData(const TextureBuffer &Other)
Copies image data from another buffer into this buffer.
QualityMode
An enum used to set the quality.