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

Problem: Projector texture (artifacts / repeating)

Discussion in 'Editor & General Support' started by GeroldS, Feb 29, 2008.

  1. GeroldS

    GeroldS

    Joined:
    Dec 30, 2007
    Posts:
    34
    EDIT: Solution

    I got a projector set up with a shader to do additive blending (its a customized blob-shadow shader), alpha-only falloff texture and RGBA cookie texture. It all works with just a minor problem: The projected texture repeats infinately outside the projection cone.

    Here's a pic:



    Whats going on?

    Here is the shader code:

    Code (csharp):
    1. Shader "FX/Projector Add" {
    2.     Properties {
    3.         _ShadowTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
    4.         _FalloffTex ("FallOff", 2D) = "white" { TexGen ObjectLinear }
    5.     }
    6.  
    7.     Subshader {
    8.         Pass {
    9.             ZWrite Off
    10.             // Offset -1, -1
    11.  
    12.             Fog { Color (1, 1, 1) }
    13.             AlphaTest Greater 0
    14.             ColorMask RGB
    15.             Blend One One
    16.             SetTexture [_ShadowTex] {
    17.                 combine texture, ONE - texture
    18.                 Matrix [_Projector]
    19.             }
    20.             SetTexture [_FalloffTex] {
    21.                 constantColor (0,0,0,0)
    22.                 combine previous lerp (texture) constant
    23.                 Matrix [_ProjectorClip]
    24.             }
    25.         }
    26.     }
    27. }
    Any ideas?
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    You presumably just need to select the offending texture in the Project pane and set it to Clamp instead of Repeat in the inspector.
     
  3. GeroldS

    GeroldS

    Joined:
    Dec 30, 2007
    Posts:
    34
    That almost did it, yet there are still some odd artifacts. I tried painting a black edge around the projected texture... that dimmed the streaks a bit but didn't remove them entirely. Also the streaks in the projector's YZ plane aren't going away.

     
  4. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Clamping stops the texture at the edge pixels, then stretches those pixels off in all directions. Make sure your texture has a single colour border around it to avoid that.

    EDIT: oops, I see you tried that. What about a thicker border?

    EDIT 2: does it help if you remove AlphaTest Greater 0?
     
    ExtraCat likes this.
  5. GeroldS

    GeroldS

    Joined:
    Dec 30, 2007
    Posts:
    34
    It helps to make the border wider and set aniso higher.

    Leaves only the artifacts in the YZ plane.
     
  6. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Turn off mipmaps in the import settings? I vaugley remember Nicholas giving me this advice and it worked great.
    HTH
    AC

    Edit: or it was Turn off border mipmaps-try that
     
  7. GeroldS

    GeroldS

    Joined:
    Dec 30, 2007
    Posts:
    34
    Thanks, now it works.

    So for all who come after me here is a summary:

    To make a custom Projector:
    - Set all involved textures to "Clamp"
    - Depending on your blend mode, draw a white/black/transparent border around your texture. 1+ pixels wide.
    - import the textures with "Border Mipmaps ON".
     
  8. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I think ideally you'd still want mipmaps, so try the turn off border mipmaps option. Hows that looking?
    AC