BlueRoseNote/07-Other/Unity/Unity通用渲染管线(URP)系列(三)——方向光(Direct Illumination).md
2023-06-29 11:55:02 +08:00

72 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## BRDF
案例中使用了迪士尼模型。
## 混合模式
`SrcBlend``One``DetBlend``OneMinusSrc`
## Shader GUI
`Shader`{}内添加`CustomEditor“ CustomShaderGUI”`。之后添加脚本:
```c#
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
public class CustomShaderGUI : ShaderGUI {
MaterialEditor editor;
Object[] materials;
MaterialProperty[] properties;
public override void OnGUI (
MaterialEditor materialEditor, MaterialProperty[] properties
) {
base.OnGUI(materialEditor, properties);
editor = materialEditor;
materials = materialEditor.targets;
this.properties = properties;
}
}
```
之后实现
```c#
bool HasProperty (string name) =>
FindProperty(name, properties, false) != null;
void SetProperty (string name, string keyword, bool value) {
if (SetProperty(name, value ? 1f : 0f)) {
SetKeyword(keyword, value);
}
}
bool SetProperty (string name, float value) {
MaterialProperty property = FindProperty(name, properties, false);
if (property != null) {
property.floatValue = value;
return true;
}
return false;
}
void SetKeyword (string keyword, bool enabled) {
if (enabled) {
foreach (Material m in materials) {
m.EnableKeyword(keyword);
}
}
else {
foreach (Material m in materials) {
m.DisableKeyword(keyword);
}
}
}
```
就可以添加若干自定义Shader属性的`Set`函数了。添加按钮逻辑如下:
```c#
bool PresetButton (string name) {
if (GUILayout.Button(name)) {
editor.RegisterPropertyChangeUndo(name);
return true;
}
return false;
}
```