implemented CRTP shader on ColorShader and Rectangle
This commit is contained in:
@@ -16,6 +16,8 @@ namespace UwU {
|
||||
Color c;
|
||||
|
||||
Color shade(uint16_t x, uint16_t y) {
|
||||
(void)x;
|
||||
(void)y;
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "shaderbase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class HGradienthader : public ShaderBase<HGradientShader> {
|
||||
public:
|
||||
HGradientShader(uint16_t u0, uint16_t u1, Color c0, Color c1) {
|
||||
this->u0;
|
||||
this->uScale = 0xffffffff / (1 + (uint32_t)u1 - (uint32_t)u0);
|
||||
this->c0 = c0;
|
||||
this->c1 = c1;
|
||||
}
|
||||
uint16_t u0;
|
||||
uint16_t uScale;
|
||||
Color c0;
|
||||
Color c1;
|
||||
|
||||
Color shade(uint16_t u, uint16_t u) {
|
||||
uint32_t t = (((uint32_t)u - (uint32_t)u0) * uScale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -7,11 +7,11 @@
|
||||
#include "../buffer.cpp"
|
||||
|
||||
namespace UwU {
|
||||
template <typename Derived>
|
||||
template <class ShaderT>
|
||||
class ShaderBase {
|
||||
public:
|
||||
Color shade(uint16_t x, uint16_t y) {
|
||||
return static_cast<Derived*>(this)->shade(x, y);
|
||||
return static_cast<ShaderT*>(this)->shade(x, y);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "shaderbase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class VGradienthader : public ShaderBase<VGradientShader> {
|
||||
public:
|
||||
VGradientShader(uint16_t v0, uint16_t v1, Color c0, Color c1) {
|
||||
this->v0;
|
||||
this->vScale = 0xffffffff / (1 + (uint32_t)v1 - (uint32_t)v0);
|
||||
this->c0 = c0;
|
||||
this->c1 = c1;
|
||||
}
|
||||
uint16_t v0;
|
||||
uint16_t vScale;
|
||||
Color c0;
|
||||
Color c1;
|
||||
|
||||
Color shade(uint16_t u, uint16_t u) {
|
||||
uint32_t t = (((uint32_t)v - (uint32_t)v0) * vScale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user