ABSTRACT

This chapter shows how to create lens effects for three-dimensional scenes within virtual reality (VR), with implementation examples using Unity. It shows how the same basic rendering technique can create a window or portal-like lens. The chapter also shows how Unity’s built-in VR features can be used for immersive stereoscopic lens viewing in consumer devices such as the Rift or Vive. The code will be comprehensible to Unity developers with moderate knowledge of shaders. It is recommended to read Unity’s “Gentle Introduction to Shaders” before starting. A Unity feature called Replacement Shaders allows a camera to replace the shader of every object seen with another specified shader. When converting the fragment position to canonical lens space, it is possible to perform the matrix multiplication in the vertex shader, with the results being interpolated by hardware into fragment values.