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 Az_Ainamart · Jan 11, 2014 at 09:11 AM · shaderstrumpy

Something wrong with lines shading created with GL.LINES

I have to draw grid of lines as in the editor view. Also I need that grid to dissolve near the camera and on a distance. So I create a shader with SSE and apply it on lines. Everything works fine when there is some geometry in camera view. But when there no objects in scene or no objects in camera view lines become dark. What happens? And even more! In some camera position lines start blinking with about 2Hz period I use Unity 4.3.1f1, there buil-in Intel HD4000 graphics with latest driver, Windows 8. Maybe deferred rendering could help there but I have no Pro to test it. enter image description here enter image description here

SSE shader here: enter image description here

 Shader "GridShader"
 {
     Properties 
     {
 _Color("_Color", Color) = (1,1,1,1)
 _DepthDividerExponent("_DepthDividerExponent", Float) = 10
 _DepthDividerSin("_DepthDividerSin", Float) = 10
     }
     SubShader 
     {
         Tags
         {
 "Queue"="Transparent"
 "IgnoreProjector"="False"
 "RenderType"="Transparent"
         }
 Cull Back
 ZWrite On
 ZTest LEqual
 ColorMask RGBA
 Fog{
 }
         CGPROGRAM
 #pragma surface surf BlinnPhongEditor  alpha decal:blend vertex:vert
 #pragma target 2.0
 float4 _Color;
 float _DepthDividerExponent;
 float _DepthDividerSin;
 sampler2D _CameraDepthTexture;
             struct EditorSurfaceOutput {
                 half3 Albedo;
                 half3 Normal;
                 half3 Emission;
                 half3 Gloss;
                 half Specular;
                 half Alpha;
                 half4 Custom;
             };
             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;
 return c;
             }
             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
             {
                 half3 h = normalize (lightDir + viewDir);
                 half diff = max (0, dot ( lightDir, s.Normal ));
                 float nh = max (0, dot (s.Normal, h));
                 float spec = pow (nh, s.Specular*128.0);
                 half4 res;
                 res.rgb = _LightColor0.rgb * diff;
                 res.w = spec * Luminance (_LightColor0.rgb);
                 res *= atten * 2.0;
                 return LightingBlinnPhongEditor_PrePass( s, res );
             }
             struct Input {
                 float4 screenPos;
             };
             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.Normal = float3(0.0,0.0,1.0);
                 o.Alpha = 1.0;
                 o.Albedo = 0.0;
                 o.Emission = 0.0;
                 o.Gloss = 0.0;
                 o.Specular = 0.0;
                 o.Custom = 0.0;
 float4 ScreenDepthDiff0= LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;
 float4 Add0=ScreenDepthDiff0 + float4( -1,-1,-1,-1 );
 float4 Abs0=abs(Add0);
 float4 Divide0=Abs0 / _DepthDividerSin.xxxx;
 float4 Sin0=sin(Divide0);
 float4 Divide2=Abs0 / _DepthDividerExponent.xxxx;
 float4 Log1=log(Abs0);
 float4 Pow0=pow(Divide2,Log1);
 float4 Divide1=Sin0 / Pow0;
 float4 Master0_1_NoInput = float4(0,0,1,1);
 float4 Master0_2_NoInput = float4(0,0,0,0);
 float4 Master0_3_NoInput = float4(0,0,0,0);
 float4 Master0_4_NoInput = float4(0,0,0,0);
 float4 Master0_7_NoInput = float4(0,0,0,0);
 float4 Master0_6_NoInput = float4(1,1,1,1);
 o.Albedo = _Color;
 o.Alpha = Divide1;
                 o.Normal = normalize(o.Normal);
             }
         ENDCG
     }
     Fallback "Diffuse"
 }

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

1 Reply

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

Answer by Az_Ainamart · Jan 14, 2014 at 05:41 PM

Well, there is correct answer about fixing this problem now at SO.

I had to edit one line in shader:

 inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
 {
 half3 spec = light.a * s.Gloss;
 half4 c;
 c.rgb = _Color; // (s.Albedo * light.rgb + light.rgb * spec);
 c.a = s.Alpha;
 return c;
 }

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

18 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

Related Questions

Strumpy Shader Editor - Can't view preview window 1 Answer

Strumpy shaders... Y U NO dynamic batch ?? 0 Answers

Particle shader with Strumpy Shader Editor 0 Answers

Strumpy shader - Overlay(Add) two textures for Unlit 1 Answer

How to force the compilation of a shader in Unity? 5 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