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(src, 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!

I didn’t understand this part:

Can you perhaps clarify a bit in what way the first method wasn’t working?

Thanks for your attention~~

The word I should use may be “Bump”, forget about this that it’s nothing related to my question.

First of all, if one GameObject contains many materials, maybe it’s not a efficient way.

I’ll show you some pictures to describe my problem:

487091--17104--$example1.png487091--17105--$example2.png487091--17106--$example3.png

The first picture is the original one, the result I want when setting alpha to 0.5 is the third picture instead of the second one. I know that you’ve got it, right?

My purpose can be described as “the hidden area should be always hidden when changing alpha”. That’s why I want to try image effect, but still not make it work currently. Any suggestions for me?

Yes, the screenshots make it very clear :slight_smile: Unfortunately a solution isn’t springing to mind at this exact moment, but maybe now that the question has been clarified, someone will be able to help.

[Edit: I’ll just quickly mention the renderQueue setting, which exists both at the shader level and in the material class, and can be used to specify the order in which alpha-blended objects are rendered. In your example image, if the cup were rendered first, the result should look something like the third image rather than like the second. However, the scenario you describe is a lot more complicated than that, so I’m unsure at the moment whether a solution could be derived from this.]

Very thanks for your help. I’m just thinking from your point.

Just as you said, the solution you gives may be worked only for the simple scenario. Imagine that If I rotate the camera to see from the back of the floor. The result I want is only the floor, because the cup should be covered by the floor. So the “renderQueue” has to be changed dynamically according to the camera which seems a lot complex.

Well, detecting when the camera is above or below the floor and adjusting render queue settings accordingly wouldn’t be too hard. Again though, I’m just speculating as to a solution here (partially because I don’t have a full understanding of what the desired behavior is).

Bump…