Unity bridge · lesson 1 of 2 · Intermediate · about 6 min

Taking it into Unity

You will build: Free play. Export it with the button above.

The picture produced by the shader in the lesson "Taking it into Unity"
The target picture. In the lesson you write the shader that draws it, and a match bar shows how close you are.

Everything you've written here is the fragment function of a Unity shader. Unity wraps it with a bit of boilerplate. Hit “Copy for Unity” above the editor to get a complete ShaderLab file for any exercise.

Try it (5 minutes)

  1. In Unity: Assets → Create → Shader → Unlit Shader, open it, replace everything with the exported text.
  2. Create → Material, pick your shader, drag the material onto a Quad (or a Sphere!).

What the boilerplate does

  • Vertex shader (vert): runs once per vertex of the mesh and places it on screen. A Quad has 4 vertices. The GPU then fills in the pixels between them.
  • Per-vertex values like the UV are interpolated across the triangle and arrive in the fragment shader: that's where uv comes from. On this page the “mesh” is just one rectangle covering the screen.
  • Fragment shader (frag): runs once per pixel — what you've been writing.

Differences to know

This pageIn Unity
time_Time.y (works on this page too)
aspect_ScreenParams.x / _ScreenParams.y (also works on this page), or 1 on a square Quad
uv on a screen-filling rectangleuv from the mesh (0..1 over a Quad; whatever the artist unwrapped on other models)
solid colors onlyadd Properties { _Color("Color", Color) = (1,1,1,1) } to expose sliders/colors; sampler2D _MainTex + tex2D(_MainTex, uv) for textures

The 3D raymarch lessons work on a Quad too, but in Unity you'd often shade real meshes instead: your fragment function would get world normals and light directions from the vertex stage. The next step on your own: learn Shader Graph or surface shaders to get Unity's lighting for free — the math you've practiced is the same.

Below is a free playground. Hit Reset for the starter; no target, just experiment!

Try it in your own language

The lesson is written once and shown in every language. Pick yours: Unity (Built-in), Unity (URP), Unreal, Shadertoy / WebGL, OpenGL (LWJGL, raylib), three.js, GameMaker, LÖVE (Lua), Godot, Apple (iOS, macOS), WebGPU / Bevy.

Start coding

Go deeper

Part of the learning path: From Shadertoy to Unity.