当前位置:网站首页>[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 .
边栏推荐
- 让田头村变甜头村的特色农产品是仙景芋还是白菜
- SystemVerilog learning-07-class inheritance and package use
- JMM details
- Make: g++: command not found
- [summary of knowledge points] chi square distribution, t distribution, F distribution
- 蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
- ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)
- 68 cesium code datasource loading czml
- 【ITSM】什么是ITSM,IT部门为什么需要ITSM
- 分布式锁实现
猜你喜欢

浅谈SIEM
![[summary of knowledge points] chi square distribution, t distribution, F distribution](/img/a6/bb5cabbfffb0edc9449c4c251354ae.png)
[summary of knowledge points] chi square distribution, t distribution, F distribution

记磁盘扇区损坏导致的Mysql故障排查

68 cesium code datasource loading czml

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

ForkJoin和Stream流测试

B-树系列

Solve the problem of garbled files uploaded by Kirin v10

分布式锁实现
![Pit of kotlin bit operation (bytes[i] and 0xff error)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
Pit of kotlin bit operation (bytes[i] and 0xff error)
随机推荐
【自动化运维】自动化运维平台有什么用
[ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
Golang panic recover custom exception handling
HDU - 1501 zipper (memory deep search)
pycharm 配置jupyter
How did ManageEngine Zhuohao achieve the goal of being selected into Gartner Magic Quadrant for four consecutive years?
Restframework-simplejwt rewrite authentication mechanism
B-tree series
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
The row and column numbers of each pixel of multi-source grid data in the same area are the same, that is, the number of rows and columns are the same, and the pixel size is the same
High order binary search tree
10 golang operator
libpng12.so. 0: cannot open shared object file: no such file or directory
【网络安全工具】USB控制软件有什么用
【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全
C语言课设工资管理系统(大作业)
【KV260】利用XADC生成芯片温度曲线图
sql中TCL语句(事务控制语句)
C语言课设职工信息管理系统(大作业)
On siem