Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[WITH PIC] Projector makes image on wrong side :)

Discussion in 'Editor & General Support' started by KEMBL, Jul 9, 2011.

  1. KEMBL

    KEMBL

    Joined:
    Apr 16, 2009
    Posts:
    181
    Hi, All!

    I have an issue with the standard projector. The projector makes an image on the side at front of it and, by some unknown reason, on the far back wrong side of the mesh (regular Unity cube)!!! Is this a normal behaviour?

    Take a look at the picture, I created simple Cube primitive (from unity) and projected an image to it. Suddenly, the projected image appear on the back side of the primitive. The Near or Far clip plane did not help with this issue.

    My first idea was that everyone side of Cube (from Unity primitive) lay one by one on UV map, so I create the cube with 6 distinct slices on UV map for each side and this did not help with the problem too. The wrong image from the projector still appears on back side of the cube :(((((

    Then I tried to modify standard Projector shader and you can see this on the shader name (Projector MultiplyCG) but with no luck again.

    The question is: How to make projected image appears only on one side of a mesh without this mesh deconstruction?
     

    Attached Files:

    Last edited: Feb 19, 2016
  2. KEMBL

    KEMBL

    Joined:
    Apr 16, 2009
    Posts:
    181
    There is some midisuccefus way to do right projection:

    Code (csharp):
    1.  
    2. Shader "Projector"
    3. {
    4.  Properties
    5.  {
    6.   _Color ("Main Colour", Color) = (1,1,1,1)
    7.   _MainTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
    8.   //_FalloffTex ("FallOff", 2D) = "white" { TexGen ObjectLinear   }
    9.   //_far("FarClip", float) = 1
    10.  }
    11.  
    12.  SubShader
    13.  {
    14.   Tags { "RenderType"="Transparent"  "Queue"="Transparent+100"}
    15.   Pass
    16.   {
    17.    Lighting Off
    18.    Cull Off
    19.    ZWrite Off
    20.    Offset -1, -1
    21.    
    22.    Tags { "Queue" = "Transparent" "RenderType"="Opaque" }
    23.    //Fog { Mode Off }
    24.    AlphaTest Greater 0
    25.    ColorMask RGB
    26.    Blend SrcAlpha OneMinusSrcAlpha
    27.    CGPROGRAM
    28.    #pragma vertex vert
    29.    #pragma fragment frag
    30.    #pragma fragmentoption ARB_fog_exp2
    31.    #pragma fragmentoption ARB_precision_hint_fastest
    32.    #include "UnityCG.cginc"
    33.  
    34.    struct Input
    35.    {
    36.     float4 vertex : SV_POSITION;
    37.     float3 normal : NORMAL;
    38.     //float4 color : COLOR;
    39.    };
    40.    
    41.    struct v2f
    42.    {
    43.     float4 pos : SV_POSITION;
    44.     float4 uv_Main  : TEXCOORD0;
    45.     //float4 color : COLOR0;
    46.     float koef : COLOR;
    47.    };
    48.  
    49.    sampler2D _MainTex;
    50.    //sampler2D _FalloffTex;
    51.    float4 _Color;
    52.    float4x4 _Projector;
    53.    //float4x4 _ProjectorClip;
    54.    //float _far;
    55.  
    56.    v2f vert(Input v)
    57.    {
    58.     v2f o;
    59.     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    60.     o.uv_Main = mul (_Projector, v.vertex);
    61.    
    62.     float3 normView = normalize(float3(_Projector[2][0],_Projector[2][1], _Projector[2][2]));
    63.     float d = dot(v.normal, normView);
    64.    
    65.     o.koef = d < 0 ? 1 : 0;
    66.    
    67.     return o;
    68.    }
    69.  
    70.    half4 frag (v2f i) : COLOR
    71.    {
    72.     half4 tex = tex2Dproj(_MainTex, UNITY_PROJ_COORD(i.uv_Main)) * _Color * i.koef;
    73.     //tex.a = (1 - tex.a);
    74.     return tex;
    75.    }
    76.    ENDCG
    77.   }
    78.  }
    79. }
    80.  
     
    Last edited: Jul 13, 2011
  3. Quaker_SDR

    Quaker_SDR

    Joined:
    Jun 21, 2013
    Posts:
    39
    this is not working for me any idea???
     
  4. Lunx

    Lunx

    Joined:
    Jul 23, 2014
    Posts:
    1
    Change vert function to


    Code (CSharp):
    1.    v2f vert(appdata_full v)
    2.    {
    3.     v2f o;
    4.     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    5.     o.uv_Main = mul (_Projector, v.vertex);
    6.  
    7.     float3 normView = normalize(float3(_Projector[2][0],_Projector[2][1], _Projector[2][2]));
    8.     float d =dot(v.normal, normView);
    9.     o.koef = d < 0 ? 1 : 0;
    10.  
    11.     return o;
    12.    }
    works for me