当前位置:网站首页>[unity shader custom material panel part I]
[unity shader custom material panel part I]
2022-07-01 06:24:00 【The king of scrolls is coming】
Customizing the material panel is done by UI Simple adjustments to the style can make it written Shader More convenient and easy to use .
Unity Provides the base class :
1. Different types of DrawerClass
The following table shows how to MaterialPropertyDrawer Built in different types of DrawerClass A summary is made .
| type | describe |
|---|---|
| ToggleDrawer | take float The type data is displayed as a switch , The value can only be 0 perhaps 1,0 To close ,1 For opening . |
| EnumDrawer | Enumeration will float The type data is displayed as a drop-down list , It can be used to select the mixing coefficient , Comparison methods, etc , You can also customize it . |
| KeywordEnumDrawer | and EnumDrawer similar , Will be float The type data is displayed as a drop-down list , But you need to define shader keyword Can be used . |
| PowerSliderDrawer | Sliding bar of exponential correspondence , The values on the slider no longer correspond to the linear relationship . |
| IntRangeDrawer | Display the range data as a slider that can only set integers . |
Writing Shader When ,DrawerClass It needs to be written before the corresponding attribute "[ ]" in , The suffix of the category is “Drawer” No need to add , because Unity It will be added automatically when editing .
1.1.Toggle
take float The data of type is displayed on the material property panel in the form of a switch , The value can only be set to 0 or 1“0 Bit off /1 Bit on ”.
When the switch is on ,Shader key word (keyword) Will be Unity The default setting is “Property name” + “ON”, It should be noted that , All letters of keywords must be capitalized .
for example : [Toggle] _Invert("Invert color?" , Float) = 0
Shader The keyword of will be set to _INVERT_ON
Besides using Unity Default keyword , You can also customize a special keyword ,
for example :[Toggle(ENABLE_FANCY) ] _Fancy("Fancy ?" , Float) = 0
Names in parentheses ENABLE_FANCY It's custom Shader key word .
1.2.Enum
enumeration (Enum) take float The data of type is displayed on the material property panel in the form of pull-down list ,Unity Some built-in enumeration classes are provided for users , for example BlendMode、CillMode、ComparaFunction
for example :[Enum(UnityEngine.Rendering.BlendMode) ] _Blend("Blend mode" , Float) = 1
This is a Unity Built in enumeration class of all mixing coefficients , The default value is 0 Means to select the first mixing coefficient , The default value is 1 Indicates that the second mixing coefficient is selected , And so on . The final display effect on the material panel is shown in the figure :
These options are Shader All mixing factors that can be used in .
You can also customize the name of the enumeration / Numerical pair , But an enumeration can only be customized at most 7 Names / Numerical pair .
for example :[Enum(Off, 0, On, 1) ] _ZWrite("ZWrite" , Float) = 0
The enumeration defined is “ Whether to write deeply ”, In parentheses is the name of the definition / Numerical pair , Serial number 0 Corresponding Off, Serial number 1 Corresponding On, Intermediate symbol “ , ” Interval on , The default is serial number 0, That is to say Off.
1.3.KeywordEnum
Keyword enumeration (KeywordEnum) It is similar to ordinary enumeration , Also is to float Type of data to The form of drop-down list is displayed on the material property panel , But keyword enumeration will have corresponding Shader key word , stay Shader Pass through “ #pragma shader_feature” or “ #pragma multi_compile” Command can open or close a part Shader Code .
Shader The keyword format is :property name_enum name, The attribute name +“ Draw the line down ”+ Enumeration name , All English must be capitalized , And support at most 9 Key words . for instance :[KeywordEnum(None, Add, Multiply) ] _Overlay("Overlay mode" , Float) = 0
In brackets None, Add, Multiply Are the three enumeration names defined , Intermediate use “ , ” Symbols separate . The default value is 0, Indicates the default use of None. The three options correspond to Shader The key words are :_OVERLAY_NONE、_OVERLAY_ADD and _OVERLAY_MULTIPLY.
1.4. Define keywords in the compilation instructions
Defined ToggleDrawer perhaps KeywordEnumDrawer after , If you want to use it normally , You also need to declare in the compilation directive Shader key word . for example , As defined above None、Add、Multiply Keyword enumeration , The code in the compile instruction is as follows :#pragma shader_frature _OVERLAY_NONE _OVERLAY_ADD _OVERLAY_MULTIPLY
Different keywords need to be separated by spaces .
in addition , You can also use another compilation instruction to define keywords , The code is as follows :#pragma multi_compile _OVERLAY_NONE _OVERLAY_ADD _OVERLAY_MULTIPLY
Although it seems to pass through a Shader File implements different situations , however Unity It will automatically compile different versions of Shader file , These are different versions Shader The document is called Shader variant (Variants), The above compilation instructions contain three Shader variant .
Suppose you add another instruction :#pragma shader_feature _INVERT_ON
This directive contains Toggle There are two cases of closing and opening , therefore Unity It will eventually compile 2 * 3 = 6 individual Shader variant . So a lot of shader feature or multi compile At the time of instruction , There will be a lot of Shader Variation file .
The differences between the two different compilation instructions are as follows :
- shader_feature: Only variations will be generated for the keywords used by the material , Keywords that are not used will not generate variants , Therefore, it is impossible to switch effects through scripts at runtime .
- multi_compile: Variants will be generated for all keywords , Therefore, you can switch the effects through scripts at run time .
stay Shader You can view this... In the attribute setting panel of the file Shader Number of variants generated , Pictured
Through the open "Skip unused shader_Features" Option to view only the number of variants that use keywords , You can also turn off "Skip unused shader_Features" Option to view the number of variants of all keywords . To determine what specific keywords are , You can click "Show" see .
1.5.PowerSlider
Index slider (PowerSlider) The attributes of range type values will be displayed as sliding bars corresponding to nonlinearity . The values on the slider no longer correspond to the linear relationship , But in an exponential way . for instance :[PowerSlider(3.0) ] _Brightness("Brightness" , Range(0.01, 1)) = 0
This is one with 3 Is the sliding bar of exponential correspondence , among , The values in brackets are exponents , The final effect on the material property panel is shown in the figure :
It is not difficult to find , When the value is 0.5 When , The slider is not in the middle of the slider , This is the nonlinear correspondence .
Let's take a look at y=x3 The function curve of , As shown in the figure , Variables in functions x Is the position of the sliding block ,y Is the value of the attribute .
From the curve 1 You can see from the number , When the slider is in 0.5 In position , The value of the attribute is only 0.1 A little more , From the curve 2 You can see from the number , When the attribute value is 0.5 Some time , The slider has already arrived 0.8 Left and right , This is the corresponding relationship of exponential slider .
1.6.IntRange
It also displays the value in the form of a slider on the material property panel , But the number is no longer float type , Only integer values .
for example :[IntRange] _Alpha("Alpha" , Range(0, 255)) = 100
Can use the interval on the slider [0,255] Integer values between .
边栏推荐
- ArcServer密码重置(账号不可以重置)
- 异常检测方法梳理,看这篇就够了!
- HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10
- Forkjoin and stream flow test
- Servlet
- Promise
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
- What are the functions of LAN monitoring software
- 【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
- UOW of dev XPO comparison
猜你喜欢

Arcserver password reset (account cannot be reset)

自开发软件NoiseCreater1.1版本免费试用

让田头村变甜头村的特色农产品是仙景芋还是白菜
![[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map](/img/c0/299a406efea51f24b1701b66adc1e3.png)
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map

FPGA - 7 Series FPGA internal structure clocking-01-clock Architecture Overview

【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全

async 与 await

C语言课设物业费管理系统(大作业)

SystemVerilog learning-10-validation quantification and coverage

让厦门灌口镇田头村变“甜头”村的特色农产品之一是
随机推荐
数据库产生死锁了请问一下有没有解决办法
69 cesium code datasource loading geojson
Top 10 Free 3D modeling software for beginners in 2022
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
Minio error correction code, construction and startup of distributed Minio cluster
Teach you how to implement a deep learning framework
Application of IT service management (ITSM) in Higher Education
c# Xml帮助类
What are the functions of LAN monitoring software
How does MySQL store Emoji?
【ITSM】什么是ITSM,IT部门为什么需要ITSM
Flink practice -- multi stream merge
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
[ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
json模块
Solve the problem of garbled files uploaded by Kirin v10
浅谈SIEM
Picture server project test
libpng12.so. 0: cannot open shared object file: no such file or directory