Browse Source

fixed warning, slight transparent image support, new example scene

Iver 1 month ago
parent
commit
d204e144b3

BIN
builds/libpitmap.so


BIN
builds/librasteriver.so


BIN
builds/main.bin


+ 9 - 4
changelog.txt

@@ -1,4 +1,9 @@
--added animated textures
--latest version of PitMap (8bpp images that have no compression, debug mode)
--added issues.txt
--added another gif to the readme
+-rasterizer ignores 100% transparent pixels
+-added emoji gif
+-plane obj's UVs no longer flip when it's turned around
+-fixed "
+src/main/main.c:43:67: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
+   43 |     PM_image* image = PM_load_image(filename, context.debug_flags & RI_DEBUG_PITMAP == 0 ? 0 : 1);
+   "
+-updated example screen
+-added new gif to readme

+ 3 - 0
issues.txt

@@ -0,0 +1,3 @@
+-not freeing memory every i dont think
+-i think polygons that are outside the frustum are still being added to the tiles, e.g., an object that is just off screen
+-latest version of PitMap (images now read in the correct orientation)

+ 3 - 3
objects/plane.obj

@@ -20,10 +20,10 @@ v -1.000000 0.000000 1.000000
 v 1.000000 0.000000 -1.000000
 v 1.000000 0.000000 -1.000000
 v -1.000000 0.000000 -1.000000
 v -1.000000 0.000000 -1.000000
 vn 1.0000 -0.0000 -0.0000
 vn 1.0000 -0.0000 -0.0000
-vt 1.000000 0.000000
-vt 0.000000 1.000000
-vt 0.000000 0.000000
 vt 1.000000 1.000000
 vt 1.000000 1.000000
+vt 0.000000 0.000000
+vt 0.000000 1.000000
+vt 1.000000 0.000000
 s 0
 s 0
 f 6/5/2 7/6/2 5/7/2
 f 6/5/2 7/6/2 5/7/2
 f 6/5/2 8/8/2 7/6/2
 f 6/5/2 8/8/2 7/6/2

+ 1 - 0
readme.md

@@ -2,6 +2,7 @@
 
 
 <p align="center">
 <p align="center">
    <img src="https://mynameisthe.com/f/1764353133143-ezgif-692a8b4b3535e93c.gif" alt="gif of silly example scene"> <br><i>17,700 polygon scene running at 100fps</i><br><br><br>
    <img src="https://mynameisthe.com/f/1764353133143-ezgif-692a8b4b3535e93c.gif" alt="gif of silly example scene"> <br><i>17,700 polygon scene running at 100fps</i><br><br><br>
+   <img src="https://mynameisthe.com/f/1764539867760-animated_textures_emojis_scene.gif" style="width: 512px"><br><i>animated textures</i><br><br><br>
    <img src="https://mynameisthe.com/f/1764474323607-gordon.gif" style="width: 512px"><br><i>example showcasing animated textures and triangle tiling (green boxes)</i><br><i>~400,000 tris, 14fps</i>
    <img src="https://mynameisthe.com/f/1764474323607-gordon.gif" style="width: 512px"><br><i>example showcasing animated textures and triangle tiling (green boxes)</i><br><i>~400,000 tris, 14fps</i>
 </p>
 </p>
 
 

+ 5 - 3
src/kernels/kernels.cl

@@ -791,7 +791,7 @@ __kernel void rasterizer(__global RI_renderable_face *renderable_faces, __global
     uint num_faces_in_cur_tile = tiles[tile_array_index];
     uint num_faces_in_cur_tile = tiles[tile_array_index];
 
 
     // debug tiles
     // debug tiles
-    if (num_faces_in_cur_tile > 0) pixel_color = 0x00AA00FF;
+    // if (num_faces_in_cur_tile > 0) pixel_color = 0x00AA00FF;
 
 
     for (int face_i = 0; face_i < num_faces_in_cur_tile; ++face_i){
     for (int face_i = 0; face_i < num_faces_in_cur_tile; ++face_i){
         __global RI_renderable_face *current_face = &renderable_faces[tiles[tile_array_index + face_i + 1]];
         __global RI_renderable_face *current_face = &renderable_faces[tiles[tile_array_index + face_i + 1]];
@@ -847,7 +847,10 @@ __kernel void rasterizer(__global RI_renderable_face *renderable_faces, __global
         uint texel_index = current_face->texture.index + 
         uint texel_index = current_face->texture.index + 
             texel_y * current_face->texture.width + texel_x;
             texel_y * current_face->texture.width + texel_x;
 
 
-        pixel_color = textures[texel_index];
+        if (textures[texel_index] & 0x000000FF){ // skip any pixel that is completly transparent
+            pixel_color = textures[texel_index];
+            z = interpolated_z;
+        }
 
 
         // debug clipped tris
         // debug clipped tris
         // pixel_color = 0x777777FF;
         // pixel_color = 0x777777FF;
@@ -855,7 +858,6 @@ __kernel void rasterizer(__global RI_renderable_face *renderable_faces, __global
         // if (current_face->is_shrunk) pixel_color |= 0xFFFFFFFF;
         // if (current_face->is_shrunk) pixel_color |= 0xFFFFFFFF;
         // if (current_face->is_transformed) pixel_color |= 0xFF00FFFF;
         // if (current_face->is_transformed) pixel_color |= 0xFF00FFFF;
 
 
-        z = interpolated_z;
     }
     }
     
     
     // debug tiles
     // debug tiles

+ 36 - 27
src/launch program/main.c

@@ -15,7 +15,7 @@ int main(){
     }
     }
     
     
     RI_scene *scene = RI_new_scene();
     RI_scene *scene = RI_new_scene();
-    context->debug_flags |= RI_DEBUG_TRANSFORMER_TIME | RI_DEBUG_RASTERIZER_TIME | RI_DEBUG_PITMAP | RI_DEBUG_FRAME_START_END_MARKERS;
+
 
 
     scene->camera.FOV = 1.5;
     scene->camera.FOV = 1.5;
     scene->camera.min_clip = 0.1;
     scene->camera.min_clip = 0.1;
@@ -27,14 +27,16 @@ int main(){
     RI_mesh *gordon_mesh = RI_load_mesh("objects/terrain.obj");
     RI_mesh *gordon_mesh = RI_load_mesh("objects/terrain.obj");
     RI_mesh *gordon_head_mesh = RI_load_mesh("objects/gordon_freeman_head.obj");
     RI_mesh *gordon_head_mesh = RI_load_mesh("objects/gordon_freeman_head.obj");
     RI_mesh *text_mesh = RI_load_mesh("objects/gordon_freeman.obj");
     RI_mesh *text_mesh = RI_load_mesh("objects/gordon_freeman.obj");
-    RI_mesh *plane_mesh = RI_load_mesh("objects/plane_subdivided.obj");
+    RI_mesh *plane_mesh = RI_load_mesh("objects/plane.obj");
 
 
     scene->actors = malloc(sizeof(RI_actor) * 5);
     scene->actors = malloc(sizeof(RI_actor) * 5);
 
 
-    RI_texture* skybox_texture = RI_load_image("textures/alley_skybox_3072x3072.bmp");
+    RI_texture* skybox_texture = RI_load_animation("textures/emoji_angry.bmp", 40);
     RI_texture* gordon_texture = RI_load_image("textures/terrain_texture.bmp");
     RI_texture* gordon_texture = RI_load_image("textures/terrain_texture.bmp");
     RI_texture* gordon_face_texture = RI_load_animation("textures/gordon_face_animated.bmp", 3);
     RI_texture* gordon_face_texture = RI_load_animation("textures/gordon_face_animated.bmp", 3);
     RI_texture* emoji_texture = RI_load_image("textures/gordon_body.bmp");
     RI_texture* emoji_texture = RI_load_image("textures/gordon_body.bmp");
+    RI_texture* iver_texture = RI_load_animation("textures/emoji_gif.bmp", 11);
+    RI_texture* sky_texture = RI_load_image("textures/skybox_texture_4_cube_1024x1024.bmp");
 
 
     scene->actors[0] = RI_new_actor();
     scene->actors[0] = RI_new_actor();
     scene->actors[1] = RI_new_actor();
     scene->actors[1] = RI_new_actor();
@@ -44,22 +46,16 @@ int main(){
 
 
     context->window.aspect_mode = RI_ASPECT_MODE_LETTERBOX;
     context->window.aspect_mode = RI_ASPECT_MODE_LETTERBOX;
 
 
-    scene->actors[0]->mesh = skybox_mesh;
-    scene->actors[0]->texture = skybox_texture;
-    scene->actors[0]->scale = (RI_vector_3){1000, 1000, 1000};
-    scene->actors[0]->position = (RI_vector_3){0, 0, 300};
-scene->actors[0]->active = 0;
-
-    scene->actors[1]->mesh = gordon_head_mesh;
-    scene->actors[1]->texture = gordon_face_texture;
-    scene->actors[1]->scale = (RI_vector_3){3, 1, 3};
-    scene->actors[1]->position = (RI_vector_3){0, 900, -400};
+    scene->actors[1]->mesh = skybox_mesh;
+    scene->actors[1]->texture = sky_texture;
+    scene->actors[1]->scale = (RI_vector_3){1000, 1000, 1000};
+    scene->actors[1]->position = (RI_vector_3){0, 0, 0};
 // scene->actors[1]->active = 0;
 // scene->actors[1]->active = 0;
 
 
-    scene->actors[2]->mesh = gordon_mesh;
+    scene->actors[2]->mesh = plane_mesh;//gordon_mesh;
     scene->actors[2]->texture = gordon_texture;
     scene->actors[2]->texture = gordon_texture;
     scene->actors[2]->scale = (RI_vector_3){2000, 1000, 2000};
     scene->actors[2]->scale = (RI_vector_3){2000, 1000, 2000};
-    scene->actors[2]->position = (RI_vector_3){0, -150, 0};
+    scene->actors[2]->position = (RI_vector_3){0, -30, 0};
     // scene->actors[2]->active = 0;
     // scene->actors[2]->active = 0;
 
 
     scene->actors[3]->mesh = text_mesh;
     scene->actors[3]->mesh = text_mesh;
@@ -68,20 +64,23 @@ scene->actors[0]->active = 0;
     scene->actors[3]->position = (RI_vector_3){0, 900, -400};
     scene->actors[3]->position = (RI_vector_3){0, 900, -400};
 // scene->actors[3]->active = 0;
 // scene->actors[3]->active = 0;
 
 
+    float scale = 30;
+
+    scene->actors[0]->mesh = plane_mesh;
+    scene->actors[0]->texture = skybox_texture;
+    scene->actors[0]->scale = (RI_vector_3){scale * 1.261904762, scale, scale};
+    scene->actors[0]->position = (RI_vector_3){60, 0, 180};
+
     scene->actors[4]->mesh = plane_mesh;
     scene->actors[4]->mesh = plane_mesh;
-    scene->actors[4]->texture = emoji_texture;
-    scene->actors[4]->scale = (RI_vector_3){100, 50, 30};
+    scene->actors[4]->texture = iver_texture;
+    scene->actors[4]->scale = (RI_vector_3){scale, scale, scale};
     scene->actors[4]->position = (RI_vector_3){60, 40, 180};
     scene->actors[4]->position = (RI_vector_3){60, 40, 180};
-scene->actors[4]->active = 0;
+// scene->actors[4]->active = 0;
 
 
-    RI_euler_rotation_to_quaternion(&scene->actors[0]->rotation, (RI_vector_3){0, 0, 0});
+    RI_euler_rotation_to_quaternion(&scene->actors[0]->rotation, (RI_vector_3){3.14159 / 2, 0.3, 0});
     // RI_euler_rotation_to_quaternion(&scene->actors[1]->rotation, (RI_vector_3){0, 3.14159, 0});
     // RI_euler_rotation_to_quaternion(&scene->actors[1]->rotation, (RI_vector_3){0, 3.14159, 0});
     RI_euler_rotation_to_quaternion(&scene->actors[2]->rotation, (RI_vector_3){0, 0.78539816339, 0});
     RI_euler_rotation_to_quaternion(&scene->actors[2]->rotation, (RI_vector_3){0, 0.78539816339, 0});
 
 
-    scene->camera.position = (RI_vector_3){0, 1000, -500};
-
-    RI_euler_rotation_to_quaternion(&scene->camera.rotation, (RI_vector_3){-.7, 0, 0});
-
     scene->length_of_actors_array = 5;
     scene->length_of_actors_array = 5;
 
 
     long int start, end;
     long int start, end;
@@ -95,19 +94,29 @@ scene->actors[4]->active = 0;
     
     
     double rotation = 0;
     double rotation = 0;
     
     
+    float animation_frame = 0;
+
     while (context->is_running){
     while (context->is_running){
         start = clock();
         start = clock();
         
         
         // scene->camera.FOV = context->current_frame;
         // scene->camera.FOV = context->current_frame;
         
         
-        scene->actors[1]->texture_frame++;
+        scene->actors[4]->texture_frame = rotation * 20;
+        scene->actors[0]->texture_frame = rotation * 15;
+
+
+        RI_euler_rotation_to_quaternion(&scene->actors[4]->rotation, (RI_vector_3){3.14159 / 2, -fabs(fmod(rotation, 3.14159)) + -3.14159 / 2, 0});
 
 
-        // RI_euler_rotation_to_quaternion(&scene->camera.rotation, (RI_vector_3){0, .7 + rotation / 10, 0});
-        RI_euler_rotation_to_quaternion(&scene->actors[1]->rotation, (RI_vector_3){0, rotation / 4, 0.7});
         RI_euler_rotation_to_quaternion(&scene->actors[3]->rotation, (RI_vector_3){0, rotation / 4, 0.7});
         RI_euler_rotation_to_quaternion(&scene->actors[3]->rotation, (RI_vector_3){0, rotation / 4, 0.7});
 // scene->actors[2]->position.z += delta_time;
 // scene->actors[2]->position.z += delta_time;
 
 
-        rotation += delta_time;
+        scene->actors[4]->position = (RI_vector_3){cos(fmod(rotation, 3.14159)) * 200, 0, sin(fmod(rotation, 3.14159)) * 200};
+
+    scene->actors[0]->position = (RI_vector_3){60, fabs(sin(fabs(rotation) * 6)) * 10, 180};
+
+
+
+        rotation += delta_time * .7;
 
 
         RI_render(scene);
         RI_render(scene);
 
 

BIN
src/libraries/libpitmap.so


+ 1 - 1
src/main/main.c

@@ -40,7 +40,7 @@ void debug(char *string, int debug_flag, ...){
 }
 }
 
 
 RI_texture* RI_load_image(char* filename){
 RI_texture* RI_load_image(char* filename){
-    PM_image* image = PM_load_image(filename, context.debug_flags & RI_DEBUG_PITMAP == 0 ? 0 : 1);
+    PM_image* image = PM_load_image(filename, (context.debug_flags & RI_DEBUG_PITMAP) == 0 ? 0 : 1);
 
 
     RI_texture* texture = RI_malloc(sizeof(RI_texture));
     RI_texture* texture = RI_malloc(sizeof(RI_texture));
 
 

BIN
textures/Untitled.bmp


BIN
textures/emoji_angry.bmp


BIN
textures/emoji_gif.bmp


BIN
textures/gordon_face_animated.bmp