Browse Source

fixed math issue with uv render resolution tiling, changed example scene

IverMartinson 5 months ago
parent
commit
9d21a7a7ad
5 changed files with 10 additions and 5 deletions
  1. BIN
      build/librasteriver.so
  2. BIN
      build/main.bin
  3. 3 2
      src/headers/custom_types.h
  4. 1 1
      src/launch_program/main.c
  5. 6 2
      src/library/rasteriver.c

BIN
build/librasteriver.so


BIN
build/main.bin


+ 3 - 2
src/headers/custom_types.h

@@ -60,8 +60,8 @@ typedef enum {
     RI_MATERIAL_DONT_DEPTH_TEST = ((uint64_t)1 << 8), // should check Z buffer (if 1, render on top of everything)
     RI_MATERIAL_DONT_DEPTH_WRITE = ((uint64_t)1 << 9), // should write to the Z buffer (if 1, render behind everything)
     RI_MATERIAL_DOUBLE_SIDED = ((uint64_t)1 << 10), // ignore backface culling
-    RI_MATERIAL_USE_UV_LOOP_MULTIPLIER = ((uint64_t)1 << 11), // use multiplier that tells how many times to loop the texture
-    RI_MATERIAL_USE_UV_RENDER_RESOLUTION = ((uint64_t)1 << 12), // use custom resolution that textures always appear as (scaling just tiles the texture)
+    RI_MATERIAL_USE_UV_LOOP_MULTIPLIER = ((uint64_t)1 << 11), // use multiplier that tells how many times to loop the texture (scaling also scales texture)
+    RI_MATERIAL_USE_UV_RENDER_RESOLUTION = ((uint64_t)1 << 12), // use custom resolution that textures always appear as (scaling doesn't change texture)
 } RI_material_flags;
 
 typedef struct {
@@ -96,6 +96,7 @@ typedef struct {
     RI_material* material_reference;
     int min_screen_x, max_screen_x, min_screen_y, max_screen_y;
     int should_render;
+    RI_actor* parent_actor;
 } RI_renderable_face;
 
 typedef struct {

+ 1 - 1
src/launch_program/main.c

@@ -43,7 +43,7 @@ int main(){
     wall_material->flags = RI_MATERIAL_DOUBLE_SIDED | RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_USE_UV_RENDER_RESOLUTION;
     wall_material->albedo = 0xFF7777FF;
     wall_material->texture_reference = wall_texture;
-    wall_material->texture_render_size = (RI_vector_2f){200, 400};
+    wall_material->texture_render_size = (RI_vector_2f){25, 50};
 
     RI_material* test_object_material = &materials[2];
     test_object_material->flags = RI_MATERIAL_HAS_TEXTURE;

+ 6 - 2
src/library/rasteriver.c

@@ -518,6 +518,8 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
 
                 RI_renderable_face *cur_r_face = &scene->faces_to_render[current_renderable_face_index];
 
+                cur_r_face->parent_actor = current_actor;
+
                 cur_r_face->material_reference = current_actor->material_reference;
 
                 cur_r_face->position_0 = current_actor->mesh_reference->vertex_positions[vert_pos_0_index];
@@ -701,6 +703,8 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
 
                         RI_renderable_face *cur_r_split_face = &scene->faces_to_render[scene->face_count + current_split_renderable_face_index];
 
+                        cur_r_split_face->parent_actor = current_actor;
+
                         cur_r_split_face->should_render = 1;
 
                         cur_r_split_face->material_reference = cur_r_face->material_reference;
@@ -884,8 +888,8 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
                         }
 
                         if (mat->flags & RI_MATERIAL_USE_UV_RENDER_RESOLUTION){
-                            ux *= mat->texture_reference->resolution.x / mat->texture_render_size.x;
-                            uy *= mat->texture_reference->resolution.y / mat->texture_render_size.y;
+                            ux *= (current_face->parent_actor->transform.scale.x / mat->texture_render_size.x);
+                            uy *= (current_face->parent_actor->transform.scale.y / mat->texture_render_size.y);
                         }
 
                         ux = mod(ux, 1.0);