I updated the Force field (shield) shader in the wiki.
Here is a snapshot from my efforts
Oops !
The new working shader is here : http://www.unifycommunity.com/wiki/index.php?title=Shield
Thanks, I just build a shield with it, works great.
It looks really, really attractive. I wonder if there’s a fast way to use this on ios. I would probably think of ways to use it deliberately as it looks so cool!
I was trying to write a simplified version of it for IOS, when I noticed that you’re not using Multiply4, which means the soft particles factor isn’t being taken into account.
Just thought you should know so you could edit the wiki.
Thanks, edited.
I wanted to quickly fix this one, so I just hacked a little with the code.
There is still much waste.
I think the iphone version should be in glsl.
I also think “generic” shaders like this one are not useful, just pretty.
Here’s my version. I rewrote it so it wasn’t so “shader editor” centric, and used types that are more IOS friendly.
On my 3GS with 6 spheres all running this shader taking up the whole display, I managed to stay at 30fps.
Also, I removed the soft particles stuff too, as it just seemed to mess up the effect (maybe I’m missing something).
630145–22507–$CheapForcefield.shader (1.81 KB)
Would you like to post it in the wiki ?
It is quite simple and it will raise the chance that someone can use it ( more visibility ).
Thanks a lot for commenting the code parts, it is very helpful.
very nice
Added to wiki
EDIT : Removed request in another thread
The updated shader is here, it has less options and *should run faster, I just do not know how to measure its efficience.
Thanks a lot gaustwick et all for sharing their code, it is really helpful.
Shader "Transparent Effects/CheapForcefield2"
{
Properties
{
_Color("_Color", Color) = (0,1,0,1)
_Rim("_Rim", Range(0,4) ) = 1.2
_Texture("_Texture", 2D) = "white" {}
_Speed("_Speed", Range(0.5,5) ) = 0.5
_Tile("_Tile", Range(1,10) ) = 5.0
_Strength("_Strength", Range(0,5) ) = 1.5
_Properties("Rim, Strength, Speed, Tile ", Vector) = (1.2, 1.5, 0.5, 5.0)
}
SubShader
{
Tags
{
"Queue"="Transparent"
"RenderType"="Transparent"
}
Cull Back
ZWrite On
ZTest LEqual
CGPROGRAM
#pragma surface surf BlinnPhong alpha
fixed4 _Color;
sampler2D _Texture;
fixed4 _Properties;
struct Input
{
half4 screenPos;
half3 viewDir;
half2 uv_Texture;
};
inline fixed Fresnel(half3 viewDir)
{
return fixed(1.0) - dot( normalize(viewDir), fixed3(0.0,0.0,1.0));
}
void surf (Input IN, inout SurfaceOutput o)
{
// fresnel related effects
fixed stepfresnel = step( Fresnel( IN.viewDir ) , fixed(1.0));
fixed rimContrib = pow( Fresnel( IN.viewDir ) , _Properties.x );
// calculate texture coords
half2 texCoords = half2( IN.uv_Texture.x , IN.uv_Texture.y + half(_Time.x) * _Properties.z ) * _Properties.ww;
// and get the texture contribution
fixed texContrib = tex2D (_Texture, texCoords).x * _Properties.y;
// put the contributions together into the alpha
o.Alpha = texContrib * rimContrib * _Color.a;
// set the colours
o.Albedo = fixed3(0.0,0.0,0.0);
o.Emission = _Color.rgb;
o.Normal = fixed3(0.0,0.0,1.0);
}
ENDCG
}
Fallback "Diffuse"
}
Just ran it on the same phone I tested mine on, and got an extra 1-2 fps for the same scene.
Thanks a lot for the feedback.
Could you please explain the method you use ?
I think it boils down to just using a standard ms based timer for before and after the draw call. A full screen quad with shader would query ms before its drawn, and after it’s draw - classic methods of trial and error apply here I believe - I don’t think there’s any way we can measure it on the low level.
Actually, I just used the Unity IOS built in profiler
The total render time for CheapForcefield was 1.3ms/frame, and for CheapForcefield2 was 1.2ms/frame.
Thanks a lot for the info, I totally missed that page.