Forgotten Shader Procedural Texture-Yanbian Indented Texture

Recent feelings:

I believe that the little friends who learn Shader very much start from Feng Lele's introduction. The same is true for me. The length of the program texture is very short.
Here is an example: 9 points are drawn on one surface. At the time, my idea was to draw some points on the map, what effect can this do?
So I quickly skipped it after reading it, and recently re-read the book again, as if to open a "dog hole" in a new world.
Hahaha...If you don’t pay attention, you just ignore it. The procedural texture can do too much...

text:

The final result of a recent request is shown in the figure: The
Insert picture description here
texture is like this
Insert picture description here

That is, draw a circle inward along the edge of the model, let's not care about the use of this effect.
Indeed, I browsed many websites and failed to find any useful information. I also tried many methods.
For example:
What I think is to use 3 Passes to pass the level, each one is up a little bit higher than the previous one, and the vertex shrinks a little towards the center to achieve this effect.
The performance trumpet is very big. If you superimpose other effects on it, it is very troublesome and inoperable.
The effect is roughly like this: the
Insert picture description here
following is the general process of using procedural textures:
1. First, find all vertices in the section.
2. Record the UV vertices corresponding to all vertices.
3. Use the average of all UV vertices to calculate the approximate UV center point.
4. Each UV vertex connects the center point to get an included angle.
Fifth, the vertices can be sorted through the angle of the fourth step.
6. Use procedural texture to draw lines and connect all points in order.
Seven, the head and tail are connected and sealed.

Questions:
1. How is the vertex corresponding to the UV determined?
Answer: One way of own model, you can edit when UVW is unfolded.
Here is the (EzySlice) tool for slicing. It can only be used to cut simple models. After cutting, a surface will be directly generated and an independent material will be used directly. We can make a fuss on this.

2. How to draw lines on the texture.
Answer: This part is also the core. Share the code with everyone:
1. The OperateTexture parameter is (sorted vertices, original texture map).
2. Re-assign the image returned by the method to the material.

//画线部分
    //**************************************************************************************
    private float lineNum = 1000f;
    private int lineWidth = 10;//设置笔宽
    private Color lineColor = new Color(1,0.658f, 0.525f);// Color.red;

    private Texture2D OperateTexture(List<Vector2> listPoint, Texture2D targetTex)//, TextureLineType lineType
    {
    
    
        Texture2D curTex2D = new Texture2D(targetTex.width, targetTex.height);
        curTex2D.SetPixels(targetTex.GetPixels());

        for (int i = 0; i < listPoint.Count - 1; i++)
        {
    
    
            draw(curTex2D, listPoint[i], listPoint[i + 1]);
        }
        draw(curTex2D, listPoint[listPoint.Count-1], listPoint[0]);

        curTex2D.Apply();
        return curTex2D;
    }

    private void draw(Texture2D tex, Vector2 start, Vector2 end)
    {
    
    
        for (int j = 0; j < lineNum; j++)
        {
    
    
            float scaleX = Mathf.Lerp(start.x, end.x, j / lineNum);
            float scaleY = Mathf.Lerp(start.y, end.y, j / lineNum);
            int textureX = (int)(scaleX * tex.width);
            int textureY = (int)(scaleY * tex.height);
            // 线条加粗
            for (int a = textureX - lineWidth; a < textureX + lineWidth; a++)
            {
    
    
                for (int b = textureY - lineWidth; b < textureY + lineWidth; b++)
                {
    
    
                    tex.SetPixel(a, b, lineColor);
                }
            }
        }
    }
    //**************************************************************************************

The above are questions that I can think of for the time being and feel meaningful to share. If there are any more, please leave a message or private message me, I will add it again, thank you everyone

Digression:
In fact, this is only part of my needs. After the demand itself is a flat cut model, draw a circle on the cut surface.

The tool used for precise cutting is: Shatter Toolkit,
which cuts out an accurate model, but fails to divide the cut surface into another material.

The inaccurate tool used is: EzySlice
can only cut some simple models, and also pick out the cut surface to another material for calculation.

But I can't cut it to achieve the effect very well. Using very precise cutting tools can only use tiled textures directly, so I have a headache recently.
It is estimated that the next step is to try using precision cutting tools, and then pick out the points on the cutting surface and apply another material to UV calculation.

In this process, I tried many methods piecemeal, but there was no way to achieve it. Of course, I will share the method with everyone if it is implemented later.
If you have a better way, please also remind me, thank you very much.

Guess you like

Origin blog.csdn.net/ww1351646544/article/details/107139303