Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FatWednesday · Sep 05, 2012 at 04:53 PM · shaderblendingnormal

Fading Normal Map

Right, we have a shader that we are using to create a "spreading grass" effect. using a tilling texture for the diffuse, a texture which is animated (grayscale) this controls if the surface shows the plain white colour, or the texture, creating the "growth".

Everything works fine for it except for the normal maps. much like the texture, I only want the normal map to have an effect as the grass grows over the area. (I figured do a lerp between whatever the normal would be if I wasn't setting it, with the value from the bump map, controlled by the grayscale value).

However I can't seem to work out how to get the normal value into my surface shader (that is the default normal value that would be used if I didn't set it).

I originally tried just using float3 worldNormal in my input. (but then if I try to use this I get compile errors, saying "ERROR: 0:428: 'TtoW0' : no such field in structure" Then i saw a post that said you needed to use INTERNAL_DATA and do the following

 o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_MainTex));
 float3 worldNormal = WorldNormalVector (IN, o.Normal);

This also doesn't give me back the "unedited" normal of the surface.

I'm sure its just me missing a step, or misunderstanding what I've read, but if anyone could explain it, or provide some sample code I'd really appreciate it.

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
0
Best Answer

Answer by ScroodgeM · Sep 05, 2012 at 06:59 PM

If you want to do reflections that are affected by normal maps, it needs to be slightly more involved: INTERNAL_DATA needs to be added to the Input structure, and WorldReflectionVector function used to compute per-pixel reflection vector after you've written the Normal output. (link to)

for just normal fade in/out you need:

  • read normal vector

  • lerp it with unbumped normal (0,0,1)

  • normalize it

so finally your line should look like:

o.Normal = normalize(lerp(UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)), float3(0,0,1), [lerp_value]));

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 FatWednesday · Sep 06, 2012 at 10:49 AM 0
Share

We're not looking to do any reflections at all. just fading the effect of the normal map based on a grayscale value. Already have INTERNAL_DATA added to the input structure.

however this post did make me recheck the "default normal" we were trying to use, for some reason it wasnt 0,0,1 thats been switched now and seems to be working ok. Thanks for the post.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Blending normal texture and texture made with shader 0 Answers

"Blend SrcFactor DstFactor, SrcFactorA DstFactorA" Does not work 2 Answers

Shader: Add one image's alpha to the other while keeping it unlit 1 Answer

Problem of color in custom vertex shader 0 Answers

Intersection / Geometry blend shader graph problem 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