summaryrefslogtreecommitdiff
path: root/src/core/rasterizer.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-07-19 17:01:00 +0800
committerchai <chaifix@163.com>2020-07-19 17:01:00 +0800
commit5b89a0fab0a46764c92979797681bf170125a7da (patch)
tree753d40800dc7dc423bd89e429e6154ca8441d654 /src/core/rasterizer.c
parent4deff343b5fd928ae9475eedcf9b6add34b31ae2 (diff)
*early back face culling
Diffstat (limited to 'src/core/rasterizer.c')
-rw-r--r--src/core/rasterizer.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/core/rasterizer.c b/src/core/rasterizer.c
index 55d4ad3..9276cbd 100644
--- a/src/core/rasterizer.c
+++ b/src/core/rasterizer.c
@@ -44,7 +44,7 @@ float ssrR_area(Vec2* v1, Vec2* v2, Vec2* v3) {
return area;
}
-/*from https://github.com/ssloy/tinyrenderer */
+/*https://github.com/ssloy/tinyrenderer */
bool ssrR_barycentric(Vec2* A, Vec2* B, Vec2* C, Vec2* p, Vec3* out) {
ssr_assert(A && B && C && p && out);
Vec3 s[2], u;
@@ -87,24 +87,10 @@ extern UniformCollection* g_uniforms ;
void ssrR_triangle(
Vec4* CA, Vec4* CB, Vec4* CC,
uint IA, uint IB, uint IC,
- Program* program,
- bool early_culled
+ Program* program
) {
ssr_assert(CA && CB && CC && program);
- /*late back face culling*/
- if (!early_culled && ssr_isenable(ENABLE_BACKFACECULL)) {
- float w0 = 1 / CA->w, w1 = 1 / CB->w, w2 = 1 / CC->w;
- Vec2 ab, ac;
- ab.x = CB->x * w1 - CA->x * w0;
- ab.y = CB->y * w1 - CA->y * w0;
- ac.x = CC->x * w2 - CA->x * w0;
- ac.y = CC->y * w2 - CA->y * w0;
- if (ab.x * ac.y - ab.y * ac.x <= 0) {
- return;
- }
- }
-
UniformCollection* uniforms = g_uniforms;
Vec4 SA, SB, SC;
@@ -164,7 +150,7 @@ void ssrR_triangle(
for (p.x = from; order * (p.x - to) <= 0; p.x += order) { \
/*calculate barycentric coordinate*/ \
s[0].z = sa->x - p.x; \
- internal_vec3_cross(&s[0], &s[1], &u); \
+ internal_vec3_cross(&s[0], &s[1], &u); \
discardif(compare(u.z, 0)); \
u.z = 1.f / u.z; \
bc.x = 1.f - (u.x + u.y) * u.z; \
@@ -173,7 +159,7 @@ void ssrR_triangle(
discardif(bc.x < 0 || bc.y < 0 || bc.z < 0); \
/*perspective correction*/ \
bc.x *= CAw; bc.y *= CBw; bc.z *= CCw; \
- internal_vec3_scale(&bc, 1.f / (bc.x + bc.y + bc.z), &bc); \
+ internal_vec3_scale(&bc, 1.f / (bc.x + bc.y + bc.z), &bc); \
/*early depth testing*/ \
if(depth_test){ \
depth = bc.x*sa->z + bc.y*sb->z + bc.z*sc->z; \
@@ -189,7 +175,7 @@ void ssrR_triangle(
/*interpolate varying variables*/ \
ssrS_solveregsbcp(&bc, IA, IB, IC); \
/*enter fragment shader*/ \
- discard = !frag_shader(out_color[0]); \
+ discard = !frag_shader(out_color[0]); \
discardif(discard); \
/*put point*/ \
ssr_blendandputpoint(p.x, p.y, blend); \