Search Unity

Projecting a hole?

Discussion in 'Editor & General Support' started by dangermouse, Nov 30, 2009.

  1. dangermouse

    dangermouse

    Joined:
    Nov 28, 2009
    Posts:
    73
    I've been playing with projectors and gotten quite confidant making my blob shadow, but is theere a way to use the same technique to, instead of painting black onto stuff, paint transparency?

    I've tried plugging different shaders into the projector and just end up with garbage results like whole objects glowing when the projector is aimed at them, so i guess maybe im barking up the wrong tree.

    SIMPLIFIED, is there a way to point a projector at a plane, and punch a transparent hole in that plane? i want to to move, so that an ixnay on the alpha map
     
  2. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I thought this was an interesting idea and wanted to see if I could get it to work... a little help from Aras and presto ;)
     

    Attached Files:

    PhoenixRising1 and jpthek9 like this.
  4. dangermouse

    dangermouse

    Joined:
    Nov 28, 2009
    Posts:
    73
    holy crap dude, thats awesome! even looking at the example, i have no idea how you did it :p

    im in a sticky spot though and not sure if i'll have time to use it (im setting up a demo for a friday meeting), but if i do can i have your permission to use what you've made in my scene?

    it's only temporary, and i'd gladly send you what I've done next week
     
  5. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Woah... I didn't think that was possible :eek:
     
  6. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Read the EULA I included in the project... it clearly states that you can't use this for anything other than poking round holes in checker textured spheres... :p

    But seriously, please share whatever crazy game ideas you come up with using this... I'd love to see them.
     
  7. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    That is so cool. Now I have to play with this all day, totally ruins my productivity ;)

    /P
     
  8. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I'd definitely be interested in seeing what you come up with using this Patrik ;)
     
  9. GusM

    GusM

    Joined:
    Aug 27, 2005
    Posts:
    585
    Really nice, thanks.
     
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    The problem with the approach taken in that unitypackage is that unless you stack multiple cameras, your holes cut all the way to whatever your camera clears to. Here's a solution to that.

    I used the simplest possible shader for the plane that's getting a hole cut in it. The shaders system is just a couple lines, so feel free to cut and paste into a more robust shader, and ask me if you need any help.

    Also, for some reason, what Ethan posted doesn't work in Unity iPhone, even with emulation off. What I'm posting does work on the iPhone. Ethan, should I try to figure out what's going on, and log a bug, or is this a known issue?
     

    Attached Files:

    PhoenixRising1, jpthek9 and rakkarage like this.
  11. rEo

    rEo

    Joined:
    Feb 12, 2010
    Posts:
    1
    Hey Jessy ...

    I have been looking at the unity package you provided above and find it very intruiging ... I would like to use it for a Fog of War mechanism, that I am making for an RTS game. The idea is to place a projector with you transperency projector shader above any units in the scene, such as to cut holes in a Fog of war mesh situated between the camera/projectors and the units/objects in the scene. It works like a charm as long as only one projector is utilised to cut a whole in the mesh, but when more than one projector is utilised, the wholes in the fog of war mesh dissappear ...

    So do you have any ideas, as to how one could utilize multiple projectors to cut multiple wholes in a mesh?
     
  12. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    Thanks aNTeNNa and Jessy

    Epix :D <3
     
  13. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I do have an idea, and this seems to work fine in Unity, but it doesn't in Unity iPhone. I'm not confident that Unity is utilizing rendering queues properly: it seems that unless I separate them by large values, things break. If anyone can educate me about that, please do. It seems to me that "Geometry+1" should be as good as "Geometry+500", but I don't actually know what this stuff does, inside a GPU.

    Anyway, for the time being, until anyone can supply something more reliable, check this out. It's the same as the last project, but I rewrote the hole projecting shader, hopefully yielding a performance gain. And then, there's a shader/material called "Transparency Projectors", to go along with Transparency Projector". You need the "Transparency Projector" before you can use the "Transparency Projectors", but after you have one "Transparency Projector", you should be able to add as many "Transparency Projectors" as you like.
     

    Attached Files:

  14. slidingcarlos

    slidingcarlos

    Joined:
    Apr 9, 2010
    Posts:
    7
    Hey Jessy!!

    Thanks for the great solution to projecting a hole true a poly surface!!!

    ... I am making a game, were I would like to project holes true one layer at a time... If I use your shader, than ALL of the surfaces whit the "transparent via projector" shader becomes transparent....!!

    ... Its is a game about an archaeological dig!!

    Is it not possible to only have the transparency happen on ONE layer at the time(seen from above)!!!

    -thanks for any answer you may have!!
     
  15. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Change your surfaces' materials to something else when you don't want to cut a hole in it. Or just change its renderqueue.
     
  16. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    We've PM'd a bit and I suggested that. I'll let slidingcarlos continue here, if he wants, because I don't know what else to say.
     
  17. slidingcarlos

    slidingcarlos

    Joined:
    Apr 9, 2010
    Posts:
    7
    Hey Jessy!!

    Thanks for the great solution to projecting a hole true a poly surface!!!

    ... I am making a game, were I would like to project holes true one layer at a time... If I use your shader, than ALL of the surfaces whit the "transparent via projector" shader becomes transparent....!!

    ... Its is a game about an archaeological dig!!

    I it not possible to only have the transparency happen on ONE layer at the time(seen from above)!!!

    -thanks for any answer you may have!!
     
  18. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Sorry to come to this conversation so late; but this is just what I'm looking for. Jessy, your solution seems to work great, except that the surface that's getting the hole has that super-simple shader (which you explained).

    I've been trying to buff it up to allow for the shader to take a texture map, but it's proven to be such a dark art (shaders still escape me). My latest attempt (based off of the straight diffuse - which doesn't work) looks like this:

    Code (csharp):
    1.  
    2. Shader "Transparent via Projector" {
    3.  
    4. Properties {
    5.     _Color ("Main Color", Color) = (1,1,1,1)
    6.     _MainTex ("Base (RGB)", 2D) = "white" {}
    7. }
    8.  
    9. SubShader
    10. {
    11.     Tags {"Queue" = "Geometry+300"}
    12.     Pass
    13.     {
    14.         // The alpha is supplied by the projector.
    15.         Blend OneMinusDstAlpha DstAlpha
    16.        
    17.     }
    18.  
    19. CGPROGRAM
    20. #pragma surface surf Lambert
    21.  
    22. sampler2D _MainTex;
    23. float4 _Color;
    24.  
    25. struct Input {
    26.     float2 uv_MainTex;
    27. };
    28.  
    29. void surf (Input IN, inout SurfaceOutput o) {
    30.     half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    31.     o.Albedo = c.rgb;
    32.     o.Alpha = c.a;
    33. }
    34. ENDCG
    35. }
    36.  
    37. }
    Could I get some guidance on how to fix this? Thanks!
     
  19. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you give any detail about what goes wrong with the code you've attempted? Does it just seem to do nothing or give the wrong effect?
     
  20. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Thanks andeeee. I think the biggest problem is that I don't know what I'm doing :)

    Anyway. I think I got a shader to work. I just simplified way back. This is what works:

    Code (csharp):
    1.  
    2. Shader "Hole Shader" {
    3. Properties {
    4.     _Color ("Main Color", Color) = (1,1,1,1)
    5.     _MainTex ("Base (RGBA)", 2D) = "white" {}
    6. }
    7.  
    8. SubShader {
    9.     Tags {"Queue"="Transparent" "IgnoreProjector"="False" "RenderType"="Transparent"}
    10.     LOD 200
    11.    
    12.         Pass {
    13.         // The alpha is supplied by the projector.
    14.         Blend OneMinusDstAlpha DstAlpha
    15.        
    16.         //This just defines the texture
    17.         SetTexture [_MainTex]
    18.         }
    19. }
    20.  
    21. Fallback "Transparent/VertexLit"
    22. }
    23.  
    This works alright. Although if there is not a projector providing the alpha then the entire object goes clear or Unity crashes. Not sure if there are ways to do conditionals in shaders. It might be that I need to swap out shaders via javascript when I instantiate a hole-creating projector.
     
    Last edited: Nov 11, 2010
  21. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    So, an interesting problem has emerged. I'm able to cut a hole in an object, but when you look through that hole some weird stuff happens.

    When you look through the hole and see geometry, all's well. However, if you look through the hold and see sky (as in a sky box), the view totally freaks out. It kind draw geometry over the sky, and doesn't erase it as you look away. So it sort of ghosts existing geometry.

    Also, if you look through the hole at trees on a terrain, all the leaves dissappear. Is the problem my shader, or is there something else I should be considering here to fix this?
     
  22. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    Hi

    I'm trying to use this over other transparent shaders, but for now I only see the background color and solid objects through the holes :/
    How could I tweak the shader to see any other shader though the holes, even other transparents shaders ?

    Thanks for any help :)

    [EDIT] Solution found: I just had to replace the "Geometry+XXX" tags to "Transparent+XXX" :)
     
    Last edited: Mar 20, 2013
  23. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    I'm having the same trouble as its not working with transparent objects.

    There is no Geometry+ tag in any of the two shaders...adding a transparent+ tag did not change anything.

    Can you elaborate more on how you fixed it ?

    Thanks.

    EDIT: Nevermind lol, I did a stupid mistake. I missed the second package which had the updated shaders!
     
    Last edited: Mar 26, 2013
  24. GroutchoGG

    GroutchoGG

    Joined:
    Jun 5, 2013
    Posts:
    1
    Hello, I'm trying to implement this into a CarPaint shader that we use, but I have no clue how to make it work.
    Here is the car paint shader :
    Code (csharp):
    1.  
    2. Shader "CarPaint"
    3. {
    4.     Properties
    5.     {
    6. _Color("Main Color", Color) = (0.01492536,0.1178436,1,1)
    7. _MainTex("Base (RGB) Gloss (A)", 2D) = "white" {}
    8. _Cube("Reflection Cubemap", Cube) = "black" {}
    9. _Shininess("Specular", Range(0.01,10) ) = 0.01
    10. _Gloss("Gloss", Range(0.05,1) ) = 0.05
    11.  
    12.     }
    13.    
    14.     SubShader
    15.     {
    16.  
    17.         Tags
    18.         {
    19. "Queue"="Geometry"
    20. "IgnoreProjector"="False"
    21. "RenderType"="Opaque"
    22.  
    23.         }
    24.  
    25.        
    26. Cull Back
    27. ZWrite On
    28. ZTest LEqual
    29. ColorMask RGBA
    30. Fog{
    31. }
    32.  
    33.  
    34.         CGPROGRAM
    35. #pragma surface surf BlinnPhongEditor  vertex:vert
    36. #pragma target 3.0
    37.  
    38.  
    39. float4 _Color;
    40. sampler2D _MainTex;
    41. samplerCUBE _Cube;
    42. float _Shininess;
    43. float _Gloss;
    44.  
    45.             struct EditorSurfaceOutput {
    46.                 half3 Albedo;
    47.                 half3 Normal;
    48.                 half3 Emission;
    49.                 half3 Gloss;
    50.                 half Specular;
    51.                 half Alpha;
    52.                 half4 Custom;
    53.             };
    54.            
    55.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    56.             {
    57. half3 spec = light.a * s.Gloss;
    58. half4 c;
    59. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    60. c.a = s.Alpha;
    61. return c;
    62.  
    63.             }
    64.  
    65.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    66.             {
    67.                 half3 h = normalize (lightDir + viewDir);
    68.                
    69.                 half diff = max (0, dot ( lightDir, s.Normal ));
    70.                
    71.                 float nh = max (0, dot (s.Normal, h));
    72.                 float spec = pow (nh, s.Specular*128.0);
    73.                
    74.                 half4 res;
    75.                 res.rgb = _LightColor0.rgb * diff;
    76.                 res.w = spec * Luminance (_LightColor0.rgb);
    77.                 res *= atten * 2.0;
    78.  
    79.                 return LightingBlinnPhongEditor_PrePass( s, res );
    80.             }
    81.            
    82.             struct Input {
    83.                 float3 sWorldNormal;
    84. float3 worldRefl;
    85. INTERNAL_DATA
    86.  
    87.             };
    88.  
    89.             void vert (inout appdata_full v, out Input o) {
    90. float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
    91. float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
    92. float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
    93. float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
    94.  
    95. o.sWorldNormal = mul((float3x3)_Object2World, SCALED_NORMAL);
    96.  
    97.             }
    98.            
    99.  
    100.             void surf (Input IN, inout EditorSurfaceOutput o) {
    101.                 o.Normal = float3(0.0,0.0,1.0);
    102.                 o.Alpha = 1.0;
    103.                 o.Albedo = 0.0;
    104.                 o.Emission = 0.0;
    105.                 o.Gloss = 0.0;
    106.                 o.Specular = 0.0;
    107.                 o.Custom = 0.0;
    108.                
    109. float4 WorldReflection0=float4( WorldReflectionVector (IN, float4( IN.sWorldNormal.x, IN.sWorldNormal.y,IN.sWorldNormal.z,1.0 )), 1.0);
    110. float4 TexCUBE0=texCUBE(_Cube,WorldReflection0);
    111. float4 Multiply1=TexCUBE0 * TexCUBE0;
    112. float4 Saturate0=saturate(Multiply1);
    113. float4 Master0_1_NoInput = float4(0,0,1,1);
    114. float4 Master0_3_NoInput = float4(0,0,0,0);
    115. float4 Master0_4_NoInput = float4(0,0,0,0);
    116. float4 Master0_5_NoInput = float4(1,1,1,1);
    117. float4 Master0_7_NoInput = float4(0,0,0,0);
    118. float4 Master0_6_NoInput = float4(1,1,1,1);
    119. o.Albedo = _Color;
    120. o.Emission = Saturate0;
    121.  
    122.                 o.Normal = normalize(o.Normal);
    123.             }
    124.         ENDCG
    125.     }
    126.     Fallback "Diffuse"
    127. }
    If anyone comes up with a solution, that would be so great ! Thanks :D
     
  25. idlebyte

    idlebyte

    Joined:
    Feb 3, 2013
    Posts:
    17
    I still need some help with this. Changing Geometry to Transparency results in the hole going away completely. If you don't mind explaining the difference a little more I would be indebted to you. Below are some screen shots of what I'm experiencing, Any explanation would be greatly appreciated, directions to fix would be even better.

    $2 blocks - holes overlapping - back block missing pieces in front blocks hole.png
    ^ Box in the back is missing pieces when viewed through hole in front box.
    $2 blocks - moved hole.png
    ^ Just demonstrating that hole does move

    These are of visual defects that appear in the GUI when more than one hole is on the screen at a time. One hole doesn't do this.
    $visual defect 1.png
    $visual defect 2.png
     

    Attached Files:

  26. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    340
    Hi,

    @ idlebyte: Your problem looks like a Z fighting issue, are you sure that your polygons are not too close ?

    @Everybody : I've got a big trouble with this package (holey_882.unitypackage)... I don't know how it happened, but now this method doesn't work anymore on iOS

    I'm still working on unity 3.5.7f6 for this project, but I doubt this is the cause of the problem since it was working fine some weeks ago... I've tried to change build settings (target iOS version and/or sdk) without luck until now :cry: :cry:

    I'm near the deadline of my project and I'm really in pain to find how to get it back, so any help would be really appreciated !

    EDIT : I've found the answer here :)
    http://answers.unity3d.com/questions/44333/what-shader-blending-modes-dont-work-on-ios.html

    "Use 32-bit Display Buffer" under the "Resolution and Presentation" section of Player Settings must be checked !!!
     
    Last edited: Aug 12, 2013
  27. Batigol

    Batigol

    Joined:
    Oct 17, 2012
    Posts:
    234

    Attached Files:

  28. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  29. gonzorob

    gonzorob

    Joined:
    Dec 1, 2011
    Posts:
    96
    Hi Everyone,

    Using Jessy's awesome shader. I want to take the RGB of the _MainTex and move them to the alpha. In other words, I'd like to project a transparent greyscale version of input texture.

    Thoughts on how I'd do this?

    Updated : my attempt at modifying the Transparency Projector shader. I'm passing a standard RGB image to the projector - it only give me this.

    $fail.jpg

    Code (csharp):
    1.  
    2.  
    3. Shader "Transparency Projector" {  
    4.  
    5. Properties {_MainTex ("Cookie", 2D) = "" {TexGen ObjectLinear}}
    6.  
    7. SubShader
    8. {
    9.     Tags {"Queue" = "Geometry+10"}
    10.  
    11.     Pass{
    12.  
    13.     CGPROGRAM
    14.     // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
    15.     #pragma exclude_renderers gles
    16.  
    17.         #pragma fragment frag
    18.  
    19.         #include "UnityCG.cginc"
    20.  
    21.          
    22.  
    23.         sampler2D _MainTex;
    24.  
    25.          
    26.  
    27.         struct v2f {
    28.  
    29.             float4 pos : POSITION;
    30.  
    31.             float4 uv : TEXCOORD0;
    32.  
    33.         };
    34.  
    35.  
    36.         half4 frag (v2f i) : COLOR
    37.  
    38.         {
    39.  
    40.             half4 color = tex2D(_MainTex, i.uv.xy);
    41.  
    42.            return half4(0, 0,0, (color.r+color.g+color.b)/3 );
    43.  
    44.         }
    45.  
    46.         ENDCG
    47.         ColorMask A        
    48.         SetTexture[_MainTex] {Matrix[_Projector]}
    49.     }
    50.  
    51.  
    52. }
    53.  
    54.  
    55. }
    56.  
    57.  
     
    Last edited: Nov 10, 2013
  30. HarryGodden

    HarryGodden

    Joined:
    Sep 4, 2013
    Posts:
    1
    This is really incredible! This works extremely well!
     
  31. Cannonball

    Cannonball

    Joined:
    Jan 23, 2014
    Posts:
    1
    Hey guys. This is an interesting effect. Right now I'm trying to apply it to a procedurally generated grid of things… as you can see here you can see the player through the hole, but not the floor. Anyone got any ideas on how to fix this? I'm running on fumes right now.

    $p1a.png

    Here you see the player about to duck behind the wall. The hole is projected from the camera, which is orthographic.

    $p1b.png

    When the player goes behind the wall, he is visible, but nothing else.


    I wrote two new simple vertex-lit shaders, one for the floor :

    Shader "Custom/VertexLitWIthoutProjectedAlpha" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Spec Color", Color) = (1,1,1,1)
    _Emission ("Emmisive Color", Color) = (0,0,0,0)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    _MainTex ("Base (RGB)", 2D) = "white" {}
    }

    SubShader {
    Tags {"Queue" = "Geometry+200"}
    Tags { "RenderType"="Opaque" }
    LOD 100
    Pass {

    Material {
    Diffuse [_Color]
    Ambient [_Color]
    Shininess [_Shininess]
    Specular [_SpecColor]
    Emission [_Emission]
    }
    Lighting On
    SeparateSpecular On
    SetTexture [_MainTex] {
    constantColor [_Color]
    Combine texture * primary DOUBLE, texture * constant
    }
    }
    }
    Fallback "VertexLit"
    }




    ..and one for the wall, with is linked to the projector, like in the previous files:


    Shader "VertexLitProjectedAlpha" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1)
    _SpecColor ("Spec Color", Color) = (1,1,1,1)
    _Emission ("Emmisive Color", Color) = (0,0,0,0)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    _MainTex ("Base (RGB)", 2D) = "white" { }
    }

    SubShader {

    Tags {"Queue" = "Geometry+100"}
    Pass {
    Blend OneMinusDstAlpha DstAlpha
    Material {
    Diffuse [_Color]
    Ambient [_Color]
    Shininess [_Shininess]
    Specular [_SpecColor]
    Emission [_Emission]
    }
    Lighting On
    SeparateSpecular On
    SetTexture [_MainTex] {
    constantColor [_Color]
    Combine texture * primary DOUBLE, texture * constant
    }
    }
    }
    Fallback "VertexLit"
    }





    The projector attached to the camera still has the old one from the holly_882 unity package, so that's still the same. Does anyone know why the floor wouldn't be showing through the hole as well? The projector is set to ignore nothing for the ignore layers.

    It's driving me insane.
     
  32. RedHillbilly

    RedHillbilly

    Joined:
    Mar 24, 2014
    Posts:
    39
    Dear all,

    I'm sorry for digging out this old post, but Jessy's solution is the best I have stumbled upon on the forums.
    The problem I have is mostly the same than the problem Alesk had, namely, the projector digs a hole not only through the plane, but also through other objects: Sprites.
    I tried changing the tag to "Transparent+XXX", but this doesn't seem to work on sprites.
    Any ideas on how to make Jessy's solution work with sprites?

    Thanks a lot for your help :)
     
  33. gitoffame

    gitoffame

    Joined:
    Jan 3, 2013
    Posts:
    1
    This is really cool, and potentially very useful for what I'm working on.
    The problem I'm having, is that my projector-based fake shadows don't show up on it. Unfortunately, I know nothing about writing or editing shaders.
    I'm also curious whether there would be a big performance difference between projecting maybe 10 holes on a 2048x2048 texture or just editing the texture to have holes in it...

    I want to use this for cutouts in a pinball table playfield, but I'd love to see someone use this for bullet holes in a fps...
     
  34. RedHillbilly

    RedHillbilly

    Joined:
    Mar 24, 2014
    Posts:
    39
    I finally managed to make it work, and as you said, it's pretty cool :)

    I tried to use this method to enlight multiple gameObjects: when following 4 gameobjects there was no problem, but when I tried to add around 60 - 120 projectors the game became very laggy and the frame rate droped to around 15.

    What I saw in the stats is that the number of tris goes up from around 200 to 22'000. This is due to the fact that the mesh has to be redrawn with the holes in it, and to be able to draw those wholes, a lot of tris are needed. When trying to draw this plane with 22k tris every frame, this takes up a lot of ressources, slowing the game down a lot.

    I haven't found a better solution yet, but if somebody knows a solution/workaround to this problem I would be glad to know it :)

    cheers
     
  35. Chinafreak

    Chinafreak

    Joined:
    Apr 6, 2013
    Posts:
    44
    I come from future, hoorraay... but the future look horrible, because:

    @antenna tree
    Sadly, this example isn't working anymore in Unity 5 (5.4.0f3)... And the @Jessy one didn't work as well, too. :(
    Could someone fix the shader? What changed in Unity 5 which this shader isn't working anymore?

    The issue:

    http://imgur.com/EbISIIC.gif

    Please make future better! :p

    Thanks
     
    Last edited: Nov 6, 2016
  36. Chinafreak

    Chinafreak

    Joined:
    Apr 6, 2013
    Posts:
    44
    Nobody got a idea? This is a pity! :(
     
  37. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    230
  38. Chinafreak

    Chinafreak

    Joined:
    Apr 6, 2013
    Posts:
    44
    Yep, I know this already (and this is already mentioned on this thread), but this is not the solution that I'm searching... I'm searching for projector-like transparent. :s

    But thank you!
     
  39. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    80
    As I faced the same problem, I spent some time to understand how projector and shader work together and I finally write a shader (vertex/fragment) which make an hole on target model from a projector. No fancy stuff and not perfect but it's a good starting point.

    ProjectorHole.png

    How to :
    - Put the given shader on your model, choose your texture for the hole (black is hole).
    - Use Projector/Multiply from standard asset and aim your model and tada !

    Side note on unity_Projector and unity_ProjectorClip built-in variables. I didn't find documentation on those variables so here a small description : unity_Projector provide the projected uv map on the target model quite similar to textGen function (https://docs.unity3d.com/Manual/SL-ImplementingTexGen.html). unity_ProjectorClip seems to provide falloff uv map projection but it's hard to be sure of this.


    Code (CSharp):
    1.  
    2. //declaration
    3. float4x4 unity_Projector;
    4. float4x4 unity_ProjectorClip;
    5.  
    6. //Compute uv map on vertex shader
    7. o.uvShadow = mul(unity_Projector, v.vertex);
    8. o.uvFalloff = mul(unity_ProjectorClip, v.vertex);
    9.  
    10. //then we can use those uv in fragment shader
    11. o.color = tex2D(_MainTex, i.uvShadow);
    12.  
    Update : Udpate target shader (see ProjectorTextureHole.shader) :
    - Add main texture to the model + small optimisations.
     

    Attached Files:

    Last edited: Nov 21, 2016
  40. ColdSpirit

    ColdSpirit

    Joined:
    Dec 10, 2017
    Posts:
    4
    I tested this script and it works fine, but only for one object. When I trying to add new object on camera view, it becomes broken. I spend much time to solve it but no results, I not found algorythm which set right projector's uv coord to target object's uv coord.
    Can someone tell me, what is projector's uv when I adding more than one target?