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
2
Question by BHS · Jun 03, 2012 at 07:46 AM · shadernormalsangles

Shade Based on Normal Map World Position Angle (Updated)

Hi,

I have been reading for days to try and figure this out, but I can't find a way to make this happen. I'm a decent shader programmer I'm just not familiar with how to get angles through shader scripting.

Maybe this:

 float3 viewN = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);


How can I shade based on the normal map and world angle so that a texture is only rendered at the normal map angles? From what I understand normals don't render past a certain angle, unless I'm mistaken. How do you do this through shaders?

I'd like to have a diffuse shader with normals that would be used to calculate the angle for the overlay texture to render onto. So I'd have a diffuse, normal, and an overlay that would be in the middle because it would only render according to the normals of the texture.

For a visual something like the video below, except this would only be based off the normal map not heightmaps: http://www.youtube.com/watch?v=otedqKHET1w&feature=youtube_gdata_player

Update Newer: Alright I've got a decent shader working, but it only works because the main snow texture is partially transparent. The bump acts as a map for the snow to lay, so it kind of works. I also have to have 2 materials, the original bump specular, and the snow shader. This also allows your to control the alpha level of the texture. This way is unpractical as I can't make a transparent texture for every texture in the game, the shader needs to do it itself.

How can I make it so I can place just a normal transparent white texture and the bump map will guide that white texture to lay where it's supposed to, according to the bumps only. Also only laying till a certain angle to act like snow. I thought I'd receive more help on Unity Answers, I've been doing everything myself. It'd be nice to get some help as I'm literally just guessing with most of this stuff.

alt text

Update Old: So I managed to make some progress. I found a shader on the Unity wiki that shades the object based on light shinning on the normals of the texture. It gives a similar looking effect, we just need to change it so it only works on certain angles, is always on; not just affected by light, and to make sure the density can be controlled.

Here's a screen shot: 95alt text95

Here's the shader, that allows the object's normals to be affected by by light, we can use this as a reference as this is the closest thing I've found as a starting point:

This link contains all the parameters and shader inputs needed to make this happen: http://unity3d.com/support/documentation/Components/SL-SurfaceShaders

 shader "Bump Spec Rim" {

  Properties {
     _Color ("Main Color", Color) = (1,1,1,0.5)
     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
     _BumpMap ("Bumpmap (RGB) Rim-Light Ramp (A)", 2D) = "bump" {}
     _RimLightColor ("Rimlight Color", Color) = (0.6, 0.6, 0.7, 1.0)
     _RimLightRamp ("Rimlight Ramp", 2D) = "white" {}

  }
  SubShader {
       //Self-Illumination Depending on Facing Rotation
       Pass {
            Tags {"LightMode" = "PixelOrNone"}
         Blend AppSrcAdd AppDstAdd
            Color [_PPLAmbient]

            CGPROGRAM
            // profiles arbfp1
            #pragma vertex vert
            #pragma fragment frag
            #pragma fragmentoption ARB_fog_exp2

            #include "UnityCG.cginc"

            sampler2D _BumpMap;
            sampler2D _RimLightRamp;
            sampler2D _MainTex;
            float4 _RimLightColor;
            float4 _Color;

            struct v2f {
                 V2F_POS_FOG;
                 float2  uv;
                 float3  tangentSpaceLightDir;
            };

            v2f vert (appdata_tan v)
            {
                 v2f o;
                 PositionFog( v.vertex, o.pos, o.fog );
                 o.uv = TRANSFORM_UV(0);
          
                 float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
                
                 float3 binormal = cross( normalize(v.normal), 
            normalize(v.tangent.xyz) );
            float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal );
            
            o.tangentSpaceLightDir = mul(rotation, viewDir);

                 return o;
            }
            
            half4 frag (v2f i) : COLOR
            {
            half3 tangentSpaceNormal = (tex2D(_BumpMap, i.uv).rgb * 2.0) - 1.0;
         
            half4 result = float4(0, 0, 0, 1);
            
            //You might want to normalize tangentSpaceNormal and  
            i.tangentSpaceLightDir,
            //but for most meshes this will most likely have minimal, if any, impact  
            on quality.
            float rampSample = dot(tangentSpaceNormal, i.tangentSpaceLightDir);
            float intensity = tex2D(_RimLightRamp, rampSample.xx).r;
            
            
            result.rgb = intensity * _RimLightColor.rgb;
            result.rgb += tex2D(_MainTex, i.uv).rgb * _PPLAmbient.rgb;
            
            return result;
         }
      
            ENDCG
       }
    
       UsePass "Bumped Specular/PPL"
  }
   
  FallBack "Bumped Specular", 1
  }


Test2.png (403.0 kB)
Test1.png (376.3 kB)
Comment
Add comment · Show 7
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 whydoidoit · Jun 03, 2012 at 09:15 AM 0
Share

Total side note, but did you check out how they did it in snowscape just been playing with that....

avatar image BHS · Jun 03, 2012 at 02:42 PM 0
Share

Yes, snowscape used this technique, but I'm not quite sure how. I can confirm this because I read the developer saying so.

avatar image whydoidoit · Jun 03, 2012 at 03:12 PM 0
Share

Well it's in the asset store is what I was thinking...

avatar image BHS · Jun 03, 2012 at 03:22 PM 0
Share

Yes, I'm aware of snowscape, but I'd like to create my own similar shader.

avatar image whydoidoit · Jun 03, 2012 at 03:23 PM 0
Share

Sure, np...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

internally for shader any normal-mapped surface is flat, in your case you need (as i understand) to hide some areas from surface by another ones based on normal-map.

the problem is shader while rendering surface's pixel can't get any information about any other surface's pixels. so it can't calculate overlapping by other pixel.

the solution is:

  • make a geometry-based big areas and normal-map based small details

  • make a polygon with normal-map more detailed (more vertexes and tris) and use vertex shader to move verts along normals

  • limit view angle and don't let user to look at surface in sharp angles

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

6 People are following this question.

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

Related Questions

Outlines Defined by Shading Groups? 0 Answers

Shader Color Bumped elements 0 Answers

Render depth seperately 0 Answers

Lower-level way to find NEARBY TRIANGLES on the mesh? (Answered.) 4 Answers

Why is my shader showing hard edge artifacts on mesh planes? 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