znichola / minirt Goto Github PK
View Code? Open in Web Editor NEWA ray tracer with the phong lightning mode, multiple light sources, texture mapping and 4 primitive shapes; sphere, cylinder, plane and cone.
A ray tracer with the phong lightning mode, multiple light sources, texture mapping and 4 primitive shapes; sphere, cylinder, plane and cone.
poi_sphere
should be returning the distance to the poi from the origin, not an int 1/0. I tried changing the tests to fix, but can't run them to check.
Represent the currently selected object, and create the accessor functions that return a pointer to the position colour etc, whatever we might want to change via a keybind.
#include "float.h"
if (f < FLT_EPSILON)
foo();
// or man isgreater
orientation vector can't have any terms negative when loading from map, idk it's a strange bug as it's the same validation code as the other shapes which can...
Just an ides, idk if it's worth exploring, but we can make a lookup table to convert 0-255
int to float. As we'll be doing that quite a bit I think.
The t_image_data
is a struct that we need to free if we want to overwrite loaded image data, so something to free it!
They currently very strongly affect the direction the light is overall coming from but show little gradual effect. And the results just seem to be wrong.
t_intersection
Bonus !
For now...
internal structure needs to be able to hold texture, bmp and normal maps and the parsing should support any number of them.
The files are stored as a char* that is the string to the path of the file.
WARNING: ThreadSanitizer: data race (pid=59476)
Read of size 4 at 0x00010a0e82b4 by thread T8:
#0 get_ratio singletons.c:105 (miniRT:x86_64+0x100013fe8)
#1 pixel_to_ray render_world.c:44 (miniRT:x86_64+0x1000084b7)
#2 partial_render multithread.c:119 (miniRT:x86_64+0x100020c4c)
#3 thread_routine multithread.c:96 (miniRT:x86_64+0x100020b08)
Previous write of size 4 at 0x00010a0e82b4 by thread T7:
#0 get_ratio singletons.c:109 (miniRT:x86_64+0x1000140dd)
#1 pixel_to_ray render_world.c:44 (miniRT:x86_64+0x1000084b7)
#2 partial_render multithread.c:119 (miniRT:x86_64+0x100020c4c)
#3 thread_routine multithread.c:96 (miniRT:x86_64+0x100020b08)
As if synchronized via sleep:
#0 usleep <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2c5ae)
#1 thread_routine multithread.c:95 (miniRT:x86_64+0x100020ad4)
Location is global 'get_ratio.extents' at 0x00010a0e82b4 (miniRT+0x0001000482b4)
Thread T8 (tid=2616602, running) created by main thread at:
#0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2d8fd)
#1 start_threads multithread.c:68 (miniRT:x86_64+0x100020961)
#2 main main.c:49 (miniRT:x86_64+0x100003665)
Thread T7 (tid=2616601, running) created by main thread at:
#0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2d8fd)
#1 start_threads multithread.c:68 (miniRT:x86_64+0x100020961)
#2 main main.c:49 (miniRT:x86_64+0x100003665)
SUMMARY: ThreadSanitizer: data race singletons.c:105 in get_ratio
==================
ThreadSanitizer: reported 10 warnings
This is just to get some ideas down on paper, the possibility to modify stuff on the fly is kinda important for the dev process and also because it's cool.
// int scale_property(t_app *a, float *property, char *ctrl, int key, float factor)
scale_property(a, &a->l_origin.z, "my", e_mouse_right, 1);
This is the function we have now, we can "animate" any property with a change in one of the two mouse axis.
For instance the configuration above will modify the light's z value when the right button is held based on the distance the mouse has moved since the last frame.
scale_property(a, &a->sp_radius, "ky", e_key_s, 0.2)
Or for instance the radius is modified while the "s" key is held with the a scaling factor of 0.2.
The limitation of this interaction model is that each action must be mapped to a unique key and only happens while it's held.
this only seems to happen for the sphere
t_v3 pix_shader(t_scene *s, t_object *me, t_v3 poo, t_v3 poi)
{
t_v3 obj_col;
t_v3 ambiant;
t_v3 diffuse;
t_v3 specular;
t_v3 poi_norm;
poi_norm = v3_unitvec(v3_subtract(get_obj_pos(me), poi)); // need to pass this to other functions for opti!
obj_col = get_obj_emmision(me, poi);
ambiant = v3_multiply(s->ambiant.colour, s->ambiant.ratio);
t_v3 tmp = ORIGIN;
if (find_poi(s, v3_unitvec(v3_subtract(poi, get_light(s, 0)->position)), poi, &tmp))
return (col_multi(ambiant, obj_col));
else
{
diffuse = get_light_diffuse(s, 0, me, poi);
specular = get_light_specular(s, poo, poi, poi_norm);
}
// specular = ORIGIN; // uncomment to switch off spec component.
// diffuse = ORIGIN;
// ambiant = ORIGIN;
// obj_col = (t_v3){1.0f, 1.0f, 1.0f};
// return (col_multi(col_add(col_add(ambiant, diffuse), specular), obj_col));
return (col_add(col_multi(col_add(ambiant, diffuse), obj_col), specular)); // I think this is correct but it's not how the openGL site explains it.
}
We need to check if the light ray hits another object after a bounce, this can be kinda annoying, maybe the solution is the refactor find poi so it doesn't look for intersections with an object.
trace a ray from the mouse position at click and shoot a ray to select an object in world space.
The error messages are incorrect. It always outputs: invalid identifier on line ...
.
This is because i used some tricks to reduce the number of lines of code in the parse()
function.
➜ miniRT git:(refactor) cd tests
➜ tests git:(refactor) ✗ make
make archive -C ..
gcc -Wall -Wextra -Ofast -Iincludes/. -Imlx -Ilibft/includes -Ignl -c srcs/render/render_world.c -o objs/render/render_world.o
srcs/render/render_world.c:143:14: warning: unused function 'list_obj_content' [-Wunused-function]
static void *list_obj_content(t_list *obj)
^
1 warning generated.
mkdir -p tmp1 tmp2 tmp3
cd tmp1; ar -x ../mlx/libmlx.a
cd tmp2; ar -x ../gnl/libgnl.a
cd tmp3; ar -x ../libft/libft.a
ar -rcs libminirt.a tmp1/* tmp2/* tmp3/* objs/main.o objs/ui/destroy_window.o objs/ui/mouse_hooks.o objs/ui/keyboard_hooks.o objs/render/render_frame.o objs/render/put_pixel.o objs/render/render_sphere.o objs/render/trpg_colour.o objs/render/light.o objs/render/lerp_colour.o objs/render/the_moon.o objs/render/multithread.o objs/render/render_colour.o objs/render/render_world.o objs/maths/vector.o objs/maths/matrix.o objs/maths/poi_sphere.o objs/utils/debug_prints.o objs/utils/singletons.o objs/parsing/parse.o objs/parsing/parse_utils.o objs/parsing/parse_scalar.o objs/parsing/parse_properties.o objs/parsing/parse_objects1.o objs/parsing/parse_objects2.o objs/parsing/scene.o objs/parsing/parse_error.o objs/parsing/scene_add_object.o objs/primitives/sphere.o objs/primitives/plane.o objs/primitives/cylinder.o
rm -rf tmp1 tmp2 tmp3
gcc -Wall -Wextra -c -I. -I../includes/ -I../mlx -I../gnl -I../libft/includes -I/include -o main.o main.c
In file included from main.c:13:
./test.h:19:11: fatal error: 'check.h' file not found
# include "check.h"
^~~~~~~~~
1 error generated.
make: *** [main.o] Error 1
➜ tests git:(refactor) ✗
The green sphere is behind the camera, but it still shows up as in view. Interestingly it's normals seems to be inverted per pixel.
Found this bug while doing the shadows and was getting un-explained results.
The shadow at a pixel is calculated from the colour of the first intersecting object when going from the surface towards the light.
You can see that any objects along this line count as an intersection for this pixel which is not correct.
https://user-images.githubusercontent.com/12100623/227728794-09ea7a1c-efd3-4770-8045-4d6fc44204df.mov
emus order is mismatched so things are extremely wonky, it's impressive the level of mess C lets you get with.
The keybinding should be able to bind the selected object and print only the changes variable to the terminal correctly named.
Extending this: changes variables should be displayed on the screen.
it's a bug, needs fixing!
When the light is behind the sphere the sphere is actually illuminated from the front and it's inverted when moved behind. Probably an easy fix.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.