This GitHub project provides C# scripts and shaders that make Projector component work with Lightweight/Universal Render Pipeline.

Branches

branch name verified RP version
master Lightweigt RP 6.9.0
master-universalrp Universal RP 7.1.7

Install

If you use git, clone (or submodule add) the repository into the Assets folder in your Unity Project. If you don’t use git, you can download zip file and extract it into the Assets folder.
URL: https://github.com/nyahoon-games/ProjectorForLWRP.git

Setup

First of all, you need to add ProjectorRendererFeature into your Lightweight Render Pipeline. If you created your project from LWRP template (or already configured LWRP properly), a LightweightRenderPipelineAsset had been assigned to Scriptable Render Pipeline Settings in Graphics Settings.

Double click the asset to select it in Inspector View.

If you are using the default forward renderer, change Renderer Type to Custom, then click the small button of Data field, and select ForwardRendererWithProjectorPass (Universal RP doesn’t have Renderer Type field. Just replace the default renderer with ForwardRendererWithProjectorPass).

If you are already using your custom forward renderer, please add ProjectorRendererFeature into your forward renderer data.

How to use

Add a Projector For LWRP component to your Projector object, if you already have one. If you want to create a new Projector object, just add a Projector For LWRP component to an empty GameObject, then Projector component will also be added.

Projector component will automatically disabled by Projector For LWRP component though(No longer disabled**), you still need to setup the properties of Projector component as usual. One thing that is different from usual settings is that you cannot use the projector shaders in Standard Assets. Please use one of the shaders in this project, or create a custom shader if needed (see below for more details). The shaders in Fast Shadow Receiver and Dynamic Shadow Projector are also available.

** If you have used old version, you need to manually enable Projector components in your existing scenes. Otherwise, the projector will not be rendered. If it is inconvenient to do so, you can uncheck Check Unity Projector Component Enabled field of ProjectorRendererFeature in your ForwardRendererData asset.

In addition to setting up Projector properties, you might need to setup the properties of Projector For LWRP component.

Properties of Projector For LWRP component

Cameras An array of cameras in which the projector is rendered. If it is empty, Camera.main will be used. To add a camera to the array, increase Size first, then put the camera to the last element of the array.
Shader Tag List An array of LightMode tag values. Only the renderers whose material has a shader that contains a pass whose LightMode tag value is identical to one of the values in the array can receive projection. If a shader pass doesn’t have LightMode tag, its LightMode tag value is considered as SRPDefaultUnlit. To add a value, please increase Size first.
Render Queue Lower/Upper Bound Only the renderers of which the render queue values of their materials are within this range can receive projection.
Render Pass Event An event in which projector render pass is inserted. Please be aware that the render queue value of the projector’s material is ignored.
Per Object Data Kinds of per object data (other than transform matrix) that are required by the projector’s material.
Use Stencil Test There is a chance to improve the rendering performance if stencil test is enabled. Just try and see if it is effective or not. Don’t need to use stencil test, if the projector is used with Fast Shadow Receiver.

Create a custom projector shader

If you need a custom projector shader, please include “Assets/ProjectorForLWRP/Shaders/P4LWRP.cginc” and use fsrTransformVertex function to transform vertex and projection uv. The shader must be compiled with FSR_PROJECTOR_FOR_LWRP keyword.

Sample Code:

Links

12 thoughts on “Projector For LWRP

  • 2019/06/06 at 3:34 PM
    Permalink

    You guys are lifesavers! This helped so much! Just a side note for anyone else who may come across the problem we did, leaving “Draw Instanced” on a Terrain will prevent a projector from showing up on that Terrain. At least for 2019.1f.

    Reply
    • 2019/06/12 at 10:56 AM
      Permalink

      Thank you for sharing your experience! If you want to keep “Draw Instanced” on, try our another asset Fast Shadow Receiver which can receive a projector shadow on behalf of the terrain.

      Reply
  • 2019/07/25 at 12:47 PM
    Permalink

    Where is the option to add ProjectorRendererFeature in Unity 2018?

    Reply
    • 2019/07/26 at 9:55 AM
      Permalink

      It seems like Projector For LWRP is not available in Unity 2018. The latest version of LWRP available in Unity 2018 is 4.10 preview which doesn’t have ScriptableRendererFeature class.

      Reply
  • 2019/07/29 at 12:12 AM
    Permalink

    Hi,

    Anyone that can confirm that it works LWRP 5.16.1 as well? It seems that I can not make it work properly with 5.16.1.

    Reply
    • 2019/07/29 at 2:59 PM
      Permalink

      I tried LWRP 5.16.1 and I didn’t see problems. What kind of issues did you find?

      Reply
  • 2020/01/13 at 1:00 PM
    Permalink

    Thank you so much for this!
    Just tried it on Unity 2019.3.0f1 with the latest LWRP and seems to work perfectly!
    Just leaving a few comments here because I had never used projectors before and had some trouble setting up the texture. The way I got it to work was by importing the texture as a Default texture (not cookie, with cookie it didn’t show at all) and changing the wrap mode from Repeat to Clamp. As I said, it may be the way it always worked with projectors, but might help someone who hadn’t used them before.
    Thanks again!

    Reply
  • 2020/02/13 at 7:06 AM
    Permalink

    Works great in the editor together with the dynamic shadow projected for URP but in the build I get the following errors.

    Releasing render texture that is set as Camera.targetTexture!
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

    Error building Player: Releasing render texture that is set as Camera.targetTexture!

    Would appreciate some help in resolving these thank you.

    Reply
    • 2020/02/13 at 2:38 PM
      Permalink

      Thank you for the bug report. I tried on both Windows and Mac, but I couldn’t see the error. Which platform are you making a build for?

      A suspicious code I can think of is the line 590 in DynamicShadowProjector/Scripts/ShadowTextureRenderer.cs (OnDestroy function).
      DestroyImmediate(m_shadowTexture);
      Please try to remove this line and see if you still get the error.

      Reply
    • 2020/03/05 at 3:08 PM
      Permalink

      There was an issue that will show “Releasing render texture that is set as Camera.targetTexture!” error message if there is a prefab object of a ShadowTextureRenderer. I fixed this issue in version 1.1.1 of DynamicShadowProjector which will be available soon on Asset Store. I am not sure if this is your case though, please try this new version.

      Reply
  • 2020/03/08 at 4:18 AM
    Permalink

    I’m having an issue using this in my scene where it only render from a certain angle and from the other side it disappears.

    Reply
    • 2020/03/10 at 5:15 PM
      Permalink

      I fixed view clipping issue. Please try the latest version.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti Spam Code *