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.