---
title: "viewRay"
description: "The direction the viewer looks along at this pixel, for reflections that sweep across a face."
group: "light"
groupTitle: "Noise, light & materials"
categoryId: "materials"
categorySlug: "materials"
categoryTitle: "Materials & surfaces"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/materials.ts#L435"
---

# viewRay

The direction the viewer looks along at this pixel, for reflections that sweep across a face.

```ts
viewRay(
  params: GpuFragmentParams,
  field: Pick<SurfaceField, 'aspect'>,
  fov: number = 0.6,
): Expr
```

Import `materials` from `shaders/std` and use `materials.viewRay`.

A unit 3D vector pointing into the canvas. `fov` sets how much it leans off-axis toward the edges (0.6 is the usual value, 0.55 flatter).

## Parameters

| Name | Type | Notes |
|---|---|---|
| `params` | `GpuFragmentParams` |  |
| `field` | `Pick<SurfaceField, 'aspect'>` |  |
| `fov` | `number` | Optional. Default `0.6`. |

## Example

```ts
const view = viewRay(params, field)
```

## See also

- [`grazingOf`](/docs/primitives/materials/grazingof) — How edge-on the surface is to the viewer: 0 face-on, 1 grazing.
- [`reflect`](/docs/primitives/math/reflect) — The direction `i` bounced off a surface with unit normal `n`.
- [`studioSoftboxes`](/docs/primitives/materials/studiosoftboxes) — The brightness of a five-light studio seen in a reflected direction.

## Used by

[BrushedMetal](/docs/components/brushedmetal), [CarbonFiber](/docs/components/carbonfiber), [Chrome](/docs/components/chrome), [LiquidMetal](/docs/components/liquidmetal), [Nebula](/docs/components/nebula), [Obsidian](/docs/components/obsidian), [Satin](/docs/components/satin)