Search Unity

How do you define a custom CGinclude??

Discussion in 'Shaders' started by transporter_gate_studios, Sep 13, 2020.

  1. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Ok, so ultimately my goal to just get a terrain shader that blends the terrain texture transitions using the alpha channel of the individual alpha channels of the textures OR some kind of heightmaps that I can define. I found a post that shows how to do it:
    Code (CSharp):
    1. void surf(Input IN, inout SurfaceOutput o) {
    2.             fixed4 splat_control = tex2D(_Control, IN.uv_Control);
    3.             fixed3 col;
    4.             col = splat_control.r * tex2D(_Splat0, IN.uv_Splat0).rgb;
    5.             col += splat_control.g * tex2D(_Splat1, IN.uv_Splat1).rgb;
    6.             col += splat_control.b * tex2D(_Splat2, IN.uv_Splat2).rgb;
    7.             col = col * clamp(pow(1 - splat_control.a * 1.1 - splat_control.a * tex2D(_Splat3, IN.uv_Splat3).a, 3.4), 0, 1) + tex2D(_Splat3, IN.uv_Splat3).rgb * clamp(splat_control.a * 3.0 + splat_control.a * tex2D(_Splat3, IN.uv_Splat3).a * 4, 0.0, 1.0);
    8.             o.Albedo = col;
    9.             o.Alpha = 0.0;
    10.         }
    11.         ENDCG
    12.         }
    However this code doesn't work with 2020 unity's terrain shader. So. I downloaded the default shaders and i renamed the diffuse, diffusebase, addpass, and firstpass shaders. After looking at the code it appears (correct me if im wrong) that the code that actually does the splat blending is in an include file called terrainsplatmapcommin.cginc

    Sooo, if I need to implement the above code in here, how do I tell my copied default shaders to use the custom cginclude?

    Do i just copy the default include file, rename it, then change the #include "TerrainSplatmapCommon.cginc" to some thing like #include "TerrainSplatmapCommonCUSTOM.cginc" ??


    I dont think this is it because this line in the original include file worries me:
    #ifndef TERRAIN_SPLATMAP_COMMON_CGINC_INCLUDED
    #define TERRAIN_SPLATMAP_COMMON_CGINC_INCLUDED

    I think this might be what determines which include to use but what do I change this to?


    also, if you happen to know an easier way to do height based splat blending, please tell.


    thanks.
     
  2. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    OK, so I couldn't figure out the cginclude thing. But I was able to find the cginclude for the splatshader in the unity engine. (its in the data folder of the install dir for unity editor). I was able to implement the code there and its working in the terrain now.