Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Slime Rancher Windows

Discussion in 'Scripting' started by MICKDOii, Nov 13, 2016.

  1. MICKDOii

    MICKDOii

    Joined:
    Jan 12, 2015
    Posts:
    69
    Does anyone know how they achieved this effect with the windows have some sort of depth to them.
    As i moving to the side of the window the dark images become less 3 dimensional so I assume they're not 3d models. Untitled-1.jpg
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. Malakym

    Malakym

    Joined:
    Nov 18, 2012
    Posts:
    2
    Hello!
    I'm the current artist on Slime Rancher so I can say with some authority that GroZZler is correct.



    The effect is pulled off by using three images set to different parallax depth in the shader. The deeper the image the more the emissive value is increased as well. No geometry needed.


    https://dl.dropboxusercontent.com/u/11697995/sr/window.gif
     
  4. MICKDOii

    MICKDOii

    Joined:
    Jan 12, 2015
    Posts:
    69
  5. MICKDOii

    MICKDOii

    Joined:
    Jan 12, 2015
    Posts:
    69

    Hey there, Well this is as good as it gets coming from the man himself.
    I appreciate you taking the time.

    While I have you here if you can answer one more question for me.
    I remember seeing a video of someone with a map editor and whenever they'd move specific models the textures would transition, how is this achieve?
     
  6. Malakym

    Malakym

    Joined:
    Nov 18, 2012
    Posts:
    2
    No
    No problem.

    https://dl.dropboxusercontent.com/u/11697995/sr/vertexSplat.gif

    What you're probably seeing is world space triplanar mapping. This is when the UV coordinates of the material are defined by their physical space in the world and projected using one of three directions.

    http://www.martinpalko.com/triplanar-mapping/

    This has its benefits in that the model requires no UV mapping and also that the textures will always be a uniform scale/placement no matter how you scale or rotate the mesh. We use this method on almost all our environment models in Slime Rancher as a way of speeding up production.

    I do all my shader work in Shader Forge. As such, you can see the exact node tree I use on their wiki here:
    http://acegikmo.com/shaderforge/wiki/index.php?title=Triplanar_Mapping
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
  8. MICKDOii

    MICKDOii

    Joined:
    Jan 12, 2015
    Posts:
    69

    Okay I've manage to replecate both tri

    Okay I've manage to replicate both, only I'm using a window shader script I found whilst googling that only allows one "3DTexture".
    How would I add multiple layers as I'm not to savvy with shader coding.
    I tried duplicating alot of the code but ran into an error I couldn't seem to fix.

    Code (CSharp):
    1. Shader "Custom/WindowShader" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _Diffuse ("MainTex", 2D) = "white" {}
    5.    
    6.     _BumpMap ("Normalmap", 2D) = "bump" {}
    7.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    8.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    9.    
    10.     _MainTex ("3DTexture", 2D) = "white" {}
    11.     [MaterialToggle(_COLOR_ON)] _TintColor ("HQ", Float) = 1
    12.     _RoomColor ("3DTexture_Color", Color) = (0.6,0.6,0.6,0.5)
    13.    
    14.     [MaterialToggle(_Dist_ON)] _TintColor2 ("Distortion_On", Float) = 0
    15.     _Distortion ("Distortion", Range (0.0, 5)) = 1.0
    16.    
    17.     _Lightning ("Lightning", Range (0.01, 1)) = 0.01
    18.    
    19.     _Offset ("Offset", Range (0.001, 8.0)) = 0.01
    20.     _Depth ("Depth", Range (0.001, 8.0)) = 0.01
    21.    
    22.    
    23.     _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    24.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    25.     _rim_power("Rim_power", Range(0.1,5) ) = 5
    26.    
    27.    
    28. }
    29. SubShader {
    30.     LOD 200
    31.     Tags { "RenderType"="Opaque" }
    32.    
    33. CGPROGRAM
    34. #pragma surface surf BlinnPhong
    35. #pragma target 3.0
    36. #include "UnityCG.cginc"
    37. #pragma multi_compile _COLOR_OFF _COLOR_ON
    38. #pragma multi_compile _Dist_OFF _Dist_ON
    39.  
    40. sampler2D _MainTex;
    41. samplerCUBE _Cube;
    42. sampler2D _Diffuse;
    43. sampler2D _BumpMap;
    44. float  _Depth;
    45. float _Offset;
    46. fixed4 _Color;
    47. fixed4 _ReflectColor;
    48. fixed4 _RoomColor;
    49. half _Shininess;
    50. half _Lightning;
    51. half _rim_power;
    52. half _Distortion;
    53.  
    54. struct Input {
    55.     float2 uv_MainTex;
    56.     float2 uv_Diffuse;
    57.     float3 worldRefl;
    58.     float3 viewDir;
    59.     INTERNAL_DATA
    60. };
    61.  
    62.  
    63.  
    64.    
    65.    
    66.  
    67. void surf (Input IN, inout SurfaceOutput o) {
    68.  
    69.     half h = tex2D (_MainTex, IN.uv_MainTex).w;
    70.    
    71.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_Diffuse));
    72.    
    73.    
    74.     #if _Dist_ON
    75.     float2 offset = ParallaxOffset  (h , -1, IN.viewDir ) + o.Normal * _Distortion  ;
    76.     #else
    77.     float2 offset = ParallaxOffset  (h , -1, IN.viewDir ) ;
    78.     #endif
    79.    
    80.     #if _COLOR_ON
    81.     float2 uv1 = IN.uv_MainTex += offset * _Offset*0.1 * _Depth ;
    82.     float2 uv2 = IN.uv_MainTex += offset * 0.03 * _Offset;
    83.     float2 uv3 = IN.uv_MainTex += offset * 0.035 * _Offset;
    84.     float2 uv4 = IN.uv_MainTex += offset * 0.04 * _Offset;
    85.     float2 uv5 = IN.uv_MainTex += offset * 0.045 * _Offset;
    86.     float2 uv6 = IN.uv_MainTex += offset * 0.05 * _Offset;
    87.     float2 uv7 = IN.uv_MainTex += offset * 0.055 * _Offset;
    88.     float2 uv8 = IN.uv_MainTex += offset * 0.06 * _Offset;
    89.     float2 uv9 = IN.uv_MainTex += offset * 0.065 * _Offset;
    90.    
    91.    
    92.     fixed4 tex = tex2D(_MainTex, uv1)*0.6;
    93.     fixed4 tex2 = tex2D(_MainTex, uv2)*0.22;
    94.     fixed4 tex3 = tex2D(_MainTex, uv3)*0.22;
    95.     fixed4 tex4 = tex2D(_MainTex, uv4)*0.21;
    96.     fixed4 tex5 = tex2D(_MainTex, uv5)*0.2;
    97.     fixed4 tex6 = tex2D(_MainTex, uv6)*0.15;
    98.     fixed4 tex7 = tex2D(_MainTex, uv7)*0.12;
    99.     fixed4 tex8 = tex2D(_MainTex, uv8)*0.11;
    100.     fixed4 tex9 = tex2D(_MainTex, uv9)*0.09;
    101.    
    102.     fixed4 room = tex + tex2 + tex3 + tex4 + tex5  + tex6 + tex7 + tex8 + tex9 ;
    103.      #else
    104.    
    105.      float2 uv1 = IN.uv_MainTex += offset * _Offset*0.1 * _Depth ;
    106.     float2 uv3 = IN.uv_MainTex += offset * 0.045 * _Offset;
    107.     float2 uv7 = IN.uv_MainTex += offset * 0.055 * _Offset;
    108.     float2 uv9 = IN.uv_MainTex += offset * 0.065 * _Offset;
    109.    
    110.    
    111.     fixed4 tex = tex2D(_MainTex, uv1)*0.6;
    112.     fixed4 tex3 = tex2D(_MainTex, uv3)*0.52;
    113.     fixed4 tex7 = tex2D(_MainTex, uv7)*0.42;
    114.     fixed4 tex9 = tex2D(_MainTex, uv9)*0.32;
    115.     fixed4 room = tex + tex3 + tex7 + tex9 ;
    116.    
    117.    
    118.    
    119.      #endif
    120.    
    121.    
    122.      fixed4 diff  = tex2D (_Diffuse, IN.uv_Diffuse)    ;
    123.    
    124.    
    125.      
    126.    
    127.     o.Albedo =      (diff *  diff.a )* _Color   +  (room.rgb *_RoomColor*3 +_RoomColor.a) *  (1-diff.a) ;
    128.    
    129.     o.Gloss = 1-diff.a + diff*2  ;
    130.     o.Specular = _Shininess ;
    131.    
    132.     fixed4 Fresnel_1 = float4(0,0,1,1);
    133.     fixed4 Fresnel_2 =(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Fresnel_1.xyz )   )).xxxx;
    134.     fixed4 Pow = pow(Fresnel_2,_rim_power.xxxx  );
    135.    
    136.     float3 worldRefl = WorldReflectionVector (IN, o.Normal);
    137.     fixed4 reflcol = texCUBE (_Cube, worldRefl )* Pow  ;
    138.     reflcol *= (1- diff.a) * _ReflectColor;
    139.     o.Emission = (room.rgb *_Lightning*2) *  (1-diff.a)  +   reflcol ;
    140.     o.Alpha = reflcol.a * _ReflectColor.a;
    141.    
    142.    
    143. }
    144. ENDCG
    145. }
    146.    
    147. FallBack "Reflective/VertexLit"
    148. }
    149.