created buffer shader and added shader logic to rectangle
This commit is contained in:
+18
-7
@@ -35,11 +35,12 @@ namespace UwU {
|
||||
}
|
||||
|
||||
// BUFFER shader
|
||||
// Shader(uint16_t u, uint16_t v, Buffer buffer) {
|
||||
// this->shaderType = BUFFER;
|
||||
// this->u0 = u;
|
||||
// this->v0 = v;
|
||||
// }
|
||||
Shader(uint16_t u, uint16_t v, Buffer buffer) {
|
||||
this->shaderType = BUFFER;
|
||||
this->u0 = u;
|
||||
this->v0 = v;
|
||||
this->buffer = buffer;
|
||||
}
|
||||
|
||||
ShaderType shaderType;
|
||||
uint16_t u0;
|
||||
@@ -47,13 +48,23 @@ namespace UwU {
|
||||
Color c0;
|
||||
Color c1;
|
||||
uint32_t scale;
|
||||
Buffer buffer;
|
||||
};
|
||||
|
||||
class ShaderMethods {
|
||||
public:
|
||||
static Color gradient(uint16_t uv0, uint32_t scale, Color c0, Color c1, uint16_t uv) {
|
||||
uint32_t t = (((uint32_t)uv - (uint32_t)uv0) * scale) / 0x01000000;
|
||||
static Color gradient(uint16_t uv0, uint32_t scale, Color c0, Color c1, uint16_t xy) {
|
||||
uint32_t t = (((uint32_t)xy - (uint32_t)uv0) * scale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
|
||||
static Color buffer(uint16_t u0, uint16_t v0, Buffer buffer, uint16_t x, uint16_t y) {
|
||||
size_t i = ((size_t)y - (size_t)v0) * buffer.stride + ((size_t)x - (size_t)u0) * 4;
|
||||
uint8_t b = buffer.pixels[i + 0];
|
||||
uint8_t g = buffer.pixels[i + 1];
|
||||
uint8_t r = buffer.pixels[i + 2];
|
||||
uint8_t a = buffer.pixels[i + 3];
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user