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 Abaobao · Mar 20, 2016 at 02:01 PM · shadowsurface shader

Problem with Point light and shadow in Surface Shader custom Light Model.

  • The shadow problem : I cannot cast any shadow though i use the #progma surface surf CustomBlinnPhong fullforwardshadows I

  • The Point Light reaction problem: My model is react right in the Directional light.Then i add a Point Light,it react right when the point light is far away from it ,but my i move the point light closer to it, the model will light up the whole part suddenly when it's near to the point light's border that is not in the point light area. In the real world, it shouldn't light up if it doesn't touch the point light,and it will light up smoothly when it get closer to the light source.Here is more detail in the screenshots.And it seems the point light reaction looks different in different view direction.alt textalt text

and Here is my code:


    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _MainTint("Diffuse Tint", Color) = (1, 1, 1, 1)
        _Cutoff ("Cutoff Value", Range(0,1)) = 0.5
        _NormalTex("Normal Map", 2D) = "bump" {}
        _NormalIntensity("Normal Intensity", Range(0.01, 10)) = 1
        _SpecularMask("Speculr Texture", 2D) = "white" {}
        _SpecularColor("Specular Color", Color) = (1, 1, 1, 1)
        _SpecPower("Specular Power", Range(0.01, 100)) = 1
        _Gloss("Gloss", Range(0, 10)) = 0
        _CubeMap ("Environment CubeMap", CUBE) = "" {}
        _ReflAmount ("ReflAmount", Range(0, 10)) = 0.5
        _ReflMask ("ReflectMask", 2D) = "white" {}
        _EmissionMap ("Emission", 2D) = "Emission" {}
        _EmissionColor ("Emission Color", Color) = (0, 0, 0, 0)
        _EmissiveIntansity("Emissive Intansity", Range(0, 10)) = 1
        _SSSMask("SSS Mask", 2D) = "white" {}
        _BChanelIntensity("B Chanel Intensity", Range(0, 10)) = 1
        _SSSColor("Skin Color", Color) = (1, 1, 1, 1)
    }
    SubShader
    {
        Tags {"RenderType"="Opaque" }
        LOD 200
        Cull Off
        CGPROGRAM
        #pragma surface surf CustomBlinnPhong alphatest:_Cutoff
        #pragma target 3.0
        sampler2D _MainTex;
        float4 _MainTint;
        sampler2D _NormalTex;
        float _NormalIntensity;
        sampler2D _SpecularMask;
        float4 _SpecularColor;
        float _SpecPower;
        float _Gloss;
        samplerCUBE _CubeMap;
        float _ReflAmount;
        sampler2D _ReflMask;
        sampler2D _EmissionMap;
        float4 _EmissionColor;
        float _EmissiveIntansity;
        struct SurfaceCustomOutput
        {
            fixed3 Albedo;
            fixed3 Normal;
            fixed3 Emission;
            half Specular;
            float Gloss;
            float Alpha;
            fixed3 SSSMask;
        };
        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NormalTex;
            float2 uv_SpecularMask;
            fixed3 rim;
            float3 worldRefl;
            float3 worldPos;
            float3 worldNormal;
            INTERNAL_DATA
        };
        inline fixed4 LightingCustomBlinnPhong(SurfaceCustomOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
        {
            float3 halfVector = normalize(lightDir + viewDir);
            float diff = max(0, dot(s.Normal, lightDir));
            s.Normal = normalize(s.Normal);
            float nh = max(0, dot(s.Normal, halfVector));
            float spec = pow(nh, s.Specular * 128.0 )* s.Gloss;
            float3 finalSpec = _SpecularColor.rgb * spec;
            float3 sss = (1 - dot(viewDir, s.Normal)) / 50 * _SSSColor;
            sss +=  sss * s.SSSMask.b * _BChanelIntensity;
            float4 c;
            c.rgb = (s.Albedo * _LightColor0.rgb * diff) + (_LightColor0.rgb * finalSpec) * (atten * 2) + sss * atten * 3;
            c.a = s.Alpha;
            return c;
        }
        void surf(Input IN, inout SurfaceCustomOutput o)
        {
            half4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint;
            float3 normalMap = UnpackNormal(tex2D(_NormalTex, IN.uv_NormalTex));
            normalMap.z = normalMap.z / _NormalIntensity;
            o.Normal = normalize(normalMap);
            //Reflection- G channel in SpecularTexture
            //Emissive - B channel in SpecularTexture
            float4 reflMask = tex2D(_ReflMask, IN.uv_MainTex);
            float3 reflection = texCUBE(_CubeMap, WorldReflectionVector(IN, o.Normal)).rgb;
            float3 emission = tex2D(_EmissionMap, IN.uv_MainTex).b * _EmissionColor;
            o.Emission = (reflection * reflMask.g ) * _ReflAmount;
            o.Emission += emission.rgb * _EmissiveIntansity ;
            //Specular - R channel in SpecularTexture
            float4 specMask = tex2D(_SpecularMask, IN.uv_SpecularMask) * _SpecularColor;
            o.Specular = specMask.r / _SpecPower;
            o.Gloss = specMask.g * _Gloss;
            //SSS - B channel in NormalTexture
            float4 sssMask = tex2D(_SSSMask, IN.uv_MainTex);
            o.SSSMask = sssMask.rgb;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }

I am a fresh in shader.Hope your help.

screen-shot-2016-03-20-at-41040-pm.png (301.4 kB)
screen-shot-2016-03-20-at-41045-pm.png (351.5 kB)
Comment
Add comment · Show 1
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 Abaobao · Mar 21, 2016 at 05:56 AM 0
Share

$$anonymous$$aybe I should compute the position of the point light?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Abaobao · Mar 21, 2016 at 09:40 AM

I find a solution for my problem. I use the UnityGI struct instead of the light information which is only the first light source in custom light model. The UnityGI struct is in the UnityLightingCommon.cginc And the sample light model with UnityGI is in the Lighting.cginc For the shadow add FallBack "Diffuse" can solved.

But I still want to know how to solve this problem what if i don't use the UnityGI struct.

Comment
Add comment · Show 1 · 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 HonoraryBob · Sep 26, 2016 at 07:26 PM 0
Share

I'm also having difficulty with this. Would you be willing to explain in more detail how you solved it (i.e. a small code snippet) ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Vertex Offset not written to depth buffer in Surface Shader 0 Answers

Surface Shader vertex displacement, shadows not moving 1 Answer

How to get pure black shadow on gradient shader 0 Answers

How to make surface shader receive shadows? 1 Answer

Transparent shadow in surface shader 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