Unit CastleCubeMaps

Description

Utilities for cube (environment) maps.

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TCubeMapInfo  

Functions and Procedures

function CubeMapDirection(const Side: TCubeMapSide; const Pixel: Cardinal): TVector3;
procedure DirectionToCubeMap(const Dir: TVector3; out Side: TCubeMapSide; out Pixel: Cardinal);
procedure Direction4ToCubeMap(const Dir: TVector3; out Side: TCubeMapSide4; out Pixel: TVector4Cardinal; out Ratio: TVector4);
function CubeMapSolidAngle(const Side: TCubeMapSide; const Pixel: Cardinal): Single;

Types

TCubeMapSide = CastleCompositeImage.TCubeMapSide;
TCubeMapSide4 = array [0..3] of TCubeMapSide;
TCubeMapFloat = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Float;
PCubeMapFloat = ˆTCubeMapFloat;
TCubeMapByte = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Byte;
PCubeMapByte = ˆTCubeMapByte;

Constants

CubeMapSize = 16;
CubeMapInfo: array [TCubeMapSide] of TCubeMapInfo = ( (Dir: (Data: ( 1, 0, 0)); Up: (Data: (0, -1, 0)); Side: (Data: ( 0, 0,-1)); ScreenX: 3; ScreenY: 0), (Dir: (Data: (-1, 0, 0)); Up: (Data: (0, -1, 0)); Side: (Data: ( 0, 0, 1)); ScreenX: 1; ScreenY: 0), (Dir: (Data: ( 0, 1, 0)); Up: (Data: (0, 0, 1)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: -1), (Dir: (Data: ( 0, -1, 0)); Up: (Data: (0, 0, -1)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: +1), (Dir: (Data: ( 0, 0, 1)); Up: (Data: (0, -1, 0)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: 0), (Dir: (Data: ( 0, 0, -1)); Up: (Data: (0, -1, 0)); Side: (Data: (-1, 0, 0)); ScreenX: 0; ScreenY: 0) );

Description

Functions and Procedures

function CubeMapDirection(const Side: TCubeMapSide; const Pixel: Cardinal): TVector3;

Direction corresponding to given cube map side and pixel number. That is, assuming that the middle of cube is placed at (0, 0, 0), each pixel of the cube map corresponds to some direction.

Pixel number must be between 0 and CubeMapSize*2-1. It's assumed that pixels are in the same order as they are in OpenGL images, that is row-by-row, from the lowest row to highest, in each row from left to right.

Returned vector is not normalized.

procedure DirectionToCubeMap(const Dir: TVector3; out Side: TCubeMapSide; out Pixel: Cardinal);

Return cube map side and pixel that is the closest to given direction Dir. This is the reverse of CubeMapDirection function.

Given here Dir need not be normalized, although must not be zero.

procedure Direction4ToCubeMap(const Dir: TVector3; out Side: TCubeMapSide4; out Pixel: TVector4Cardinal; out Ratio: TVector4);

Return 4 cube map indexes (side and pixel, along with ratio) that are closest to given direction Dir. All ratios will sum to 1.

This is like DirectionToCubeMap, except this returns 4 values. It allows you to do bilinear interpolation between cube map items.

function CubeMapSolidAngle(const Side: TCubeMapSide; const Pixel: Cardinal): Single;

Calculate solid angle of given pixel on the cube map.

Types

TCubeMapSide = CastleCompositeImage.TCubeMapSide;
 
TCubeMapSide4 = array [0..3] of TCubeMapSide;
 
TCubeMapFloat = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Float;

Cube map, with each item being a Float.

PCubeMapFloat = ˆTCubeMapFloat;
 
TCubeMapByte = array [TCubeMapSide, 0..Sqr(CubeMapSize) - 1] of Byte;

Cube map, with each item being in 0..1 range, encoded as a Byte. This assumes that every item is actually a float in 0..1 range, encoded as Byte.

PCubeMapByte = ˆTCubeMapByte;
 

Constants

CubeMapSize = 16;
 
CubeMapInfo: array [TCubeMapSide] of TCubeMapInfo = ( (Dir: (Data: ( 1, 0, 0)); Up: (Data: (0, -1, 0)); Side: (Data: ( 0, 0,-1)); ScreenX: 3; ScreenY: 0), (Dir: (Data: (-1, 0, 0)); Up: (Data: (0, -1, 0)); Side: (Data: ( 0, 0, 1)); ScreenX: 1; ScreenY: 0), (Dir: (Data: ( 0, 1, 0)); Up: (Data: (0, 0, 1)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: -1), (Dir: (Data: ( 0, -1, 0)); Up: (Data: (0, 0, -1)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: +1), (Dir: (Data: ( 0, 0, 1)); Up: (Data: (0, -1, 0)); Side: (Data: ( 1, 0, 0)); ScreenX: 2; ScreenY: 0), (Dir: (Data: ( 0, 0, -1)); Up: (Data: (0, -1, 0)); Side: (Data: (-1, 0, 0)); ScreenX: 0; ScreenY: 0) );

Information about cube map faces.

Names and orientation of faces match precisely OpenGL naming and orientation (see http://www.opengl.org/registry/specs/ARB/texture_cube_map.txt), so it's straighforward to use this for OpenGL cube maps.


Generated by PasDoc 0.15.0.