Added color gradient for the terrain blend maps
Added terrainBuffer struct Added shared methods to genereate random UV's and intensities Added water to the terrain Added random UV's to the shader Removed the vector3d class since DX can deal with that stuff...
This commit is contained in:
56
Graphics2/ColorGradient.cpp
Normal file
56
Graphics2/ColorGradient.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "ColorGradient.h"
|
||||
|
||||
ColorGradient::ColorGradient(float min, float max, vector<RGBA> colorSteps)
|
||||
{
|
||||
_minValue = min;
|
||||
_maxValue = max;
|
||||
_colorSteps = colorSteps;
|
||||
}
|
||||
|
||||
ColorGradient::~ColorGradient()
|
||||
{
|
||||
_colorSteps.clear();
|
||||
}
|
||||
|
||||
// Get the RGBA value at the give point
|
||||
RGBA ColorGradient::GetRGBAValue(float inputValue)
|
||||
{
|
||||
if (inputValue <= _minValue)
|
||||
{
|
||||
return _colorSteps.front();
|
||||
}
|
||||
else if (inputValue >= _maxValue)
|
||||
{
|
||||
return _colorSteps.back();
|
||||
}
|
||||
|
||||
float range = _maxValue - _minValue;
|
||||
float value = inputValue - _minValue;
|
||||
float steps = range / (float)(_colorSteps.size() - 1);
|
||||
|
||||
int colorStepInside = (int)(value / steps);
|
||||
|
||||
float normalisedValue = (value - (colorStepInside * steps)) / steps;
|
||||
|
||||
return Interpolate(_colorSteps[colorStepInside], _colorSteps[colorStepInside + 1], normalisedValue);
|
||||
}
|
||||
|
||||
// Method for interpolating the color between each step
|
||||
RGBA ColorGradient::Interpolate(RGBA a, RGBA b, float pointValue)
|
||||
{
|
||||
if (pointValue <= 0.0f)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else if (pointValue >= 1.0f)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
unsigned int currentRed = (unsigned int)((1.0f - pointValue) * a.red + pointValue * b.red);
|
||||
unsigned int currentGreen = (unsigned int)((1.0f - pointValue) * a.green + pointValue * b.green);
|
||||
unsigned int currentBlue = (unsigned int)((1.0f - pointValue) * a.blue + pointValue * b.blue);
|
||||
unsigned int currentAlpha = (unsigned int)((1.0f - pointValue) * a.alpha + pointValue * b.alpha);
|
||||
|
||||
return RGBA{ currentRed, currentGreen, currentBlue, currentAlpha };
|
||||
}
|
Reference in New Issue
Block a user