• 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 Hamesh81 · Jan 06, 2013 at 09:06 AM · textureruntimenormalnormalmap

Is it possible to adjust normal map strength at runtime?

I have an "old age" normal map for my characters which at full strength creates strong wrinkles on the character's skin. I would like to be able to control the strength of this normal map via some sort of slider, so that players can choose "how old" and hence how "wrinkly" their character is. I haven't been able to find a shader nor texture setting which allows for this to be done at runtime. Can this be done?

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 drudiverse · Oct 03, 2014 at 04:36 PM 0
Share

see this: http://answers.unity3d.com/questions/278685/add-a-slider-to-bumped-specular-shader-for-normal.html

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by velipekka · Jan 07, 2013 at 02:25 PM

You need an custom shader for that one.

You can download the build-in shaders from here: http://unity3d.com/unity/download/archive

It's pretty easy to make your own variations from those.

Here is a simple example that has a slider between two normal maps:

alt text

 Shader "Bumped Diffuse Lerp" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _BumpMap ("Normalmap", 2D) = "bump" {}
     
     // Slider to control fading between normalmaps
     _BumpMapSlider ("BumpMap Slider", Range (0, 1)) = 0
     
     // Second normal map
     _BumpMap2 ("Normalmap 2", 2D) = "bump" {}
 }
 
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 300
 
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 sampler2D _BumpMap;
 fixed4 _Color;
 
 // Remember to add your properties in here also. Check ShaderLab References from manual for more info
 float _BumpMapSlider;
 sampler2D _BumpMap2;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 
     // Read values from _BumpMap and _BumpMap2
     fixed3 normal1 = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
     fixed3 normal2 = UnpackNormal(tex2D(_BumpMap2, IN.uv_BumpMap));
     
     // Interpolater between them and set the result to the o.Normal
     o.Normal = lerp(normal1, normal2, _BumpMapSlider);
 }
 ENDCG  
 }
 
 FallBack "Diffuse"
 }
 

You can change _BumpMapSlider value at runtime from script, or even with the animation editor. http://docs.unity3d.com/Documentation/ScriptReference/Material.SetFloat.html

With this shader it would be the following: renderer.material.SetFloat( "_BumpMapSlider", wrinklyness);

I hope this does the trick ;)


shadernormallerp.jpg (49.9 kB)
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 Hamesh81 · Jan 08, 2013 at 12:34 PM 0
Share

That looks like a great idea, I'll test it when I get the chance. Just curious though, I'm guessing the additional normal map would add an additional drawcall wouldn't it? Could there be a way to use a slider with only one normal map and adjust it's strength, similar to when doing this in the advanced texture settings?

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 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

Related Questions

export normal texture at runtime 2 Answers

Importing and configuring Normal Maps at runtime ? 2 Answers

Runtime Loaded Bump/Normal Texture into "Bumped Diffuse" Shader 2 Answers

Load texture and shaders at runtime on iPhone 2 Answers

Normal map strange shading lines. 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