0
\$\begingroup\$

I recently added the Lightweight Render Pipeline to my project as I'd like to start experimenting with Shadergraph to see if I can get a better basic understanding of shaders.

Everything has gone pretty smoothly except the Shader used by my Projectors, the Projection Shader Standard asset no longer works (does not project the texture) and I have very little experience with Shaders.

The main concern for me is that I cannot find anyone else who seems to be having this problem.

I have tried reading through the older shader and recreating it in ShaderGraph but I'm out of my depth.

So could anyone provide me with a simple projection shader or materials on where I could learn to write one, or just learn more about them projection specifically.

thanks

edit: To clarify I was using the Projectors to project a simple square texture on to each tile that I could tint, to show selectable/current/target tiles. Picture of Old Setup

Old shader that no longer works under Lightweight Render Pipeline From DevGuy @ Unity Forums

// Upgrade NOTE: replaced '_Projector' with 'unity_Projector'
// Upgrade NOTE: replaced '_ProjectorClip' with 'unity_ProjectorClip'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

  Shader "Projector/AdditiveTint" {
     Properties {
       _Color ("Tint Color", Color) = (1,1,1,1)
       _Attenuation ("Falloff", Range(0.0, 1.0)) = 1.0
       _ShadowTex ("Cookie", 2D) = "gray" {}
     }
     Subshader {
       Tags {"Queue"="Transparent"}
       Pass {
         ZWrite Off
         ColorMask RGB
         Blend SrcAlpha One // Additive blending
         Offset -1, -1

         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #include "UnityCG.cginc"

         struct v2f {
           float4 uvShadow : TEXCOORD0;
           float4 pos : SV_POSITION;
         };

         float4x4 unity_Projector;
         float4x4 unity_ProjectorClip;

         v2f vert (float4 vertex : POSITION)
         {
           v2f o;
           o.pos = UnityObjectToClipPos (vertex);
           o.uvShadow = mul (unity_Projector, vertex);
           return o;
         }

         sampler2D _ShadowTex;
         fixed4 _Color;
         float _Attenuation;

         fixed4 frag (v2f i) : SV_Target
         {
           // Apply alpha mask
           fixed4 texCookie = tex2Dproj (_ShadowTex, UNITY_PROJ_COORD(i.uvShadow));
           fixed4 outColor = _Color * texCookie.a;
           // Attenuation
           float depth = i.uvShadow.z; // [-1 (near), 1 (far)]
           return outColor * clamp(1.0 - abs(depth) + _Attenuation, 0.0, 1.0);
         }
         ENDCG
       }
     }
  }
\$\endgroup\$
  • \$\begingroup\$ There are a lot of things projectors get used for, and they're not necessarily the most "lightweight" way of achieving some of them. Can you tell us more about what game feature you're trying to use projectors for? The best solution might not be replicating the projector shader itself, but something else that gives an equivalent effect. \$\endgroup\$ – DMGregory Jul 21 '18 at 14:45
  • \$\begingroup\$ I was using them to display the selectable/current/target tiles by projecting a simple square outline onto each tile and changing the tint (selectable white, current red etc) before this I was changing the material color but that looked horrid haha. \$\endgroup\$ – Pheonix2105 Jul 21 '18 at 14:49
  • \$\begingroup\$ Can you show us a screenshot of your desired effect, and how you had set it up in the scene? \$\endgroup\$ – DMGregory Jul 21 '18 at 14:51
  • \$\begingroup\$ Added it to the main question, sorry should have done that from the start, took a few minutes as I had to remove LWRP again to get the old shader functioning. \$\endgroup\$ – Pheonix2105 Jul 21 '18 at 14:59
  • \$\begingroup\$ Hm. Doesn't look like you need projectors for this effect at all. A few textured quads could achieve the same effect more efficiently, if you're looking to do it in a "lightweight" manner (as I'm guessing by your choice of render pipeline that efficiency might be your goal) \$\endgroup\$ – DMGregory Jul 23 '18 at 14:49
1
\$\begingroup\$

Sounds like exactly my situation that I've been looking into.

The new HD pipeline does have a decal projector that can give you the same effect. Though I am unsure of the overhead and if switching to the HD pipeline is worth it for this one effect. It takes a little tweaking to get it to work, but there is a discussion on it here: https://forum.unity.com/threads/deferred-decals-built-in-with-new-srp.514296/

Or, like people mentioned, you can use quads. In your case it would give you the same effect. But, if you have bumpy terrain, then your decal is either going to hover over parts of the terrain or clip into it.

Hopefully they will add something to solve this with LWRP. Though from all of the discussions that I've read with Unity devs, it seems unlikely.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.