Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Texture in Unity

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to achieve Texture in Unity, which is very detailed and has a certain reference value. Interested friends must read it!

Learn about Texture2D

As pictured above, Texture2D is a two-dimensional picture.

It's made up of a pixel.

It is usually arranged from low to high, from left to right.

If we want to manipulate pixels through code, we have to know the coordinates of the pixels, and now let's verify that they are really arranged in this way.

We use a short code to NEW an image and assign values pixel-by-pixel according to the XMagi Y axis corresponding to the RMagne G channel. We will get a red and green gradient diagram, as follows.

According to the color gradient process of the picture, we can be sure that the pixels are arranged in the same order as we predicted.

What is TextureFormat?

TextureFormat is the type of map, ARGB 32-bit, on behalf of ARGB4 channels, each channel color has 8 bits, corresponding to A8 Jing RGB 24 and so on. Any picture is essentially like this.

The common JPG,PNG is the compressed / uncompressed read format adopted by the operating system, and ETC/DDS is the compressed format read by the graphics interface.

Why do you need Apply after assignment

Because when the map changes the pixel, it does not change the current memory directly, but in another memory space, GPU also reads the old map location in real time.

When Apply, the changed content will be applied to the current memory.

Are all the pictures arranged in the same order of pixels?

As a matter of fact, OpenGL and DX are different in UV direction and value, so we should thank Unity3D for what he has done for us to make everything easier.

Make a simple brush to achieve the final effect.

Let's make some changes to the above code.

We introduce a map in the first red line, and the second red line, multiplying the pixels by the alpha channel of the corresponding position of the map.

Each channel on the color level is 8 bits, 0-255, but is a floating-point number when calculated. 0-1.

So if alpha is 0, any color multiplied by him, the result is 0.

Through the above code, we achieve the following effect:

This map is an Alpha channel of 0 and 1. If 1 has color, 0 naturally has no color. You can also use a value between 0-1 to achieve a gradient.

Similarly, since only one channel is used, we can compress it into a single-channel 8-bit map of Alpha8 to save space.

Achieve textur

We make changes to the above code again and also introduce a map to make the texture.

This time we multiply colors, because the colors are floating-point values, so the result of their multiplication will not be greater than 1, nor less than 0.

And the overload operator, in the process of *, helps us to correspond to the RGBA channel one by one.

Here we use multiplication, and many people encounter words such as multiplication, addition, division, subtraction and so on when using image software.

At first, I wonder why I named it this way. Now we know that they are the mathematical relationship between pixels.

These are all the contents of the article "how to achieve Texture in Unity". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report