Task 065: Efficient parametric surface for ray-tracing

Your task is to implement a general parametric surface as a new solid (ISolid) in our ray-tracer. The core if the assignment is to implement suitable accelerating structure for a triangle mesh, which is created using parametric surface definition.

parametric surface

Basis

Your solution can start with either the 048montecarlo project or the 048rtmontecarlo-script project from our repository grcis. In the latter case you will be able to define your scene using CS-script (one additional .cs file per scene).

Relevant interfaces and classes

  • ISolid - general interface for R-T solids, the basic functionality is the ability to compute intersections with rays. Your new class must implement this interface.
  • Sphere - an example of concrete simple solid, you can see what you will need to implement.
  • Expression - arithmetic expression able to be re-evaluated many times - you can substitute actual numbers for variables (see NCalc.dll).

If you use CS-script scene definition (048rtmontecarlo-script project), you do not have to deal with expression evaluation - you will simply use function delegate and lambda-expression to define parametric surface function.

What to modify

You are supposed to work with the MonteCarloRT.cs source file. You will create a new class public class Parametric : DefaultSceneNode, ISolid with the required functionality.
At least one instance of your new class should be used in the scene definition (CustomScene()). If you will prepare more demo scenes, you have to add more scene definition functions and to include them in a listbox (see the InitializeScenes() function). Your scene-construction function can accept a text parameter Param: from the form.

Your new class (surface) has to be able to define parametric functions in the constructor. Use either string symbolic expression with the help of the toolkit NCalc.dll or (in case of CS-script defined scenes) you can easily use function delegates and lambda-expression. The domain of the parametric variables u and v can be explicitly defined or fixed to <0.0,1.0>2.

If you want to define your scene using CS-script, you have to use the 048rtmontecarlo-script project, your scene-definition script will be in a separate .cs file (see the data/rtscenes/ for inspiration, scripting instructions). Scripts have access to the text paramter Param: as well.

Ideas

Decompose the parametric surface into high number of small triuangles (connected into one continuous triangle-mash). Efficient ray-mesh intersectiong algorithms: KD-tree or R-tree (BVH) or Octree. KD-tree and Octree can (usually) contain duplicate triangles, R-tree does not need duplicates. Please use the "bucket-tree" technique for higher efficiency: leaf nodes contain 1 to N triangles for some reasonable number N, e.g. 2 <= N <= 16 (it is a good idea to declare N as a parameter and study the efficiency while increasing it).

Beware: Your code must be re-entrant, it will be executed in a multi-thread environment. You are not allowed to store any temporary (intersection-specific) values in the class instance! Accelerating data structure should be built at the beginning, after this init-phase the tree must be treated as "read-only" and thus shareable.

Geometric support

There are useful support functions in the class Geometry: RayTriangleIntersection(), RayBoxIntersection() or RayBoxIntersectionInv(). Use them for ray intersections with triangles or bounding boxes (AABB).
Don't forget to increment counters CSGInnerNode.countBoundingBoxes or CSGInnerNode.countTriangles - the will show number of needed instersections (with AABB-s or triangles).

Literature

Intermediate to advanced:

What to hand in

You must send the modified file MonteCarloRT.cs. You can include a couple of nice pictures.

In case you will be using 048rtmontecarlo-script project, you must include your scene definition[s] in separate file[s]. Script format: see the data/rtscenes/ directory in the repository.

Deadline

Hand in the assignment before: 1. 7. 2018

Points

Basis: 30 points (general parametric surface, reasonable acceleration, shading - correct normal vectors),
Bonus points: for more interesting surfaces, efficient computation, configurable 2D texture coordinates, etc.

Project

Visual Studio project: 048rtmontecarlo or 048rtmontecarlo-script

Source file

Modify and hand in the source file: MonteCarloRT.cs
Edit your name in the InitializeScenes() function!
Don't forget the .cs script if you are defining your scene using CS-script.
You can attach a couple of nice pictures in a smaller resolution.


Copyright (C) 2013-2018 J.Pelikán, last change: 2018-05-23 15:13:41 +0200 (Wed, 23 May 2018)