Advertisement

Simple RayTracing Shader

Started by April 26, 2019 04:10 AM
5 comments, last by MJP 5 years, 9 months ago

Hey guys. I am extremely interested in jumping into the whole RayTracing bandwagon to get with the times and increase the realism in my app. Problem is, this technology is so new, it is difficult to find any sort of tutorial on this sort of thing, even if it is a simple triangle. However, after doing some digging, the main method used is to use a Compute Shader. To be quite honest, I never used one. I mainly have been using only vertex shaders and fragment shaders. Compute shaders I found are not part of the rendering pipeline at all, but somehow feed information in parallel to the GPU to speed up processing, which adds more confusion because it only feeds information not rendering to the GPU. I could not find any sample code showing what this could look like. And the code that is out there are either too complex with way too much overhead in getting the bits needed in rendering a simple ray tracer, or are all Unity and Unreal Engine. Try Googling it yourself and its mainly all Unity and Unreal Engine, and very difficult to find anything. It gets to the point you end up finding Chinese sites.

So I gave up in the search and brought up this topic here. I was curious in knowing if any of you have any information in doing a simple Ray Tracer. What is a Compute Shader, and how exactly does a Compute Shader get used for Ray Tracing because I am still lost? Thanks in advance.

Simpliest rayshader would be that you draw a box (that has set up verts)

Now in fragment shader (depending on the need) you can calculate two points that intersect with with this box - that means you shoot a ray from camera position to the actual fragment position (all worldspace) knowing first hit and last hit, you may lets say sample a set of textures to find a proper match effect - consider cloud rendering you have a set of 32 textures (bottom to top) which define how much light passes through each of its pixels. So having start and end point (you need to define how much passes you need to sample ) - this means you go through 3d grid in the direction of (from end to start in cloud case) and sample each texture pixel, after the loop is done you end up with the final light intensity function (value) which tells you how much the final fragment (pixel) should be...

 

 

If you asked for some newer raytracing techniques which were introduced some time ago then i have no idea..

Advertisement
22 hours ago, Psychopathetica said:

Problem is, this technology is so new, it is difficult to find any sort of tutorial on this sort of thing, even if it is a simple triangle.

Get started here...

https://developer.nvidia.com/rtx/raytracing

If that doesn't do it for you, use search terms "NVIDIA RTX Ray Tracing"

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Simplest way to get into raytracing is with spheres and software rendering. I can't help you with compute shaders, but I wrote a software raytracer (sphere only) in C# with most of the features you'd expect (multiple light sources, reflection, transparent items) in about a day; takes a few minutes to get an HD image with 5 spheres in it. Anything more than drawing an handful of spheres will be a nontrivial challenge. Start here:

https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-ray-tracing

You need to know linear algebra (line/sphere intersection for sphere and line/plane intersection for anything else), that's pretty much it.

If you're looking to write an actual realtime renderer, I can't help you and there are few who can.

Are there examples of how a compute shader is used at least? Been stuck only using vertex and fragment shaders for years now.

 

[EDIT] I also found this awesome tutorial off of gamedev:

 

I haven't gone through it myself, but a lot of people say great things about Peter Shirley's Ray Tracing in a Weekend. It's meant to get you up to speed on the basics of ray tracing, and doesn't assume that you know the details.

This series of blog posts runs through the steps of creating a simple path tracer, starting with C++ and eventually working towards a GPU implementation.

This topic is closed to new replies.

Advertisement