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

There are several Shader rendering modes in Unity

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly shows you "there are several Shader rendering modes in Unity". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "there are several Shader rendering modes in Unity".

Shader in Unity has four rendering modes, which are:

-- Opaque (opaque)

-- Cutout (Hollow)

-- Fade (looming)

-- Transparent (transparent)

I came across a need to add a frozen effect to a specific game object, but to my Shader

Is a completely frozen Shader, and its color value cannot be adjusted by parameters. And then my colleague told me that

This is achieved by changing the alpha value of the object itself by modifying the rendering mode, so the first step I looked for online about modifying the operation

The code for line-time Shader rendering mode is as follows.

Http://www.voidcn.com/article...

Then there is a simple code operation, as follows.

/ / get the rendering component on the target

Var renderer = GetComponentsInChildren ()

/ / create a frozen array. The second array element is the frozen special effect found in advance.

Material [] frostMatetials = new Material [2] {renderer.material

FrostEffect}

/ / add frozen special effects to the array of characters

Renderer.materials = frostMatetials

/ / instantiate a rendering mode variable

Var fadeMode = SetMaterialRenderingMode.RenderingMode.Fade

/ / change your Shader rendering mode to Fade according to the online method

SetMaterialRenderingMode.SetMaterialRenderingModeMethod (

Renderer.materials [0], fadeMode)

Because the Alpha value of Color is read-only and cannot be modified, but Color can be modified, so get the target

The RGB value of the object Color, and then instantiate a Color to change it to the Alpha value you want with the constructor. As follows:

Color currentcolor03 = new Color

{

A = 0.8f

R = renderer.materials [0] .color.r

G = renderer.materials [0] .color.g

B = renderer.materials [0] .color.b

}

/ / the target Color attribute can be replaced.

In fact, this method is not very good, mainly because the given Shader cannot modify the attribute value, and then I got it and can change it.

The Shader of the attribute value makes things a lot easier.

This is the material I got. You can find the Shader contained in the material through the material, and you can see the parameters corresponding to each value.

In this case, you only need to call the method Material.SetFloat (); and similar methods, with two parentheses

One is a parameter of type String, which indicates that the parameter you want to change is obtained through String, and the second is the changed value.

During this period, I encountered a problem, and finally found out for a long time that it was the compiler. When I used the first method, if it was normal.

In this case, you can change the rendering mode, and I replaced the gradient effect with three Color in turn, but if I am in the

Select this object in the Hierarchy panel and the changing object will suddenly change back to its default state before the change, or as shown in

If you pre-select the object to be changed, it will have the same effect, but you cannot select the game in the compiled state.

The rendering status of the play object cannot be viewed in the Inspector panel. Finally, I came up with a term for runtime rendering.

Describe this behavior.

If you change the rendering mode of the game object Shader at runtime, viewing his rendering mode will result in his rendering model

Type property reset.

The above is all the content of this article entitled "there are several Shader rendering modes in Unity". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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