scene

package
v0.0.0-...-e791307 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2023 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BvhNode

type BvhNode struct {
	Min   types.Vec3
	LData int32

	Max   types.Vec3
	RData int32
}

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) GetMeshIndex

func (n *BvhNode) GetMeshIndex() (index uint32)

Get Mesh index.

func (*BvhNode) GetPrimitives

func (n *BvhNode) GetPrimitives() (firstPrimIndex, count uint32)

Get primitive index and count.

func (*BvhNode) OffsetChildNodes

func (n *BvhNode) OffsetChildNodes(offset int32)

Add offset to indices of child nodes.

func (*BvhNode) SetBBox

func (n *BvhNode) SetBBox(bbox [2]types.Vec3)

Set bounding box.

func (*BvhNode) SetChildNodes

func (n *BvhNode) SetChildNodes(left, right uint32)

Set left and right child node indices.

func (*BvhNode) SetMeshIndex

func (n *BvhNode) SetMeshIndex(index uint32)

Set mesh instance index.

func (*BvhNode) SetPrimitives

func (n *BvhNode) SetPrimitives(firstPrimIndex, count uint32)

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 NewCamera

func NewCamera(fov float32) *Camera

func (*Camera) InvViewProjMat

func (c *Camera) InvViewProjMat() types.Mat4

func (*Camera) Move

func (c *Camera) Move(dir CameraDirection, offset float32)

Move camera towards a specific direction using a particular offset.

func (*Camera) SetupProjection

func (c *Camera) SetupProjection(aspect float32)

Setup camera projection matrix.

func (*Camera) Update

func (c *Camera) Update()

Update camera.

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

type Frustrum [4]types.Vec4

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

func (Frustrum) String

func (fr Frustrum) String() string

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
}

func (*Scene) Stats

func (sc *Scene) Stats() string

Build a tabular representation of scene statistics.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL