Skip to content

Ray Tracer

The Ray Tracer is a class that handles emitting rays and collecting scene information into different buffers.

Important

The Ray Tracer needs a Ray Tracing Camera to be able to render a scene.


Creating a Ray Tracer


RayTracer RayTracer.new(RayTracingCamera camera, int maxBounces? [=1], table<Shader> shaders?, table<PostProcessingShader> postProcessingShaders?, RaycastParams raycastParams?)

Creates a new RayTracer. camera is the camera that will be used to render the scene. maxBounces? is the maximum number of bounces that will be performed. If maxBounces is not provided, 1 will be used. shaders? is a table of shaders that will be used to render the scene. postProcessingShaders? is a table of post-processing shaders that will be used to render the scene. raycastParams? is the raycast parameters that will be used to raycast the scene.


Properties


RayTracingCamera Camera

The RayTracingCamera that is used to render the scene.


int MaxBounces

The maximum number of bounces that will be performed. Defaults to 1.


table<Shader> Shaders

The shaders that will be used to render the scene. Defaults to an empty table.


table<PostProcessingShader> PostProcessingShaders

The post-processing shaders that will be used to render the scene. Defaults to an empty table. Post-processing shaders are applied after the scene is rendered.


dict {2D table<Color3> Color, 2D table<float> Depth, 2D table<Color3> Normal} Buffers

The buffers that will be used to render the scene. Each buffer is a 2D table where the first index is the x-coordinate and the second index is the y-coordinate. Buffers are usually accessed by post-processing shaders.


Methods


void ClearBuffers()

Clears all buffers of the RayTracer.


void CreateBuffer(string name, default [=0])

Creates a new empty buffer with the given name. default is the default value that will be used for all pixels in the buffer and will be used to initialise TracedRay.Out when rendering. If default is not provided, 0 will be used. The default value can be any type.

Tip

Buffers created before calling RayTracer.Render can be written to by vertex shaders during the render process.


void RemoveBuffer(string name)

Removes the buffer with the given name.


2D table<Color3> Render(...)

Clears all buffers and renders the scene. Returns the color buffer after the render is complete. ... is the arguments that will be passed to the shaders.

Note

Post-processing shaders are not applied in this method. To apply post-processing shaders, use the PostProcess method after the initial render is complete.


dict PostProcess(...)

Applies post-processing shaders to the scene. ... is any number of arguments passed to the post-processing shaders. Returns all buffers after the post-processing shaders are applied.


Color3 GetPixel(int x, int y)

Gets the color of the pixel at x, y from the color buffer.


void SetPixel(int x, int y, Color3 color)

Sets the color of the pixel at x, y in the color buffer.


Color3 VisualizeNormal(Vector3 normal)

Visualizes a unit vector normal as a color.