Search Unity

Question Help me please with resources, tutorials and advices that can help me to implement this shader

Discussion in 'Shaders' started by blablaalb, Aug 18, 2022.

  1. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    I know something about shaders, I have written some very basic shaders. This is the most advanced shader I have written so far.

    It's been several days since I conceived the idea of trying to recreate this shader, but I still can't wrap my head around on how to approach it.

    I figured out I can hide part of the object by making the texture fully transparent and then, after player moves the brush across the object, project the brush on to the object and reveal that part of the texture.
    Code (CSharp):
    1. Shader "Custom/Masked Transparent" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    5.         _MaskTex("Mask Texture", 2D) = "white" {}
    6.     }
    7.  
    8.     SubShader {
    9.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    10.         LOD 200
    11.  
    12.         CGPROGRAM
    13.         #pragma surface surf Lambert alpha:fade
    14.  
    15.         sampler2D _MainTex;
    16.         sampler2D _MaskTex;
    17.         fixed4 _Color;
    18.  
    19.         struct Input {
    20.             float2 uv_MainTex;
    21.         };
    22.  
    23.         void surf (Input IN, inout SurfaceOutput o) {
    24.             fixed4 main_color = tex2D(_MainTex, IN.uv_MainTex);
    25.             fixed4 mask_color = tex2D(_MaskTex, IN.uv_MainTex);
    26.             o.Albedo = main_color.rgb;
    27.             o.Alpha = mask_color.r;
    28.         }
    29.         ENDCG
    30.     }
    31. }


    But this implementation lacks the perceived height and liquidity you can observe in the original shader . How do I implement the effect of smearing acrylic paint? Any advice, resources, tutorials and maybe there's ready to use assets - anything is welcome! Thanks!
     
  2. kiselevsereja

    kiselevsereja

    Joined:
    Sep 22, 2019
    Posts:
    4
    A couple of ideas:
    1. First you can try to generate random normals using noise.

    2. Pass these normals to the surface shader output.

    3. Apparently, this effect looks like basic PBR with metallic by 1 and smoothness by 0.5. You can try pass this parameters to shader output.
    4. in general, it doesn't look like this effect was done by the shader alone. perhaps a real-time mesh generation used here or something like that.
     
  3. cgDoofus

    cgDoofus

    Joined:
    Jun 15, 2021
    Posts:
    48
    what should greatly help you here is not having a sharp brush stroke, but rather a perfect radial gradient brush, so that you can measure how far any given pixel is from the "border" of the drawing, with this scalar info you should be able to do various tricks like generating custom normals based on the gradient and shrinking/expanding border by clipping at different values, and maybe also distorting the border by adding in some noise.
    Good luck!