Browse Source

added perspectivegit add .git add .git add .

iver 7 months ago
parent
commit
d5bc521cc8

BIN
builds/final binaries/librasteriver.so


BIN
builds/final binaries/main.bin


+ 12 - 12
src/RasterIver/kernels/master_kernel.h

@@ -75,7 +75,7 @@ __kernel void raster_kernel(__global float* objects, __global float* verticies,
     int id_x = get_global_id(0) - width / 2; \
     int id_x = get_global_id(0) - width / 2; \
     int id_y = get_global_id(1) - height / 2; \
     int id_y = get_global_id(1) - height / 2; \
     \
     \
-    float z_pixel = 0; \
+    float z_pixel = INFINITY; \
     uint frame_pixel = 0x22222222; \
     uint frame_pixel = 0x22222222; \
     \
     \
     float highest_z = 800;\
     float highest_z = 800;\
@@ -148,15 +148,15 @@ __kernel void raster_kernel(__global float* objects, __global float* verticies,
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);\
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);\
             }\
             }\
             \
             \
-            z0 = z0 * object_s_z + object_z;\
-            x0 = x0 * object_s_x + object_x;\
-            y0 = y0 * object_s_y + object_y;\
-            z1 = z1 * object_s_z + object_z;\
-            x1 = x1 * object_s_x + object_x;\
-            y1 = y1 * object_s_y + object_y;\
-            z2 = z2 * object_s_z + object_z;\
-            x2 = x2 * object_s_x + object_x;\
-            y2 = y2 * object_s_y + object_y;\
+            z0 = (z0 * object_s_z + object_z);\
+            x0 = (x0 * object_s_x + object_x) / z0;\
+            y0 = (y0 * object_s_y + object_y) / z0;\
+            z1 = (z1 * object_s_z + object_z);\
+            x1 = (x1 * object_s_x + object_x) / z1;\
+            y1 = (y1 * object_s_y + object_y) / z1;\
+            z2 = (z2 * object_s_z + object_z);\
+            x2 = (x2 * object_s_x + object_x) / z2;\
+            y2 = (y2 * object_s_y + object_y) / z2;\
             \
             \
             if (i3 < 0 || i4 < 0 || i5 < 0){\
             if (i3 < 0 || i4 < 0 || i5 < 0){\
                 has_normals = 0;\
                 has_normals = 0;\
@@ -208,7 +208,7 @@ __kernel void raster_kernel(__global float* objects, __global float* verticies,
                 \
                 \
                 float denominator = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2); \
                 float denominator = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2); \
                 \
                 \
-                if (denominator <= 0) { \
+                if (denominator >= 0) { \
                     continue; \
                     continue; \
                 } \
                 } \
                 w0 = ((y1 - y2) * (id_x - x2) + (x2 - x1) * (id_y - y2)) / denominator; \
                 w0 = ((y1 - y2) * (id_x - x2) + (x2 - x1) * (id_y - y2)) / denominator; \
@@ -217,7 +217,7 @@ __kernel void raster_kernel(__global float* objects, __global float* verticies,
                 \
                 \
                 float z = w0 * z0 + w1 * z1 + w2 * z2; \
                 float z = w0 * z0 + w1 * z1 + w2 * z2; \
                 \
                 \
-                if (z > z_pixel){ \
+                if (z < z_pixel){ \
                     z_pixel = z; \
                     z_pixel = z; \
                     \
                     \
                     float n_x0 = normals[i3 + 0];\
                     float n_x0 = normals[i3 + 0];\

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

@@ -870,7 +870,7 @@ RI_result RI_Tick(){
         if (use_cpu){
         if (use_cpu){
 for (int id_y = -height / 2; id_y < height / 2; id_y++){
 for (int id_y = -height / 2; id_y < height / 2; id_y++){
 for (int id_x = -width / 2; id_x < width / 2; id_x++){
 for (int id_x = -width / 2; id_x < width / 2; id_x++){
-            float z_pixel = 0; 
+            float z_pixel = INFINITY; 
     unsigned int frame_pixel = 0x22222222; 
     unsigned int frame_pixel = 0x22222222; 
     
     
     float highest_z = 800;
     float highest_z = 800;
@@ -943,15 +943,15 @@ for (int id_x = -width / 2; id_x < width / 2; id_x++){
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);
             }
             }
             
             
-            z0 = z0 * object_s_z + object_z;
-            x0 = x0 * object_s_x + object_x;
-            y0 = y0 * object_s_y + object_y;
-            z1 = z1 * object_s_z + object_z;
-            x1 = x1 * object_s_x + object_x;
-            y1 = y1 * object_s_y + object_y;
-            z2 = z2 * object_s_z + object_z;
-            x2 = x2 * object_s_x + object_x;
-            y2 = y2 * object_s_y + object_y;
+            z0 = (z0 * object_s_z + object_z);
+            x0 = (x0 * object_s_x + object_x) / z0 * width;
+            y0 = (y0 * object_s_y + object_y) / z0 * height;
+            z1 = (z1 * object_s_z + object_z);
+            x1 = (x1 * object_s_x + object_x) / z1 * width;
+            y1 = (y1 * object_s_y + object_y) / z1 * height;
+            z2 = (z2 * object_s_z + object_z);
+            x2 = (x2 * object_s_x + object_x) / z2 * width;
+            y2 = (y2 * object_s_y + object_y) / z2 * height;
             
             
             if (i3 < 0 || i4 < 0 || i5 < 0){
             if (i3 < 0 || i4 < 0 || i5 < 0){
                 has_normals = 0;
                 has_normals = 0;
@@ -1003,7 +1003,7 @@ for (int id_x = -width / 2; id_x < width / 2; id_x++){
                 
                 
                 float denominator = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2); 
                 float denominator = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2); 
                 
                 
-                if (denominator <= 0) { 
+                if (denominator >= 0) { 
                     continue; 
                     continue; 
                 } 
                 } 
                 w0 = ((y1 - y2) * (id_x - x2) + (x2 - x1) * (id_y - y2)) / denominator; 
                 w0 = ((y1 - y2) * (id_x - x2) + (x2 - x1) * (id_y - y2)) / denominator; 
@@ -1012,7 +1012,7 @@ for (int id_x = -width / 2; id_x < width / 2; id_x++){
                 
                 
                 float z = w0 * z0 + w1 * z1 + w2 * z2; 
                 float z = w0 * z0 + w1 * z1 + w2 * z2; 
                 
                 
-                if (z > z_pixel){ 
+                if (z < z_pixel){ 
                     z_pixel = z; 
                     z_pixel = z; 
                     
                     
                     float n_x0 = normals[i3 + 0];
                     float n_x0 = normals[i3 + 0];

+ 6 - 2
src/launch program/main.c

@@ -27,14 +27,18 @@ int main(){
     }
     }
 
 
     RI_newObject object_buffer[3] = {
     RI_newObject object_buffer[3] = {
-        {0, 0, 300,      0, 0.0, 0, -9999999,          50, 50, 50,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
-        {0, 0, 300,         0, 0, 0, -9999999,  60, 60, 60,     "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
+        {0, 0, 15,         0, 0, 0, -9999999,  1, 1, 1,     "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
         {200, 0, 300,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/cube_texture.png"},
         {200, 0, 300,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/cube_texture.png"},
+        {0, 0, 300,      0, 0.0, 0, -9999999,          50, 50, 50,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
     };
     };
 
 
     RI_objects objects = RI_RequestObjects(object_buffer, 1);
     RI_objects objects = RI_RequestObjects(object_buffer, 1);
 
 
     while (RI_IsRunning() == RI_RUNNING){
     while (RI_IsRunning() == RI_RUNNING){
+        //objects[3] += 0.3;
+        objects[4] -= 0.4;
+        //objects[5] += 0.3;
+        
         RI_Tick();
         RI_Tick();
     }
     }