- Home /
Masking a plane object (which has an animated texture offset)
Hello, I have a plane with a material that has an animated texture offset, and I would like to mask out part of that plane.
I tried different shaders, but the invisible area seems to move along with the offset...
I tried with an additional camera (ortho) + culling mask, but the mask gets resized in different aspect ratios and it looks wrong...
Is there a way that I'm missing to clip the plane so the result will be something like the image below?
Imagine the black screen as the entire game view, and the Plane is just a normal plane with a repeating texture and animated offset... the Visible Area is what is actually being rendered, and the darker area of the plane is not being rendered at all. I made it darker here just for illustration purposes.
Thanks for any help and insights!
Answer by kilgore · May 07, 2013 at 11:34 PM
You need a shader that uses one texture to display the image and uses one texture as an alpha. Below is an Unlit example. "Base" is used for the image you want to animate and BaseA is your alpha.
Shader "Unlit/TransparentSeperateAlpha"
{
Properties
{
_MainTex ("Base", 2D) = "white" {}
_MainTexA("BaseA", 2D) = "white" {}
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Lighting Off
SetTexture [_MainTex]
{
Combine texture
}
SetTexture [_MainTexA]
{
Combine texture * previous
}
}
}
}
Thanks, kilgore! You're awesome. Works like a charm!
Just out of curiosity, are there any optimization for mobile for that shader? Because I did notice that Unity has $$anonymous$$obile-Unlit and regular Unlit shaders (for example).
I do get 55-60fps on my scene on iPhone4/iPad2, still haven't checked on 3GS. Thanks!
To be honest I know little about shader optimization. This comes from a source I had searched a good while ago to solve the same issue. If someone on Answers is willing to post a 'mobile' optimized version of the above script I'd be more than happy to give some karma.
By the way sounwav_, really nice use of a gif to explain your question! I appreciate the effort in putting that together to pinpoint your problem.
Yeah, I thought it would explain the issue best :) Thanks!
Hopefully I won't be needing an optimization for the 3GS, but I will try to read-up on shader optimizations in the near future.
And thanks for the great answer!