13inline static int roundfloat(
const float &in) {
14 return in < 0 ? in - 0.5f : in + 0.5f;
17inline static int rounddouble(
const double &in) {
18 return in < 0 ? in - 0.5f : in + 0.5f;
26 std::vector<std::tuple<Vertex2 *, Mesh *>>
fragments;
43 clearedz[x] = -std::numeric_limits<float>::max();
66#define EXTRA_VERTEX_INFO vec3
68#define EXTRA_VERTEX_INFO vec3_T<vec3>
104 layout (location = 0) in vec3 aPos;
105 layout (location = 1) in vec2 texCoord;
109 gl_Position = vec4(aPos.xyz, 1.0);
117 uniform sampler2D tex;
120 FragColor = texture(tex,f_texCoord);
121 //FragColor = vec4(f_texCoord.x,f_texCoord.y,0,0);
122 // if(FragColor.xyz==vec3(0)){
123 // //FragColor =vec4(FragColor.w);
131 -1.0f, -1.0f, -0.0f, 0.f, 0.f,
132 1.0f, 1.0f, -0.0f, 1.f, 1.f,
133 -1.0f, 1.0f, -0.0f, 0.f, 1.f,
134 1.0f, -1.0f, -0.0f, 1.f, 0.f};
148 engine(
const uint32_t &x,
const uint32_t &y) {
151 glGenVertexArrays(1, &
vao);
152 glGenBuffers(1, &
vbo);
153 glGenBuffers(1, &
ibo);
155 glBindVertexArray(
vao);
157 glBindBuffer(GL_ARRAY_BUFFER,
vbo);
160 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
ibo);
161 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
indices),
indices, GL_STATIC_DRAW);
163 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 *
sizeof(
float), (
void *)0);
164 glEnableVertexAttribArray(0);
165 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 *
sizeof(
float), (
void *)(3 *
sizeof(
float)));
166 glEnableVertexAttribArray(1);
167 glBindVertexArray(0);
169 glBindBuffer(GL_ARRAY_BUFFER, 0);
172 GLcall(glActiveTexture(GL_TEXTURE0));
173 GLcall(glBindTexture(GL_TEXTURE_2D,
tex));
174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
177 GLcall(glBindTexture(GL_TEXTURE_2D, 0));
182 unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
184 glCompileShader(vertexShader);
188 glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
190 glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
191 std::cout <<
"ERROR::SHADER::VERTEX::COMPILATION_FAILED\n"
192 << infoLog << std::endl;
195 unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
197 glCompileShader(fragmentShader);
199 glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
201 glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
202 std::cout <<
"ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n"
203 << infoLog << std::endl;
206 shader = glCreateProgram();
207 glAttachShader(
shader, vertexShader);
208 glAttachShader(
shader, fragmentShader);
211 glGetProgramiv(
shader, GL_LINK_STATUS, &success);
213 glGetProgramInfoLog(
shader, 512, NULL, infoLog);
214 std::cout <<
"ERROR::SHADER::PROGRAM::LINKING_FAILED\n"
215 << infoLog << std::endl;
217 glDeleteShader(vertexShader);
218 glDeleteShader(fragmentShader);
221 auto location = glGetUniformLocation(
shader,
"tex");
223 std::cout <<
"Warning: uniform tex does not exist !" << std::endl;
224 glUniform1i(location, 0);
244 glClear(GL_COLOR_BUFFER_BIT);
254 draw_bresenham_adjusted(roundfloat(std::get<0>(tris)[0].v.position.x), roundfloat(std::get<0>(tris)[0].v.position.y), roundfloat(std::get<0>(tris)[1].v.position.x), roundfloat(std::get<0>(tris)[1].v.position.y),
color(255));
255 draw_bresenham_adjusted(roundfloat(std::get<0>(tris)[1].v.position.x), roundfloat(std::get<0>(tris)[1].v.position.y), roundfloat(std::get<0>(tris)[2].v.position.x), roundfloat(std::get<0>(tris)[2].v.position.y),
color(255));
256 draw_bresenham_adjusted(roundfloat(std::get<0>(tris)[2].v.position.x), roundfloat(std::get<0>(tris)[2].v.position.y), roundfloat(std::get<0>(tris)[0].v.position.x), roundfloat(std::get<0>(tris)[0].v.position.y),
color(255));
268 GLcall(glBindTexture(GL_TEXTURE_2D,
tex));
270 glBindVertexArray(
vao);
271 GLcall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
nullptr));
323 col =
color(*ret, *(ret + 1), *(ret + 2));
332 color result(0, 0, 0, 255);
341 float int_by_at = light.intensity / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
342 if (int_by_at > 0.01) {
373 for (
size_t i = 0; i <
indices.size() / 3; i++) {
383 assert(time >= 0.f && time < 24.f);
384 dirlight.
intensity = 0.7666921f * exp(-pow((time - 12.4125f) / (3.047894f), 2.f) / 2.f);
386 const uint8_t min = floor(time),
max = ceil(time);
391 alpha = (
max - time) / (
max - min);
396 const float t = M_PI * sin(M_PI * time / 24);
412 std::unordered_map<uint8_t, float>
413 greenTimeMap = {{0, 0}, {1, 0.1}, {2, 0.3}, {3, 0.3}, {4, 0.35}, {5, 0.4}, {6, 0.5}, {7, 0.55}, {8, 0.6}, {9, 1}, {10, 1}, {11, 1}, {12, 1}, {13, 1}, {14, 1}, {15, 1}, {16, 1}, {17, 0.8}, {18, 0.5}, {19, 0.4}, {20, 0.3}, {21, 0.25}, {22, 0.1}, {23, 0.06}, {24, 0}},
414 blueTimeMap = {{0, 0}, {1, 0}, {2, 0}, {3, 0.05}, {4, 0.06}, {5, 0.1}, {6, 0.15}, {7, 0.25}, {8, 0.35}, {9, 0.75}, {10, 0.8}, {11, 1}, {12, 1}, {13, 1}, {14, 1}, {15, 1}, {16, 0.8}, {17, 0.6}, {18, 0.4}, {19, 0.1}, {20, 0.01}, {21, 0}, {22, 0}, {23, 0}, {24, 0}};
416 static inline float max(
const float &first,
const float &second) {
417 return first > second ? first : second;
434 return std::move(diffuse);
442 const float diff =
max(
vec3::dot(normal, lightDir), 0.0);
449 return (diffuse + specular);
455 std::array<bool, 3> clip{
false,
false,
false};
456 std::array<Vertex2, 3> t;
459 std::array<EXTRA_VERTEX_INFO, 3> extraInfoAboutVertex{modelmat * points[0].position, modelmat * points[1].position, modelmat * points[2].position};
461 std::array<EXTRA_VERTEX_INFO, 3> extraInfoAboutVertex;
462 extraInfoAboutVertex[0].x = modelmat * points[0].position;
463 extraInfoAboutVertex[1].x = modelmat * points[1].position;
464 extraInfoAboutVertex[2].x = modelmat * points[2].position;
466 std::array<vec4, 3> modelviewTransformed{view * (modelmat * points[0].position), view * (modelmat * points[1].position), view * (modelmat * points[2].position)};
468 if (modelviewTransformed[0].z > -
nearPlane) {
472 if (modelviewTransformed[1].z > -
nearPlane) {
476 if (modelviewTransformed[2].z > -
nearPlane) {
480 points[0].position = modelviewTransformed[0];
481 points[0].normal = modelmat * points[0].normal;
482 points[1].position = modelviewTransformed[1];
483 points[1].normal = modelmat * points[1].normal;
484 points[2].position = modelviewTransformed[2];
485 points[2].normal = modelmat * points[2].normal;
487 vec4 centroid = (points[0].position + points[1].position + points[2].position) / 3;
494 fillExtraInformationForGoraudShading(points[0], extraInfoAboutVertex[0]);
495 fillExtraInformationForGoraudShading(points[1], extraInfoAboutVertex[1]);
496 fillExtraInformationForGoraudShading(points[2], extraInfoAboutVertex[2]);
499 if ((clip[0] && clip[1] && clip[2])) {
501 }
else if (clip[0]) {
503 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 0, 1, 2, t);
506 }
else if (clip[2]) {
507 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 0, 2, 1, t);
514 }
else if (clip[1]) {
516 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 1, 2, 0, t);
519 }
else if (clip[0]) {
520 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 1, 0, 2, t);
527 }
else if (clip[2]) {
529 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 2, 0, 1, t);
532 }
else if (clip[1]) {
533 clip2helper(per, extraInfoAboutVertex, modelviewTransformed, points.data(), 2, 1, 0, t);
545 t[0].extraInfoAboutVertex *= t[0].v.position.z;
546 t[1].extraInfoAboutVertex *= t[1].v.position.z;
547 t[2].extraInfoAboutVertex *= t[2].v.position.z;
581 int dx = abs(x2 - x1);
582 int dy = abs(y2 - y1);
584 int lx = x2 > x1 ? 1 : -1;
585 int ly = y2 > y1 ? 1 : -1;
588 bool changed =
false;
597 for (
int k = 0; k <= dx; k++) {
613 p += 2 * dy - 2 * dx;
618 inline void clip1(
const std::array<vec4, 3> &tris,
unsigned char which,
float &u1,
float &u2)
const {
619 u1 = -(
nearPlane + tris[which].z) / (tris[(which + 1) % 3].z - tris[which].z);
620 u2 = -(
nearPlane + tris[which].z) / (tris[(which + 2) % 3].z - tris[which].z);
623 inline void clip2(
const std::array<vec4, 3> &tris,
unsigned char idx1,
unsigned char idx2,
unsigned char rem,
float &u1,
float &u2)
const {
624 u1 = -(
nearPlane + tris[idx1].z) / (tris[rem].z - tris[idx1].z);
625 u2 = -(
nearPlane + tris[idx2].z) / (tris[rem].z - tris[idx2].z);
631 inline void clip2helper(
const mat4f &per,
const std::array<EXTRA_VERTEX_INFO, 3> &extraInfoAboutVertex,
const std::array<vec4, 3> &modelviewTransformed,
Vertex *points,
unsigned char idx1,
unsigned char idx2,
unsigned char rem, std::array<Vertex2, 3> &t) {
633 clip2(modelviewTransformed, idx1, idx2, rem, u1, u2);
635 t[idx1] =
Vertex2(
Vertex::perspectiveMul(points[idx1] + (points[rem] - points[idx1]) * u1, per), extraInfoAboutVertex[idx1] + (extraInfoAboutVertex[rem] - extraInfoAboutVertex[idx1]) * u1);
636 t[idx2] =
Vertex2(
Vertex::perspectiveMul(points[idx2] + (points[rem] - points[idx2]) * u2, per), extraInfoAboutVertex[idx2] + (extraInfoAboutVertex[rem] - extraInfoAboutVertex[idx2]) * u2);
637 t[rem] =
Vertex2(
Vertex(modelviewTransformed[rem], points[rem].normal, points[rem].texCoord).perspectiveMul(per), extraInfoAboutVertex[rem]);
639 t[idx1].extraInfoAboutVertex *= t[idx1].v.position.z;
640 t[idx2].extraInfoAboutVertex *= t[idx2].v.position.z;
641 t[rem].extraInfoAboutVertex *= t[rem].v.position.z;
647 inline void clip1helper(
const mat4f &per,
const std::array<EXTRA_VERTEX_INFO, 3> &extraInfoAboutVertex,
const std::array<vec4, 3> &modelviewTransformed,
Vertex *points,
unsigned char idx1, std::array<Vertex2, 3> &t, std::vector<std::tuple<std::array<Vertex2, 3>,
Mesh *>> &
triangles) {
649 unsigned char idx2 = (idx1 + 1) % 3, idx3 = (idx1 + 2) % 3;
650 clip1(modelviewTransformed, idx1, u1, u2);
652 t[idx1] =
Vertex2(
Vertex::perspectiveMul(points[idx1] + (points[idx2] - points[idx1]) * u1, per), extraInfoAboutVertex[idx1] + (extraInfoAboutVertex[idx2] - extraInfoAboutVertex[idx1]) * u1);
653 t[idx2] =
Vertex2(
Vertex(modelviewTransformed[idx2], points[idx2].normal, points[idx2].texCoord).perspectiveMul(per), extraInfoAboutVertex[idx2]);
654 t[idx3] =
Vertex2(
Vertex(modelviewTransformed[idx3], points[idx3].normal, points[idx3].texCoord).perspectiveMul(per), extraInfoAboutVertex[idx3]);
655 t[idx1].extraInfoAboutVertex *= t[idx1].v.position.z;
656 t[idx2].extraInfoAboutVertex *= t[idx2].v.position.z;
657 t[idx3].extraInfoAboutVertex *= t[idx3].v.position.z;
658 const std::lock_guard<std::mutex> lock(
fboCPUMutex);
661 t[idx3] =
Vertex2(
Vertex::perspectiveMul(points[idx1] + (points[idx3] - points[idx1]) * u2, per), extraInfoAboutVertex[idx1] + (extraInfoAboutVertex[idx3] - extraInfoAboutVertex[idx1]) * u2);
662 t[idx3].extraInfoAboutVertex *= t[idx3].v.position.z;
677 int yStart = (int)ceil(v0.
v.
position.
y - 0.5f);
678 const int yEnd = (int)ceil(v2.
v.
position.
y - 0.5f);
683 Vertex2 diff0 = v2 - v0, diff1 = v2 - v1, diff2;
686 if (yStart <= fboCPU->ymin) {
690 for (
int y = yStart; y < yEnd && y <
fboCPU->
ymax; ++y, u0 += unit0) {
694 vx0 = v0 + diff0 * u0;
695 vx1 = v1 + diff1 * u0;
698 int xStart = (
int)ceil(px0 - 0.5f);
699 const int xEnd = (int)ceil(px1 - 0.5f);
701 const double unit2 = 1.f / (px1 - px0);
705 if (xStart <= fboCPU->xmin) {
709 for (
int x = xStart; x < xEnd && x <
fboCPU->
xmax; x++, u2 += unit2) {
710 const double z = 1 / (vx0.v.position.z + (diff2.v.position.z) * u2);
712 const std::lock_guard<std::mutex> lock(
fboCPUMutex);
716 vx2 = vx0 + diff2 * u2;
737 const int yStart = (int)ceil(v0.
v.
position.
y - 0.5);
738 const int yEnd = (int)ceil(v2.
v.
position.
y - 0.5);
741 double u0 = 0, u1 = 0;
743 Vertex2 diff0 = v1 - v0, diff1 = v2 - v0, diff2;
746 for (
int y = yStart; y < yEnd && y <
fboCPU->
ymax; y++, u0 += unit0, u1 += unit1) {
747 if (y <= fboCPU->ymin) {
753 vx0 = v0 + diff0 * u0;
754 vx1 = v0 + diff1 * u1;
757 const int xStart = (
int)ceil(px0 - 0.5f);
758 const int xEnd = (int)ceil(px1 - 0.5f);
760 const double unit2 = 1.0 / (px1 - px0);
764 for (
int x = xStart; x < xEnd && x <
fboCPU->
xmax; x++, u2 += unit2) {
765 if (x <= fboCPU->xmin) {
768 double z = 1 / (vx0.v.position.z + (diff2.v.position.z) * u2);
770 const std::lock_guard<std::mutex> lock(
fboCPUMutex);
774 vx2 = vx0 + diff2 * u2;
785 const float area = (v2.
y - v3.
y) * (v1.
x - v3.
x) + (v3.
x - v2.
x) * (v1.
y - v3.
y);
786 values[0] = fabs(((v2.
y - v3.
y) * (p.
x - v3.
x) + (v3.
x - v2.
x) * (p.
y - v3.
y)) / area);
787 values[1] = fabs(((v3.
y - v1.
y) * (p.
x - v3.
x) + (v1.
x - v3.
x) * (p.
y - v3.
y)) / area);
788 values[2] = 1.f - values[0] - values[1];
837 const int yStart = (int)ceil(v0.
v.
position.
y - 0.5f);
838 const int yEnd = (int)ceil(v2.
v.
position.
y - 0.5f);
844 std::array<float, 3> coefficients;
846 for (
int y = yStart; y < yEnd && y <
fboCPU->
ymax; ++y, u0 += unit0) {
847 if (y <= fboCPU->ymin) {
853 const int xStart = (
int)ceil(px0 - 0.5);
854 const int xEnd = (int)ceil(px1 - 0.5);
856 const double unit2 = (px1 - px0) / (xEnd - xStart);
859 for (
int x = xStart; x < xEnd && x <
fboCPU->
xmax; x++, u2 += unit2) {
860 if (x <= fboCPU->xmin) {
868 const std::lock_guard<std::mutex> lock(
fboCPUMutex);
872 vx2 = v0 * coefficients[0] + v1 * coefficients[1] + v2 * coefficients[2];
890 const int yStart = (int)ceil(v0.
v.
position.
y - 0.5);
891 const int yEnd = (int)ceil(v2.
v.
position.
y - 0.5);
897 std::array<float, 3> coefficients;
899 for (
int y = yStart; y < yEnd && y <
fboCPU->
ymax; ++y, u0 += unit0) {
900 if (y <= fboCPU->ymin) {
906 const int xStart = (
int)ceil(px0 - 0.5);
907 const int xEnd = (int)ceil(px1 - 0.5);
909 const double unit2 = (px1 - px0) / (xEnd - xStart);
912 for (
int x = xStart; x < xEnd && x <
fboCPU->
xmax; x++, u2 += unit2) {
913 if (x <= fboCPU->xmin) {
921 const std::lock_guard<std::mutex> lock(
fboCPUMutex);
925 vx2 = v0 * coefficients[0] + v1 * coefficients[1] + v2 * coefficients[2];
936 auto &v0 = std::get<0>(tris)[0];
937 auto &v1 = std::get<0>(tris)[1];
938 auto &v2 = std::get<0>(tris)[2];
939 const auto &mesh = std::get<1>(tris);
942 if (v1.v.position.y < v0.v.position.y) {
945 if (v2.v.position.y < v1.v.position.y) {
948 if (v1.v.position.y < v0.v.position.y) {
952 if (v0.v.position.y == v1.v.position.y)
954 if (v1.v.position.x < v0.v.position.x) {
962 }
else if (v1.v.position.y == v2.v.position.y)
964 if (v2.v.position.x < v1.v.position.x) {
974 assert(v2.v.position.y > v1.v.position.y && v1.v.position.y > v0.v.position.y);
976 const double alphaSplit = (v1.v.position.y - v0.v.position.y) / (v2.v.position.y - v0.v.position.y);
977 const auto vi = v0 + (v2 - v0) * alphaSplit;
980 if (v1.v.position.x < vi.v.position.x)
990 if (v1.v.position.x < vi.v.position.x)
1010 for (unsigned int i = start; i < end; i++) {
1011 rasterizeTrianglesHelper(triangles[i]);
1025#ifndef PHONG_SHADING
1027 const auto viewDir = (cam->
eye - vertPos.
x).normalize();
1029 for (
auto &light : pointLights) {
1030 float dist =
vec3::dist(vertPos.x, light.getpos());
1031 float int_by_at = light.intensity / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
1033 if (int_by_at > 0.000001) {
1037 vertPos.x += light.get_ambient_color().getcolorVec3() * currentMesh->
material.
AmbientStrength * light.intensity * int_by_at;
1038 vertPos.y += light.get_diffuse_color().getcolorVec3() * currentMesh->
material.
DiffuseStrength * light.intensity * diff * int_by_at;
1039 vertPos.z += light.get_diffuse_color().getcolorVec3() * currentMesh->
material.
SpecularStrength * light.intensity * spec * int_by_at;
camera class implementing simple camera movement
A C++17 thread pool class.
void parallelize_loop(const T1 &first_index, const T2 &index_after_last, const F &loop, ui32 num_blocks=0)
Parallelize a loop by splitting it into blocks, submitting each block separately to the thread pool,...
#define EXTRA_VERTEX_INFO
class to store information about material read from .mtl file along with obj
Vertex + extra info required for shading.
Vertex2 operator-(const Vertex2 &f) const
Vertex2(const Vertex &vin, const EXTRA_VERTEX_INFO &pos)
Vertex2 operator+(const Vertex2 &f) const
Vertex2 operator*(const float &f) const
EXTRA_VERTEX_INFO extraInfoAboutVertex
Vertex perspectiveMul(const mat4f &per)
class that holds color with 8 bits per channel with 4 channels rgba.
this class represents all drawable entities that has a material and vertices
backend for all rendering purposes
void clip2helper(const mat4f &per, const std::array< EXTRA_VERTEX_INFO, 3 > &extraInfoAboutVertex, const std::array< vec4, 3 > &modelviewTransformed, Vertex *points, unsigned char idx1, unsigned char idx2, unsigned char rem, std::array< Vertex2, 3 > &t)
clips and perspective transforms input triangle vertices if two points are out of clip space
float getpixelZ_adjusted(int x, int y) const
get z value of specified pixel from framebuffer
void makeRequiredTriangles(const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, const mat4f &modelmat)
fill triangles array by doing required clipping and culling
void clip1(const std::array< vec4, 3 > &tris, unsigned char which, float &u1, float &u2) const
void fillTopFlatTriangle(const Vertex2 &v0, const Vertex2 &v1, const Vertex2 &v2, Mesh *mesh)
rasterize TopFlatTriangle: v0 is bottom unique and v2.x > v1.x
void fillBottomFlatTriangleBary(const Vertex2 &v0, const Vertex2 &v1, const Vertex2 &v2, Mesh *mesh)
rasterize BottomFlatTriangle: v2 is top unique and v1.x > v0.x
const char * vertexShaderSource
void clear()
clear all drawing surface
static vec3 reflect(const vec3 &I, const vec3 &N)
void draw_bresenham_adjusted(int x1, int y1, int x2, int y2, const color &col=color(0))
bresenham line drawing function to draw wireframe of objects
float lightRenderDistance
engine(const uint32_t &x, const uint32_t &y)
constructor and opengl draw surface initialization
color CalcDirLight(const vec3 &normal, const vec3 &viewdir, const color &col, const Material *material) const
function to calculate effect of directional light in a fragment with color col
color getcolor(const Vertex2 &v, Mesh *mesh) const
essentially a fragment shader : inputs fragment position and information and outputs color value for ...
void fillTopFlatTriangleBary(const Vertex2 &v0, const Vertex2 &v1, const Vertex2 &v2, Mesh *mesh)
static color CalcPointLight(const pointLight &light, const vec3 &normal, const vec3 &fragPos, const vec3 &viewDir, const color &diffuseColor, float int_by_at, const Material *material)
function to calculate effect of a point light in a fragment with color col
Mesh * currentMesh
which material to use for further render calls
bool cullBackface
switch for backface culling
void putpixel_adjusted(int x, int y, float z, const color &col=color(255))
putpixel assuming middle of screen to be the origin
void draw()
send framebuffer from cpu to gpu as texture to be able to render using opengl
void calculateBarycentricCoordinates(const vec2 &p, const vec4 &v1, const vec4 &v2, const vec4 &v3, std::array< float, 3 > &values)
void clip1helper(const mat4f &per, const std::array< EXTRA_VERTEX_INFO, 3 > &extraInfoAboutVertex, const std::array< vec4, 3 > &modelviewTransformed, Vertex *points, unsigned char idx1, std::array< Vertex2, 3 > &t, std::vector< std::tuple< std::array< Vertex2, 3 >, Mesh * > > &triangles)
clips and perspective transforms input triangle vertices if one point is out of the clip space
const char * fragmentShaderSource
void makeRequiredTrianglesHelper(std::array< Vertex, 3 > &points, const mat4f &modelmat, const mat4f &view, const mat4f &per)
std::vector< std::tuple< std::array< Vertex2, 3 >, Mesh * > > triangles
set of triangles to be drawn to screen
std::vector< pointLight > pointLights
float ambientLightIntensity
lights.
void clip2(const std::array< vec4, 3 > &tris, unsigned char idx1, unsigned char idx2, unsigned char rem, float &u1, float &u2) const
float nearPlane
nearplane of camera for clipping and culling
std::unordered_map< uint8_t, float > greenTimeMap
static float max(const float &first, const float &second)
void fillBottomFlatTriangle(const Vertex2 &v0, const Vertex2 &v1, const Vertex2 &v2, Mesh *mesh)
rasterize BottomFlatTriangle: v2 is top unique and v1.x > v0.x
void rasterizeTriangles()
helper function to rasterize triangles in vector of triangles.
std::unordered_map< uint8_t, float > blueTimeMap
void rasterizeTrianglesHelper(std::tuple< std::array< Vertex2, 3 >, Mesh * > &tris)
Framebuffer implementation for cpu.
color * clearedcolorlayer
std::vector< std::tuple< Vertex2 *, Mesh * > > fragments
framebuffer(const size_t &x, const size_t &y)
const vec3 & getpos() const
const color & get_ambient_color() const
const color & get_diffuse_color() const
static float dot(const vec3_T< float > &a, const vec3_T< float > &b)
static double dist(const vec3_T< float > &a, const vec3_T< float > &b)
A C++17 thread pool for high-performance scientific computing.