Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by x2stone · Jun 02, 2021 at 07:37 AM · shadershader programmingshader writingsurface shader

Custom Surface shader don't work with fresnel reflection and normal map at the same time

Hi Unity users,

As the Standard shader don't have the fresnel reflection parameter exposed, I'm trying to write my own custom surface shader with "classic" parameters and a fresnel exponent which control the reflection amount on glazing angles. I succeeded to have a working shader with that fresnel reflection, but the moment I add the normal map parameter, it doesn't work anymore... Any idea ? Of course I read the Unity documentation on Custom Shaders but they use the emissive slot to mimic reflected material and I can't use that method because I will also need to keep that parameter, I really need to deal with metallic/smoothness parameters. Thanks a lot for any help. Here is my shader code :

 Shader "MyShaders/StandardFresnel" {
     Properties {
         _Color ("Tint", Color) = (0, 0, 0, 1)
         _Diffuse ("Diffuse", 2D) = "white" {}
         _Smoothness ("Smoothness", Range(0, 1)) = 0
         _Metallic ("Metalness", Range(0, 1)) = 0
         _Normal ("Normal", 2D) = "bump" {}
         [HDR] _Emission ("Emission", color) = (0,0,0)
         [PowerSlider(4)] _FresnelExponent ("Fresnel Exponent", Range(0.25, 4)) = 1
     }
     SubShader {
         Tags{ "RenderType"="Opaque" "Queue"="Geometry"}
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows
         #pragma target 3.0
 
         sampler2D _Diffuse;
         sampler2D _Normal;
         fixed4 _Color;
 
         half _Smoothness;
         half _Metallic;
         half3 _Emission;
           float _FresnelExponent;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv_Normal;
             float3 worldNormal;
             float3 viewDir;
             INTERNAL_DATA
         };
 
         void surf (Input i, inout SurfaceOutputStandard o) {
             fixed4 col = tex2D(_Diffuse, i.uv_MainTex);
             fixed4 normal = tex2D (_Normal, i.uv_Normal);
             col *= _Color;
             o.Albedo = col.rgb;

             // Fresnel stuff
             float fresnel = dot(i.worldNormal, i.viewDir);
             fresnel = saturate(1 - fresnel);
             fresnel = pow(fresnel, _FresnelExponent);

             o.Metallic = _Metallic * fresnel;
             o.Smoothness = _Smoothness;
 
             // When I add the above line, fesnel parameter don't work anymore...
             o.Normal = UnpackNormal (normal);
         }
         ENDCG
     }
     FallBack "Standard"
 }

  
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

0 Replies

· Add your reply
  • Sort: 

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

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

Problem with surface shader using uv2 1 Answer

How do I get the fragment position in world coordinates? 1 Answer

How to write a shader like this? [Screenshots] 0 Answers

Shader - SV_Target 1 Answer

,Help Changing a "Doom" Style Billboard Shader to a 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