Spaces Module
Coordinate-space transforms, projection helpers, depth reconstruction, and tangent bases.
Turn the guide into code
Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.
Open PlaygroundCoordinate-space transforms, projection helpers, depth reconstruction, and tangent bases.
Import
import Spaces
This module imports: Math.
Constants
None.
Structs
Ray
struct Ray {
float3 origin;
float3 direction;
};
Basis
struct Basis {
float3 tangent;
float3 bitangent;
float3 normal;
};
Enums
No enums found.
Functions
transform_point
Reference: https://en.wikipedia.org/wiki/Homogeneous_coordinates
transform_point :: (mat4 m, float3 p) -> float3
transform_vector
Transforms a direction or offset by a 4x4 matrix without translation.
transform_vector :: (mat4 m, float3 v) -> float3
transform_direction
Transforms and normalizes a direction or offset by a 4x4 matrix.
transform_direction :: (mat4 m, float3 v) -> float3
transform_normal
Reference: https://en.wikipedia.org/wiki/Normal_(geometry)
transform_normal :: (mat4 objectToWorld, float3 n) -> float3
project_point
Projects a world-space position to clip space with a view-projection matrix.
project_point :: (mat4 viewProjection, float3 worldPos) -> float4
clip_to_ndc
Reference: https://en.wikipedia.org/wiki/Viewing_frustum
clip_to_ndc :: (float4 clipPos) -> float3
ndc_to_uv
Converts normalized device coordinates in [-1, 1] to texture UV coordinates in [0, 1].
ndc_to_uv :: (float2 ndc) -> float2
uv_to_ndc
Converts texture UV coordinates in [0, 1] to normalized device coordinates in [-1, 1].
uv_to_ndc :: (float2 uv) -> float2
screen_to_uv
Converts pixel coordinates to normalized UV coordinates using viewport size.
screen_to_uv :: (float2 pixel, float2 viewportSize) -> float2
uv_to_screen
Converts normalized UV coordinates to pixel coordinates using viewport size.
uv_to_screen :: (float2 uv, float2 viewportSize) -> float2
linearize_depth_01
Reference: https://developer.nvidia.com/content/depth-precision-visualized
linearize_depth_01 :: (float depth, float nearPlane, float farPlane) -> float
linearize_depth_ndc
Linearizes an NDC depth value in [-1, 1] to view-space depth units.
linearize_depth_ndc :: (float ndcDepth, float nearPlane, float farPlane) -> float
reconstruct_view_position
Reference: https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/
reconstruct_view_position :: (float2 uv, float depth, mat4 inverseProjection) -> float3
reconstruct_world_position
Reference: https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/
reconstruct_world_position :: (float2 uv, float depth, mat4 inverseViewProjection) -> float3
make_basis
Reference: https://en.wikipedia.org/wiki/Orthonormal_basis
make_basis :: (float3 normal) -> Basis
tangent_to_world
Converts a tangent-space vector to world space using a Basis.
tangent_to_world :: (float3 tangentSpaceVector, Basis basis) -> float3
tangent_to_world
Converts a tangent-space vector to world space from explicit tangent, bitangent, and normal.
tangent_to_world :: (float3 tangentSpaceVector, float3 tangent, float3 bitangent, float3 normal) -> float3
world_to_tangent
Converts a world-space vector into tangent space using a Basis.
world_to_tangent :: (float3 worldVector, Basis basis) -> float3
view_ray_from_uv
Builds a view-space ray through a screen UV from an inverse projection matrix.
view_ray_from_uv :: (float2 uv, mat4 inverseProjection) -> Ray
Source
Generated from compiler-reference/modules/Spaces.bwsl.