summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device.c1
-rw-r--r--src/core/rasterizer.c14
-rw-r--r--src/core/shader.h1
-rw-r--r--src/core/vert.h5
4 files changed, 12 insertions, 9 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 23e4bb3..70ae11f 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -500,6 +500,7 @@ static void render_prims_triangle(uint varying_flag) {
/*back face culling*/
if (ssr_isenable(ENABLE_BACKFACECULL)) {
+ /*cull in ndc*/
float w0 = 1 / c0->w, w1 = 1 / c1->w, w2 = 1 / c2->w;
Vec3 ab, ac;
ab.x = c1->x * w1 - c0->x * w0;
diff --git a/src/core/rasterizer.c b/src/core/rasterizer.c
index a7d3544..d6a9fc1 100644
--- a/src/core/rasterizer.c
+++ b/src/core/rasterizer.c
@@ -92,17 +92,17 @@ void ssrR_triangle(
) {
ssr_assert(CA && CB && CC && program);
- Vec3 SA, SB, SC;
- vec4_dividew(CA, &SA); ssrU_viewport(&SA, &SA);
- vec4_dividew(CB, &SB); ssrU_viewport(&SB, &SB);
- vec4_dividew(CC, &SC); ssrU_viewport(&SC, &SC);
+ Vec4 SA, SB, SC;
+ vec4_dividewnoz(CA, &SA); ssrU_viewport(&SA, &SA);
+ vec4_dividewnoz(CB, &SB); ssrU_viewport(&SB, &SB);
+ vec4_dividewnoz(CC, &SC); ssrU_viewport(&SC, &SC);
/*
puttriangle(&SA, &SB, &SC, 0xffff0000);
return;
*/
- Vec3 *sa = &SA, *sb = &SB, *sc = &SC, *tmp;
+ Vec4 *sa = &SA, *sb = &SB, *sc = &SC, *tmp;
Vec4 *v4tmp;
uint itmp;
#define swap(t, a, b) {t = a; a = b; b = t;} /*sort in y axis*/
@@ -163,7 +163,9 @@ void ssrR_triangle(
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; \
+ depth = bc.x*sa->z + bc.y*sb->z + bc.z*sc->z; \
+ depth /= bc.x*sa->w + bc.y*sb->w + bc.z*sc->w; \
+ /*depth = bc.x*sa->z+bc.y*sb->z+bc.z*sc->z;*//*wrong*/ \
pass_depth_test = ssr_testdepth(p.x, p.y, depth); \
} \
/*early stencil testing*/ \
diff --git a/src/core/shader.h b/src/core/shader.h
index 3737e8c..26606b8 100644
--- a/src/core/shader.h
+++ b/src/core/shader.h
@@ -152,6 +152,7 @@ typedef struct {
byte* output; /*fragment-in*/
} ActiveReg;
+/*interpolation registers*/
Register registers[REG_TOTAL];
ActiveReg active_regs[REG_TOTAL];
diff --git a/src/core/vert.h b/src/core/vert.h
index 8578d87..6c968b5 100644
--- a/src/core/vert.h
+++ b/src/core/vert.h
@@ -22,16 +22,15 @@ Color color32_tocolor(Color32* c);
void color_tocolor32(Color c, Color32* out);
void color32_saturate(Color32* c);
-/*readonly*/
typedef struct Vert {
uint index;
Vec3 position;
Vec3 normal;
- Vec4 tangent;
+ Vec4 tangent; // w for handness
Vec2 texcoord;
Color color;
/*
- Vec2 texcoord1;
+ Vec2 texcoord1; // for lightmap
Vec4 joint;
Vec4 weight;
*/