Search Unity

Question Shader Behaviour in Android

Discussion in 'Shader Graph' started by kislotaooankit, Jul 6, 2020.

  1. kislotaooankit

    kislotaooankit

    Joined:
    Apr 20, 2020
    Posts:
    15
    Hey all ,

    I am a Newbie who just started with shaders graphs. I was designing a clipping plane which would turn the alpha of mesh behind the plane as 0 and infront of it in an ARfoundation Application

    I am doing this by calculating plane normal and using the dot product of 3d model and plane normal vector to decide whether the point of mesh is above plane or behind.

    Desired Working Video :


    In above example I have attached a clipping shader on 3d model ,clipping script on Quad Plane, and its working as desired in unity editor.

    Problem In android :


    However the plane behavior angle is completely changed in my phone .

    Clipping Script attached to Quad Plane.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. //[ExecuteInEditMode]
    6. public class ClippingPlane : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.  
    10.     public Material mat;
    11.     public int slider; //used to determine how early clipping should start from the plane
    12.  
    13.     void Start()
    14.     {
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         Vector4 planepos = new Vector4(transform.position.x, transform.position.y, transform.position.z + slider, 0);
    21.         mat.SetVector("_PlanePos", planepos);
    22.         mat.SetVector("_PlaneNorm", transform.forward); // to get the normal vector of plane emitting outwards
    23.         //mat.SetVector("_PlaneNorm", transform.right); tried with all possible combination
    24.         //mat.SetVector("_PlaneNorm", transform.up);    but still getting that same left to right clipping in my                                                                                             phone.
    25.  
    26.     }
    27. }
    Shader Graph for clipping Image. (Cropped nodes are there for simple Fresnel effect )

    Observation 1: if i provide a Normal vector (vector3 node) manually filled to my dot product node the desired operation is working fine in android too (but the clipping angle is fixed on one axis and i want to move my clipping plane freely around the model and clip from any position and angle)

    View attachment 657245

    Observation 2: If i provide a normal vector node as an property where value is filled on runtime by a script then it is posing the error. (however it is working fine in unity editor).

    View attachment 657248

    I am not able to figure out why it is working differently in mobile phone butt my guess it the AR camera is doing some alternation with axes ...

    Any help would be appreciated.
     

    Attached Files:

    Last edited: Jul 8, 2020