• 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 /
This question was closed Nov 25, 2017 at 06:14 PM by Bunny83 for the following reason:

Problem is not reproducible or outdated. Crystal-ball-question. The question is lacking important information about the problem (specifically the shader).

avatar image
0
Question by Jonesy19 · Nov 25, 2017 at 02:28 PM · shadereditormeshbuildrender

Shader does not display properly in game/editor view, but building it works.

Hey everyone, I have an issue where my shader is showing up as white in the editor and the game view. When I build it, it plays and renders properly. I tried reimporting it, yet that did not work. Any ideas?

Thanks!

Here is the shader:

 /*
     Created by chenjd
     http://www.cnblogs.com/murongxiaopifu/
 */
 Shader "chenjd/ForceField"
 {
 Properties
 {
     _Color("Color", Color) = (0,0,0,0)
     _NoiseTex("NoiseTexture", 2D) = "white" {}
     _DistortStrength("DistortStrength", Range(0,1)) = 0.2
     _DistortTimeFactor("DistortTimeFactor", Range(0,1)) = 0.2
     _RimStrength("RimStrength",Range(0, 10)) = 2
     _IntersectPower("IntersectPower", Range(0, 3)) = 2
 }
 
 SubShader
 {
     ZWrite Off
     Cull Off
     Blend SrcAlpha OneMinusSrcAlpha
 
     Tags
     {
         "RenderType" = "Transparent"
         "Queue" = "Transparent"
     }
 
     GrabPass
     {
         "_GrabTempTex"
     }
 
 Pass
 {
     CGPROGRAM
 #pragma target 3.0
 #pragma vertex vert
 #pragma fragment frag
 
 #include "UnityCG.cginc"
 
     struct appdata
 {
     float4 vertex : POSITION;
     float2 uv : TEXCOORD0;
     float3 normal : NORMAL;
 };
 
 struct v2f
 {
     float4 vertex : SV_POSITION;
     float2 uv : TEXCOORD0;
     float4 screenPos : TEXCOORD1;
     float4 grabPos : TEXCOORD2;
     float3 normal : NORMAL;
     float3 viewDir : TEXCOORD3;
 };
 
 sampler2D _GrabTempTex;
 float4 _GrabTempTex_ST;
 sampler2D _NoiseTex;
 float4 _NoiseTex_ST;
 float _DistortStrength;
 float _DistortTimeFactor;
 float _RimStrength;
 float _IntersectPower;
 
 sampler2D _CameraDepthTexture;
 
 v2f vert(appdata v)
 {
     v2f o;
     o.vertex = UnityObjectToClipPos(v.vertex);
 
     o.grabPos = ComputeGrabScreenPos(o.vertex);
 
     o.uv = TRANSFORM_TEX(v.uv, _NoiseTex);
 
     o.screenPos = ComputeScreenPos(o.vertex);
 
     COMPUTE_EYEDEPTH(o.screenPos.z);
 
     o.normal = UnityObjectToWorldNormal(v.normal);
 
     o.viewDir = normalize(UnityWorldSpaceViewDir(mul(unity_ObjectToWorld, v.vertex)));
 
     return o;
 }
 
 fixed4 _Color;
 
 
 fixed4 frag(v2f i) : SV_Target
 {
     float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)));
     float partZ = i.screenPos.z;
 
     float diff = sceneZ - partZ;
     float intersect = (1 - diff) * _IntersectPower;
 
     float3 viewDir = normalize(UnityWorldSpaceViewDir(mul(unity_ObjectToWorld, i.vertex)));
     float rim = 1 - abs(dot(i.normal, normalize(i.viewDir))) * _RimStrength;
     float glow = max(intersect, rim);
 
     float4 offset = tex2D(_NoiseTex, i.uv - _Time.xy * _DistortTimeFactor);
     i.grabPos.xy -= offset.xy * _DistortStrength;
     fixed4 color = tex2Dproj(_GrabTempTex, i.grabPos);
 
     fixed4 col = _Color * glow + color;
     return col;
 
 }
 
 ENDCG
 }
 }
 }
Comment
Add comment
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

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

139 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Render layers differing between Editor and Build 2 Answers

Shader isn't displaying properly in editor view, but when built it displays properly. 0 Answers

Can a shader render darkness inside a mesh? 2 Answers

Character mesh breaks when build 4 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