Search Unity

Shader transition from Unity 4.x to Unity 5 -- Projector

Discussion in 'Shaders' started by Velo222, Jan 20, 2015.

  1. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hello,

    I had a shader that worked in Unity 4.x, but no longer works in Unity 5, and I'd like to make it work in Unity 5 if possible. It will be used on a material on a Projector component (to project a texture down onto the terrain). At least, that's what it used to do well in Unity 4.

    So here is the shader code:

    Code (CSharp):
    1. Shader "Custom/Projector1" {
    2.     Properties {
    3.      _Color ("Main Color", Color) = (1,1,1,1)    
    4.      _ShadowTex ("Cookie", 2D) = "" { TexGen ObjectLinear }
    5.      _FalloffTex ("FallOff", 2D) = "white" { TexGen ObjectLinear }
    6.   }
    7.   Subshader {
    8.      Tags { "RenderType"="Transparent-1" }
    9.      Pass {
    10.         ZWrite Off
    11.         AlphaTest Greater 0
    12.         Offset -1, -1
    13.         ColorMask RGB
    14.         Blend SrcAlpha OneMinusSrcAlpha
    15.         Color [_Color]
    16.         SetTexture [_ShadowTex] {
    17.             constantColor [_Color]
    18.             combine texture*constant
    19.             Matrix [_Projector]
    20.         }
    21.         SetTexture [_FalloffTex] {
    22.            constantColor (0,0,0,0)
    23.            combine previous lerp (texture) constant
    24.            Matrix [_ProjectorClip]
    25.         }
    26.      }
    27.   }
    28.  
    29.     FallBack "Diffuse"
    30. }

    I read that the "TexGen" command and the "Matrix" command may have been removed. Is there some way to re-write this code to work with Unity 5?

    If not, could someone point me in the direction to where I could find a shader (or the like) that will allow me to project a texture onto the terrain (Unity's terrain).

    Thank you.
     
  2. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Does anyone know? I think all I need to do is replace line #19 where it says "Matrix [_Projector]" with whatever the equivalent of grabbing the projector matrix would be in Unity 5. I can't find how to do it, or the command needed to grab or set the Projector's matrix though, now that the Matrix command has been "deprecated".

    Maybe someone could point me to where I could learn how to write the necessary Projector shader myself?

    Thank you.
     
  3. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Nobody eh? :(
     
  4. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
  5. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437