Projecting a hole?

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

I’m not sure if this is helpful or not, but you can take a look at this and see if it helps. http://www.unifycommunity.com/wiki/index.php?title=DepthMask

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 :wink:

232285--8318--$screen_shot_2009_12_01_at_115255_am_692.png
232285–8319–$depthmaskprojector_847.unitypackage (29.3 KB)

2 Likes

holy crap dude, thats awesome! even looking at the example, i have no idea how you did it :stuck_out_tongue:

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

Woah… I didn’t think that was possible :shock:

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… :stuck_out_tongue:

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

That is so cool. Now I have to play with this all day, totally ruins my productivity :wink:

/P

I’d definitely be interested in seeing what you come up with using this Patrik :wink:

Really nice, thanks.

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?

232985–8344–$holey_190.unitypackage (24.7 KB)

3 Likes

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?

Thanks aNTeNNa and Jessy

Epix :smile: <3

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.

289374–10339–$holey_882.unitypackage (25.8 KB)

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!!

Change your surfaces’ materials to something else when you don’t want to cut a hole in it. Or just change its renderqueue.

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.

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!!

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:

Shader "Transparent via Projector" {

Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader
{
	Tags {"Queue" = "Geometry+300"}	
	Pass 
	{
		// The alpha is supplied by the projector.
		Blend OneMinusDstAlpha DstAlpha
		
	}

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
float4 _Color;

struct Input {
	float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}

}

Could I get some guidance on how to fix this? Thanks!

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?

Thanks andeeee. I think the biggest problem is that I don’t know what I’m doing :slight_smile:

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

Shader "Hole Shader" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGBA)", 2D) = "white" {}
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="False" "RenderType"="Transparent"}
	LOD 200
	
		Pass {
		// The alpha is supplied by the projector.
		Blend OneMinusDstAlpha DstAlpha
		
		//This just defines the texture
		SetTexture [_MainTex] 
		}
}

Fallback "Transparent/VertexLit"
}

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.