Render only certain objects through certain doors...

This is my first Shader Lab post. I’m finally biting the bullet and attempting to learn this!

I want a room with 2 doors that lead to 2 different worlds. Let’s say for ease of explanation that one door leads to Jurassic park and the other leads to Star Wars. Both doors are on the same wall so you can see the same area through each one. When looking through one door you should see a spaceship and when looking through the other door you should see a dinosaur.

Right now I’m using this for the dinosaur door:

Shader "Depth Mask" {
	SubShader {
		Tags{"Queue" = "Geometry-101"}
		Colormask A
		ztest Lequal
		Zwrite on
		Pass{
			
			}
	} 
	FallBack "Diffuse", 1
}

And this for the dinosaur’s material:

Shader "BumpedCave" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {}
	}
	SubShader {
		Tags{"Queue" = "Geometry-102"}
		UsePass "Self-Illumin/VertexLit/BASE"
		UsePass "Bumped Diffuse/PPL"
	} 
	FallBack "Diffuse", 1
}

I’m using this for the spaceship door:

Shader "Door1" {
	SubShader {
		Tags{"Queue" = "Geometry-104"}
		Colormask A
		ztest Lequal
		Zwrite on
		Pass{
			
			}
	} 
	FallBack "Diffuse", 1
}

And this for the spaceship’s material:

Shader "Objects1" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {}
	}
	SubShader {
		Tags{"Queue" = "Geometry-105"}
		UsePass "Self-Illumin/VertexLit/BASE"
		UsePass "Bumped Diffuse/PPL"
	} 
	FallBack "Diffuse", 1
}

While looking through the Spaceship door, you can’t see the dinosaur and that’s good. But while looking through the dinosaur door, of course you can see the dino and the spaceship.

I need another method of making objects invisible. The Queue isn’t working for this.

Any ideas on how I can make this work??

Thanks!

http://technology.blurst.com/camera-render-with-shader/

Daniel, thank you for your quick reply.

Is that for Unity Pro only?

Unfortunately, I’m a free version user.

Yeah, that solution requires compositing the two background with the foreground using RenderTextures and Graphics.Blit.

You might be out of luck unless you are Ok with not being able to see through both doors at the same time. Perhaps you could have the overlapping portions of the worlds disappear if they are not visible? You’d have to compute when to turn them off based on the player’s position.

Hmm… Yes you’ve got me thinking. I could put the depth masks between the doors and have it rotate constantly away from the camera (as on a hinge) so as the player’s Point of View changed, the mask… wait a sec… that won’t work.

I can put a plane between each door always flat on edge to the camera’s POV that would enable/disable mesh renderers with OnTriggerEnter / Exit… It’s a piece of work, but what isn’t?!

I was hoping to make a depth mask that would render by ‘tag’ or ‘layer’ instead of queue number, but if that simply isn’t available, then I shall use a work-around until I can buy Pro.

Thanks again.

:smile: :smile: :smile:
It’s very good!
Thank all