Black & white line procedural material

Hi nice Unity people,
i would like to create procedural material to create texture like that >>
substance is too expensive for me.
i need it dynamic that i can tweek in real time
any pist ?

Hi tarrabass!

In the image we have two things, a ‘simple’ b&w line pattern and some (twisted) geometry. The material (shader) for the pattern is easy

Shader "BWLinePattern"
{

    Properties{

        _densityLines ("Density Lines",Float) = 0
        _blurryFrontier("Blurry Frontier", Range(0.01,1.0)) = 0
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
        
            #include "UnityCG.cginc"

            float _densityLines;
            float _blurryFrontier;

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                float4 vertex : SV_POSITION;
            };
        
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                o.uv = v.uv;
                o.posWorld = mul(_Object2World,v.vertex);
                return o;
            }
        
            fixed4 frag (v2f i) : SV_Target
            {

                float f = smoothstep(-_blurryFrontier,_blurryFrontier,sin(_densityLines*i.posWorld.y));
                float4 col1 = float4(1.0,1.0,1.0,1.0);
                float4 col2 = float4(0.0,0.0,0.0,1.0);
                return lerp(col1,col2,f);
            }
            ENDCG
        }
    }
}

In this case, the line pattern is based on y position of the fragment in the world, but you can use other parameter(like uv components).

Hope this helps you! Cheers :slight_smile:

Jose Moreno

2679609–189313–BNLinePattern.shader (1018 Bytes)

For the surface, you could use the one in the image (building the mesh with the parametric expression)

Well… I have too much spare time…here a little project with ‘my version’ of your question :slight_smile:

2680171--189341--redux.gif

Here the code for the twisted mesh generation

using UnityEngine;
using System.Collections;

public class TwistedMesh : MonoBehaviour {

    public Material mat;

    public int numberVerticesX;
    public int numberVerticesY;

    Vector3[] vs;
    int[] inds;
    Vector2[] uvs;

    Mesh mesh;

    void Start () {

        vs = new Vector3[numberVerticesX*numberVerticesY];
        uvs = new Vector2[numberVerticesX*numberVerticesY];

        for(int j=0;j<numberVerticesY;j++){
            for(int i=0;i<numberVerticesX;i++){

                //Little correction (uv goes from 0 to 1, closed interval)
                float u = 1f*i/(numberVerticesX-1);
                float v = 1f*j/(numberVerticesY-1);

                vs[i+j*numberVerticesX] = new Vector3(
                    (1.0f+0.8f*Mathf.Pow(Mathf.Sin(1f*(20f*v-10f)),4f))*Mathf.Cos(2f*Mathf.PI*u),
                    (20f*v-10f)+1f*Mathf.Cos(2f*Mathf.PI*u),
                    (1.0f+0.8f*Mathf.Pow(Mathf.Sin(1f*(20f*v-10f)),4f))*Mathf.Sin(2f*Mathf.PI*u)
                );

                uvs[i+j*numberVerticesX] = new Vector3(u,v);
            }
        }

        inds = new int[6*numberVerticesX*(numberVerticesY-1)];
        int k=0;
        for(int i=0;i<numberVerticesX*(numberVerticesY-1);i++){

            if(i%numberVerticesX==numberVerticesX-1){
                inds[0+k] = i;
                inds[1+k] = i+numberVerticesX;
                inds[2+k] = i+1-numberVerticesX;
                inds[3+k] = i+1-numberVerticesX;
                inds[4+k] = i+numberVerticesX;
                inds[5+k] = i+1;
            }else{
                inds[0+k] = i;
                inds[1+k] = i+numberVerticesX;
                inds[2+k] = i+1;
                inds[3+k] = i+numberVerticesX;
                inds[4+k] = i+numberVerticesX+1;
                inds[5+k] = i+1;
            }

            k=k+6;

        }

        mesh = new Mesh();
        mesh.vertices = vs;
        mesh.uv = uvs;
        mesh.SetIndices(inds,MeshTopology.Triangles,0);
        mesh.RecalculateNormals();

        GetComponent<MeshFilter>().mesh = mesh;

    }

    void Update(){
        transform.Rotate(new Vector3(0f,40f,0f)*Time.deltaTime);
    }

}

Hope it helps!

2680171–189342–TwistedandBW.unitypackage (27.3 KB)

Yes, you can’t imagine how it help, i was diging into substance,
you help me so much, thanks
francois

You’re welcome :slight_smile:

Could you send me your email in private or send me a email to
francois@mysquare.ch
thanks again

Of course! Mail sent