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 GeraldOBBI · Aug 13, 2012 at 05:51 PM · shaderlightingrenderingnormal map

"Fading in" a Normal Map

Hello all!

I'm currently attempting to "fade in" lighting information via a normal map in a surface shader. We're using forward rendering and gamma space lighting as well as static and dynamic batching. I won't get into the specifics for our choices unless somehow they impact the solution to my problem. The shader interpolates between the colours of two textures and as the _LerpAmt approaches 1, the normal map should "fade in". I'm using this to blend in some procedural detail as the camera comes closer while allowing me to blend the high detail colour/normal information with a lower resolution base texture (essentially a compositor). The approach I took is that I'm lerping the normal vector from "straight up" to the desired direction specified by the normal map using a shader constant with a range [0,1].

So here's my issue: the shader which I've written seems to work as I expect in the preview window while the game isn't running and an example of the desired effect is shown below.

alt text

Now, when running the game the amount at which the geometry is lit appears to start at gray and go to full white as _LerpAmt approaches 1. I've made sure that the material's colour is set to full white (1, 1, 1, 1) when I instantiate the geometry. The light I'm using is a global directional light with a colour of (1, 1, 1, 1), an intensity of 0.5 and a strength of 1: I first thought that the intensity was an issue however, if I increase the intensity at all the colours become blown out when _LerpAmt approaches 1 (the higher the intensity, the sooner the colours become blown out, as expected).

Now, here's the kicker. If I remove the LERP for the normal map information (and just use the unpacknormal for o.Normal) there is no change in the amount of light the surface receives. I've attached the shader as a code snippet below!

So anyone with some experience in these matters know what the problem may be? Thanks!

Shader "theshader" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _DetailTex ("Detail (RGB)", 2D) = "white" {} _DetailNormal ("Detail Normal (RGB)", 2D) = "white" {} _TopLeft ("UVs into Base (Bottom, Left, Top, Right)", VECTOR) = (0, 0, 1, 1) _LerpAmt ("Interpolation between Base and Detail", Range (0, 1)) = 0 }

 SubShader
 {
     Tags { "Queue"="Geometry" }
     LOD 200

     CGPROGRAM
     #pragma surface surf Lambert

     sampler2D _MainTex;
     float4 _TopLeft;
     sampler2D _DetailTex;
     sampler2D _DetailNormal;
     float _LerpAmt;

     struct Input
     {
         float2 uv_MainTex;
         float2 uv_DetailTex;
         float2 uv_DetailNormal;
     };

     void surf (Input IN, inout SurfaceOutput o)
     {
         //Find our UV offset into the base texture
         float2 uvs = lerp(_TopLeft.xy, _TopLeft.zw, IN.uv_MainTex);
         half4 c = tex2D(_MainTex, uvs);
         c = lerp(c, tex2D(_DetailTex, IN.uv_DetailTex), clamp(sqrt(_LerpAmt) + (1f - c.a), 0, 1));
         o.Albedo = c.rgb;
         o.Alpha = c.a;
         float3 norm1 = UnpackNormal(tex2D(_DetailNormal, IN.uv_DetailNormal));
         o.Normal = normalize(lerp(float3(0.5, 0.5, 1), norm1, sqrt(_LerpAmt)));
     }
     ENDCG
 }
 FallBack "Diffuse"

}

[1]: /storage/temp/2728-lerp+1.png

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

2 Replies

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

Answer by ScroodgeM · Aug 13, 2012 at 06:08 PM

o.Normal = normalize(lerp(float3(0, 0, 1), norm1, sqrt(_LerpAmt)));

try this

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 GeraldOBBI · Aug 13, 2012 at 06:22 PM 0
Share

Worked like a charm, thanks!

Admittedly I probably tried to otherthink the problem, I guess. Simpler is better!

avatar image
0

Answer by Dragonlance · Aug 13, 2012 at 06:00 PM

why not

 float3 norm1 = UnpackNormal(tex2D(_DetailNormal, IN.uv_DetailNormal));
 float3 norm1Scaled = (norm1 - float3(0.5, 0.5, 1)) * _LerpAmt;
 o.Normal = normalize(float3(0.5, 0.5, 1) + norm1Scaled);

I have not tested it, but sounds good for me. Of yourse you have to apply the easing curve to LerpAmt outside of the shader.

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.

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

Unwanted eye adaptation effect/Overexposure after switching to HDRP 1 Answer

HDRP 2019.3.0f3 |My materials are different on my scene, and everything is gray 0 Answers

How can I render lit sprites in URP? 1 Answer

Particle system rendering Dark when looking at the light source 2 Answers

Is there any way to make the object reflecting without smoothness? 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