x


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"
}
more ▼

asked Feb 02 '12 at 08:05 PM

Xatoku gravatar image

Xatoku
152 73 81 88

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

So, for changes, you either have to jack up BaseMapDist 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.)

Feb 02 '12 at 08:21 PM Owen Reynolds

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

Feb 02 '12 at 10:05 PM Xatoku

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 Materials can chose shaders, but Terrain can't.)

Feb 03 '12 at 03:44 PM Owen Reynolds

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.

Feb 03 '12 at 09:42 PM Xatoku

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.

Feb 04 '12 at 12:02 AM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1468
x425
x124
x37
x26

asked: Feb 02 '12 at 08:05 PM

Seen: 671 times

Last Updated: Feb 04 '12 at 12:43 AM