- Home /
How would you create look for floating computer interface?
Hi there!
I'd like to create a look for an in-game computer interface, that floats like an object in the level (like in the image below). How would you create an alpha channel like those stripes? Shader? Post Effect? Something else? What do you think is the most easy way?
Thank you for your suggestions!
Answer by taoa · Nov 24, 2010 at 01:39 PM
Shader. In the Pixel shader, for a pixel whose x position on screen is odd (or even, doesn't matter), divide the alpha value by whatever you want.
thanks for the answer!
and say I want a certain texture ins$$anonymous$$d of the stripes? fi. crosshatches or another pattern. can i do something like a screenspace projection this way?
still shader based. use screen space coords to do a 2d texture lookup for your alpha, rather than hard coding it to even and odd values.
What he said. But since you're looking for a computer interface effect, and since your game renders on... a computer, you might as well make use of said computer's resolution ^^
Answer by VivienS · Jan 24, 2011 at 01:13 PM
Ok, just in case someone is interested: This is the final shader code I wrote for this effect. It uses a texture for the alpha channel, that is textured in screen coordinates, so you can decide for yourself how the alpha should look like. The Lighting function produces a flat, unlit surface.
Most likely not as performant as taoa's answer, but more flexible and better suited for what I needed.
Only drawback so far: In oder not to stretch the alpha, but tile it across the screen, you have to pass the shader the dimensions of your (quadratic) alpha texture and the screen.
Shader "FX/Computer Display" { Properties { _Color ("Color", Color) = (1,1,1,1) _AlphaTex ("Alpha Texture (R = Transparency)", 2D) = "white" {} _ScreenResW ("Screen Resolution Width", Float) = 1024 _ScreenResH ("Screen Resolution Heigth", Float) = 768 _TexRes ("Quadratic Texture Resolution", Float) = 128 }
SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent"}
CGPROGRAM
#pragma surface surf Unlit alpha
struct Input {
float4 screenPos;
};
float4 _Color;
sampler2D _AlphaTex;
float _ScreenResW;
float _ScreenResH;
float _TexRes;
void surf (Input IN, inout SurfaceOutput o) {
// calculate pixel-correct screenspace UVs
float2 screenUV = IN.screenPos.xy/IN.screenPos.w;
screenUV.x *= _ScreenResW/_TexRes;
screenUV.y *= _ScreenResH/_TexRes;
half4 ac = tex2D(_AlphaTex, screenUV);
o.Alpha = ac.r * _Color.a;
o.Albedo = _Color.rgb;
}
half4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten) {
half4 c;
c.rgb = s.Albedo * 0.2;
c.a = s.Alpha;
return c;
}
ENDCG
} Fallback "Transparent/VertexLit" }
Answer by sendel76 · Jul 22, 2011 at 12:08 PM
pragma surface surf Unlit alpha
oes not work for iPhone ? It says:Shader error in 'Mobile/Alpha Vertex Color': Surface lighting model 'Unlit' not found. Available models: BlinnPhong, Lambert at line X