summaryrefslogtreecommitdiff
path: root/src/core/rasterizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/rasterizer.c')
-rw-r--r--src/core/rasterizer.c20
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) {