Hologram Shader for Unity URP

A URP hologram shader for Unity 6: additive fresnel glow, scrolling world-space scanlines and random flicker, for sci-fi displays, ghosts and selection previews.

Also called: sci-fi shader, scanline shader, fresnel glow shader, ghost shader.

Effects URP, Unity 6000.0+ beginner MIT licensed

Use it for: Sci-fi projections, ghosts, building placement previews and highlighted pickups.

Inspector Try the properties
Shader Scripts For Unity/Hologram
HDR
Hologram Drag to rotate

The preview is a WebGL copy of the shader's maths with one fixed light, so it shows no shadows, Bloom or textures.

What it does

  • Fresnel rim that brightens the silhouette
  • Scanlines in world space that scroll at an adjustable speed
  • Random flicker with an adjustable strength
  • Additive blending, so overlapping holograms add up like light
  • HDR colour for Bloom

How it works

Opacity comes from three terms added together: a small base opacity, a fresnel term that is strongest where the surface turns away from the camera, and a sharpened sine wave of world-space height that forms the scanlines. A hash of the current time picks random moments to dip the brightness.

Setup

  1. Save the file as Hologram.shader under Assets and create a material that uses Scripts For Unity > Hologram.
  2. Assign it to any mesh; smooth meshes give the cleanest rim.
  3. Turn on Bloom for the glow, and keep the colour's intensity above 1 in the HDR picker.

Common mistakes

  • It looks washed out on bright backgrounds: additive blending can only brighten. Holograms read best against darker scenes; lower Base Opacity if they do.
  • Scanlines move when the object moves: they are in world space by design, like a projector. Use object-space height in the shader if you want them to travel with the object.

Questions

Is the hologram lit by scene lights?
No. It is unlit and additive: it adds its own colour to whatever is behind it, like a projection of light.
Can I use it on UI?
No. It is a mesh shader for 3D objects. UI elements use Unity's UI shaders.
Why does it look washed out on a bright background?
Additive blending can only make pixels brighter, so it stands out most against darker scenes. Lower Base Opacity or the colour's intensity on bright backgrounds.

Source

Hologram.shader · 105 lines · ShaderLab and HLSL for the Universal Render Pipeline 17 (Unity 6)

Hologram.shader
cpp
// Hologram: additive fresnel glow with scrolling scanlines and flicker.
// Transparent, unlit. URP 17 (Unity 6).
// Scripts For Unity, MIT licensed.
Shader "Scripts For Unity/Hologram"
{
    Properties
    {
        [HDR] _BaseColor ("Color", Color) = (0.25, 0.85, 1.6, 1)
        _BaseAlpha ("Base Opacity", Range(0, 1)) = 0.12
        _FresnelPower ("Fresnel Power", Range(0.5, 8)) = 2.2
        _ScanlineDensity ("Scanline Density", Range(1, 200)) = 60
        _ScanlineSpeed ("Scanline Speed", Range(-5, 5)) = 0.6
        _ScanlineStrength ("Scanline Strength", Range(0, 1)) = 0.35
        _Flicker ("Flicker", Range(0, 1)) = 0.15
    }

    SubShader
    {
        Tags
        {
            "RenderType" = "Transparent"
            "Queue" = "Transparent"
            "RenderPipeline" = "UniversalPipeline"
            "IgnoreProjector" = "True"
        }

        Pass
        {
            Name "Hologram"
            Tags { "LightMode" = "UniversalForward" }
            Blend SrcAlpha One
            ZWrite Off
            Cull Back

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            CBUFFER_START(UnityPerMaterial)
                half4 _BaseColor;
                float _BaseAlpha;
                float _FresnelPower;
                float _ScanlineDensity;
                float _ScanlineSpeed;
                float _ScanlineStrength;
                float _Flicker;
            CBUFFER_END

            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS : NORMAL;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float3 normalWS : TEXCOORD0;
                float3 positionWS : TEXCOORD1;
                float fogFactor : TEXCOORD2;
            };

            float SfuHash11(float x)
            {
                return frac(sin(x * 12.9898) * 43758.5453);
            }

            Varyings vert(Attributes input)
            {
                Varyings output;
                VertexPositionInputs positions = GetVertexPositionInputs(input.positionOS.xyz);
                output.positionCS = positions.positionCS;
                output.positionWS = positions.positionWS;
                output.normalWS = TransformObjectToWorldNormal(input.normalOS);
                output.fogFactor = ComputeFogFactor(positions.positionCS.z);
                return output;
            }

            half4 frag(Varyings input) : SV_Target
            {
                float3 normalWS = normalize(input.normalWS);
                float3 viewDirWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
                float fresnel = pow(1.0 - saturate(dot(normalWS, viewDirWS)), _FresnelPower);

                // Thin bright lines scrolling up the object in world space
                float wave = 0.5 + 0.5 * sin((input.positionWS.y * _ScanlineDensity - _Time.y * _ScanlineSpeed * 10.0) * TWO_PI * 0.1);
                float scanline = pow(wave, 6.0) * _ScanlineStrength;

                // Occasional brightness dips, about 20 chances a second
                float flicker = 1.0 - _Flicker * step(0.9, SfuHash11(floor(_Time.y * 20.0)));

                float alpha = saturate((_BaseAlpha + fresnel + scanline) * _BaseColor.a) * flicker;
                // Additive: fog fades the glow towards black, not towards the fog colour
                float3 color = MixFogColor(_BaseColor.rgb, half3(0.0, 0.0, 0.0), input.fogFactor);
                return half4(color, alpha);
            }
            ENDHLSL
        }
    }

    FallBack "Hidden/Universal Render Pipeline/FallbackError"
}

More shaders