• 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
1
Question by yangdongfeng123456 · Apr 22, 2017 at 08:32 AM · shaderlab

blend /= dot(blend,1.0);How could it make the weights sum up to 1 (divide by sum of x+y+z)

         fixed4 frag (v2f i) : SV_Target
         {
             // use absolute value of normal as texture weights
             half3 blend = abs(i.objNormal);
             // make sure the weights sum up to 1 (divide by sum of x+y+z)
             blend /= dot(blend,1.0);
             // read the three texture projections, for x,y,z axes
             fixed4 cx = tex2D(_MainTex, i.coords.yz);
             fixed4 cy = tex2D(_MainTex, i.coords.xz);
             fixed4 cz = tex2D(_MainTex, i.coords.xy);
             // blend the textures based on weights
             fixed4 c = cx * blend.x + cy * blend.y + cz * blend.z;
             // modulate by regular occlusion map
             c *= tex2D(_OcclusionMap, i.uv);
             return c;
         }
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 Bunny83 · Apr 22, 2017 at 08:43 AM

The dot product is defined as:

 dot(a,b)
 {
     return a.x*b.x + a.y*b.y + a.z*b.z;
 }

Of course your second parameter is not a vector, but HLSL just turns it into the vector (1,1,1). Specifically a vector of the same size as the other vector

Therefore the dot product calculates

 (a.x*1 + a.y*1 + a.z*1)

The rest should be obvious. The a /= b operator is a short hand for a = a / b

So the total expansion of that line is

 blend = blend / (a.x*1 + a.y*1 + a.z*1);

Which makes the sum of x, y and z to sum up to 1.0

Example:

 blend = (6,2,8)

 blend = blend / (6*1 + 2*1 + 8*1);
 blend = blend / (16);

 blend = (6/16, 2/16, 8/16)
 blend = (0.375, 0.125, 0.5)

 0.375 + 0.125 + 0.5 == 1.0
Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

combine deferred and forward rendering 0 Answers

ShaderLab: can I specify a portion of a texture? 1 Answer

Shardelab/CG shaders not working on iOS 1 Answer

How to use shader _SinTime? 1 Answer

Use texture to determine shading? 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