How do you make shield effect ?

HI, I’m new to unity. And I’m working at a game project now.

I want to make visual effects like this ,

Should I use particle system of unity ? if so , how ?

Any suggesstion or help will be appricated. Thanks.

You mean like this:

That’s just a sphere textured with a simple additive transparency shader with a view dependant falloff. I believe the wiki has similar shaders.

1 Like

Cameron’s right, you can find said shaders on the wiki.

http://www.unifycommunity.com/wiki/index.php?title=Planet (could be used as a shield type effect too)
and probably others out there. You could also pretty easily make one with the shader node editor available on the forum, the rim lighting example springs to mind as a starting point.

Thanks all your reply, I’ll give a try later.

BTW, why there is no image in my first post ? I did insert the link of that image.

Might be the insane looking url you used for the image stopping it from working properly. Try another url?

You linked to a webpage, not an image. Perhaps you copied it from a google image search result. The URL you used was:

http://images.google.com.hk/imglanding?q=startcraft+Shield&hl=zh-CN&newwindow=1&safe=strict&sa=G&gbv=2&biw=1280&bih=605&tbs=isch:1&tbnid=BRDwePc1ft59gM:&imgrefurl=http://www.quartertothree.com/fp/2011/01/12/tom-vs-kelly-starcraft-ii-game-one/&imgurl=http://www.quartertothree.com/fp/wp-content/uploads/2011/01/Starcraft_II_TvK_game_one_shields_up.jpg&ei=ia1cTZ_gL4eesQOsqMXfCg&zoom=1&w=600&h=377&iact=rc&oei=ia1cTZ_gL4eesQOsqMXfCg&page=1&tbnh=106&tbnw=169&start=0&ndsp=18&ved=1t:429,r:8,s:0

I dug through the URL and guessed that was the image you were wanted to show. You need to use the image URL (will end in .jpg or .gif or .png) when using the forum image feature.

Be very careful using that wiki shader though. I’m not sure who put it there but they ought to be slapped for using a SM3.0 shader like that with a diffuse fallback. Any SM2.0 cards will display the shield as a solid ball and it’s entirely possible to do a SM2.0 version of that effect. It shouldn’t haev been posted on the wiki in that state.

I try this shader : http://www.unifycommunity.com/wiki/index.php?title=Shield

But got very weird result :

What I did :

  1. create a file named Shield.shader, then copy past the following codes
Shader "Shield" {
    Properties {
        _Offset ("Time", Range (0, 1)) = 0.0
        _Color ("Tint (RGB)", Color) = (1,1,1,1)
        _SurfaceTex ("Texture (RGB)", 2D) = "white" {}
        _RampTex ("Facing Ratio Ramp (RGB)", 2D) = "white" {}
    }
    SubShader {
        ZWrite Off
        Tags { "Queue" = "Transparent" }
        Blend One One
        Cull Off

        Pass {  
            CGPROGRAM 
            #pragma vertex vert
            #pragma fragment frag
            #pragma fragmentoption ARB_fog_exp2
            #include "UnityCG.cginc" 
 
            struct v2f {
                V2F_POS_FOG;
                float2 uv : TEXCOORD0;
                float2 uv2 : TEXCOORD1;
                float3 normal : TEXCOORD2;
            };
            
            uniform float _Offset;
            
            v2f vert (appdata_base v) {
                v2f o;
                PositionFog( v.vertex, o.pos, o.fog );
                
                float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
                v.texcoord.x = v.texcoord.x;
                v.texcoord.y = v.texcoord.y + _Offset;
                o.uv = TRANSFORM_UV (1);
                o.uv2 = float2( abs (dot (viewDir, v.normal)), 0.5);
                o.normal = v.normal;
                return o;
            }
            
            uniform float4 _Color;
            uniform sampler2D _RampTex : register(s0);
            uniform sampler2D _SurfaceTex : register(s1);
                
            half4 frag (v2f f) : COLOR 
            {
                f.normal = normalize (f.normal);
                
                half4 ramp = tex2D (_RampTex, f.uv2) * _Color.a;
                half4 thisTex = tex2D (_SurfaceTex, f.uv) * ramp * _Color;
                
                return half4 (thisTex.r, thisTex.g, thisTex.b, ramp.r);
            }
            
            ENDCG 
 
            SetTexture [_RampTex] {combine texture}
            SetTexture [_SurfaceTex] {combine texture}
        }
    }
    Fallback "Transparent/VertexLit"
}
  1. create a sphere, a material, assgin the material to the sphere, then set the shader of the material to shield, here is the inspector:

  2. create a gameobject, assgin the Animation.cs(from the link above) script to it

  3. try to create a material named “ForceField”, bug got :

what is the problem ?

502459--17784--$Screen shot 2011-02-18 at ??12.32.42.png
502459--17785--$Screen shot 2011-02-18 at ??12.46.49.png

And I found this post: http://forum.unity3d.com/threads/10912-Force-field-thing

this is what I really want :

But I can’t find out how to make that still, :(, can anybody point me out , thanks .

when I add the shader with a diffuse fallback , I got this error :

In the picture of your inspector, you have your texture slots reversed. That isn’t a ramp in the ramp slot!

You are also using the old 2.x version of the shader, for some reason skipping right over the Unity 3.x compatible version at the top of the wiki entry.

Thanks, it works after I swap the textures.