Hello everyone. I have a problem. My programm on C executes very long time. What can cause this problem? When it starts it's progress goes very fast, but somewhere on y > 10 it's time to compute pixels stands very big. I think it all caused by that i dont free memory for(matricies, and stuff) or maybe processor each time that it returns to this thread decrease time for doing this work with this process. I really dont know what can i do (width height(100, 50))
In a similar vein, I wrote my ray tracer in C# too so I don't have anything concrete to offer regarding C. The very first optimisation I did was exactly the same as zass , e.g. parallelising the render to speed that up.
In another post, chrisd suggests caching the inverse of a shape's transform and I found that had an phenomenal effect at improving the performance. In my code, when a transform is applied to a shape I pre-calculate the inverse and store both - so many key functions require the inverse that is well worth doing.
One of the bonus chapters covers bounding boxes and volume hierarchies. This again provides a massive improvement for scenes involving lots of shapes, but you'll want to compute these only once as well.
ascotti also makes an interesting suggestion regarding the normalising of imported object files. This can be very useful for models that are massive, as firstly they'll slow down rendering substantially (unless you have done some of the previous tips) and secondly you won't be able to see all the detail and it can be a bit of a PITA to rotate and size these. Having them normalised to fit your scene makes that so much easier.
One thing I do want to try but haven't gotten around to yet is to use SIMD stuff that is available in more modern versions of C#. Never tried that before so no idea how it works.
bitwise -- can you share a description of the scene you're trying to render? If the scene has a lot of objects, it might be very slow to render. If the scene is simple, though, and you're getting slow renders, there might be something else at work.
Also, you mentioned that you're implementing the tracer in C. If you are allocating memory dynamically, you need to make sure to deallocate the memory when you're done with it, otherwise your process will grow very very large and your system will start to swap, which will slow things down a lot. (Note that the specific meaning of "when you're done with it" will depend on your architecture...)