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.
Lightweight RP: https://github.com/nyahoon-games/ProjectorForLWRP/tree/master
Universal RP : https://github.com/nyahoon-games/ProjectorForLWRP/tree/master-universalrp

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

Rendering Layer Mask Only the renderers whose renderingLayerMask property contains any layers in this property can receive projection.
Render Queue Lower/Upper Bound Only the renderers of which the render queue values of their materials are within this range can receive projection.
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. Default value is an empty array which means LightweightForward (or UniversalForward) and SRPDefaultUnlit are used for this property. If the array is not empty, default tags are overwritten. To add a value, please increase Size first.
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.

To make the shader SRP Batcher compatible, please use HLSLPROGRAM instead of CGPROGRAM.

Sample Code:

Links

28 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
  • 2020/04/29 at 7:52 PM
    Permalink

    I’m having a weird issue:
    The current Lightweight Render Pipeline Asset does not have Forward Renderer Data! Please set a Forward Renderer Data which contains ProjectorRendererFeature to the current render pipeline asset.
    UnityEngine.Debug:LogError(Object, Object)
    ProjectorForLWRP.ProjectorRendererFeature:AddProjector(ProjectorForLWRP, Camera) (at Assets/ProjectorForLWRP-master/Scripts/ProjectorRendererFeature.cs:34)
    ProjectorForLWRP.ProjectorForLWRP:OnBeginFrameRendering(ScriptableRenderContext, Camera[]) (at Assets/ProjectorForLWRP-master/Scripts/ProjectorForLWRP.cs:310)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    I have made sure to follow the setup but this keeps appearing.
    What I did was I selected my Lightweight Render Pipeline Asset and swapped out the default Forward Renderer to the one you provided.

    Reply
    • 2020/04/30 at 11:07 AM
      Permalink

      Hi,
      Thank you for trying Projector For LWRP. Please make sure that your Lightweight Render Pipeline Asset is selected in the Graphics settings.

      Reply
  • 2020/05/22 at 4:14 AM
    Permalink

    Hi I have issue when build to android, I used URP unity 2019.3.11f1, on editor good work but when build have messages like this:
    – No ProjectorRendererFeature instances are created!
    – NullReferenceException: Object reference not set to an instance of an object

    Editor.log
    No ProjectorRendererFeature instances are created!
    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

    NullReferenceException: Object reference not set to an instance of an object
    (Filename: Assets/ProjectorForLWRP-master-universalrp/Scripts/ProjectorRendererFeature.cs Line: 108)

    Reply
    • 2020/05/22 at 6:48 PM
      Permalink

      Hi, thank you for the bug report. I fixed this issue. Please pull the fixes from Github.

      Reply
  • 2020/05/27 at 2:42 AM
    Permalink

    I tried this out in Unity2019.2.14f1 LWPR and in Unity2019.3.14f1 LWPR but it worked unfortunately only in the older version. I might need a bit of patience for an update I guess or maybe I made something wrong? I wanted to use the projector as a simple shadow that gets smaller when a character gets further away from the ground. So I would just set up such a projector on its head. From Λ to V.

    Reply
    • 2020/05/27 at 12:29 PM
      Permalink

      Hi, I tried Unity 2019.3.14f1 but I didn’t see any problems. Did you see any error messages?

      I guess some data references are broken when update your project. Please check the render pipeline assets and forward renderer data again.

      Or, I noticed that the user interface for ForwardRendererData was changed in newer version of URP. To add ProjectorRendererFeature to a ForwardRendererData, please click “Add Renderer Feature” button at the bottom of Inspector view of the ForwardRemdererData.

      Reply
      • 2020/05/27 at 10:15 PM
        Permalink

        No, unfortunately, I didn’t see any error messages. The materials are also looking as they should look and both forward render in my project have the ProjectorRendererFeature assigned to them and the “Check Unity Projector Component Enabled” is Enabled.
        I also have the Render Pipeline Asset assigned to the “ForwardRendererWithProjectorPass” and the Render Pipeline Asset is assigned to the Graphics settings but I still don’t see any kind of projection anywhere when I use unity 2019.3.14f1. Maybe it’s a setting issue or it has something to do with importing/updating the scripts to the newest unity version?

        Reply
        • 2020/05/28 at 12:54 PM
          Permalink

          Maybe, I know the reason. You have upgraded your project from Unity 2019.2 to Unity 2019.3 right? Unfortunately, it doesn’t work. You need to use ‘master_universalrp’ branch instead of ‘master’ branch.

          Reply
          • 2020/05/28 at 8:14 PM
            Permalink

            It works much perfectly now. It was just difficult to get there because there were some issues. When I made a build of it every object in the range of the projector turns pink. Then I discarded every change, tried it again and suddenly only the projector was replaced with a pink square in the build. Next discard everything turned white in the range of the projector outside the build. Then I only switched from your Sample Scene back and to mine and back again and suddenly it worked perfectly and I have no idea why.

          • 2020/05/29 at 4:40 PM
            Permalink

            This kind of issue is supposed to be fixed at the commit made on May 22. However another person reported me a similar issue which happens only on Vulkan Graphics API.
            Are you building for Android? What if Vulkan is removed from Graphics API in Player Settings?
            Also, this issue seems to happen only when Fast Shadow Receiver (our paid asset) is used together. I am still investigating it.

  • 2020/05/29 at 5:16 PM
    Permalink

    Could the projector turn into a pink square, when making a build when using Universal RP 7.3.1 instead of 7.1.7. I don’t think Vulcan was even in use, but I could be wrong. I am not building for android, I chose “PC, Mac & Linux Standalone”. Sadly I don’t think it is possible to downgrade the Universal RP.

    Reply
    • 2020/05/29 at 8:26 PM
      Permalink

      Thank you for the information. It seems a different issue than the Vulkan one. I also use Universal RP 7.3.1, but I couldn’t reproduce it on my Mac. Are you using Windows PC?

      The issue I fixed on May 22 was caused by shader stripping. I added ProjectorForLWRP/Scripts/Editor/ProjectorMaterialPreprocessor.cs which enables “FSR_PROJECTOR_FOR_LWRP” keywords for each projector material. To make sure that the projector materials have this keyworkd, can you manually add it in the Inspector View? You might need to change the mode from ‘Normal’ to ‘Debug’ by clicking the small ‘three vertical dots’ button on top-right corner of the inspector view.

      Reply
      • 2020/05/29 at 8:48 PM
        Permalink

        yes, I use a Windows PC. I have sadly not enough understanding of this so look further into it. I am sorry. Is there maybe a better way to stay in contact? I fear to fill up your side with my many questions even more.

        Reply
        • 2020/05/29 at 11:44 PM
          Permalink

          I fixed the Vulkan issue. It was not actually related to Vulkan API. It might happen to other platforms. Please update ProjectorForLWRP from Github, and try again.
          If you still have the issue, please contact me via email or contact form.

          Reply
  • 2020/07/05 at 12:29 AM
    Permalink

    Hi takao! We’ve purchased Fast Shadow Receiver a while ago and now want to use it with URP (latest version) on 2019.4. The projector component from your GitHub works fine (using the instructions above) but I don’t understand how it relates to FSR. Should we use the Projector *plus* FSR to get better performance, or does FSR give additional features, or can we ignore FSR now? Our use case is rather simple: we have a single flat shadow receiver (a very simple terrain) and multiple, movable shadow casters. Built-in shadows for URP produce too much artefacts and performance is abysmal, so we really want to use your solution to improve performance. Thanks!

    Reply
    • 2020/07/06 at 7:31 PM
      Permalink

      Hi, thank you for the purchase of Fast Shadow Receiver.
      In your case (single flat shadow receiver and multiple movable shadow casters), FSR will improve the performance a lot. You can use Easy Setup Wizard to set up FSR.

      Reply

Leave a Reply to Ertugrul Cancel reply

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

Anti Spam Code *