CPU Raytracer

Started by
11 comments, last by Turbo14 6 years ago

I wanted to show my WIP CPU raytracer. I probably won't implement too many more features. I just want something that looks decent with a little GI and AO and a few dynamic lights and textures. The video is rendered at 160x90 and captured at 320x180. It runs around 20fps on one thread on an i3-6320. Not sure if that is slow or fast for what I have. I plan on making an attempt to add multi-threading. I can't use SIMD since this was made in Unity.  At least I don't think there is support for it. I'm making it in Unity so making games is easier since I won't have to make a whole engine.

 

https://www.youtube.com/watch?v=iL8z04nZ0J8

 

EDIT: I'm gonna post all future updates here.

New video with improved frame-rate and overall better looking than the original.

https://youtu.be/tXWXOWXnU50

Sorry about the image quality... YouTube took a dump on it. I had to forget the idea of using SIMD since using .Net 4.6 breaks the raycasting against complex mesh colliders. Still need to work on the aliasing.

Color absorb values seem off. I think ambient occlusion is show better here, but dark box edges are back. I just gotta send transform values to my filter to brighten them.

https://imgur.com/rajEQky

Better AO example: https://imgur.com/gNPIjNM

Unfortunately, I think the only way I'm gonna get this to run at higher resolutions with playable frame rates is by moving it to the GPU since I can't thread my trace code using Unity.

 

EDIT: 4/13/2018 - I'm wondering if I can use Embree to make a library that I can call from within Unity. Should be faster than Unity's ray-cast. Anyway here's a new vid with some bouncing balls. I only do GI/AO every other pixel now so they have a little reduced effect... also increased contrast. I'm now blurring the whole render which makes it a little fuzzy. if I don't, there's flickering around object edges when moving around. Video is at 160x88.

https://youtu.be/_OC3_BwELzk

 

4/15/2018 - Using a small amount of help from the GPU I was able to make it higher resolution, but from the crap youtube compression it still looks low rez so here are some screens too..This was rendered at 1080p and captured at half that. Trying to figure out a solution for shadows fading out at distances larger than a few meters.

High Res AO Example-https://imgur.com/2nKISzW

High Res GI Example-https://imgur.com/1oe4BFd

 

 

Advertisement

How do you calculate GI and AO (it seems quite smooth to what I'm used with unbiased rendering)? Can you give us some bigger screenshot (full res - like FullHD)?

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Depending on your Unity version you might be able to switch to "C#6 & .NET 4.6" which is in an experimental state according to this.

Then you could use SIMD instructions.

I'd be also interested in how many sample/pixel you actually trace to get such a smooth result.

Highres screenshot ++

Here are some higher rez screens. I only use 1spp, the rest of the work is done in the post process filter with some gbuffer data. I've been trying to set up a multi process renderer since I don't want to deal with the headache of multithreading in unity without being able to use their API from threads other than the main one, but the latency is pretty bad.. I'm bad at networking so that's probably not good either. I've never really made amultithreaded app, so that's why I'd rather do multi process so I don't have to deal with the locking and crap which I honestly think would slow it down instead of speeding it up. I think the latency is mostly due to sending large udp packets from the ray trace apps to the main app that does the post processing and input. I'll have to keep working on it or maybe switch to TCP or maybe I should look for some sort of image streaming library. That's probably what I should have done as the first option.

Anyways I could use some suggestions on the best way to make it use multiple threads/processes.

https://imgur.com/tN1qYF8

https://imgur.com/xXTmQ4V

Working on a 1080p render atm... taking a bit.

I'm thinking of maybe trying to port this to Radeon-Rays but I know nothing about it.

 

Here's a 1080p render... with only 1spp the color bleeding is hardly noticeable.

https://imgur.com/j7wYnlc

I think I need to do a micro render pre-pass and then blend that with the higher res render to preserve color bleeding for higher resolutions.

I'm having problems keeping creased corners and bright edges at the same time with my filter. If I have bright edges I also have bright looking creases. And if I have dark creases I also have dark edges.

As you might have guessed, the smoothness is due to a very liberal blur filter while attempting to keep edges and corners.

Here's another shot after some tweaking to reduce ugly edges on the box.

https://imgur.com/aAecpmc

Shot with improved color bleeding from blended pre pass micro render.

https://imgur.com/3hVaik4

I was able to do a little multithreading since my blur filter uses none of the unity API, and I also only trace 1/4 of the screen per frame, so there is some trearing with fast movements. I also decreased the screen resolution by 10 pixels vertically from the original video. As a result it now runs at 85-90 FPS at 160x80 resolution. I would keep the vertical res at 90 but it causes crashes if I don't have a vertical resolution divisible by 4 as a whole number. 160x80 is hardly an enjoyable resolution, but it's still fun to mess with. Maybe I can upscale it and apply my blur filter to that.

Shot of my progress.

https://imgur.com/4uoHdUV

Also, bonus shot, pre-filter.

https://imgur.com/SBmT1mp

On 4/6/2018 at 5:59 AM, Valdiralita said:

Depending on your Unity version you might be able to switch to "C#6 & .NET 4.6" which is in an experimental state according to this.

Then you could use SIMD instructions.

I just tried dong this but it slowed down my program by a significant amount.

Here's an example what I was doing. Never really used simd so not sure what I'm doing that slowed it down.


Color SimdMulColor(Color c, float s)  

{
        Vector4f v = new Vector4f(c.r, c.g, c.b,1f);

        v *= new Vector4f(s, s, s, 1f);

        return new Color(v.X, v.Y, v.Z);
    }

Edit: Wait I tried using the mono simd while using visual studio. I wonder if the system.numerics will speed it up.

After reading a bit about how simd works best, I'm not really sure I can adjust my code to benefit from it.

This topic is closed to new replies.

Advertisement