Browse Source

added quadratic curve shader, fixed issue where uv coords would wrap when they shouldn't

Iver 4 months ago
parent
commit
5693d4a20d

BIN
build/librasteriver.so


BIN
build/main.bin


BIN
compiled_libs/librasteriver.so


+ 1 - 1
src/headers/custom_types.h

@@ -74,7 +74,7 @@ typedef struct {
     uint64_t flags;
     RI_vector_2f uv_loop_multiplier;
     RI_vector_2f texture_render_size;
-    double (*shader_function_pointer) (int pixel_x, int pixel_y, RI_vector_3f position, RI_vector_3f normal, RI_vector_2f uv, uint32_t color);
+    double (*shader_function_pointer) (int pixel_x, int pixel_y, RI_vector_3f v_pos_0, RI_vector_3f v_pos_1, RI_vector_3f v_pos_2, RI_vector_3f normal, RI_vector_2f uv, uint32_t color);
 } RI_material;
 
 typedef struct { // An entity that has an mesh, transform, materials, etc

+ 3 - 3
src/launch_program/main.c

@@ -1,9 +1,9 @@
 #include "../headers/rasteriver.h"
 #include <time.h>
 
-double shader_function(int pixel_x, int pixel_y, RI_vector_3f position, RI_vector_3f normal, RI_vector_2f uv, uint32_t color){
-    if (color == 0xFFFFFFFF) return 0;
-    else return 1;
+double shader_function(int pixel_x, int pixel_y, RI_vector_3f v_pos_0, RI_vector_3f v_pos_1, RI_vector_3f v_pos_2, RI_vector_3f normal, RI_vector_2f uv, uint32_t color){
+    if (uv.y > uv.x * uv.x) return 1;
+    else return 0;
 }
 
 int main(){

+ 9 - 3
src/library/rasteriver.c

@@ -1140,8 +1140,14 @@ int RI_render(RI_scene *scene, RI_texture *target_texture, int clear_texture){
                             uy *= (current_face->parent_actor->transform.scale.y / mat->texture_render_size.y);
                         }
 
-                        ux = mod(ux, 1.0);
-                        uy = mod(-uy, 1.0);
+                        if (mat->flags & RI_MATERIAL_USE_UV_LOOP_MULTIPLIER || mat->flags & RI_MATERIAL_USE_UV_RENDER_RESOLUTION){
+                            ux = mod(ux, 1.0);
+                            uy = mod(-uy, 1.0);
+                        } else{
+                            ux = fmax(fmin(ux, 1.0), 0.0);
+                            uy = fmax(fmin(1.0 - uy, 1.0), 0.0);
+                        }
+                        
 
                         RI_vector_2 texel_position = {mat->texture_reference->resolution.x * ux, mat->texture_reference->resolution.y * uy};
                         
@@ -1172,7 +1178,7 @@ int RI_render(RI_scene *scene, RI_texture *target_texture, int clear_texture){
                     
                     double shader_result = 1;
                     
-                    if (current_face->material_reference->shader_function_pointer != NULL) shader_result = current_face->material_reference->shader_function_pointer(x, y, (RI_vector_3f){0, 0, 0}, normal, (RI_vector_2f){ux, uy}, pixel_color);
+                    if (current_face->material_reference->shader_function_pointer != NULL) shader_result = current_face->material_reference->shader_function_pointer(x, y, *pos_0, *pos_1, *pos_2, normal, (RI_vector_2f){ux, uy}, pixel_color);
 
                     // set alpha after checking shader result becuase things with alpha 0 should still depth write