Vixen
02b45cc4
csharp
public readonly struct Viewport

The region of a render target being drawn into, and the depth range mapped onto it. Floats rather than integers, because that is what both Vulkan and D3D12 take.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

MinDepth and MaxDepth are the *viewport transform*, which is a separate thing from reverse-Z. Reverse-Z lives in the projection matrix; the viewport range stays 0 to 1 and only changes when something deliberately compresses depth, such as a first-person weapon rendered into a sliver of the buffer.

Fields and properties (8)

  • public readonly float X

    The left edge, in pixels.

  • public readonly float Y

    The top edge, in pixels.

  • public readonly float Width

    The width, in pixels.

  • public readonly float Height

    The height, in pixels.

  • public readonly float MinDepth

    The depth written for the near end of the range.

  • public readonly float MaxDepth

    The depth written for the far end of the range.

  • public Rectangle Bounds

    The region, as a rectangle.

  • public float AspectRatio

    Width divided by height, for feeding to a projection.

Methods (14)

  • public Viewport(float x, float y, float width, float height)

    Builds a viewport covering a region, with the full depth range.

  • public Viewport(float x, float y, float width, float height, float minDepth, float maxDepth)

    Builds a viewport covering a region, with an explicit depth range.

  • public Viewport(Rectangle bounds)

    Builds a viewport covering a rectangle, with the full depth range.

  • public Vector3 Project(Vector3 point, in Matrix4x4 worldViewProjection)

    Where a world-space point lands on screen. The result's Z is the depth that would be written, which under reverse-Z is near 1 for close geometry.

  • public Vector3 Unproject(Vector3 point, in Matrix4x4 worldViewProjection)

    The world-space point a screen position came from. The inverse of Project, and how a mouse position becomes a picking ray.

  • public Ray GetPickingRay(Vector2 screenPosition, in Matrix4x4 viewProjection)

    The ray through a screen position, pointing away from the camera. What a click becomes.

  • public static bool NearEqual(Viewport left, Viewport right, float tolerance = 1E-06)

    Whether two viewports agree to within a tolerance.

  • public static bool operator ==(Viewport left, Viewport right)

    Exact equality, IEEE semantics. See NearEqual.

  • public static bool operator !=(Viewport left, Viewport right)

    The negation of op_Equality.

  • public bool Equals(Viewport other)

    Indicates whether the current object is equal to another object of the same type.

  • public override bool Equals(object? obj)

    Indicates whether this instance and a specified object are equal.

  • public override int GetHashCode()

    Returns the hash code for this instance.

  • public override string ToString()

    Returns the fully qualified type name of this instance.

  • public string ToString(string? format, IFormatProvider? formatProvider)

    Formats the value of the current instance using the specified format.

Used by (23)

  • FullScreenRendererVixen.Rendering
  • GlCommandListVixen.Graphics.OpenGL
  • ICommandListVixen.Graphics
  • ImpostorBakeVixen.Rendering
  • ImpostorBakeCellVixen.Rendering
  • ImpostorBakeTestsVixen.Rendering.Tests
  • NativeWebGpuTestsVixen.Graphics.WebGPU.Tests
  • NullCommandListVixen.Graphics.Null
  • OrderProbeVixen.Graphics.RenderGraph.Tests
  • RectangleAndViewportTestsVixen.Core.Mathematics.Tests
  • RenderPassRendererVixen.Rendering
  • ShadowAtlasTileDeviceTestsVixen.Graphics.Golden.Tests
  • ShadowCascadeTestsVixen.Rendering.Tests
  • ShadowCascadesVixen.Rendering
  • ShadowMapRendererVixen.Rendering
  • TrackingCommandListVixen.Graphics.RenderGraph.Tests
  • TypeRegistrationVixen.Core.Mathematics
  • VirtualShadowRendererVixen.Rendering
  • Vixen_Core_Mathematics_ViewportSerializerVixen.Core.Mathematics
  • VulkanCommandListVixen.Graphics.Vulkan
  • WebGpuCommandListVixen.Graphics.WebGPU
  • WebGpuCommandTestsVixen.Graphics.WebGPU.Tests
  • EditorCameraVixen.Editor.SceneView