- Home /
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?
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
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.)
Thank you. It was because of metalic value. But without metalic as 1, terrain is too shiny
have you tried reducing smoothness value? smoothness makes it "glossy"