How to make the model semi-transparent?

I’m a new guy here.

Currently I’m working on a project to view a house model on iPad, it contains several floors. Only one floor is displayed each time. I want to do an animation when switching from one floor to another. The animation I imagine is that fade out one floor and fade in another floor. So the question is how to make a GameObject semi-transparent from 0 to 1?

I learned from the iPhone example Penelope that I can set the alpha value to every material shader using by the model. The shader I used looks like this and I change the alpha value of the color when doing animation.

Shader "iOS/Lightmap Alpha"
{
	Properties
	{
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_LightMap ("Lightmap (RGB)", 2D) = "white" { LightmapMode }
	}

	SubShader
	{
		Tags { "Queue" = "Transparent"}
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass
		{
			Name "BASE"
			Tags {"LightMode" = "Always"}
	
			BindChannels {
				Bind "Vertex", vertex
				Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
				Bind "texcoord", texcoord1 // main uses 1st uv
			}
			SetTexture [_LightMap] {
				constantColor [_Color]
				combine texture * constant
			}
			SetTexture [_MainTex] {
				combine texture * previous DOUBLE
			}
		}
	}
}

This works but the problem of it is that when alpha is 1, the floor is covered by many furnitures. If I set the alpha to 0.5, for example, I can see the floor through the furnitures which is not the way I want.

Now I’m tring to use image effect to implement my idea. There is no guide on how to implement the image effect, but I guess it can resolve my problem but I don’t know how.

Here is my code which is not work currently:

public var shader : Shader;
private var material : Material;

function Start() {
	material = new Material(shader);
	material.hideFlags = HideFlags.HideAndDontSave;
}

function OnRenderImage(src:Texture, dest:RenderTexture) {
	material.mainTexture = src;
	Graphics.Blit(buffer, dest, material);
}

The shader I used for this is very very simple:

Shader "iOS/Alpha Only"
{
	Properties
	{
		_Color ("Main Color", Color) = (1,1,1,0.1)
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}

	SubShader
	{
		Tags { "Queue" = "Transparent" }
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass
		{
			Name "BASE"
	
			SetTexture [_MainTex] {
				constantColor [_Color]
				combine texture * constant
			}
		}
	}
}

I’m sure that OnRenderImage() is called, but I can’t make the model semi-transparent. I get the totally opaque model everytime. Seems the alpha value is not working.

Any help is welcome, please give me some guides on how to implement my idea? Do my 2 solutions be common and make sense or are there any other good solutions to solve my problem?

Thanks.

Keep this thread on the top, I’m eager to get the answer!

Bump…

I’m not exactly sure what effect you are looking for here. Are you switching floors by jumping from one to the other (and you want a fade transition) or are you going down stairs and want the upper floor to fade out so the lower floor is visible from above? If it’s the latter, do you want the furniture to fade out first before the floor?

Thanks for your attention and sorry for the unclear description about my request.

In my case, I have 3 floors: basement, floor 1 and floor 2. I can view one floor model at one time and each floor contains many furnitures. Suppose I’m in floor 1 and want to see floor 2, I’ll transform my camera a little high, fade out the floor one and fade in the floor two together with all furnitures on the that floor. I’ll attach some pictures to show this step and you’ll see my problem.

489509--17191--$floor1  2.png489509--17190--$current effect.png489509--17189--$effect wanted.png

The first picture shows the original model of the first and second floor. The second picture is the current effect. From the red rectangles you can see my problem is:

  1. I can see the table and furniture throw the wall in the floor 2
  2. The plants that use “alpha test” shader can’t be semi-transparent by changing the alpha of the materail

The third picture which I made in photoshop is what I want. I want to see that one floor can be treated as a whole to be set alpha to it, like setting the alpha to a picture. This is why I want to try “Image Effect” in unity. But during investigating these days, I find “Image Effect” can only be applied to the entire screen, it can’t be used to set a sub-rect of the screen or only the thing which can be seen in one camera. Am I right?

Hope I make my request clear now, any suggestions?

Here is one snapshot of my model hierachy, some are using alpha test shader and some are using lightmap with alpha shader. Do I need some changes to the model or the shader if I want to implement my idea.

Bump…

Is it possible to have a black plane object sandwiched in between the two floors and vary the alpha on that? If you make it very large then you shouldn’t be able to see the edges against the black background.

Have you tried using a transparent shader that does a Zwrite pass first? This should allow you to fade whole rooms or floors out at a time, as long as the contents of the rooms are in the same mesh as the room itself. This would mean switching to polygonal plants instead of alpha tested ones, which is probably a good idea on iOS anyway.

maybe have the material color be changed darker to match the rest of the bottom half,

if it doesnt work because its lightmapped maybe change the lightmap to a darker one

OR (lol)

change the material completely. your bottom floor is now dark, so does the plant really need a lightmap? change the material to transparent/vertex lit and level the vertex lit color to match the rest of the floors brightness, and then have it swap back

by the way, your renders look sweet! very professional quality, keep it up :slight_smile:

I’m very appreciate for your helps.

The pictures I show is just a simplified example, there are many floors. But I think I’ve got your idea, I thought of a better solution that using one polygon for each floor that the polygon’s shape is just the same as the edge of each floor. Then I can use your idea to simulate shade out and shade in floors.

I haven’t try this, but I will try. Currently I don’t have a clear understanding about Zwrite command. I think that the object using this will draw the object at a random order, is it right? If so, the plants display will be weird.

Very very heart-stirring. Thanks