esp::gfx namespace

GFX library.

Contents

Classes

class DepthShader
Depth-only shader.
class Drawable
Drawable for use with DrawableGroup.
class DrawableGroup
Group of drawables, and shared group parameters.
class GenericDrawable
struct LightInfo
Contains a single light's information.
struct MaterialData
struct PhongMaterialData
class PTexMeshDrawable
class PTexMeshShader
class RenderCamera
class Renderer
class RenderTarget
class WindowlessContext

Enums

enum class LightPositionModel { CAMERA = 0, GLOBAL = 1, OBJECT = 2 }

Typedefs

using LightSetup = std::vector<LightInfo>
using ShaderManager = Magnum::ResourceManager<Magnum::GL::AbstractShaderProgram, gfx::LightSetup, gfx::MaterialData>

Functions

void initGfxBindings(pybind11::module& m)
auto calculateDepthUnprojection(const Magnum::Matrix4& projectionMatrix) -> Magnum::Vector2
Calculate depth unprojection coefficients for unprojectDepth()
void unprojectDepth(const Magnum::Vector2& unprojection, Corrade::Containers::ArrayView<Magnum::Float> depth)
Unproject depth values.
auto operator==(const LightInfo& a, const LightInfo& b) -> bool
auto operator!=(const LightInfo& a, const LightInfo& b) -> bool
auto getLightPositionRelativeToCamera(const LightInfo& light, const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& cameraMatrix) -> Magnum::Vector3
Get position relative to a camera for a LightInfo and a rendered object.
auto getLightsAtBoxCorners(const Magnum::Range3D& box, const Magnum::Color4& lightColor = Magnum::Color4{0.4f}) -> LightSetup
Get a LightSetup with lights at the corners of a box.
void setLightSetupForSubTree(scene::SceneNode& root, const Magnum::ResourceKey& lightSetup)
Set the light setup for a subtree.

Enum documentation

enum class esp::gfx::LightPositionModel

Enumerators
CAMERA

Light position is relative to the camera.

GLOBAL

Light position is relative to scene.

OBJECT

Light position is relative to the object being rendered.

Typedef documentation

Function documentation

void esp::gfx::initGfxBindings(pybind11::module& m)

Magnum::Vector2 esp::gfx::calculateDepthUnprojection(const Magnum::Matrix4& projectionMatrix)

Calculate depth unprojection coefficients for unprojectDepth()

Given a projection transformation of vector $ \boldsymbol{v} $ using a matrix $ \boldsymbol{P} $ where $ x $ and $ y $ are arbitrary, the transformation can be reduced to a 2x2 matrix multiplication:

\[ \begin{array}{rcl} \boldsymbol{P} \boldsymbol{v} & = & \begin{pmatrix} p & 0 & 0 & 0 \\ 0 & q & 0 & 0 \\ 0 & 0 & a & b \\ 0 & 0 & -1 & 0 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} \\[2.5em] \boldsymbol{P'} \boldsymbol{v} & = & \begin{pmatrix} a & b \\ -1 & 0 \end{pmatrix} \begin{pmatrix} z \\ 1 \end{pmatrix} = \begin{pmatrix} az + b \\ -z \end{pmatrix} \end{array} \]

In the OpenGL depth buffer, the depth values $ d $ are in range $ [ 0 ; 1 ] $ and the final depth value is after a perspective divide. The output has Z going forward, not backward, so we're looking for the value of $ -z $ :

\[ \begin{array}{rcl} 2d - 1 & = & \cfrac{az + b}{-z} \\[1.25em] -z & = & \cfrac{b}{2d + a - 1} \end{array} \]

Finally, to reduce the amount of operations in unprojectDepth(), we integrate the constants into $ a $ and $ b $ , returning $ a' $ and $ b' $ :

\[ \begin{array}{rcl} -z & = & \cfrac{b}{2d + (a - 1)} \\[1.25em] -z & = & \cfrac{\frac{1}{2}b}{d + \frac{1}{2}(a - 1)} \\[1.25em] -z & = & \cfrac{b'}{d + a'} ; ~~~~ a' = \frac{1}{2}(a - 1), ~~~~ b' = \frac{1}{2}b \end{array} \]

void esp::gfx::unprojectDepth(const Magnum::Vector2& unprojection, Corrade::Containers::ArrayView<Magnum::Float> depth)

Unproject depth values.

Parameters
unprojection in Unprojection coefficients from calculateDepthUnprojection()
depth in/out Depth values in range $ [ 0 ; 1 ] $

See calculateDepthUnprojection() for the full algorithm explanation. Additionally to applying that calculation, if the input depth is at the far plane (of value 1.0f), it's set to 0.0f on output as consumers expect zeros for things that are too far.

bool esp::gfx::operator==(const LightInfo& a, const LightInfo& b)

bool esp::gfx::operator!=(const LightInfo& a, const LightInfo& b)

Magnum::Vector3 esp::gfx::getLightPositionRelativeToCamera(const LightInfo& light, const Magnum::Matrix4& transformationMatrix, const Magnum::Matrix4& cameraMatrix)

Get position relative to a camera for a LightInfo and a rendered object.

Parameters
light
transformationMatrix Describes object position relative to camera
cameraMatrix Describes world position relative to camera
Returns Magnum::Vector3 Light position relative to camera

LightSetup esp::gfx::getLightsAtBoxCorners(const Magnum::Range3D& box, const Magnum::Color4& lightColor = Magnum::Color4{0.4f})

Get a LightSetup with lights at the corners of a box.

void esp::gfx::setLightSetupForSubTree(scene::SceneNode& root, const Magnum::ResourceKey& lightSetup)

Set the light setup for a subtree.

Parameters
root Subtree root
lightSetup LightSetup key in the ShaderManager

All drawables in the subtree starting at root will have the new lightSetup