|
Post by bitwise on Aug 30, 2019 4:21:03 GMT
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))
|
|
zass
New Member
Posts: 3
|
Post by zass on Aug 30, 2019 16:46:11 GMT
|
|
|
Post by Richard Moss on Aug 31, 2019 16:00:25 GMT
Hello, 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. There's probably tons you can do - one person is claiming 3 seconds render for a very complex scene (in JavaScript of all things!) but this sort of maths is still a little over my head and so while I have ran a performance profiler on my code, I haven't spend a large amount of time trying to optimise it, save implementing the suggestions above that other users made. 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. Regards; Richard Moss
|
|
|
Post by Jamis on Sept 2, 2019 1:28:15 GMT
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...) - Jamis
|
|