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 Xatoku · Feb 02, 2012 at 08:05 PM · terrainlightingnormaltoonsplat

Remove Terrain Normals

Could I change the Terrain Shader (below) to not shade around the edges, but just 'shade' the brightness? More or less having the Toon/Lighted Shader on Terrain. Here's the Terrain Script, if someone could point me in the right direction, I'd greatly appreciate it.

 /* Code provided by Chris Morris of Six Times Nothing (http://www.sixtimesnothing.com) */
 /* Free to use and modify  */
 
 
 Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" {
 Properties {
     _Control ("Control (RGBA)", 2D) = "red" {}
     _Splat3 ("Layer 3 (A)", 2D) = "white" {}
     _Splat2 ("Layer 2 (B)", 2D) = "white" {}
     _Splat1 ("Layer 1 (G)", 2D) = "white" {}
     _Splat0 ("Layer 0 (R)", 2D) = "white" {}
     // used in fallback on old cards
     _MainTex ("BaseMap (RGB)", 2D) = "white" {}
     _Color ("Main Color", Color) = (1,1,1,1)
     
     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
 }
 
 SubShader {
     Tags {
         "SplatCount" = "4"
         "Queue" = "Geometry-100"
         "RenderType" = "Opaque"
     }
 CGPROGRAM
 #pragma surface surf BlinnPhong vertex:vert
 #pragma target 3.0
 #include "UnityCG.cginc"
 
 struct Input {
     float3 worldPos;
     float2 uv_Control : TEXCOORD0;
     float2 uv_Splat0 : TEXCOORD1;
     float2 uv_Splat1 : TEXCOORD2;
     float2 uv_Splat2 : TEXCOORD3;
     float2 uv_Splat3 : TEXCOORD4;
 };
 
 // Supply the shader with tangents for the terrain
 void vert (inout appdata_full v) {
 
     // A general tangent estimation    
     float3 T1 = float3(1, 0, 1);
     float3 Bi = cross(T1, v.normal);
     float3 newTangent = cross(v.normal, Bi);
     
     normalize(newTangent);
 
     v.tangent.xyz = newTangent.xyz;
     
     if (dot(cross(v.normal,newTangent),Bi) < 0)
         v.tangent.w = -1.0f;
     else
         v.tangent.w = 1.0f;
 }
 
 sampler2D _Control;
 sampler2D _BumpMap0, _BumpMap1, _BumpMap2, _BumpMap3;
 sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
 float _Spec0, _Spec1, _Spec2, _Spec3, _Tile0, _Tile1, _Tile2, _Tile3, _TerrainX, _TerrainZ;
 float4 _v4CameraPos;
 
 void surf (Input IN, inout SurfaceOutput o) {
 
     half4 splat_control = tex2D (_Control, IN.uv_Control);
     half3 col;
     
     // 4 splats, normals, and specular settings
     col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
     o.Normal = splat_control.r * UnpackNormal(tex2D(_BumpMap0, float2(IN.uv_Control.x * (_TerrainX/_Tile0), IN.uv_Control.y * (_TerrainZ/_Tile0))));
     o.Gloss = _Spec0 * splat_control.r;
     o.Specular = _Spec0 * splat_control.r;
 
     col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
     o.Normal += splat_control.g * UnpackNormal(tex2D(_BumpMap1, float2(IN.uv_Control.x * (_TerrainX/_Tile1), IN.uv_Control.y * (_TerrainZ/_Tile1))));
     o.Gloss += _Spec1 * splat_control.g;
     o.Specular += _Spec1 * splat_control.g;
     
     col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
     o.Normal += splat_control.b * UnpackNormal(tex2D(_BumpMap2, float2(IN.uv_Control.x * (_TerrainX/_Tile2), IN.uv_Control.y * (_TerrainZ/_Tile2))));
     o.Gloss += _Spec2 * splat_control.b;
     o.Specular +=_Spec2 * splat_control.b;
     
     col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
     o.Normal += splat_control.a * UnpackNormal(tex2D(_BumpMap3, float2(IN.uv_Control.x * (_TerrainX/_Tile3), IN.uv_Control.y * (_TerrainZ/_Tile3))));
     o.Gloss += _Spec3 * splat_control.a;
     o.Specular += _Spec3 * splat_control.a;
     
     o.Albedo = col;
     o.Alpha = 0.0;
 }
 ENDCG  
 }
 
 // Fallback to Diffuse
 Fallback "Diffuse"
 }
Comment
Add comment · Show 6
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 Owen-Reynolds · Feb 02, 2012 at 08:21 PM 0
Share

One issue with changing the terrain shader is that it uses firstPass and AddPass for near terrain, but for anything further than Base$$anonymous$$apDistance it uses a secret overall lo-res map texture with the Diffuse shader (drop Base$$anonymous$$apDist in Unity, or walk around most $$anonymous$$$$anonymous$$O's with ultra low graphic setting, and you'll see.)

So, for changes, you either have to jack up Base$$anonymous$$apDist and hope perormance is fine, or try to modify the Diffuse shader to blend in well enough (ideally you'd modify the secret low-res far texture to be more toony, but not sure you can get to it.)

avatar image Xatoku · Feb 02, 2012 at 10:05 PM 0
Share

So what if I alter the Diffuse Shader to do what the Toon Shader does? Will that give the effect I'm looking for?

avatar image Owen-Reynolds · Feb 03, 2012 at 03:44 PM 0
Share

Probably -- the point is (and try this -- have FirstPass set col.r=1; and you'll see the border) that you may have to change both shaders. The "near" shader is the one above. The "far" shader is Diffuse (and try that -- drag Diffuse in, set col.r=0; in there, and the "far" area will be redish.)

Changing Diffuse seems horrible, since other things use it. Just copy Diffuse to oldDiffuse or something and have everyone else use that (since $$anonymous$$aterials can chose shaders, but Terrain can't.)

avatar image Xatoku · Feb 03, 2012 at 09:42 PM 0
Share

Okay, I set col.r = 1 and 0 for the FirstPass & AddPass respectively, but all that happened was that the far area is redish, as you said. This is still not exactly the affect I'm looking for.

Sorry if I miss-communicated a bit, but I basically want the Terrain to be lightened/darkened by light, but not shaded. Like the Toon/Lighted Shader on an object without normals.

avatar image Owen-Reynolds · Feb 04, 2012 at 12:02 AM 0
Share

I'm just pointing out that whatever you do to First/Add pass, that will only paint 1/2 the terrain. And you can't use the same code for the other half.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain Shading 1 Answer

Normal map on Terrain ? 1 Answer

Why is this happening? (Terrain/Light Issue) 1 Answer

Remove Terrain's reflection 2 Answers

Terrain Trees remain lit up when no light is cast 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