Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Here i calculate every barycentric coordinate for every subpixel to check if it is inside triangle
- float maxy = rt->curH + 1.f;
- float maxx = rt->curW + 1.f;
- float stepstart = 0.5f / rt->renderer->samplestep; //for st = 2 step is .25 for st = 4 0.125
- float step = 2.f*stepstart; //distance between
- vec3_t subpixel = {0.f, 0.f, 0.f};
- vec3_t subbc, bcsum;
- bool first = true;
- bool subsuccess;
- vec3_t *limitvec;
- for (float cury = rt->curH + stepstart; cury < maxy && cury < rt->maxy ; cury += step)
- {
- for (float curx = rt->curW + stepstart; curx < maxx && curx < rt->maxx ; curx += step)
- {
- subpixel.coords.x = curx;
- subpixel.coords.y = cury;
- //printf("subpx: %f %f\n", curx, cury);
- if ( isline(rt->shape) )
- {
- float edge = place_of_vec3(rt->pRaster[0], rt->pRaster[1], &subpixel);
- limitvec = vec3_sub_new(rt->pRaster[0], rt->pRaster[1]);
- vec3_length(limitvec);
- float limit = vec3_length(limitvec) *0.5f;
- if ( (edge <= limit && edge >= 0.f || edge >= -limit && edge <= 0.f) )
- {
- subsuccess = true;
- }
- free(limitvec);
- } else
- {
- subsuccess = is_inside_triangle( rt->pRaster[0], rt->pRaster[1], rt->pRaster[2], &subpixel, &subbc);
- }
- if(subsuccess)
- {
- if (first)
- {
- vec3_copy_dest(&bcsum,&subbc);
- first = false;
- rt->isVisible = true;
- } else
- {
- vec3_add(&bcsum,&subbc);
- }
- ++rt->cntsamplesuccess;
- }
- }
- }
- if(rt->isVisible)
- {
- vec3_set_values(&rt->bc, bcsum.coords.x / rt->cntsamplesuccess,
- bcsum.coords.y / rt->cntsamplesuccess,
- bcsum.coords.z / rt->cntsamplesuccess);
- }
- //later in the code i use this results for coloring
- if (rt->renderer->samplestep > 1.f )
- {
- float st = rt->renderer->samplestep*rt->renderer->samplestep;
- float fail = st - rt->cntsamplesuccess;
- cRGB_t subcolsucc = { curCol1.r * rt->cntsamplesuccess,
- curCol1.g * rt->cntsamplesuccess,
- curCol1.b * rt->cntsamplesuccess };
- cRGB_t bufcol = rt->renderer->frameBuffer[bi/*rt->bufferIndex*/];
- cRGB_t subcolfail = { bufcol.r * fail,
- bufcol.g * fail,
- bufcol.b * fail};
- crgb_crgb_add(&subcolsucc, &subcolfail);
- crgb_mul(&subcolsucc, 1.f/st);
- crgb_crgb_copy(&curCol1, &subcolsucc);
- }
- crgb_crgb_copy(&rt->renderer->frameBuffer[bi/*rt->bufferIndex*/], &curCol1);
Advertisement
Add Comment
Please, Sign In to add comment