Browse Source

fixed linear interpolation of perspective-warped normals

iver 7 months ago
parent
commit
82dd203613

BIN
builds/final binaries/librasteriver.so


BIN
builds/final binaries/main.bin


+ 1 - 1
readme.md

@@ -22,7 +22,7 @@ Rasterizer + Iver = RasterIver
 - [x] make todo list
 - [ ] function to request a mesh. I.E., request a number of polygons/verticies (maybe from presets? planes, cubes, idk) and be able to edit them on the fly. Useful for dynamic terrain or something like that
 - [x] texture support
-- [ ] fix interpolation issue with UV maps (and probably normals and Z values too)
+- [x] fix interpolation issue with UV maps (and probably normals and Z values too)
 - [ ] fix horribly named variables in request object functions
 - [ ] include rasteriver.h in the kernels for better code updatability
 - [ ] make kernels not be in strings (read the file at compile time and put it inside rasteriver.c as a string? put it in a header like how it is now?)

+ 3 - 3
src/RasterIver/source code/rasteriver.c

@@ -1084,9 +1084,9 @@ for (int id_x = -width / 2; id_x < width / 2; id_x++){
                             
                             break;}
                         case 2:{
-                            float nx = w0 * n_x0 + w1 * n_x1 + w2 * n_x2;
-                            float ny = w0 * n_y0 + w1 * n_y1 + w2 * n_y2;
-                            float nz = w0 * n_z0 + w1 * n_z1 + w2 * n_z2;
+                            float nx = (w0 * (n_x0 / z0) + w1 * (n_x1 / z1) + w2 * (n_x2 / z2)) / w_over_z;
+                            float ny = (w0 * (n_y0 / z0) + w1 * (n_y1 / z1) + w2 * (n_y2 / z2)) / w_over_z;
+                            float nz = (w0 * (n_z0 / z0) + w1 * (n_z1 / z1) + w2 * (n_z2 / z2)) / w_over_z;
                             
                             nx = clamppp_float((nx * 0.5f + 0.5f) * 255.0f, 0.0f, 255.0f);
                             ny = clamppp_float((ny * 0.5f + 0.5f) * 255.0f, 0.0f, 255.0f);

+ 1 - 1
src/launch program/main.c

@@ -15,7 +15,7 @@ int main(){
     RI_SetFlag(RI_FLAG_DEBUG_FPS, 0);
     RI_SetFlag(RI_FLAG_SHOW_FPS, 0);
     RI_SetFlag(RI_FLAG_SHOW_FRAME, 0);
-    RI_SetFlag(RI_FLAG_SHOW_BUFFER, RI_BUFFER_COMPLETE);
+    RI_SetFlag(RI_FLAG_SHOW_BUFFER, RI_BUFFER_NORMAL);
     RI_SetFlag(RI_FLAG_CLEAN_POLYGONS, 1);
     RI_SetFlag(RI_FLAG_POPULATE_POLYGONS, 0);
     RI_SetFlag(RI_FLAG_BE_MASTER_RENDERER, 1);