이득우 스승님이 가르쳐주신 유니티 도큐먼트. 4.3부터 Shader 메뉴 형식이 팍 들어났다.
Base class to derive custom material property drawers from.
Use this to create custom UI drawers for your material properties, without having to write custom MaterialEditor classes. This is similar to how PropertyDrawer enables custom UI without writing custom inspectors.
In shader code, C#-like attribute syntax can be used in front of shader properties to add drawers to them. Unity has several built-in drawers, and you can write your own. Here's a shader code snippet demonstrating the syntax:
Shader "Custom/Example" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} // Display a popup with None,Add,Multiply choices, // and setup corresponding shader keywords. [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0 _OverlayTex ("Overlay", 2D) = "black" {} // Display as a toggle. [Toggle] _Invert ("Invert color?", Float) = 0 } // rest of shader code... }
When implementing your own drawers, you should override OnGUI function. You can also optionally override GetPropertyHeight and Apply functions. Here's an example of a property drawer that displays a checkbox for a float property, with the value set to 0 or 1 depending on the state:
// The property drawer class should be placed in an editor script, inside a folder called Editor.// Use with "[MyToggle]" before a float shader property class MyToggleDrawer extends MaterialPropertyDrawer { // Draw the property inside the given rect function OnGUI (position : Rect, prop : MaterialProperty, label : String, editor : MaterialEditor) { // Setup EditorGUI.BeginChangeCheck (); var value : boolean = prop.floatValue != 0.0f; EditorGUI.showMixedValue = prop.hasMixedValue; // Show the toggle control value = EditorGUI.Toggle (position, label, value); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck ()) { // Set the new value if it has changed prop.floatValue = value ? 1.0f : 0.0f; } } }
no example available in C#
no example available in Boo
The built-in MaterialPropertyDrawers are: ToggleDrawer, EnumDrawer, KeywordEnumDrawer, PowerSliderDrawer. In shader code, the "Drawer" suffix of the class name is not written; when Unity searches for the drawer class it adds "Drawer" automatically.
Toggle displays a float as a toggle. The property value will be 0 or 1, depending on the toggle state. When it is on, a shader keyword with the uppercase property name +"_ON" will be set, or an explicitly specified shader keyword.
// Will set "_INVERT_ON" shader keyword when set [Toggle] _Invert ("Invert?", Float) = 0// Will set "ENABLE_FANCY" shader keyword when set [Toggle(ENABLE_FANCY)] _Fancy ("Fancy?", Float) = 0
Enum displays a popup menu for a float property. You can supply either an enum type name (preferably fully qualified with namespaces, in case there are multiple types), or explicit name/value pairs to display. Up to 7 name/value pairs can be specified.
// Blend mode values [Enum(UnityEngine.Rendering.BlendMode)] _Blend ("Blend mode", Float) = 1// A subset of blend mode values, just "One" (value 1) and "SrcAlpha" (value 5) [Enum(One,1,SrcAlpha,5] _Blend2 ("Blend mode subset", Float) = 1
KeywordEnum displays a popup menu for a float property, and enables corresponding shader keyword. This is used with "#pragma multi_compile" in shaders, to enable or disable parts of shader code. Each name will enable "property name" + underscore + "enum name", uppercased, shader keyword. Up to 9 names can be provided.
// Display a popup with None,Add,Multiply choices. // Each option will set _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY shader keywords. [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0// ...later on in CGPROGRAM code: #pragma multi_compile _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY // ...
PowerSlider displays a slider with a non-linear response for a Range shader property.
// A slider with 3.0 response curve [PowerSlider(3.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.08
'유니티 엔진' 카테고리의 다른 글
유니티 실시간 거울반사 (1) | 2014.11.13 |
---|---|
Unity Shader Properties 인터페이스 추가기능 정리 (0) | 2014.10.28 |
Unity Shader에서 Toggle 메뉴 만들기 (2) | 2014.10.27 |
유니티 큐브맵 캡쳐 스크립트 Unity Cubemap capture script (1) | 2014.10.21 |
Texture Rotation Shader 코드 (0) | 2014.09.13 |
댓글