Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What shaders would you guys want?

Discussion in 'Shaders' started by tatoforever, Aug 28, 2012.

  1. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    @Cherno,
    You can already accomplish that with black and white textures. The inverted mesh method works fast unless you want more expensive solutions such camera effects and inverting the shadows will make them invisible.
     
  2. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    The problem with the inverted mesh outline is that hard corners don't work, and it's be a mess having to round every corner of every mesh.
    Black and white textures work, but not for a Sin City look. Ideally, a texture would be completly white (with black lines for detail), and maybe some yreas in blue, red, green etc. The shader would have the option to show the texture that lies in shadow as inverted (only useful for pure black and white, of course).

     
  3. Mireneye

    Mireneye

    Joined:
    Apr 14, 2016
    Posts:
    2
    Something like this but with working normal maps (right now it just turns black). And preferably heigh/roughness (The whole PBR thing) but I'll take what I can get.

    It's kindof a Triplanar shader using one texture, in World Space, so it tiles freely:

    Many thanks in advance!

    Code (CSharp):
    1.     Shader "Custom/TriWorld" {
    2.     Properties {
    3.       _Color ("Main Color", Color) = (1,1,1,1)
    4.       _MainTex ("Diffuse Texture", 2D) = "white" {}
    5.       _BumpMap ("NormalMap", 2D) = "bump" {}
    6.       _BaseScale ("BaseScale", Vector) = (1,1,1,0)
    7.     }
    8. SubShader {
    9.       Tags { "RenderType" = "Opaque" }
    10.       CGPROGRAM
    11.       #pragma surface surf Lambert
    12.    
    13.       struct Input {
    14.           float3 worldPos;
    15.           float3 worldNormal; INTERNAL_DATA
    16.           float3 vertColors;
    17.  
    18.       };
    19.  
    20.         void vert (inout appdata_full v, out Input o)
    21.         {
    22.             o.vertColors = abs(v.normal);
    23.         }
    24.    
    25.       sampler2D _MainTex;
    26.       sampler2D _BumpMap;
    27.       fixed4 _Color;
    28.       float3 _BaseScale;
    29.  
    30. void surf (Input IN, inout SurfaceOutput o) {
    31.  
    32.  
    33.  
    34.     fixed4 texXY = tex2D(_MainTex, IN.worldPos.xy * _BaseScale.z);
    35.     fixed4 texXZ = tex2D(_MainTex, IN.worldPos.xz * _BaseScale.y);
    36.     fixed4 texYZ = tex2D(_MainTex, IN.worldPos.yz * _BaseScale.x);
    37.         fixed3 mask = fixed3(
    38.         dot (IN.worldNormal, fixed3(0,0,1)),
    39.         dot (IN.worldNormal, fixed3(0,1,0)),
    40.         dot (IN.worldNormal, fixed3(1,0,0)));
    41.     fixed4 tex = texXY * abs(mask.x) +texXZ * abs(mask.y) +texYZ * abs(mask.z);
    42.     fixed4 c = tex * _Color;
    43.  
    44.             float3 uv = IN.worldPos.xyz;
    45.  
    46.  
    47.             half4 x = tex2D(_BumpMap, uv.zy);
    48.             half4 y = tex2D(_BumpMap, uv.zx);
    49.             half4 z = tex2D(_BumpMap, uv.xy);
    50.             half4 n = float4(1,1,1,1);
    51.             n = lerp(n,x,IN.vertColors.r);
    52.             n = lerp(n,y,IN.vertColors.g);
    53.             n = lerp(n,z,IN.vertColors.b);
    54.  
    55.  
    56.  
    57.                      o.Albedo = c.rgb;
    58.                      //o.Normal = UnpackNormal(n);
    59.  
    60.       }
    61.       ENDCG
    62.     }
    63.     Fallback "Diffuse"
    64.   }
     
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Hey guys,
    I'm a bit busy right now but I'll give it a try both of your cases when I'll get some free time (later tomorrow).
    Regards,
     
  5. Vade-Mecum

    Vade-Mecum

    Joined:
    Dec 10, 2012
    Posts:
    17
    Weirdly, i googled a lot, but couldn't find a simple solution how to do a simple bump/specular v2f shader. I think some simple example would help a lot of people.
     
    tatoforever likes this.
  6. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Do you need an example using unity internal data or your own data (eg your own light position/direction)?

    @OtherGuys,
    I haven't forgotten about your posts, is just that we are kinda rushed a bit with Sony and Microsoft E3 trailers materials for our upcoming game and I'm trying to find some free time to work out on your requests.

    Regards,
     
  7. Vade-Mecum

    Vade-Mecum

    Joined:
    Dec 10, 2012
    Posts:
    17
    That would be great if you could provide both. Now i have a completely unlit shader with detailed diffuse textures and non-unity lightmaps, i suppose the surface don't have to be lit to do specularity, just need light coordinates and view point. Here's the code if someone need it:

    Code (CSharp):
    1. Shader "Genplan"
    2. {
    3.     Properties {
    4.     _Color ("Main Color", Color) = (1,1,1,1)
    5.     _MainTex ("Base (RGB)", 2D)     = "white" {}
    6.     _Lightmap ("Lightmap", 2D)     = "white" {}
    7.     _Brightness ("Brightness", Float) = 1.0
    8.     _Shift ("Shift", Float) = 1.0
    9.     }
    10.     SubShader {
    11.     Tags { "RenderType"="Transparent" "IgnoreProjector"="True"}
    12.         Pass {
    13.         Cull Back
    14.         Blend SrcAlpha OneMinusSrcAlpha
    15.         AlphaTest Off
    16.             CGPROGRAM
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             #include "UnityCG.cginc"
    20.             sampler2D _MainTex;
    21.             float4 _MainTex_ST;
    22.              sampler2D _Lightmap;
    23.               float _Brightness;
    24.             fixed4 _Color;
    25.             float _Shift;
    26.             struct v2f     {
    27.                 float2 uv : TEXCOORD0;
    28.                 float4 pos : SV_POSITION;
    29.                 half2 lightmapuv : TEXCOORD1;
    30.             };
    31.             v2f vert (appdata_full v)     {
    32.                 v2f o;
    33.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    34.                 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
    35.                 o.lightmapuv = v.texcoord1;
    36.                 return o;
    37.             }
    38.             half4 frag (v2f i) : SV_Target {
    39.                 fixed4 lm = tex2D(_Lightmap, i.lightmapuv);
    40.                 fixed4 texcol = tex2D(_MainTex, (i.uv * _Shift)) + tex2D(_MainTex, i.uv);
    41.                 texcol.rgb *= lm  * _Brightness;
    42.                 return texcol * _Color;
    43.             }
    44.             ENDCG
    45.         }
    46.     }
    47. }
    48.  
     
  8. kashifrazzaq20

    kashifrazzaq20

    Joined:
    Aug 15, 2019
    Posts:
    15
    clay shader
     
  9. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    On what are you working on?