Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Broken matcap shader since Unity 5

Discussion in 'Shaders' started by aagocs, Apr 14, 2015.

  1. aagocs

    aagocs

    Joined:
    Oct 18, 2012
    Posts:
    15
    Hello we're using a custom matcap shader, but in Unity 5, the texture is displayed very weird.

    Code (CSharp):
    1. Shader "MatCap/Vertex/Textured Lit Flat Shaded"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Color", Color) = (0,0,0,1)
    6.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Tags { "RenderType"="Opaque" }
    12.         //Cull Off
    13.      
    14.         CGPROGRAM
    15.      
    16.         #pragma surface surf Lambert vertex:vert
    17.      
    18.         sampler2D _MatCap;
    19.         float4 _Color;
    20.      
    21.         struct Input
    22.         {
    23.             float2 matcapUV;
    24.         };
    25.      
    26.         void vert (inout appdata_full v, out Input o)
    27.         {
    28.             o.matcapUV = float2(dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal),dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal)) * 0.5 + 0.5;
    29.         }
    30.      
    31.         void surf (Input IN, inout SurfaceOutput o)
    32.         {
    33.             half4 mc = tex2D(_MatCap, IN.matcapUV);
    34.             o.Albedo = ((mc * 2.0) *_Color);
    35.         }
    36.      
    37.         ENDCG
    38.     }
    39. }
    Any idea?
     

    Attached Files:

  2. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey I too had issues with the matcap shaders (and my customised versions of) after upgrading to Unity 5. I contacted the dev and he fixed them VERY quickly and uploaded new versions to the Asset Store.

    Have you tried using the latest version from the Asset Store? If you are using the latest contact the dev, he'll most likely fix it quick.
     
  3. aagocs

    aagocs

    Joined:
    Oct 18, 2012
    Posts:
    15
    Thanks for the quick reply. This is a custom made shader, not from the free pack on the asset store.
     
  4. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Oh sorry, I thought it was one you modified from the pack from the asset store! Oops.

    Edit: perhaps still worth looking at that free pack since it may shed some light on what needs to change for Unity 5.
     
  5. DayVeeMan_

    DayVeeMan_

    Joined:
    Apr 22, 2016
    Posts:
    1
    I think you need to normalize. Haven't fully tested, but something like this:

    o.matcapUV = float2(dot(normalize(UNITY_MATRIX_IT_MV[0].xyz),v.normal),dot(normalize(UNITY_MATRIX_IT_MV[1].xyz),v.normal)) * 0.5 + 0.5;

    Unity5 stopped auto compensating for scale on the CPU. Which is good for non-uniform scale and performance, but it means you may need to normalize in the shader where you didn't before, especially with scaled object.
     
    Last edited: Apr 22, 2016