---
title: "Add a Fresnel rim tint to a 3D material in C#"
url: https://recursiveai.org/onegame/cookbook/material-view-angle-tint/
description: "Add a soft Fresnel-like rim tint or a sharp Snell’s window cone to a 3D material in C# with OneGame, then render both effects on a sphere."
version: "2.7.0"
---

# Add a Fresnel rim tint to a 3D material in C#

**onegame** is a free, open-source game engine for .NET from Recursive AI. MIT or Apache-2.0, Vulkan for this example.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneGame.Render3D) · [GitHub](https://github.com/recursive-ai-oss/onegame) · [Docs](https://recursiveai.org/onegame/docs/) · [Download example (.zip)](https://recursiveai.org/onegame/cookbook/material-view-angle-tint/material-view-angle-tint.zip)

Use a Fresnel-like tint to color a surface at glancing angles.

```shell
dotnet add package RecursiveAI.OneGame.Render3D
dotnet add package RecursiveAI.OneGpu.Backends
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneGame.Render3D;
void Tint(Material3D material)
{
    material.ViewTintStrength = 1f;
    material.ViewTintColor =
        new(0.06f, 0.56f, 1f);
    material.ViewTintEdge = 0.4f;
    material.ViewTintSoftness = 0.6f;
    material.ViewTintPower = 2f;
}
```

Call `Tint` with a PBR or toon material from the model returned by `renderer.Upload(...)` (`model.Materials[0]` below). The example below uses a gray sphere and writes `soft.png` with a blue rim.

Unzip [the example](https://recursiveai.org/onegame/cookbook/material-view-angle-tint/material-view-angle-tint.zip), then `dotnet run`.

## The full program

The zip includes `sphere.gltf`, a sphere with outward normals and one matte material. The program saves PNGs using OneImage, which the glTF loader already brings in. Here’s the sphere’s material (the geometry is embedded in the file):

```json
{
  "name": "Shell",
  "pbrMetallicRoughness": {
    "baseColorFactor": [0.55, 0.57, 0.6, 1],
    "metallicFactor": 0,
    "roughnessFactor": 0.65
  }
}
```

```csharp
using System.Numerics;
using System.Runtime.InteropServices;
using OneGame.Gltf;
using OneGame.Render3D;
using OneImage;
using RecursiveAI.OneGpu;

using var device = GpuBackends.CreateDevice();
using var renderer = new Renderer3D(device);
using var model = renderer.Upload(GltfLoader.LoadFile("sphere.gltf"));
var material = model.Materials[0];
material.ViewTintColor = new Vector3(0.06f, 0.56f, 1f);
material.ViewTintStrength = 1f;
material.ViewTintEdge = 0.4f;
material.ViewTintSoftness = 0.6f;
material.ViewTintPower = 2f;

const int size = 400;
var scene = new Scene3D
{
    Camera = Camera3D.LookAt(new(0, 0, 5), Vector3.Zero, Vector3.UnitY),
    Samples = 1
};
scene.Camera.YFov = 0.5f;
scene.Add(model);
scene.Environment.Intensity = 0;
scene.Environment.Background = BackgroundMode.Color;
scene.Environment.BackgroundColor = new Vector3(0.008f, 0.014f, 0.024f);
scene.Post.Bloom = false;
scene.Post.ToneMapper = ToneMapper.None;
scene.Lights.Add(Light3D.Directional(new(0, 0, -1), Vector3.One, 2.8f));
scene.Lights.Add(Light3D.Directional(new(0, 1, -0.35f), Vector3.One, 1.1f));
scene.Lights.Add(Light3D.Directional(new(-1, 0, -0.35f), Vector3.One, 1.1f));
using var target = new Offscreen3D(renderer, size, size);
Console.WriteLine($"Adapter: {device.Adapter.Name}");
Write("soft.png");

material.ViewTintEdge = 0.66f;
material.ViewTintSoftness = 0f;
material.ViewTintPower = 1f;
Write("cone.png");

material.ViewTintZone = ViewTintZone3D.InsideCone;
Write("inside.png");

void Write(string path)
{
    var pixels = target.Capture(scene);
    var rgba = MemoryMarshal.Cast<byte, Rgba32>(pixels.AsSpan());
    var image = Image.FromPixels<Rgba32>(rgba, size, size);
    image.Save(path);
    Console.WriteLine($"Wrote {path} ({size} x {size})");
}
```

```text
Adapter: NVIDIA GeForce RTX 4070
Wrote soft.png (400 x 400)
Wrote cone.png (400 x 400)
Wrote inside.png (400 x 400)
```

![Three gray spheres: a soft blue rim, a sharply bounded blue rim, and a blue center with a gray rim](https://recursiveai.org/onegame/images/material-view-angle-tint/view-tint.webp)

Left to right: soft rim, tint outside the cone, tint inside the cone. If nothing changes, check that the material uses PBR (physically based rendering) or toon shading; flat and unlit styles don’t apply the tint.

## Variations

### Give the cone a sharp edge

On the same `material`, keep the color and strength but change where the transition happens. This is the setup for `cone.png`.

```csharp
material.ViewTintEdge = 0.66f;
material.ViewTintSoftness = 0f;
material.ViewTintPower = 1f;
```

### Tint the center instead of the rim

After setting up the cone above, change its zone to get `inside.png`:

```csharp
material.ViewTintZone = ViewTintZone3D.InsideCone;
```

## Related recipes

- [Render planar water reflections in C#](https://recursiveai.org/onegame/cookbook/planar-reflection-water/)
- [Lower 3D render scale and keep UI sharp](https://recursiveai.org/onegame/cookbook/lower-3d-render-scale-keep-ui-sharp/)

---

## The short answer

Set `ViewTintStrength` above zero and set `ViewTintColor` on your `Material3D`. The default zone, `OutsideCone`, tints glancing angles. Set `ViewTintSoftness` above zero for a gradual rim or to zero for a hard edge. Set strength back to zero to turn the tint off without restoring the other settings.

## What is the Fresnel rim effect?

Real Fresnel reflection changes with the angle you look at a surface. For example, a window can look clear head-on and more reflective from the side. [The Basics of Fresnel Shading](https://kylehalladay.com/blog/tutorial/2014/02/18/Fresnel-Shaders-From-The-Ground-Up.html) shows how the same idea can be used to mix colors at a rim. OneGame’s view tint is a color mix, not a calculation of reflected light: it blends toward a second color before lighting, so the tinted area still responds to the scene’s lighting.

The shader compares the surface normal (the direction pointing out of the surface) to the direction toward the viewer. Their dot product, clamped to zero through one, is near one head-on and near zero at a glancing angle. `ViewTintEdge` sets the cutoff in those units, not in degrees. `ViewTintSoftness` widens the transition on both sides of the cutoff. Raising `ViewTintPower` reduces the weight in the partially tinted area; reducing strength scales down the whole effect. If your material has a normal map, the shading normals from that map can make the rim ripple. See the [rendering reference](https://github.com/recursive-ai-oss/onegame/blob/376d17087a4e2fcb0bf405b74a09797e311176b8/docs/interfaces/render3d.md#L160) for the tint formula.

## What is Snell’s window?

From underwater, the view of the world above the surface is compressed into a cone. Outside it, the surface reflects back into the water. [Snell’s window](https://en.wikipedia.org/wiki/Snell%27s_window) has a half-angle of about 48.6 degrees for water and air. `ViewTintEdge = 0.66f` approximates the cosine of that angle. Keep `OutsideCone` to color the surrounding ring, or pick `InsideCone` to color the window itself. The sphere makes the two sides easy to see; the tint does not render the above-water scene or generate a reflection.

## Can a Fresnel rim change transparency too?

On a blended material, `ViewTintOpacity` specifies the opacity to move toward using the same weight as the color tint. A value of `1f` can make the outside of a water window more opaque while leaving the center at its original alpha. It doesn’t switch an opaque material into blended rendering. Leave the property at its default of `-1` if you only want the color to change.
