diff options
author | chai <chaifix@163.com> | 2020-02-26 22:52:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-26 22:52:19 +0800 |
commit | 372d77e436d21312ef1a0df622964751716963a3 (patch) | |
tree | 1a71865fea6fb9f2f532422c4b83959fff17ea76 /src/core/rasterizer.c | |
parent | 27687536844ed3b045bba1abd1aae8bb3692f6cb (diff) |
*misc
Diffstat (limited to 'src/core/rasterizer.c')
-rw-r--r-- | src/core/rasterizer.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/rasterizer.c b/src/core/rasterizer.c index d6a9fc1..d926cb0 100644 --- a/src/core/rasterizer.c +++ b/src/core/rasterizer.c @@ -237,15 +237,15 @@ void ssrR_line( ) { ssr_assert(CA && CB && program && uniforms); - Vec3 SA, SB; - vec4_dividew(CA, &SA); ssrU_viewport(&SA, &SA); - vec4_dividew(CB, &SB); ssrU_viewport(&SB, &SB); + Vec4 SA, SB; + vec4_dividewnoz(CA, &SA); ssrU_viewport(&SA, &SA); + vec4_dividewnoz(CB, &SB); ssrU_viewport(&SB, &SB); FragmentShader frag_shader = program->fragmentshader; int x0 = SA.x, y0 = SA.y; int x1 = SB.x, y1 = SB.y; - float wA = 1 / CA->w, wB = 1 / CB->w; + float wA = SA.w, wB = SB.w; float zA = SA.z, zB = SB.z; bool steep = FALSE; @@ -262,6 +262,8 @@ void ssrR_line( swapf(zA, zB); } + float inv_wA = 1 / wA, inv_wB = 1 / wB; + bool depth_test = ssr_isenable(ENABLE_DEPTHTEST); bool blend = ssr_isenable(ENABLE_BLEND); bool write_depth = ssr_isenable(ENABLE_WRITEDEPTH); @@ -274,15 +276,15 @@ void ssrR_line( #define discardif(condition) if(condition) continue - float t, depth; + float t, z, w, depth; Vec2 c; int x, y, px, py; for (x = x0; x <= x1; ++x) { t = (x - x0) / (float)(x1 - x0); y = y0 + (y1 - y0)*t; /*caculate center*/ - c.x = (1 - t) * wA; - c.y = t * wB; + c.x = (1 - t) * inv_wA; + c.y = t * inv_wB; discardif(compare(c.x+c.y, 0)); c.x /= (c.x + c.y); t = 1 - c.x; @@ -295,7 +297,9 @@ void ssrR_line( py = y; } if (depth_test) { - ssrS_lerpnum(t, &zA, &zB, &depth); + ssrS_lerpnum(t, &zA, &zB, &z); + ssrS_lerpnum(t, &wA, &wB, &w); + depth = z / w; pass_depth_test = ssr_testdepth(px, py, depth); } if (stencil_test) { |