This website uses cookies to help us give you the best experience when you visit our website. By continuing to use this website, you consent to our use of these cookies. You can learn more here.

Ray Tracing the Next Week: "4. Solid Textures"

Play
Frames: 0
Change Size

1:1

4:3

16:9

Fullscreen Mode

by abasilak

Description

0

Implementation of "Solid Textures" Chapter from https://raytracing.github.io/books/RayTracingTheNextWeek.html

Rayground API Reference


Scene Description


Scene structure is given in JSON format

Settings

Type Name Description
uint depth recursion depth of the simulation.
bool save_first_bounce enable the storing of first bounce intersection data and providing them in the Post Processing shader.

Objects

zero or more objects with a combination of the following properties

Type Name Description
string type
"quad" a unit quad, centered at (0,0,0) and facing -Z axis.
"cube" a unit cube, centered at (0,0,0).
"sphere" a unit sphere, centered at (0,0,0).
"triangles" a raw vertex buffer of a triangular mesh.
float[16] model model transformation (overrides other transformations).
float[4] rotate object rotation. (XYZ rotation axis, rotation angle in degrees).
float[3] translate object translation.
float[3] scale object scale.
float radius sphere radius (only valid for spheres).
float[] vertices an array of vertices in XYZ float format (only valid for triangles).
float[4] material_property0 .. 7 user specified material properties for the object.

Shader Stages Constants


Shader stages constants

Type Name Description
vec2 rg_Canvas canvas resolution in pixels.
vec2 rg_Pixel pixel coordinates relative to the lower left corner of the canvas.
float rg_Time fractional time in seconds since simulation start. Updates in every frame.
int rg_Frame current frame counter from previous compile. Updates in every frame.
ivec4 rg_Mouse .xy current mouse position if clicked, else (-1, -1), .zw previous click position. Updates on mouse press.
int rg_Depth current ray depth iteration. Starts at 0 and gets incremented after each ray intersection wave.
uvec4 rg_Seed cpu generated seed values. Updated for each stage.
float RG_RAY_MAX_DISTANCE 1.e27
float RG_RAY_ACTIVE_FLAG 1.0
float RG_RAY_INACTIVE_FLAG 0.0
float RG_PI 3.14159265359
float RG_TWO_PI 6.28318530718
float RG_FOUR_PI 12.5663706144
float RG_INV_PI 0.31830988618
float RG_INV_TWO_PI 0.15915494309
float RG_INV_FOUR_PI 0.07957747154

Ray Hit/Miss Stage Inputs


Ray data that triggered the hit or miss shader

in vec4 rg_PrevRayDirection previous ray direction (.xyz direction, .w max travel distance).
in vec4 rg_PrevRayOrigin previous ray origin (.xyz origin, .w RG_RAY_ACTIVE_FLAG or RG_RAY_INACTIVE_FLAG).
in vec4 rg_PrevAccumulation previous accumulation color values (.rgb color values, .a additive blending factor).
in vec4 rg_PrevPayload0 previous ray payload values.

Ray Gen/Hit/Miss Stage Outputs


Output variables that specify and pass a ray to the next stage of the pipeline

out vec4 rg_Accumulation output accumulation color values (.rgb values, .a additive blending factor).
out vec4 rg_Payload0 output ray payload values.
out vec4 rg_RayDirection output ray direction (.xyz direction, .w max travel distance).
out vec4 rg_RayOrigin output ray origin (.xyz origin, .w RG_RAY_ACTIVE_FLAG or RG_RAY_INACTIVE_FLAG).

Ray Generation Stage


Ray generation shader stage input/output variables and functions

void rg_generate ( ) entry point signature.
func vec4 rg_Random(uint index, uint seed0, uint seed1) Obtain 4 random values from a counter-based pseudo-random sequence.
func bool rg_TraceOcclusion (vec3 origin, vec3 direction, float length) Trace the given ray segment against the scene and test for intersections.

Ray Hit Stage


Ray hit shader stage input/output variables and functions

void rg_hit ( ) entry point signature.
in vec3 rg_Normal geometric normal of the intersected primitive.
in vec3 rg_Hitpoint ray hit position in world space coordinates.
in vec3 rg_BaryCoords the barycentric coordinates on the intersection with the primitive.
in vec2 rg_TexCoords the interpolated texture coordinates of the intersected primitive.
in int rg_MaterialID the primitive's material ID.
in int rg_ShapeID the primitive's shape ID.
in int rg_PrimitiveID the primitive ID.
in float rg_RayDistance the ray segment length.
func vec4 rg_MaterialProperty0 .. 7(int materialID) the material properties, as specified in the scene description for the given material ID.
func vec4 rg_Random(uint index, uint seed0, uint seed1) Obtain 4 random values from a counter-based pseudo-random sequence.
func bool rg_TraceOcclusion (vec3 origin, vec3 direction, float length) Trace the given ray segment against the scene and test for intersections.

Ray Miss Stage


Ray miss shader stage input/output variables and functions

void rg_miss ( ) entry point signature.
func vec4 rg_Random(uint index, uint seed0, uint seed1) Obtain 4 random values from a counter-based pseudo-random sequence.
func bool rg_TraceOcclusion (vec3 origin, vec3 direction, float length) Trace the given ray segment against the scene and test for intersections.

Post Processing Stage


Post processing stage input/output variables and functions

void rg_post_process ( ) entry point signature.
out vec4 rg_Pixel final pixel color to be presented.
rg_Image2D rg_AccumulatedImage a 2D image buffer with the accumulated values (after blending operation).
rg_Image2D rg_Payload0Image a 2D image buffer with the payload0 values from the previous stage.
rg_Image2D rg_FirstBounceRayOriginImage a 2D image buffer with the first generated ray origin. These values are provided by the backend if specified in the scene description.
rg_Image2D rg_FirstBounceRayDirectionImage a 2D image buffer with the first generated ray direction. These values are provided by the backend if specified in the scene description.
rg_Image2D rg_FirstBounceRayDepthImage a 2D image buffer with the first bounce depth (distance to the closest intersected primitive). These values are provided by the backend if specified in the scene description.
rg_Image2D rg_FirstBounceNormalsImage a 2D image buffer with the first bounce normals (the normal of the closest intersected primitive). These values are provided by the backend if specified in the scene description.
rg_Image2Di rg_FirstBounceMaterialID a 2D image buffer with the first bounce material ID (the material ID of the closest intersected primitive) stored in the R channel. These values are provided by the backend if specified in the scene description.
rg_Image2Di rg_FirstBounceTriangleID a 2D image buffer with the first bounce triangle ID (the triangle ID of the closest intersected primitive) stored in the R channel. These values are provided by the backend if specified in the scene description.
func vec4 rg_ImageFetch2D(rg_Image2D image, ivec2 coords) a 2D image fetch from the specified pixel coordinates.
func ivec4 rg_ImageFetch2Di(rg_Image2Di image, ivec2 coords) a 2D image fetch of integer data from the specified pixel coordinates.
Execute (Ctrl-S)
Submit Changes
Download
Export Image (Ctrl-L)