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
3
Question by Briz · Jul 03, 2012 at 08:41 PM · shaderslidernormals

Add a slider to bumped specular shader for normal strength?

I want to add a slider to the bumped specular shader that adjusts the strength of the normals. I created a slider for the shader with the following code:

File: Normal-BumpSpec.shader

 _NormalStrength ("Normal Strength", Range (0.01, 1)) = 0.5 //line 8
 
 half _NormalStrength; //line 22
 
 o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); // original of line 33 (now 35)
 //o.Normal = _NormalStrength; //attempt to modify normal strength based on slider - replaced previous line of code


o.Normal = _NormalStrength; does not properly affect the power of the normal. What is the correct way to set this?

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

3 Replies

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

Answer by ScroodgeM · Jul 14, 2012 at 09:16 AM

o.Normal is a vector, not a color, so you can't just multiply it by a number. you need to turn it over surface original normal and be sure it stays normalized. one of the way to turn vector away or close to original normal is to change it's z coordinate and normalize just after it.

Shader "Bumped Diffuse Customizible" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} //1 means do nothing. 0 means max power, 2 means low power _BumpPower ("Bump Power", Range (3, 0.01)) = 1 } SubShader { Tags { "RenderType"="Opaque" } LOD 350

CGPROGRAM #pragma surface surf Lambert

sampler2D _MainTex; sampler2D _BumpMap; fixed4 _Color; fixed _BumpPower;

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; fixed3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); normal.z = normal.z _BumpPower; o.Normal = normalize(normal); }

ENDCG
} FallBack "Bumped Diffuse" }

Comment
Add comment · Show 4 · 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 Pawl · Aug 20, 2014 at 10:16 PM 0
Share

+1, Just wanted to say this approach works well.

avatar image drudiverse · Oct 03, 2014 at 04:41 PM 0
Share

i found there are some artifacts, i think that we should lerp between the bumpmap normal and the vertex normal?

hm... it seems to work with better quality normal map.

avatar image reptilebeats · Feb 15, 2015 at 11:47 PM 0
Share

this didnt work for me, well kinda i found you need to change

normal.z = normal.z _BumpPower;

to

normal.z = normal.z /_BumpPower;

avatar image Earlybird · May 28, 2015 at 09:38 AM 0
Share

worked for me,

we also used:

normal.z = normal.z / _BumpPower;

Thanks! :)

avatar image
2

Answer by Abram-Painter · Jan 29, 2017 at 02:10 AM

wrong, you do it like this... o.Normal = lerp(UnpackNormal(tex2D (_BumpMap, IN.uv_BumpMap), fixed3(0,0,1), -_BumpPower + 1); This doesn't just get close to the original vertex normals, it goes all the way.

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 kedwards · Nov 03, 2019 at 06:41 PM 0
Share

Abram Answer is correct leaving no artefacts . $$anonymous$$inor bracket missing that's all.

o.Normal = lerp(UnpackNormal (tex2D (__Bump$$anonymous$$ap, IN.uv_Bump$$anonymous$$ap)), fixed3(0,0,1), - _BumpPower + 1.0);

Thanks Abram!

avatar image
0

Answer by jaised · Jul 13, 2012 at 03:28 PM

I did something similar to this:

 float3 normalTex = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
 float3 normal = normalTex * _NormalStrength;

I found that by using this, it increases the brightness of the spec and does nothing with the contrast. AKA the lighter parts get lighter, but the darker spots stay the same. It's a weird issue. If you try this, its almost like a brightness/contrast slider rather than intensifying the normals which is weird. If anyone has something to add to this, as to why this isn't working the way intended, please say something. It should sharpen or fade the normals out based on the value (which it sort of does, while affecting the lighting)...

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 Seneral · May 21, 2016 at 08:48 PM 0
Share

Old question, but the reason for this is that by multiplying the normal only it's length will increase. But what you really want is strengthen it, getting it away from the straight normal (0,0,1), where z is the 'height'. So in order to do this, you can decrease the z value and then normalize, which will result in an increase in the x and y values. This results in an increase of the normal vector's contrast (in relation to (0,0,1), not the normal color!) and features will be pronounced. Hope that clears it up:)

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

9 People are following this question.

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

Related Questions

3D Texture and normals 0 Answers

CutOut diffuse shader visible from both sides on a plane? 1 Answer

colorize mesh based on dot product 1 Answer

Weird sphere normals??? 2 Answers

Camera spaced normals for a surface shader 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