Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader update

Discussion in 'Unity 5 Pre-order Beta' started by creat327, Feb 24, 2015.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi

    I have no clue about shaders, but I have this on one I purchased long ago:

    Pass {
    SetTexture [_FrontTex] { combine texture }
    SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
    SetTexture [_FrontTex2] { combine previous +- primary, previous * primary }
    }

    The problem is that on Unity5 the combine +- has been removed and it fails. Anyone knows how to rewrite that so it works on U5?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    It would help to see the whole shader, since without context it's hard to say what the "primary" keyword ends up being. I'll assume it means "vertex color".

    So you'd have to rewrite that into a vertex/fragment program. Typing out of the top of my head (might not compile):

    Code (csharp):
    1.  
    2. Pass {
    3.     CGPROGRAM
    4.     #pragma vertex vert
    5.     #pragma fragment frag
    6.     #include "UnityCG.cginc"
    7.     struct v2f
    8.     {
    9.         float2 uv1 : TEXCOORD0;
    10.         float2 uv2 : TEXCOORD1;
    11.         half4 color : COLOR0;
    12.         float4 pos : SV_POSITION;
    13.     };
    14.     float4 _FrontTex_ST;
    15.     float4 _FrontTex2_ST;
    16.     v2f vert(float4 pos : POSITION, float2 uv : TEXCOORD0, float4 col : COLOR)
    17.     {
    18.         v2f o;
    19.         o.pos = mul (UNITY_MATRIX_MVP, pos);
    20.         o.uv1 = TRANSFORM_TEX(uv, _FrontTex);
    21.         o.uv2 = TRANSFORM_TEX(uv, _FrontTex2);
    22.         o.color = col;
    23.         return o;
    24.     }
    25.     sampler2D _FrontTex;
    26.     sampler2D _FrontTex2;
    27.     float _Blend;
    28.     fixed4 frag(v2f i) : SV_Target
    29.     {
    30.         fixed4 tex1 = tex2D(_FrontTex, i.uv1);
    31.         fixed4 tex2 = tex2D(_FrontTex2, i.uv2);
    32.         fixed4 col = lerp(tex2, tex1, _Blend);
    33.         col.rgb = col.rgb + i.color.rgb - 0.5;
    34.         col.a = col.a * i.color.a;
    35.         return col;
    36.     }
    37.     ENDCG
    38. }
    39.  
     
  3. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    thanks aras i'll give it a try, it also helps because that way I learn how to modify the other stuff.
    From google I found out that combine +- was the same than previous + primary - 0.5 but I didn't know how or where to place it, now I see it's in the frag area wher eyou do all calculations.
     
  4. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756