Files
UwUGL/shaders/hgradientshader.cpp
T

30 lines
729 B
C++

#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
#include "shaderbase.cpp"
namespace UwU {
class HGradientShader : public ShaderBase<HGradientShader> {
public:
HGradientShader(uint16_t u0, uint16_t u1, Color c0, Color c1) {
this->u0 = (uint32_t)u0;
this->uScale = 0xffffffff / (1 + (uint32_t)u1 - (uint32_t)u0);
this->c0 = c0;
this->c1 = c1;
}
uint32_t u0;
uint32_t uScale;
Color c0;
Color c1;
Color shade(uint16_t u, uint16_t v) {
(void)v;
uint32_t t = (((uint32_t)u - u0) * uScale) / 0x01000000;
return Helpers::lerpColor(c0, c1, (uint8_t)t);
}
};
}