Ray tracing support for Ogre 2.2+

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Ray tracing support for Ogre 2.2+

Post by dark_sylinc »

RenderSystem is the wrong place to do it. It's too low level.

See VctVoxelizer (Components/Hlms/Pbs/include/Vct/OgreVctVoxelizer.h) and see VctCascadedVoxelizer (Components/Hlms/Pbs/include/Vct/OgreVctCascadedVoxelizer.h) the latter which accepts static and dynamic objects to generate the GI.

Of course you'd need to add RenderSystem interfaces to perform the RayTracing API calls, but RayTracing itself should be encapsulated somewhere else.

The only thing I am wondering is that VctCascadedVoxelizer requires manually adding each Item to be tracked; while I am thinking that is perhaps a mistake; and GI per-object settings should live in Item; while VctCascadedVoxelizer gets attached to SceneManager to be the active GI.

But overall RayTracing should be encapsulated into its own interface that is plugged into SceneManager and makes the necessary RenderSystem calls.

Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 226
Joined: Thu Oct 14, 2010 12:30 pm
x 56

Re: Ray tracing support for Ogre 2.2+

Post by Hotshot5000 »

As I was playing with reconstructing from depth I realised that the far corner normals provided in the reconstruct from depth sample are interpolated in the cameraDir variable passed from the vertex to fragment shader. The only issue is that in the compute shader I am not aware of any way to do this interpolation automatically.

So that would mean that I need to do the interpolation myself based on the x, y position in clip space provided by the gl_GlobalInvocationID.xy. Kind of like the barycentric triangle coords but using the screen quad. Is this worth it or will it kill performance?

Is there an easier way to get the cameraDir(farCorners) available in the compute shader ready to be used as viewRays to be multiplied with linearDepth?
Just using the inverseViewProj matrix doesn't seem to work as the x, y positions don't seem to take into account the actual view frustum with the farCorners when unprojected.

Also I need all of this to end up in world space as the ray.origin and ray.direction are in world space in order to trace the rays correctly.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Ray tracing support for Ogre 2.2+

Post by dark_sylinc »

You'll have to do the interpolation by hand.

This is quite easy. The unoptimized formula is:

Code: Select all

result =
lerp(
  lerp( v00, v10 ), fract( uv.x ),
  lerp( v01, v11 ), fract( uv.x ),
  fract( uv.y ) );

Where fract returns the decimal part, e.g. fract( 13.456 ) = 0.456

The formula can be optimized by expanding it and cancelling some terms and use algebra properties to reduce the number of multiplies & additiions, but this form is the most intuitive to understand what's going on.

You'll have to send all 4 corners (which are normally passed to the "normals" vertex component) from the compute shader.

Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 226
Joined: Thu Oct 14, 2010 12:30 pm
x 56

Re: Ray tracing support for Ogre 2.2+

Post by Hotshot5000 »

Thanks for the support! Now it looks like the cube projects a shadow onto the plane using rays.

Shadow texture
https://imgur.com/iHyOu84
Red is where the rays didn't hit anything from the reconstructed pos from depth. White represents contact with a triangle.

Normal rendertarget:
https://imgur.com/Si8aDEv

Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 226
Joined: Thu Oct 14, 2010 12:30 pm
x 56

Re: Ray tracing support for Ogre 2.2+

Post by Hotshot5000 »

Didn't have much time to continue working on this but I managed to get the dynamic shadows showing:

https://imgur.com/a/ClHQE8n

Right now it's only refitting the AS as it assumes that the objects in the scene don't change position too much (right now they only rotate around an axis) and it's not optimized in any way but at least there is something on the screen. The red background is for intersection misses as it hits no objects.

I will continue the work here and keep posting updates when I get something interesting working.

EDIT: Forgot to mention this is working only for directional light.

Post Reply