Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Relief Terrain Pack (RTP) v3 on AssetStore

Discussion in 'Assets and Asset Store' started by tomaszek, Oct 22, 2013.

  1. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    The same value as hole cut is used for flattening POM effect. It doesn't change geometry, but perceived visual POM effect depth - that's why you feel it changes height. You could apply flatten more gradual around the well borders for the effect to be not that aburpt. One might ask why I introduced such feature (flattening) - it's related to geom blending. you can refer to my docs.

    For SSAO - which solution do you use? At least in deferred depth and normals data should stay intact (i.e. from AO post FX perspective it should be just a hole geometry, hole in both depth and normals which are not supposed to be drawn). You could try to inspect it via frame debugger and see what is taken as input for SSAO effect and if such data is correct (hollow).

    Tom
     
  2. Kusras

    Kusras

    Joined:
    Jul 9, 2015
    Posts:
    131
    I am using this https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/ssao-pro-22369
    I am using deferred, but tried both as I know that in deffered mode, it culls transparent water inside well. So I created opaque water and it is solved. But it means, that it writes into depth buffer as it is terrain. i have somewhere shaders which shows depth buffer or world normal... just forgot where. i can show you pictures. I also tried to add custom RenderType in Hidden/Camera-DepthNormalTexture, used parts from transparentCutouts and added clip(-1) to be sure all is clipped as a debug, but somehow it did not changed anything. I will take a look after that shaders or write new ones, to take picture of worldNormal & depth.

    That first issue. Good, thanks for an answer than it is feature to save extra data in shader. Good, thicker walls solves it. With distortion I have an issue, that it is making hole bigger and more randomly. As it is done by code, it is harder to repair it by hand. This is OK. just wanted to point at this weird height change.
     
  3. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Hidden/Camera-DepthNormalTexture is used in forward only AFAIK.
     
  4. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    Hi Tom

    I am trying to get RTP to work with this shader, which shades an entire planet.

    The terrain is procedural generated using a heightmap.

    I would like to use the script from the Terrain2GeometryScene that applies the textures on the mesh. I am wondering if it is possible to do this with a procedural mesh?

    The planetary terrain script I have basically creates the textures for the terrain based on the heightmaps height value.

    Basically I would have to take your script apart but I am wondering if it would be possible to add ambient occlusion and tessellation to this shader I have?

    I also want to add fog that RTP uses.

    How would I go about making this shader compatible with RTP?

    I would really really appreciate a response.

    Here is my shader code:

    Code (CSharp):
    1. Shader "PlanetaryTerrain/PlanetSurfaceShaderStandard" {
    2.     Properties {
    3.  
    4.         _FColor ("Fog color day (RGB)", Color) = (1,1,1,1)
    5.         _FColor2 ("Fog color sunset (RGB)", Color) = (1,0.8,0.4,1)
    6.         _FColor3 ("Fog color night (RGB+A density)", Color) = (0.2,0.3,0.6,1)
    7.         _Fdensity ("Fog density", Float) = 0.002
    8.         _Fstart ("Fog linear start", Float) = 10
    9.         _Fend ("Fog linear end", Float) = 200
    10.        
    11.         _Tex1 ("Texture 0 (Beach)", 2D) = "white" {}
    12.         _Nor1 ("Normal", 2D) = "bump" {}
    13.         _Color1 ("Color", Color) = (1,1,1,1)
    14.         _NorPow1 ("Normal Power", Range(0,4)) = 0.0
    15.         _Glossiness1 ("Smoothness", Range(0,1)) = 0.5
    16.         _Metallic1 ("Metallic", Range(0,1)) = 0.0
    17.         _Brightness1 ("Brightness", Range(0,1)) = 0.0
    18.         _TexScale1 ("Texture Scale", Float) = 1
    19.        
    20.         _Tex2 ("Texture 1", 2D) = "white" {}
    21.         _Nor2 ("Normal", 2D) = "bump" {}
    22.         _Color2 ("Color", Color) = (1,1,1,1)
    23.         _NorPow2 ("Normal Power", Range(0,4)) = 0.0
    24.         _Glossiness2 ("Smoothness", Range(0,1)) = 0.5
    25.         _Metallic2 ("Metallic", Range(0,1)) = 0.0
    26.         _Brightness2 ("Brightness", Range(0,1)) = 0.0
    27.         _TexScale2 ("Texture Scale", Float) = 1
    28.  
    29.         _Tex3 ("Texture 2", 2D) = "white" {}
    30.         _Nor3 ("Normal", 2D) = "bump" {}
    31.         _Color3 ("Color", Color) = (1,1,1,1)
    32.         _NorPow3 ("Normal Power", Range(0,4)) = 0.0
    33.         _Glossiness3 ("Smoothness", Range(0,1)) = 0.5
    34.         _Metallic3 ("Metallic", Range(0,1)) = 0.0
    35.         _Brightness3 ("Brightness", Range(0,1)) = 0.0
    36.         _TexScale3 ("Texture Scale", Float) = 1
    37.  
    38.         _Tex4 ("Texture 3", 2D) = "white" {}
    39.         _Nor4 ("Normal", 2D) = "bump" {}
    40.         _Color4 ("Color 4", Color) = (1,1,1,1)
    41.         _NorPow4 ("Normal Power", Range(0,4)) = 0.0
    42.         _Glossiness4 ("Smoothness", Range(0,1)) = 0.5
    43.         _Metallic4 ("Metallic", Range(0,1)) = 0.0
    44.         _Brightness4 ("Brightness", Range(0,1)) = 0.0
    45.         _TexScale4 ("Texture Scale", Float) = 1
    46.  
    47.         _Tex5 ("Texture 4", 2D) = "white" {}
    48.         _Nor5 ("Normal", 2D) = "bump" {}
    49.         _Color5 ("Color", Color) = (1,1,1,1)
    50.         _NorPow5 ("Normal Power", Range(0,4)) = 0.0
    51.         _Glossiness5 ("Smoothness", Range(0,1)) = 0.5
    52.         _Metallic5 ("Metallic", Range(0,1)) = 0.0
    53.         _Brightness5 ("Brightness", Range(0,1)) = 0.0
    54.         _TexScale5 ("Texture Scale", Float) = 1
    55.  
    56.         _Tex6 ("Texture 5 (Mountains)", 2D) = "white" {}
    57.         _Nor6 ("Normal", 2D) = "bump" {}
    58.         _Color6 ("Color", Color) = (1,1,1,1)
    59.         _NorPow6 ("Normal Power", Range(0,4)) = 0.0
    60.         _Glossiness6 ("Smoothness", Range(0,1)) = 0.5
    61.         _Metallic6 ("Metallic", Range(0,1)) = 0.0
    62.         _Brightness6 ("Brightness", Range(0,1)) = 0.0
    63.         _TexScale6 ("Texture Scale", Float) = 1
    64.  
    65.        
    66.     }
    67.     SubShader {
    68.         Tags { "RenderType"="Opaque" }
    69.         LOD 700
    70.         Fog { Mode Off }
    71.         ZTest LEqual
    72.         CGPROGRAM
    73.         // Physically based Standard lighting model, and enable shadows on all light types
    74.         #pragma surface surf Standard fullforwardshadows nolightmap
    75.         #pragma target 3.0
    76.         #include "UnityStandardUtils.cginc"
    77.        
    78.         // Use shader model 3.0 target, to get nicer looking lighting
    79.         #pragma target 3.0
    80.        
    81.        
    82.         sampler2D _Tex1;
    83.         sampler2D _Tex2;
    84.         sampler2D _Tex3;
    85.         sampler2D _Tex4;
    86.         sampler2D _Tex5;
    87.         sampler2D _Tex6;
    88.  
    89.         sampler2D _Nor1;
    90.         sampler2D _Nor2;
    91.         sampler2D _Nor3;
    92.         sampler2D _Nor4;
    93.         sampler2D _Nor5;
    94.         sampler2D _Nor6;
    95.  
    96.         float _TexScale1;
    97.         float _TexScale2;
    98.         float _TexScale3;
    99.         float _TexScale4;
    100.         float _TexScale5;
    101.         float _TexScale6;
    102.  
    103.         struct Input {
    104.  
    105.             float2 uv_Tex1;
    106.             float2 uv4_Tex2;
    107.             float4 color: COLOR;
    108.         };
    109.  
    110.         half _Glossiness1;
    111.         half _Metallic1;
    112.         half _Brightness1;
    113.         half _NorPow1;
    114.         fixed4 _Color1;
    115.  
    116.         half _Glossiness2;
    117.         half _Metallic2;
    118.         half _Brightness2;
    119.         half _NorPow2;
    120.         fixed4 _Color2;
    121.  
    122.         half _Glossiness3;
    123.         half _Metallic3;
    124.         half _Brightness3;
    125.         half _NorPow3;
    126.         fixed4 _Color3;
    127.  
    128.         half _Glossiness4;
    129.         half _Metallic4;
    130.         half _Brightness4;
    131.         half _NorPow4;
    132.         fixed4 _Color4;
    133.  
    134.         half _Glossiness5;
    135.         half _Metallic5;
    136.         half _Brightness5;
    137.         half _NorPow5;
    138.         fixed4 _Color5;
    139.  
    140.         half _Glossiness6;
    141.         half _Metallic6;
    142.         half _Brightness6;
    143.         half _NorPow6;
    144.         fixed4 _Color6;
    145.        
    146.  
    147.        
    148.  
    149.        
    150.         //UNITY_INSTANCING_BUFFER_START(Props)
    151.             // put more per-instance properties here
    152.         //UNITY_INSTANCING_BUFFER_END(Props)
    153.        
    154.  
    155.         void surf (Input IN, inout SurfaceOutputStandard o) {
    156.        
    157.            
    158.            
    159.             fixed4 c1 = tex2D (_Tex1, IN.uv_Tex1 * _TexScale1) * _Color1 * _Brightness1;
    160.             fixed4 c2 = tex2D (_Tex2, IN.uv_Tex1 * _TexScale2) * _Color2 * _Brightness2;
    161.             fixed4 c3 = tex2D (_Tex3, IN.uv_Tex1 * _TexScale3) * _Color3 * _Brightness3;
    162.             fixed4 c4 = tex2D (_Tex4, IN.uv_Tex1 * _TexScale4) * _Color4 * _Brightness4;
    163.             fixed4 c5 = tex2D (_Tex5, IN.uv_Tex1 * _TexScale5) * _Color5 * _Brightness5;
    164.             fixed4 c6 = tex2D (_Tex6, IN.uv_Tex1 * _TexScale6) * _Color6 * _Brightness6;
    165.            
    166.             //half c7Intensity = 1 - (IN.color.r + IN.color.g + IN.color.b + IN.color.a + IN.uv4_Tex2.x + IN.uv4_Tex2.y);
    167.  
    168.             o.Albedo = IN.color.r * c1 + IN.color.g * c2 + IN.color.b * c3 + IN.color.a * c4 + IN.uv4_Tex2.x * c5 + IN.uv4_Tex2.y * c6;
    169.  
    170.             o.Metallic = IN.color.r * _Metallic1 + IN.color.g * _Metallic2 + IN.color.b * _Metallic3 + IN.color.a * _Metallic4 + IN.uv4_Tex2.x * _Metallic5 + IN.uv4_Tex2.y * _Metallic6;
    171.             o.Smoothness = IN.color.r * _Glossiness1 + IN.color.g * _Glossiness2 + IN.color.b * _Glossiness3 + IN.color.a * _Glossiness4 + IN.uv4_Tex2.x * _Glossiness5 + IN.uv4_Tex2.y * _Glossiness6;
    172.  
    173.             o.Normal = UnpackScaleNormal(tex2D(_Nor1, IN.uv_Tex1 * _TexScale1), _NorPow1) * IN.color.r + UnpackScaleNormal(tex2D(_Nor2, IN.uv_Tex1 * _TexScale2), _NorPow2) * IN.color.g
    174.             + UnpackScaleNormal(tex2D(_Nor3, IN.uv_Tex1 * _TexScale3), _NorPow3) * IN.color.b + UnpackScaleNormal(tex2D(_Nor4, IN.uv_Tex1 * _TexScale4), _NorPow4) * IN.color.a
    175.             + UnpackScaleNormal(tex2D(_Nor5, IN.uv_Tex1 * _TexScale5), _NorPow5) * IN.uv4_Tex2.x + UnpackScaleNormal(tex2D(_Nor6, IN.uv_Tex1 * _TexScale6), _NorPow6) * IN.uv4_Tex2.y;
    176.         }
    177.        
    178.  
    179.         ENDCG
    180.     }
    181.     FallBack "Diffuse"
    182. }
     
  5. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Yes, RTP can do the job. You would need first to look around my docs first to get better ortientation about RTP basics and how it's solved script/shader side to implement it in your project. I can see your shader is very basic one with 6 layers used and coverage controlled by color.RGBA + uv.xy. In RTP you should generaly use either 4 or 8 layers. In 4 layers scenario you control coverage by vertex colors. In 8 layers you control it using 4 RGBA textures (like Unity terrain does). What RTP does is adjusting used features via LOD manager script which recompiles RTP shaders with set of features #define KEYWORDx. Unity draws it with regular shader/material. RTP feeds such material properties with RTP script properties (they are transported to material with any of Refresh() or RefreshAll() functions you can find in my code). RTP operates on so called "global textures" which are spanned over whole terrain tile (Unity terrain or mesh), These are global colormap, global normalmap. For tessellation it's combined texture with height data on two texture channels and normals on 2 others. So - it's possible to use tessellation and any RTP feature runtime/procedurally as far as you can feed RTP script attached with right set of parameters (and textures). Or you could feed just material used on your procedural mesh and feed its properties yourself. From rendering standpoint it doesn't matter.

    Tom
     
  6. truculencias

    truculencias

    Joined:
    Aug 7, 2015
    Posts:
    7
    Hi, Relief terrain still not working with High definition Render pipeline?
     
  7. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    First you need to know that even Unity does not recommend using SRPs in real projects as this feature is still WIP... (only available getting current working state from github which is also not that easy as I found recently :) ). Furthermore any current shader solution, esp. surface shaders is not meant to work with SRP. Neither RTP untill Unity introduce some kind of surface shader solution for specific SRP (hidef or lightweight).

    Tom
     
  8. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    Hi Tom

    Is it recommended I modify the current shader I have to work with RTP or that I modify the ReliefTerrain script to work with my project? If I have to modify the shader that I already have, does that mean I should use 4 RGBA textures? If I modify the ReliefTerrain script, when I attach the script to my planet generator it says

    There is no 'Renderer' attached to the "PlanetEden" game object, but a script is trying to access it.
    You probably need to add a Renderer to the game object "PlanetEden". Or your script needs to check if the component is attached before using it.

    So I need the ReliefTerrain script to be able to get access to the material slot as there is no renderer on the Planet generator. Here is a screenshot.
     

    Attached Files:

  9. truculencias

    truculencias

    Joined:
    Aug 7, 2015
    Posts:
    7
    I see, thanks for this fast answer!!
     
  10. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    ReliefTerrain script needs either Terrain component or MeshRenderer attached to the same transform. Material access is not enough. However, for sake of rendering changing material might be enough to some extent. If you assign dummy mesh renderer with the same material (you can disable such dummy MeshRenderer) RTP would feed the material with parameters. Still - it might be not enough because RTP makes some assumptions and calculations basing on mesh renderer size, placement, etc. This means it would be necessary to customize RTP scripts for such specific scenario.

    Tom
     
  11. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    Ok I have decided to edit the shader I have to be compatible with RTP, mostly looking at the ReliefTerrainTriPlanarPlanet shader. I have also opened up the hood of RTP_Base.cginc from reading your documentation.
    I am trying to include the fog you have on that shader into the planet shader I have.

    This the code I am starting off with based on the Custom Fog with Final Color Modifier examples on Unity's3D docs. Here:
    https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

    So for my surface output standard I have this:


    Code (CSharp):
    1. void mycolor (Input IN, SurfaceOutputStandard o, inout fixed4 color){  
    2.         fixed3 fogColor = _FogColor.rgb;
    3.         #ifdef UNITY_PASS_FORWARDADD
    4.         fogColor = 0;
    5.         #endif
    6.        
    7.         color.rgb = lerp (color.rgb, fogColor, IN.fog);
    8.         }
    Which produces a fog around the camera on the terrain (see screenshot attached below), where as I need the fog to be in the distance. I have coloured the fog red to illustrate in the screenshot.

    Now I want to include the code from RTP_Base.cginc which is basicaly what you got here:

    Code (CSharp):
    1. #if defined(RTP_FOG_EXP2)
    2.         void customFog (Input IN, SurfaceOutputStandard o, inout fixed4 color) {
    3.             float realFogDistance=(o.distance-max(0.0,AtmosphereDistance(o.distance)));
    4.             float val=_Fdensity*realFogDistance;
    5.             float f=exp2(-val*val*1.442695);
    6.             #ifdef UNITY_PASS_FORWARDADD
    7.                 color.rgb*=f;
    8.             #else
    9.                 float lightScatterValue=o.lightDir.z*2+1; // lightDir.z for planet has dot(light, surface normal)
    10.                 f=lerp(f, 1, saturate( (o.lightDir.w-_PlanetRadius) / _PlanetAtmosphereLength ) );
    11.                 float3 _FColorBack=lerp( lerp(color.rgb, _FColor3.rgb, _FColor3.a), _FColor2, saturate(lightScatterValue));
    12.                 color.rgb=lerp( lerp(_FColorBack, _FColor, saturate(o.lightDir.z*2)), color.rgb, f);
    13.             #endif
    14.         }
    so I tried with float lightScatterValue=o.lightDir.z*2+1; first

    So I added that line to my surface output:
    Code (CSharp):
    1. void mycolor (Input IN, SurfaceOutputStandard o, inout fixed4 color){  
    2.         fixed3 fogColor = _FogColor.rgb;
    3.         #ifdef UNITY_PASS_FORWARDADD
    4.         fogColor = 0;
    5.         #endif
    6.         float lightScatterValue=o.lightDir.z*2+1;
    7.         color.rgb = lerp (color.rgb, fogColor, IN.fog);
    8.         }
    And it is coming up with an error "invalid subscript 'lightDir' at line 158".

    So obviously I need to define lightDir
    Where exactly is lightDir defined in RTP_Base.cginc?

    Thanks

    Mark

     

    Attached Files:

  12. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    I'm redefining SurfaceOutputStandard to include some additional features. If you're in forward rendering path you could actually use Unity's predefined constant which is

    _WorldSpaceLightPos0

    For directional lights (in forwardbase shader pass) it holds direction. So _WorldSpaceLightPos0.xyz would be replacement for o.lightDir.xyz

    Tom
     
  13. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    Thanks Tom

    Code (CSharp):
    1. #if defined(RTP_FOG_EXP2)
    2.         void customFog (Input IN, SurfaceOutputStandard o, inout fixed4 color) {
    3.             float realFogDistance=([B]o.distance[/B]-max(0.0,AtmosphereDistance([B]o.distance[/B])));
    4.             float val=_Fdensity*realFogDistance;
    5.             float f=exp2(-val*val*1.442695);
    6.             #ifdef UNITY_PASS_FORWARDADD
    7.                 color.rgb*=f;
    8.             #else
    9.                 float lightScatterValue=o.lightDir.z*2+1; // lightDir.z for planet has dot(light, surface normal)
    10.                 f=lerp(f, 1, saturate( (o.lightDir.w-_PlanetRadius) / _PlanetAtmosphereLength ) );
    11.                 float3 _FColorBack=lerp( lerp(color.rgb, _FColor3.rgb, _FColor3.a), _FColor2, saturate(lightScatterValue));
    12.                 color.rgb=lerp( lerp(_FColorBack, _FColor, saturate(o.lightDir.z*2)), color.rgb, f);
    13.             #endif
    14.         }
    What about o.distance? Can I replace that with something else as well?
     
  14. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    length(_WorldSpaceCameraPos - IN.worldPos)

    You have to include worldPos in your surface shader Input structure.

    Tom
     
  15. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    Thanks Tom for answering my questions, I still haven't got it to work quite right yet, at least not how you have it in your planet shader. I am guessing it has something to do with my vertex function.

    Code (CSharp):
    1.     void myvert (inout appdata_full v, out Input data)
    2.       {
    3.           UNITY_INITIALIZE_OUTPUT(Input,data);
    4.           float4 hpos = UnityObjectToClipPos(v.vertex);
    5.           hpos.xy/=hpos.w;
    6.           data.fog = min (1, dot (hpos.xy, hpos.xy)*0.5);
    7.       }
    Basically the fog doesn't set itself in the distance. Where the camera is positioned there is fog, I only want the fog to render in the distance....is there a way I can do this inside my vertex function? Using these float values?

    _FogStart ("Fog Start", Float) = 0.002
    _FogEnd ("Fog End", Float) = 0.002

    Thanks so much for answering my questions, shading is a very tricky task.

    My SurfaceOutput function looks like this at the moment.

    Code (CSharp):
    1. void mycolor (Input IN, SurfaceOutputStandard o, inout fixed4 color)
    2.       {
    3.           float realFogDistance=length(_WorldSpaceCameraPos - IN.worldPos);
    4.           float val=_Fdensity*realFogDistance;
    5.           float f=exp2(-val*val*1.442695);
    6.          // fixed3 fogColor = _FogColor.rgb;
    7.           #ifdef UNITY_PASS_FORWARDADD
    8.           color.rgb*=f;
    9.           #else
    10.           float lightScatterValue=_WorldSpaceLightPos0.z*2+1;
    11.           f=lerp(f, 1, saturate( (_WorldSpaceLightPos0.w-_PlanetRadius) / _PlanetAtmosphereLength ) );
    12.           float3 _FColorBack=lerp( lerp(color.rgb, _FogColor3.rgb, _FogColor3.a), _FogColor2, saturate(lightScatterValue));
    13.          // fogColor = 0;
    14.           color.rgb=lerp( lerp(_FColorBack, _FogColor, saturate(_WorldSpaceLightPos0.z*2)), color.rgb, f);
    15.           #endif
    16.        
    17.       }
     
  16. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    I don't get the part with data.fog = min (1, dot (hpos.xy, hpos.xy)*0.5);
    hpos.xy is camera clip space, not any kind of distance?

    Tom
     
  17. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    189
    That vert function is copied from the Unity example

    https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

    Custom Fog with Final Color Modifier

    Code (CSharp):
    1. Shader "Example/Fog via Final Color" {
    2.     Properties {
    3.       _MainTex ("Texture", 2D) = "white" {}
    4.       _FogColor ("Fog Color", Color) = (0.3, 0.4, 0.7, 1.0)
    5.     }
    6.     SubShader {
    7.       Tags { "RenderType" = "Opaque" }
    8.       CGPROGRAM
    9.       #pragma surface surf Lambert finalcolor:mycolor vertex:myvert
    10.       struct Input {
    11.           float2 uv_MainTex;
    12.           half fog;
    13.       };
    14.       void myvert (inout appdata_full v, out Input data)
    15.       {
    16.           UNITY_INITIALIZE_OUTPUT(Input,data);
    17.           float4 hpos = UnityObjectToClipPos(v.vertex);
    18.           hpos.xy/=hpos.w;
    19.           data.fog = min (1, dot (hpos.xy, hpos.xy)*0.5);
    20.       }
    21.       fixed4 _FogColor;
    22.       void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
    23.       {
    24.           fixed3 fogColor = _FogColor.rgb;
    25.           #ifdef UNITY_PASS_FORWARDADD
    26.           fogColor = 0;
    27.           #endif
    28.           color.rgb = lerp (color.rgb, fogColor, IN.fog);
    29.       }
    30.       sampler2D _MainTex;
    31.       void surf (Input IN, inout SurfaceOutput o) {
    32.            o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    33.       }
    34.       ENDCG
    35.     }
    36.     Fallback "Diffuse"
    37.   }
    So the clip space is what is making the distance of the fog near the camera? If you have a look at my screenshots, you see the fog doesn't seem linear in the sense that it should be clear near the camera and then fade into fog in the distance, I know it has something to do with my vert function. For instance if I have my _PlanetRadius float turned all the way up to a hundred and my atmosphere depth set to 5 from the same values as your example scene ShaderOnPlanetModel...it will go completely white or whatever the fogs color is. I am not getting that transparency that you are able to achieve on your planet shader.
     

    Attached Files:

    Last edited: Jun 22, 2018
  18. VisualTech48

    VisualTech48

    Joined:
    Aug 23, 2013
    Posts:
    240
    I'm sometimes experiencing this issue and it only happens in the 5th or more texture layer (8 Layer Pass):
    upload_2018-6-22_19-28-23.png

    Like its in some sort of water when its not
     
  19. ng93

    ng93

    Joined:
    Aug 31, 2012
    Posts:
    40
    I'm getting an error when enabling instancing on a material using "Relief Pack - Standalone/Parallax Mapped Triplanar" shader.

    Shader error in 'Relief Pack - Standalone/Parallax Mapped Triplanar': invalid subscript 'instanceID' 'UnitySetupInstanceID': no matching 1 parameter function at line 720 (on d3d11)

    Tested using Unity 2017.4.6 and 2018.2b9 with clean projects, same error in both.

    - Create new project
    - Install latest version of RTP from asset store
    - Open "ShaderOnTriplanarMesh" example scene
    - Select the planet and check "Enable GPU instancing" in the material
     
  20. tcourbet

    tcourbet

    Joined:
    Oct 5, 2017
    Posts:
    46
    Hey guys,

    Been playing around lately with RTP and I was wondering if it handles LODs for GeomBlend objects at all.
    (I've tried searching this thread but it's quite extensive and a lot of the time "LOD" refers to the LOD manager, etc...)

    So basically, I have a very easy standard setup with my object lod0 --> 4 and while the blending works well on my independent lods, once I'm on the parent (or running in game), it just doesn't work at all.
    Anyone has a way around that? Or am I doing something wrong?


    Thanks!
     
    Last edited: Jun 25, 2018
  21. Amandin-E

    Amandin-E

    Joined:
    Feb 4, 2015
    Posts:
    419
    Hi @tomaszek

    I thought you'd be glad to get a look at the latest demo of Ultimate Terrains because it uses the triplanar version of RTP3 :)

    I think it makes a good showcase for your asset too, as it shows the powerfulness of your triplanar shader, as well as snow and vertical texturing (on the red planet). Hope you'll like it!

    Here is the video:


    And the link to the downloadable demo: https://uterrains.com/demo/
     
    akareactor, ftejada and tomaszek like this.
  22. imtehQ

    imtehQ

    Joined:
    Feb 18, 2013
    Posts:
    230
    So i got a issue, the terrain looks like to ignore lights/shadows
    With light:


    Without light source:


    Any idea what im going wrong?

    Thats with Gradient colors in light settings, with color its even worse:

     
  23. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Might be missing diffuse/albedo texture packed in atlas for layers 5-8. You can check it in RTP/combined textures/atlas. The reason 2nd atlas hasn't been created might be source textures are of different sizes. It's reflected in console output when RTP fails on that. How many layers do you use? It has to be either 4 or 8. Attach RTP after adding 8 textures to terrain. You could also check if somehow layers 5-8 brightness set per layer is not damped to zero.

    It's been released from U5.5 (and it works for U5.5 and above) where new instancing treatment has not been yet introduced (manul toggle checkbox in material inspector). That's why I missed it. Solution is simple and I will include it in the next RTP update. In case you need it right now (for these 1000 meteorits rendered in your space game :) ), open RTP_Base.cginc. Find this (must be around line 1000):

    Code (csharp):
    1. fixed4 color : COLOR;
    and add a line of code before bracket. Will look like this:

    Code (csharp):
    1. fixed4 color : COLOR;
    2.        UNITY_VERTEX_INPUT_INSTANCE_ID
    3.     };
    4.  
    then (around line 1100)

    Code (csharp):
    1.  
    2. #else
    3.    void vert (inout appdata v) {
    4. #endif
    5.  
    and add a line, it will look like this:

    Code (csharp):
    1.  
    2. #else
    3.    void vert (inout appdata v) {
    4. #endif
    5.    UNITY_SETUP_INSTANCE_ID(v);
    6.  
    Save RTP_Base and reimport problematic shader.
     
    Last edited: Jun 27, 2018
  24. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Just checked it on my side on example scene and it works. I did it like this. Created empty game object and put stone1 and stone2 into this. Added LOD group to the game object. Removed lod2 (only lod0, lod1 and culled). Dragged stone1 as renderers of lod0. The same for lod1. So lod0 and lod1 both consist of 2 renderers (geom blend object and underlying object). In your case you're using prefab wchi might be problematic. Mesh on main geom blend object and underlying one is created by RTP script and is not permament asset by default (it's scene object). Making prefab makes it loose references. The same for underlying object material. For performance reason you could create the same material with Hidden/ReliefTerrainGeometryBlendBase shader. So - after you add your MetalScrapsPile01 to scene it's better to not treat it as prefab (even though some parameters can be still associated with prefab).

    RTP needs light source (one directional light) to be present and with intensity above 0.01. I would need more info about your setup to know what could be the reason shadows are not present. Is it lightmapped terrain? Forward or deferred? Do you use RTP's deferred lighting shader?

    Tom
     
  25. imtehQ

    imtehQ

    Joined:
    Feb 18, 2013
    Posts:
    230
    I got it sorted, it was the light settings that where messed up.
     
  26. tcourbet

    tcourbet

    Joined:
    Oct 5, 2017
    Posts:
    46
    Yeah! I can confirm that it does work if I break the prefab connection and just use the model. I understand why it's that way but unfortunately it is a bit bothersome in some instances where I really need the prefab connection to be present. Well, at least I know, thanks for the help!
     
  27. dkm

    dkm

    Joined:
    Sep 9, 2013
    Posts:
    15
    Hey guys!

    I'm considering buying RTP (for multiple reasons!) but I'm mostly interested in the mesh blending with terrain options.
    I have 2 questions about that. Can you geom-blend with the terrain:
    - a transparent (alpha or cutout) object?
    - an object for which you have created custom shaders?

    Thanks!
     
  28. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Geom blend is object that renders 2 meshes. First - object mesh using terrain shader (mesh is treated as terrain - mapped topplanar). Then real object is rendered using transparency for places where we want to see terrain (at the bottom where object intersects). So - to answer the first question - I'm not sure what would you like to blend actually - we need underalying "mimic terrain geom blend object". It's not transparent, so overlying transparent object would make sense only if you could remove some triangles from underlying object (leaving only those intersecting terrain for sake of blending). Answer for the 2nd question is - yes, definitely. Simply you can use any transparent shader that controls its transparency at the bottom (intersection with terrain). By default RTP assumes its vertex color alpha channel used to control it (you can painbt it as shown on my YT videos using built-in RTP vertex brush functionality).

    Tom
     
  29. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    341
    Good afternoon. went to version 2018.1.8f1. I compile the shader and nothing changes. Also many settings stopped working. I'm doing everything right. what could be the problem. deleted the folder completely and installed again. all the textures are the same size. After the transition. between the two screenshots look at the difference. so the landscape flickers. I approach or delete and there is a flicker.
     

    Attached Files:

    Last edited: Jul 26, 2018
  30. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Not sure what could change in Unity2018.1.8 particularily because I checked newest RTP (3.3m - check verinfo.txt file after installing) release against both 2018.1 and 2018.2. Plese check installing RTP from asset stoe on fresh project under your Unity version and the same LOD manager settings. Then we know if this is something specific to your project or RTP vs. U2018.1.8 fails.

    Tom
     
  31. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    102
    hi will it work for open gl es 3.2?
     
  32. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    I guess so. You need to be aware it's feature packed shader so performance might be problematic on some low-end gles3 mobile hardware.

    Tom
     
    mukki014 likes this.
  33. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    341
    I created a new terrain. Attached to it your script and assigned textures. and all the settings work well. But moving to my old terrane nothing works although there is the same thing. !! I copy the script on the map and replace it with the old map but also the settings do not work. the difference is that. my old card consists of pieces of cut. When I upgraded to a new version, I also encountered such a problem. What do I need to do to make my settings work on my multiterrains?
     

    Attached Files:

  34. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Copying ReliefTerrain component mighte be not good idea as you can easily break a lot of references. Better to setup it again with help of RTP presets that can save time of retweaking all parameters. Esp. copying ReliefTerrain component from single terrain to multiple ones would be troublesome. On your screenshot it looks like coverage textures are broken. Try to use RefreshAll button in RTP/Settings/Main. Take care coverage textures reference to terrain alpha textures (subassets of terrain object). Coverage texturesused in RTP shader can be viewed in RTP/Combined Textures/Coverage

    Tom
     
  35. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    341
    On the screen I showed that everything is good on the new terrain. I clicked to update everything. It did not help. I was trying to delete the script. delete the library folder. None of this helps. - ((
     
  36. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    102
    Thank you
     
  37. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    341
    To me to make presets, I need to set up parameters that I can not configure for some unknown reason. I create a new terrain and everything is configurable. and my old terranes do not work.
     
  38. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    It might be that something got screwed in globalSettingsHolder object that's shared across all terrains. If you remove ReliefTerrain from single terrain object and add the RTP component back it will get globalSettingsHolder from another terrain. I guess it might be necessary to setup it one again for your terrains. I mean - remove ReliefTerrain components from _all_ terrains. Remove LODManager from scene. Make sure import newest RTP version from asset store and reassign ReliefTerrain component to terrains again, setup/recompile LODmanager features. I should definitely work as far as it works on my example scene and when you attach RTP to new terrain in separte test scene (this is what I understand you did and it worked).

    Tom
     
  39. yotingo

    yotingo

    Joined:
    Jul 10, 2013
    Posts:
    38
    Hi Tom,

    Some of my questions are quite general, I hope it is not out-of-line to ask here.

    I'm creating a spherical mesh terrain (the player traverses the inside of a planet). After studying the documentation I still have a few questions:

    1. Are there any specific settings I need to enable for everything to work properly on the inside of a sphere? (opposite of your planet demo)
    2. With hopes that I can avoid proper UV mapping, I'm trying to use Substance Painter to create the Splat / Coverage Map. Can you offer any advice on how to export a Splat / Coverage Map from Substance Painter?
    3. Do the "Advanced Water Features" in RTP include a water/ocean shader (as seen in the video)?

    I'm having a lot of difficulty figuring out how to paint and create my coverage map, any advice would be appreciated.

    Thanks for your time!
    - Yotingo
     
    Last edited: Aug 10, 2018
  40. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Actually I left planet shader as part of RTP only for people that uses planetary terrain, but this system is abadoned for a long time. Inside planet I assume you want to render kind of tunnel indie planet or section of a sphere. I believe triplanar standalone shader could make a job as far as you can provide mesh with vertex colors that would control layer selection (one of four layers available). You need to switch shader to this mode (at the bnegining of shader code it's extensively commented where do you need to change it).

    I'm not much into Substance Painter. Proper UV mapping I imagine you want to use kind of triplanar mapping? Such solution is available (look above about planet).

    Water features shows some water on the mesh suface (wetness, puddles with rain droplets), it's not a replacement for ocean shaders.

    Tom
     
  41. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    341
    good afternoon. I did everything as you wrote, but everything remains as before. my problem did not dare. Do you have any other thoughts?
     

    Attached Files:

    • е5.jpg
      е5.jpg
      File size:
      375.5 KB
      Views:
      352
    • е6.jpg
      е6.jpg
      File size:
      365.2 KB
      Views:
      322
    • е7.jpg
      е7.jpg
      File size:
      566.7 KB
      Views:
      314
    • е8.jpg
      е8.jpg
      File size:
      288 KB
      Views:
      298
    • е9.jpg
      е9.jpg
      File size:
      278.3 KB
      Views:
      261
  42. yotingo

    yotingo

    Joined:
    Jul 10, 2013
    Posts:
    38
    Thanks! It sounds like the Triplanar Standalone Shader will work best for me.

    With the Triplanar Standalone Shader, how do I apply it to multiple mesh pieces without seems/edges?
     
  43. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    It can do triplanar mapping in worldspace coords. For global maps - here it's more complex, because it's meant to be mapped spanned over xz plane (not shpere/planet). By global maps I mean - global colormap, normalmap, etc.

    Tom
     
  44. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Not sure about shading beyond far distance range (screenshots 1,2) - what's your setup in perlin normal tab (distance)? Looks like this doesn't render correctly. How many layers your terrain has? In LOD manager it's shown as 8layers rendered in first pass. Do you have 8 layers present on terrain (and in RTP)? If coverage is still a problem check coverage/splat maps tab in RTP and check if they refer to terrain splat textures (subassets of terrain object asset).

    Tom
     
  45. brunofls

    brunofls

    Joined:
    Nov 22, 2017
    Posts:
    1
    Hi tom.

    Is there a way to integrate RTP with Curved World? Would be nice to see my terrains with curve effect featured by the Curved World asset, however I don't know if that's technically possible or already implemented somewhere.

    Thanks.
     
  46. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    Actually, I've got no idea how Curved World is realised. You might ask CW developer if it works with Unity terrains and if it needs special shaders for it. It might be that it just tweaks the way meshes are projected (thru projection matrix which has nothing to do with shaders, they just use it) or additionaly via some vertex shader function modifications.

    Tom
     
  47. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,785
    I seem to recall it does.
    "shader does not modify mesh vertex positions"
    "Bend effects are based on parabola equitation[sic] and each one is supposed to be observed from specific points."
    and finally
    "Curved World comes with huge amount of shaders (with about 500000 (half of million) variations) for all type of devices - from ancient mobiles to high-end PC and consoles. Here they are:
    Unlit, One Directional Light, Matcap, Standard, Legacy, Terrain (Unity and Mobile), Unity Foliage, SpeedTree, Water, DX11 tessellation, Sprite, Projector, 2D Skybox, Flare, Glass (Dynamic refraction)."

    Hope it helps

    I am reasonably sure he meant Equation and not Horse-riding
     
  48. Doctor06

    Doctor06

    Joined:
    Nov 1, 2014
    Posts:
    31
    I did a quick search on update to make sure i don't ask this question like an idiot. But if i missed the thread it walks about when you are updating, please forgive me. But i was wondering when your next release will be to the import warning message does not show up on 2018 Unity.
    Great work on the asset by the way. I always love complementing your work.
     
  49. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,747
    I've just imported RTP3.3m on fresh project in 2018.2.6f1 and see no warning after performing automated C# API updater. Can you tell more about warning and your project context?

    Tom

    P.S. I've got 2 small fixes not submited yet (RTP3.3n):
    - fixed Geom Blend Standard Shader compilation bug in Unity 2018
    - fixed instancing error when using it on triplanar standalone shader
     
  50. tcourbet

    tcourbet

    Joined:
    Oct 5, 2017
    Posts:
    46
    This is great, thanks!
    Do you already know when this will be submitted? Very much looking forward to the geom blend fix :)