Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Graeme P · Mar 28, 2011 at 08:51 AM · shadercustominvisibleshield

"Shield Shader isnt visable? please help."


If anyone else gets this issue, i would advise just using some other code, i got it to work by using ' tpelham42's ' code -

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 {
             float4 pos : SV_POSITION;
             float2 uv : TEXCOORD0;
             float2 uv2 : TEXCOORD1;
             float3 normal : TEXCOORD2;
         };

         uniform float _Offset;

         v2f vert (appdata_base v) {
             v2f o;
             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);

             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 tex = tex2D (_SurfaceTex, f.uv) * ramp * _Color;

             return half4 (tex.r, tex.g, tex.b, ramp.r);
         }

         ENDCG

         SetTexture [_RampTex] {combine texture}
         SetTexture [_SurfaceTex] {combine texture}
     }
 }
 Fallback "Transparent/VertexLit"

}

its much the same, with the exception of not having the main texture slide around, but that wont be hard to write.

Thanks anyway guys!


Hi, im having some trouble with getting a shader to work, its the sheild shader writen by Omar Rojo (Toack).

I right clicked and created a new shader, i removed all the stock code (should i have done that?) and pasted in the Java version of the shader...


Shader "ForceField" { Properties { _Color("_Color", Color) = (0,1,0,1) _SoftParticlesFactor("_SoftParticlesFactor", Range(0.1,3) ) = 2 _Inside("_Inside", Range(0,0.2) ) = 0 _Rim("_Rim", Range(1,2) ) = 1.2 _Texture("_Texture", 2D) = "white" {} _Speed("_Speed", Range(0.5,5) ) = 0.5 _Tile("_Tile", Range(1,10) ) = 5 _Strength("_Strength", Range(0,5) ) = 1.5

 }

 SubShader
 {
     Tags
     {

"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"

     }


Cull Off ZWrite On ZTest LEqual

     CGPROGRAM

pragma surface surf BlinnPhongEditor alpha vertex:vert

pragma target 3.0

float4 _Color; sampler2D _CameraDepthTexture; float _SoftParticlesFactor; float _Inside; float _Rim; sampler2D _Texture; float _Speed; float _Tile; float _Strength;

         struct EditorSurfaceOutput {
             half3 Albedo;
             half3 Normal;
             half3 Emission;
             half3 Gloss;
             half Specular;
             half Alpha;
         };

         inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
         {

half3 spec = light.a * s.Gloss;

half4 c;

c.rgb = (s.Albedo light.rgb + light.rgb spec);

c.a = s.Alpha + Luminance(spec);

return c;

         }

         inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
         {
             viewDir = normalize(viewDir);
             half3 h = normalize (lightDir + viewDir);

             half diff = max (0, dot (s.Normal, lightDir));

             float nh = max (0, dot (s.Normal, h));
             float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;

             half4 res;
             res.rgb = _LightColor0.rgb * (diff * atten * 2.0);
             res.w = spec * Luminance (_LightColor0.rgb);

             return LightingBlinnPhongEditor_PrePass( s, res );
         }

         struct Input {
             float4 screenPos;

float3 viewDir; float2 uv_Texture;

         };


         void vert (inout appdata_full v, out Input o) {

float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);

         }


         void surf (Input IN, inout EditorSurfaceOutput o) {
             o.Albedo = 0.0;
             o.Normal = float3(0.0,0.0,1.0);
             o.Emission = 0.0;
             o.Gloss = 0.0;
             o.Specular = 0.0;
             o.Alpha = 1.0;

float4 ScreenDepthDiff0= LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z; float4 Multiply6=ScreenDepthDiff0 _SoftParticlesFactor.xxxx; float4 Saturate0=saturate(Multiply6); float4 Fresnel0_1_NoInput = float4(0,0,1,1); float4 Fresnel0=float4( 1.0 - dot( normalize( float4(IN.viewDir, 1.0).xyz), normalize( Fresnel0_1_NoInput.xyz ) ) ); float4 Step0=step(Fresnel0,float4( 1.0 )); float4 Clamp0=clamp(Step0,_Inside.xxxx,float4( 1.0 )); float4 Pow0=pow(Fresnel0,_Rim.xxxx); float4 Multiply5=_Time _Speed.xxxx; float4 UV_Pan0=float4((IN.uv_Texture.xyxy).x,(IN.uv_Texture.xyxy).y + Multiply5.x,(IN.uv_Texture.xyxy).z,(IN.uv_Texture.xyxy).w); float4 Multiply1=UV_Pan0 _Tile.xxxx; float4 Tex2D0=tex2D(_Texture,Multiply1.xy); float4 Multiply2=Tex2D0 _Strength.xxxx; float4 Multiply0=Pow0 Multiply2; float4 Multiply3=Clamp0 Multiply0; float4 Multiply4=Saturate0 * Multiply3; float4 Master0_0_NoInput = float4(0,0,0,0); float4 Master0_1_NoInput = float4(0,0,1,1); float4 Master0_3_NoInput = float4(0,0,0,0); float4 Master0_4_NoInput = float4(0,0,0,0); float4 Master0_6_NoInput = float4(1,1,1,1); o.Emission = _Color; o.Alpha = Multiply4;

         }
     ENDCG
 }
 Fallback "Diffuse"

}


I then created a new material and applyed the shader, and added a texture to to the texture slot, in the inspector the shader looks fine, but when i add it to an object (default spheare primatave) it doesnt show up anything in either the real-time or editor windows, but the object is still there.

I was under the impression that the shader should have had a texture slot for a B/W ramp, but i dont see one. Could someone please tell me what i have done wrong?

This is the page where i got the code.

  • http://www.unifycommunity.com/wiki/index.php?title=Shield

A solution would be really appreciated.

Thanks! - Graeme.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Paulius-Liekis · Mar 28, 2011 at 10:01 AM 3
Share

You're supposed to post your answer as an answer, ins$$anonymous$$d of editing your question. And then mark your answer as correct (once you have permission to do that). And please format your code properly. We're trying to keep things tidy here. Help others - help yourself.

avatar image AngryOldMan · Mar 28, 2011 at 11:18 AM 2
Share

As Paulius said format your code properly and post your answer seperate to your question ins$$anonymous$$d of just putting "SOLVED" in the title. Do the Irish proud Graeme!

avatar image Justin Warner · Mar 28, 2011 at 11:51 AM 1
Share

He did format his code right, just, when you add code in a post, highlight it all,and press the 10101 button up top =) it'll make it pretty, And congrats on finding out your answer! Please post it!!!

avatar image Graeme P · Mar 28, 2011 at 12:36 PM 0
Share

Opps, sorry guys. Im pretty new, il try and keep things more tidy in the future. I did try to post my answer in the comment, but because it contained code, it was much too long. so i just put it at the top as an edit ins$$anonymous$$d - ah, i just noticed the big "Answer Your Question," Button... Thanks for all the advice.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Graeme P · Mar 28, 2011 at 12:39 PM

If anyone else gets this issue, i would advise just using some other code, i got it to work by using ' tpelham42's ' code -

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 {
             float4 pos : SV_POSITION;
             float2 uv : TEXCOORD0;
             float2 uv2 : TEXCOORD1;
             float3 normal : TEXCOORD2;
         };

         uniform float _Offset;

         v2f vert (appdata_base v) {
             v2f o;
             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);

             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 tex = tex2D (_SurfaceTex, f.uv) * ramp * _Color;

             return half4 (tex.r, tex.g, tex.b, ramp.r);
         }

         ENDCG

         SetTexture [_RampTex] {combine texture}
         SetTexture [_SurfaceTex] {combine texture}
     }
 }
 Fallback "Transparent/VertexLit"

}

its much the same, with the exception of not having the main texture slide around, but that wont be hard to write.

Thanks anyway guys!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The objects with a custom shader become invisible when i activate the lightmap 0 Answers

Lightmapping on a custom shader 0 Answers

Objects Not Visible In Low End Computer. (Shader Error) 1 Answer

SSAO showing through objects with custom shader 2 Answers

Adding BRDF lighting to custom Terrain Shader. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges