Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 /
avatar image
0
Question by Scrillrock · Jan 20, 2021 at 07:25 AM · shadershader programmingshader writingnormalmapnormal map

Layering multiple Normal maps into one without blending in a Surface shader script

I'm remaking an older Unity project right now and I'm rewriting a shader I made for it, the main point of which being that it combines multiple textures into one and applies them to the Albedo layer. This time around I'm trying to have the same system apply to the Normal/Bump map as well, but it seems like I'm doing something wrong every time I try to make it work.


My "layers" consist of a regular foundation normal and a couple more images with transparency that are meant to go over the bottom layer and overlap each other. To my understanding, the combined texture should be in a format, suitable to use with UnpackNormal and then to be applied to the material.


I'm fairly new to shader scripting and I'm not sure how normal maps are read by Unity exactly. I've tried several ways of making it work, including different ways of blending, but I couldn't figure out how to make them work with more than two "layers" and with overlapping. I tried using the same method I used for layering the textures, but the type required for a normal map by the UnpackNormal function seems to be one with 4 parameters, rather than one with 3, like the ones I used in this.


I'm going to include an example of my surf function in the aforementioned state just for reference on how I've managed the texture layering and generally just for reference I suppose:


         float4 baseTex = tex2D(_BaseTex, IN.uv_BaseTex);
         float4 eyeTex = tex2D(_EyeTex, IN.uv_BaseTex);
         float4 accentTex = tex2D(_AccentTex, IN.uv_BaseTex);

         float4 normal = tex2D(_NormalMap, IN.uv_NormalMap);

         float4 baseNormal = tex2D(_BaseNormal, IN.uv_NormalMap);
         float4 eyeNormal = tex2D(_EyeNormal, IN.uv_NormalMap);
         float4 accentNormal = tex2D(_AccentNormal, IN.uv_NormalMap);

         half3 baseTexVisible = baseTex.rgb * (1 - eyeTex.a) * (1 - accentTex.a) * _BaseColor;
         half3 eyeTexVisible = eyeTex.rgb * eyeTex.a * _EyeColor;
         half3 accentTexVisible = accentTex.rgb * accentTex.a * _AccentColor;

         half3 normalVisible = normal.rgb * (1 - baseNormal.a) * (1 - eyeNormal.a) * (1 - accentNormal.a);
         half3 baseNormalVisible = baseNormal.rgb  * (1 - eyeNormal.a) * (1 - accentNormal.a);
         half3 eyeNormalVisible = eyeNormal.rgb * eyeNormal.a;
         half3 accentNormalVisible = accentNormal.rgb * accentNormal.a;

         float3 finalNormal = normalVisible + baseNormalVisible + eyeNormalVisible + accentNormalVisible;

         float3 finalTexture = baseTexVisible + eyeTexVisible + accentTexVisible;

         fixed4 c = tex2D(_BaseTex, IN.uv_BaseTex);
         o.Albedo = finalTexture;
         o.Metallic = _Metallic;
         o.Smoothness = _Glossiness;
         o.Alpha = c.a;

         o.Normal = UnpackNormal(float4(finalNormal.r,finalNormal.g,finalNormal.b,baseNormal.r * baseNormal.g * baseNormal.b));
         o.Normal.y = o.Normal.y * _NormalLevel;
         //o.Normal.z = finalNormal.b;


Any help would be greatly appreciated.

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

175 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

Related Questions

Making shader not ignore Light on transparent areas ? 0 Answers

Standard Surface Shader with fade too dark 0 Answers

Help converting stencil shader in HDRP 1 Answer

Wireframe shader with constant width and no diagonals 1 Answer

Is a water shader with these features possible or easy to make? 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