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 SanQri · Jul 30, 2017 at 12:01 PM · shadershadowsurface shader

How to make surface shader receive shadows?

Hello! I have a surface shader, which blends some textures. It doesn't receive shadows. What is the problem?

alt text

 Shader "Custom/TextureBlend" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _NoiseTex ("NoiseGREY", 2D) = "asd" {}
         _SandTex ("Sand", 2D) = "sdf" {}
         _SnowTex ("Snow", 2D) = "dfg" {}
         _GrassTex ("Grass", 2D) = "dfg" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Metallic ("Metallic", Range(0,1)) = 0.0
         _BlendSmoothness ("BlendSmoothness", Range(1,50)) = 0.0
     }
     SubShader {
         Tags { "RenderType"="Opaque" "Queue" = "Geometry"  }
         LOD 200
         
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Standard fullforwardshadows
 
         // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
 
         sampler2D _NoiseTex;
         sampler2D _SandTex;
         sampler2D _SnowTex;
         sampler2D _GrassTex;
 
         struct Input {
             float2 uv_NoiseTex;
             float2 uv_SandTex;
             float2 uv_SnowTex;
             float2 uv_GrassTex;
         };
 
         half _Glossiness;
         half _BlendSmoothness;
         half _Metallic;
         fixed4 _Color;
 
         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
         // #pragma instancing_options assumeuniformscaling
         UNITY_INSTANCING_CBUFFER_START(Props)
             // put more per-instance properties here
         UNITY_INSTANCING_CBUFFER_END
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             // Albedo comes from a texture tinted by color
             float4 inp = tex2D(_NoiseTex, IN.uv_NoiseTex);
             float m = 2.0;
             float _m = 1 / m;
 
             uint sh = inp.r > 0.5;
             uint fh = inp.r <= 0.5;
             float4 a = atan((inp - _m / 2 - _m * sh) * _BlendSmoothness) * 0.364 + 0.5;
             float4 c = (tex2D(_SnowTex, IN.uv_SnowTex) * sh + tex2D(_SandTex, IN.uv_SandTex) * fh) * a * m;
             c += (tex2D(_SandTex, IN.uv_SandTex) * sh + tex2D(_GrassTex, IN.uv_GrassTex) * fh) * (1 - a) * m;
             o.Albedo = c.rgb;
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
             o.Alpha = 1;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }


unityanswer.png (409.7 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
1
Best Answer

Answer by Namey5 · Jul 31, 2017 at 10:25 AM

Surface shaders by default receive shadows automatically. Either your metallic value is too high for them to be taken into account, or there is something else happening (object is set to not receive shadows, you've manually set the render queue to Transparent, etc.)

Comment
Add comment · Show 2 · 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
avatar image SanQri · Jul 31, 2017 at 11:00 AM 0
Share

Thank you. It was because of metalic value. But without metalic as 1, terrain is too shiny

avatar image TheFoveal SanQri · Oct 27, 2017 at 06:21 AM 0
Share

have you tried reducing smoothness value? smoothness makes it "glossy"

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

106 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

Related Questions

How to get pure black shadow on gradient shader 0 Answers

Transparent shadow in surface shader 0 Answers

Modify Color in Surface Shader After Lighting (Forward Rendering) 0 Answers

Add shadow receiver to 3D text shader. 0 Answers

Basic surface shader question ... 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