Documentation ¶
Index ¶
- type BvhNode
- func (n *BvhNode) GetMeshIndex() (index uint32)
- func (n *BvhNode) GetPrimitives() (firstPrimIndex, count uint32)
- func (n *BvhNode) OffsetChildNodes(offset int32)
- func (n *BvhNode) SetBBox(bbox [2]types.Vec3)
- func (n *BvhNode) SetChildNodes(left, right uint32)
- func (n *BvhNode) SetMeshIndex(index uint32)
- func (n *BvhNode) SetPrimitives(firstPrimIndex, count uint32)
- type Camera
- type CameraDirection
- type EmissivePrimitive
- type EmissivePrimitiveType
- type Frustrum
- type MaterialNode
- type MeshInstance
- type Scene
- type TextureMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BvhNode ¶
Bvh nodes are comprised of two Vec3 and two multipurpose int32 parameters whose value depends on the node type:
- For non-leaf nodes (top/bottom) BVH they are both >0 and point to the L/R child nodes - For top BVH leafs:
- left W is <= 0 and points to the mesh instance index
- For bottom BVH leafs:
- left W is <= 0 and point to the first triangle primitive index
- right W is >0 and contains the count of leaf primitives
func (*BvhNode) GetPrimitives ¶
Get primitive index and count.
func (*BvhNode) OffsetChildNodes ¶
Add offset to indices of child nodes.
func (*BvhNode) SetChildNodes ¶
Set left and right child node indices.
func (*BvhNode) SetMeshIndex ¶
Set mesh instance index.
func (*BvhNode) SetPrimitives ¶
Set primitive index and count.
type Camera ¶
type Camera struct { Position types.Vec3 LookAt types.Vec3 Up types.Vec3 Pitch float32 Yaw float32 ViewMat types.Mat4 ProjMat types.Mat4 Frustrum Frustrum // Camera FOV FOV float32 // Adjust the frustrum so that Y is inverted InvertY bool }
The camera type controls the scene camera.
func (*Camera) InvViewProjMat ¶
func (*Camera) Move ¶
func (c *Camera) Move(dir CameraDirection, offset float32)
Move camera towards a specific direction using a particular offset.
func (*Camera) SetupProjection ¶
Setup camera projection matrix.
type CameraDirection ¶
type CameraDirection uint8
Constants for the directions that cameras can move.
const ( Up CameraDirection = iota Down Left Right Forward Backward )
type EmissivePrimitive ¶
type EmissivePrimitive struct { // A transformation matrix for converting the primitive vertices from // local space to world space. Transform types.Mat4 // The area of the emissive primitive. Area float32 // The triangle index for this emissive. PrimitiveIndex uint32 // The material node index for this emissive. MaterialNodeIndex uint32 // The type of the emissive primitive. Type EmissivePrimitiveType }
An emissive primitive.
type EmissivePrimitiveType ¶
type EmissivePrimitiveType uint32
The type of an emissive primitive.
const ( AreaLight EmissivePrimitiveType = iota EnvironmentLight )
type Frustrum ¶
Stores the ray directions at the for corners of our camera frustrum. It is used as a shortcut for generating per pixel rays via interpolation of the corner rays. While we don't care about the W coordinate we use Vec4 since opencl provides a vectorized float4 type
type MaterialNode ¶
type MaterialNode struct { // Layout: // [0] type // [1] left child // [2] right child or transmittance texture // [3] bump map, reflectance, specularity or radiance texture Union1 [4]int32 // Layout: // [0-3] reflectance or specularity or radiance // [0-3] RGB intIORs for dispersion // [0] mix weight Union2 types.Vec4 // Layout: // [0-3] transmittance // [0-3] RGB extIORs for dispersion Union3 types.Vec4 // Layout: // [0] internal IOR // [1] external IOR // [2] roughness or radiance scaler Union4 types.Vec3 // Layout: // [0] roughness texture Union5 [1]int32 }
Materials are represented as a tree where nodes define a blending operation and leaves define a BxDF for the surface. This allows us to define complex materials (e.g. 20% diffuse and 80% specular). In order to use the same structure for both nodes and leaves we define a "union-like" field whose values depend on the node type.
type MeshInstance ¶
type MeshInstance struct { MeshIndex uint32 // The BVH tree root for the mesh geometry. This is shared by all // instances of the same mesh. BvhRoot uint32 // A transformation matrix for positioning the mesh. Transform types.Mat4 // contains filtered or unexported fields }
The MeshInstance structure allows us to apply a transformation matrix to a scene mesh so that it can be positioned inside the scene.
type Scene ¶
type Scene struct { BvhNodeList []BvhNode MeshInstanceList []MeshInstance MaterialNodeList []MaterialNode EmissivePrimitives []EmissivePrimitive // Texture definitions and the associated data. TextureData []byte TextureMetadata []TextureMetadata // Primitives are stored as an array of structs. VertexList []types.Vec4 NormalList []types.Vec4 UvList []types.Vec2 MaterialIndex []uint32 // Indices to material nodes used for storing the scene global // properties such as diffuse and emissive colors. SceneDiffuseMatIndex int32 SceneEmissiveMatIndex int32 // The scene camera. Camera *Camera }
type TextureMetadata ¶
type TextureMetadata struct { // Texture format. Format texture.Format // Texture dimensions. Width uint32 Height uint32 // Offset to the beginning of texture data DataOffset uint32 }
The texture metadata. All texture data is stored as a contiguous memory block.