Chicken shader: L1 jade, stripes, and lattice materials based on Lambert's principle

Let’s briefly talk about the principle here. I used a plug-in shaderforge of unity a long time ago. It seems that it has been no longer maintained in the unity resource store in recent years, but there is the official website of shader forge: here, you can check the official documents when you encounter nodes. You can directly read the code after reading it again and again. It is very convenient, and the nodes are relatively small . In fact, it can be done with ue, but the ue4 node is not very familiar. First use unity to familiarize yourself with the principle, and then it is convenient to switch to ue.

jade material

First put the effect of the material:
insert image description here
insert image description here

The first is the basic principle of Lambert. The semi-Lambert model is used here. The value range of the Lambert model is [-1,1], but if it is mapped to the material in this way, more than half of the area is black, because the default color of the area with a value less than 0 is black, so the value range of Lambert is changed to [0,1], that is, the original range is first multiplied by 0.5 and then added with 0.5. Then sample our own texture, the specific nodes are as follows:
insert image description here
You can see that my material ball has two highlight points, and the Fresnel effect is added to increase the transparency of the material.

  • The two highlight points are offset twice to the normal vector.
  • Add the Fresnel effect at the end.

Two highlights:
insert image description here

  • The two HighLightOffsets are responsible for offsetting the direction of the normal.
  • The two HighLights are the thresholds of the "high light point". If the dot product result of the shifted finding and the light direction is less than the threshold, it will output 0, otherwise it will output 1. In this way, "highlight points" can be obtained. Except for the high light points, other areas are black.
  • Then use max to take the value of the two "highlight points", because this is an operation for each vertex. On a single vertex, if the value is large, the value of the black place is still black. Compare the value of the highlight point with the black, and take the value of the highlight point, so that two highlight points can appear at the same time.

insert image description here
insert image description here

  • Use the lerp node to mix our texture and highlight points, similar to using a layer mask in ps. After adding a mask to the top layer, the mask area will become the content in the next mask. The value of max will only be 0 or 1.
  • If the value of the highlight point max is 1, then output HighLightColor as the color of the vertex, if the value of max is 0, output the color sampled by the half-Lambert model as the vertex color.

insert image description here

  • The last is the Fresnel item. Use the built-in Fresnel node, multiply the color, and mix it with the result of the previous lerp on the screen, and adjust the parameters appropriately in the panel. Finally, the result of the jade material is obtained.
    insert image description here

Stripe material

insert image description here
insert image description here
insert image description here

  • The screen position screen uv coordinates are multiplied by the depth value of the model in the camera, which can ensure that when we adjust the distance of the window, the far and near looks exactly the same.

Look at near:
insert image description here
look at far
insert image description here
insert image description here

  • The blue part is to add a color to the light and dark.
  • The step in the red part uses the previously calculated stripe effect and the light and shade effect to compare the step. If the value of the stripe on the vertex is smaller than the value of the light and shade, return 1 to allow the stripe to exist. Otherwise return 0, allowing light and shade to exist.
  • The lerp in the red part uses the value of the previous step to judge the dark and bright parts. In the model, the dark parts are where there are no stripes, and the bright parts are where there are stripes. Then set the color value for the dark part and bright part respectively.

insert image description here

  • Finally, the stripe effect and the light and shade effect are superimposed, and the clamp0-1 function is used to prevent the final value from exceeding the range [0,1], as the final self-illumination result.

dot matrix effect

insert image description here

insert image description here

  • Here is an explanation of why the screenshot of the monkey head model uses a square-like box, because the screen uv coordinates are also used here. When the width of the screen is particularly long, the dot matrix will be stretched.

like this:
insert image description here
insert image description here

  • The first is the mapping of uv coordinates on the screen. In screen coordinates, the origin is at the center of the screen, so in order to produce a dot matrix effect, we first need to expand the uv coordinates from [0,1] to [0, dotsize], where dotsize is the multiple we want to expand. When we expand the dotsize so many times, we use the frac node to take decimals of the result.
    insert image description here
  • We have expanded uv by so many times as dotsize, which can also be seen as expanding from uv coordinates [0,1] to uv coordinates [0, dotsize], and then each 1*1 square is a small uv coordinate. As shown in the figure below, each orange box is a small uv coordinate system before the dotsize is not enlarged. The meaning of taking decimals is to arrange them again in each small coordinate system, and the range is [0,1].
    insert image description here
  • After taking the decimal, we remap and map the [0,1] interval to the [-0.5,0.5] interval, which means moving the uv center from the lower left corner to the center of each square. Means the lower left quarter of the square is black, but this is not useful later on, just to make sure things are done right up to this point.
  • At this time, we use length to get the length. At this time, the origin of our uv coordinates is the center of each square. The length is taken from the center origin, and the length of each point in the square from the origin is calculated, so that each square can be turned into a circle with black inside and white outside.

insert image description here
insert image description here

  • Here we use the Lambert model to calculate the light and shade, and add the light attenuation part. I don’t know the principle yet. The scene uses parallel light, and the light attenuation should be useless.

insert image description here

  • After calculating the light and dark, we need to remap, map the light and dark interval [1,0] to [-0.5,2], and then perform power operation. Power is actually a power function, and the power function is in the form of x^y, that is, x multiplied by itself, and the number of times of multiplication is as many as y. Then if the color is darker, that is, the number of decimals less than 1 is multiplied by itself, it will become smaller and smaller, and the color will naturally become darker and darker. Finally, the round node is used for rounding, as the final self-illumination result.

Guess you like

Origin blog.csdn.net/weixin_43789369/article/details/130464665