Back to projects
Unity / Shaders2025

Rim Light Shader

Efficient Fresnel-based rim lighting shader with HDR support and real-time parameter control.

UnityHLSLShaderLab
Fresnel EffectRim LightingHDRSurface ShaderView-DependentEmission

Overview

A custom surface shader implementing view-dependent rim lighting via the Fresnel effect. Features HDR color support for bloom compatibility, adjustable power curves for falloff control, and optimized single-pass rendering suitable for mobile platforms.

Key Features

  • Fresnel-based rim light calculation
  • HDR color support for post-processing bloom
  • Adjustable rim power for falloff sharpness
  • Threshold control for edge appearance
  • View-dependent intensity (changes with camera angle)
  • PBR compatible with Unity's Standard lighting model
  • Single-pass surface shader for mobile performance

Technical Breakdown

How It Works

  1. 1Calculate dot product between surface normal (N) and view direction (V)
  2. 2Invert result: rim = 1 - dot(N, V) — edges get higher values
  3. 3Apply smoothstep for soft threshold transitions
  4. 4Apply pow() for artistic falloff control
  5. 5Output to Emission channel for self-illumination effect

Architecture

  • RimLightShader.shader — Single-file surface shader
  • Properties block — Rim Color (HDR), Power, Threshold
  • surf() function — Main surface calculation logic

Notable Details

  • Fresnel effect: objects glow at edges where surface is perpendicular to view
  • smoothstep provides smooth falloff vs hard threshold cutoff
  • pow() exponent controls how sharply rim fades toward center
  • Emission channel enables glow without external light sources
  • LOD 200 ensures compatibility across quality levels

Setup & Usage

Installation

  1. 1Copy RimLightShader.shader to Assets/Shaders/
  2. 2Create new material: Right-click → Create → Material
  3. 3Select shader: Custom/RimLightShader
  4. 4Apply material to 3D object

Parameters

NameTypeEffect
Rim ColorColor (HDR)Edge light color, use HDR values for bloom
Rim PowerRangeFalloff sharpness (higher = tighter edge)
Rim ThresholdRangeWhen rim effect starts appearing

Challenges & Learnings

  • Understood Fresnel effect physics and its shader implementation
  • Applied smoothstep and pow for artistic falloff control
  • Learned how Emission channel enables self-illumination
  • Optimized for mobile with minimal texture lookups

Outcomes

  • Clean, reusable rim light implementation
  • Educational resource for view-dependent shader techniques
  • Suitable for characters, UI highlights, and stylized effects