Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_8itKATni7a8qXQ · Nov 14, 2018 at 03:30 PM · shadershaderslayersshader programming

Objects not drawn with custom vertex/fragment shader when in any other layer than the default layer

I need some specific objects to be in another layer than the default layer so that instances of these objects don't collide with each other, but still do so with everything else.

These objects are rendered by a custom vertex lit shader which needs to know the location of a point light source as well as the light's intensity. So when i select any other layer than the default layer, the objects just disappear. I googled the problem and checked that the culling mask of my main camera is set to everything, but it's still not working.


As you can see in the screenshot, the two wireframes on the left are not drawn. They should look like the rest of the green cones. alt text


I also tried different shaders, and all the built in shaders render the cones (almost) perfectly regardless of the specified layer. But i also noticed that when i used the built in shaders, and put the objects in any other layer than default, the objects ignored the point light. That is a big deal for me since i depend on using that point light.

Why is rendering behaviour tied to physics collision groups anyways? Can i somehow avoid this whole problem by not changing the layers at all and have the cones not collide with each other in another way?


Here's my shader:

 Shader "Cone Shader"
  {
      Properties{
          _Color("Color", Color) = (1,0,0,0)
          _Offset("Offset", Range(0,5))  = 0.2
          _DistExp("Distance Exponent",Range(0,4)) = 1
      }
      SubShader
      {
          Pass
          {
              Tags {"LightMode" = "ForwardAdd"}
              
              CGPROGRAM
              #pragma vertex vert
              #pragma fragment frag
              #pragma multi_compile_fwdadd_fullshadows
              // shadow helper functions and macros
              #include "UnityCG.cginc"
              #include "AutoLight.cginc"
  
              struct v2f
              {
                  float4 pos : SV_POSITION;
                  float3 normal : NORMAL;
                  float light : BLENDWEIGHT0;
                  SHADOW_COORDS(1)
              };
              float _Offset;
              float _DistExp;
              v2f vert(appdata_base v)
              {
                  v2f o;
                  o.pos = UnityObjectToClipPos(v.vertex);
                  // get vertex normal in world space
                  o.normal = UnityObjectToWorldNormal(v.normal);
                  //_WorldSpaceLightPos0 doesn't work in any other layer than default layer
                  float3 delta = (_WorldSpaceLightPos0.xyz - mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1.0)).xyz);
                  float dist = length(delta);
                  o.light = (dot(delta / dist, v.normal) + (1.0 + _Offset))  / (2.0 + _Offset);
                  o.light /= pow(dist+1.0,_DistExp);
                  TRANSFER_SHADOW(o);
                  return o;
              }
              float4 _Color;
              
              uniform float4 _LightColor0;
              fixed4 frag(v2f i) : SV_Target
              {
                  float light = i.light;
                  if (SHADOW_ATTENUATION(i) < 0.9) {
                      light *= 0.4;
                  }
                  return _Color * light * _LightColor0;
              }
              ENDCG
          }
      }
  }
 
unityq.png (258.2 kB)
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 unity_8itKATni7a8qXQ · Nov 14, 2018 at 09:59 PM

Ok i found the solution - the point light source has anoter culling mask and it was set to default only. enabled the point light culling mask for the layer of the cones and now everything is working perfectly :)

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

162 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 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

Image effect shader that masks spritelayer 1 Answer

Shader Problem 0 Answers

Creating a line between different colors? 0 Answers

Stretching when using world coordinates 2 Answers

Shader: How to write a shader that respects sorting order first and then depth 1 Answer


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