简体   繁体   中英

Unity Shader Graph Colored Faces

Imagine that we have a Cube with 6 faces. Now, can I somehow color all Faces in different colors in Shader Graph?

Basically what I want to do is to reproduce "Minimalist - Lowpoly Flat/Gradient Shader" myself with Shader Graph. Any tips?

It depends on what kind of geometry you want to be able to show. If you are just using cardinal axes, you can use the split X/Y/Z components of the object space normal, saturate, and multiply them with their respective colors and then add them together. This covers 3 of the 6 faces. For the others, do the same except do OneMinus for all the axes before you saturate.

The most general way of solving this though is using the dot product. The dot product calculates how parallel a vector is to another vector, and returns the result in the range of -1 to 1, where 1 is completely parallel and -1 is anti-parallel. For the axes (1, 0, 0), (0, 1, 0) and (0, 0, 1), do Dot(normal, axis), saturate, and multiply with the color, and add the color results together. Use the same approach as above and pipe the dot product into a OneMinus node before saturating to get the other 3 axes. This allows you to apply the effect both in world-space and object-space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM