浏览代码
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop
Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop
# Conflicts: # Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl/main
Evgenii Golubev
8 年前
当前提交
80814477
共有 27 个文件被更改,包括 810 次插入 和 854 次删除
-
27Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
-
23Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity
-
3Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs
-
32Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
-
39Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
27Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightUtilities.hlsl
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePassLoop.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
-
329Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/LitUI.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
-
276Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/UnlitUI.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.shader
-
66Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
38ProjectSettings/GraphicsSettings.asset
-
334Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/BaseLitUI.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/BaseLitUI.cs.meta
-
279Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/BaseUnlitUI.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Editor/BaseUnlitUI.cs.meta
-
13Assets/basicrenderloop.asset
-
8Assets/basicrenderloop.asset.meta
-
14Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs
-
12Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs.meta
-
93Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs
-
12Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 2400b74f5ce370c4481e5dc417d03703 |
|||
timeCreated: 1480265826 |
|||
timeCreated: 1480436907 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
#ifndef UNITY_LIGHT_UTILITIES_INCLUDED |
|||
#define UNITY_LIGHT_UTILITIES_INCLUDED |
|||
|
|||
#include "LightDefinition.cs.hlsl" |
|||
|
|||
void InitSkyEnvLightData(int index) |
|||
EnvLightData InitSkyEnvLightData(int envIndex) |
|||
_EnvLightSky.envShapeType = ENVSHAPETYPE_SKY; |
|||
_EnvLightSky.envIndex = index; |
|||
_EnvLightSky.forward = float3(0.0, 0.0, 1.0); |
|||
_EnvLightSky.up = float3(0.0, 1.0, 0.0); |
|||
_EnvLightSky.right = float3(1.0, 0.0, 0.0); |
|||
_EnvLightSky.positionWS = float3(0.0, 0.0, 0.0); |
|||
_EnvLightSky.offsetLS = float3(0.0, 0.0, 0.0); |
|||
_EnvLightSky.innerDistance = float3(0.0, 0.0, 0.0); |
|||
_EnvLightSky.blendDistance = 1.0; |
|||
EnvLightData output; |
|||
output.envShapeType = ENVSHAPETYPE_SKY; |
|||
output.envIndex = envIndex; |
|||
output.forward = float3(0.0, 0.0, 1.0); |
|||
output.up = float3(0.0, 1.0, 0.0); |
|||
output.right = float3(1.0, 0.0, 0.0); |
|||
output.positionWS = float3(0.0, 0.0, 0.0); |
|||
output.offsetLS = float3(0.0, 0.0, 0.0); |
|||
output.innerDistance = float3(0.0, 0.0, 0.0); |
|||
output.blendDistance = 1.0; |
|||
|
|||
return output; |
|||
#endif // UNITY_LIGHT_UTILITIES_INCLUDED |
|||
#endif // UNITY_LIGHT_UTILITIES_INCLUDED |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public abstract class BaseLitGUI : ShaderGUI |
|||
{ |
|||
protected static class Styles |
|||
{ |
|||
public static string OptionText = "Options"; |
|||
public static string SurfaceTypeText = "Surface Type"; |
|||
public static string BlendModeText = "Blend Mode"; |
|||
public static string detailText = "Inputs Detail"; |
|||
public static string lightingText = "Inputs Lighting"; |
|||
|
|||
public static GUIContent alphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "Threshold for alpha cutoff"); |
|||
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff"); |
|||
public static GUIContent doubleSidedModeText = new GUIContent("Double Sided", "This will render the two face of the objects (disable backface culling)"); |
|||
|
|||
public static readonly string[] surfaceTypeNames = Enum.GetNames(typeof(SurfaceType)); |
|||
public static readonly string[] blendModeNames = Enum.GetNames(typeof(BlendMode)); |
|||
|
|||
public static string InputsOptionsText = "Inputs options"; |
|||
|
|||
public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel"); |
|||
public static GUIContent UVBaseMappingText = new GUIContent("UV set for Base", ""); |
|||
public static GUIContent texWorldScaleText = new GUIContent("Scale to apply on world coordinate in case of Planar/Triplanar", ""); |
|||
public static GUIContent UVBaseDetailMappingText = new GUIContent("UV set for Base and Detail", ""); |
|||
public static GUIContent normalMapSpaceText = new GUIContent("Normal/Tangent Map space", ""); |
|||
public static GUIContent heightMapModeText = new GUIContent("Height Map Mode", ""); |
|||
public static GUIContent detailMapModeText = new GUIContent("Detail Map with Normal", "Detail Map with AO / Height"); |
|||
public static GUIContent UVDetailMappingText = new GUIContent("UV set for Detail", ""); |
|||
public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask"); |
|||
|
|||
public static string InputsText = "Inputs"; |
|||
|
|||
public static string InputsMapText = ""; |
|||
|
|||
public static GUIContent baseColorText = new GUIContent("Base Color + Opacity", "Albedo (RGB) and Opacity (A)"); |
|||
public static GUIContent baseColorSmoothnessText = new GUIContent("Base Color + Smoothness", "Albedo (RGB) and Smoothness (A)"); |
|||
|
|||
public static GUIContent metallicText = new GUIContent("Metallic", "Metallic scale factor"); |
|||
public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness scale factor"); |
|||
public static GUIContent maskMapESText = new GUIContent("Mask Map - M(R), AO(G), E(B), S(A)", "Mask map"); |
|||
public static GUIContent maskMapEText = new GUIContent("Mask Map - M(R), AO(G), E(B)", "Mask map"); |
|||
public static GUIContent maskMapText = new GUIContent("Mask Map - M(R), AO(G)", "Mask map"); |
|||
public static GUIContent maskMapSText = new GUIContent("Mask Map - M(R), AO(G), S(A)", "Mask map"); |
|||
|
|||
public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map (RGBA)", "Specular Occlusion Map"); |
|||
|
|||
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (DXT5) - Need to implement BC5"); |
|||
|
|||
public static GUIContent heightMapText = new GUIContent("Height Map (R)", "Height Map"); |
|||
|
|||
public static GUIContent tangentMapText = new GUIContent("Tangent Map", "Tangent Map (BC5) - DXT5 for test"); |
|||
public static GUIContent anisotropyText = new GUIContent("Anisotropy", "Anisotropy scale factor"); |
|||
public static GUIContent anisotropyMapText = new GUIContent("Anisotropy Map (G)", "Anisotropy"); |
|||
|
|||
public static GUIContent detailMapNormalText = new GUIContent("Detail Map A(R) Ny(G) S(B) Nx(A)", "Detail Map"); |
|||
public static GUIContent detailMapAOHeightText = new GUIContent("Detail Map A(R) AO(G) S(B) H(A)", "Detail Map"); |
|||
public static GUIContent detailMaskText = new GUIContent("Detail Mask (B)", "Mask for detailMap"); |
|||
public static GUIContent detailAlbedoScaleText = new GUIContent("Detail AlbedoScale", "Detail Albedo Scale factor"); |
|||
public static GUIContent detailNormalScaleText = new GUIContent("Detail NormalScale", "Normal Scale factor"); |
|||
public static GUIContent detailSmoothnessScaleText = new GUIContent("Detail SmoothnessScale", "Smoothness Scale factor"); |
|||
public static GUIContent detailHeightScaleText = new GUIContent("Detail HeightScale", "Height Scale factor"); |
|||
public static GUIContent detailAOScaleText = new GUIContent("Detail AOScale", "AO Scale factor"); |
|||
|
|||
public static GUIContent emissiveText = new GUIContent("Emissive Color", "Emissive"); |
|||
public static GUIContent emissiveIntensityText = new GUIContent("Emissive Intensity", "Emissive"); |
|||
|
|||
public static GUIContent emissiveWarning = new GUIContent("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive."); |
|||
public static GUIContent emissiveColorWarning = new GUIContent("Ensure emissive color is non-black for emission to have effect."); |
|||
} |
|||
|
|||
public enum SurfaceType |
|||
{ |
|||
Opaque, |
|||
Transparent |
|||
} |
|||
public enum BlendMode |
|||
{ |
|||
Lerp, |
|||
Add, |
|||
SoftAdd, |
|||
Multiply, |
|||
Premultiply |
|||
} |
|||
public enum DoubleSidedMode |
|||
{ |
|||
None, |
|||
DoubleSided, |
|||
DoubleSidedLightingFlip, |
|||
DoubleSidedLightingMirror, |
|||
} |
|||
|
|||
void SurfaceTypePopup() |
|||
{ |
|||
EditorGUI.showMixedValue = surfaceType.hasMixedValue; |
|||
var mode = (SurfaceType)surfaceType.floatValue; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
mode = (SurfaceType)EditorGUILayout.Popup(Styles.SurfaceTypeText, (int)mode, Styles.surfaceTypeNames); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type"); |
|||
surfaceType.floatValue = (float)mode; |
|||
} |
|||
|
|||
EditorGUI.showMixedValue = false; |
|||
} |
|||
|
|||
protected void ShaderOptionsGUI() |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel); |
|||
SurfaceTypePopup(); |
|||
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent) |
|||
{ |
|||
BlendModePopup(); |
|||
} |
|||
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text); |
|||
if (alphaCutoffEnable.floatValue == 1.0) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text); |
|||
} |
|||
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text); |
|||
|
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
private void BlendModePopup() |
|||
{ |
|||
EditorGUI.showMixedValue = blendMode.hasMixedValue; |
|||
var mode = (BlendMode)blendMode.floatValue; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode"); |
|||
blendMode.floatValue = (float)mode; |
|||
} |
|||
|
|||
EditorGUI.showMixedValue = false; |
|||
} |
|||
|
|||
protected void FindOptionProperties(MaterialProperty[] props) |
|||
{ |
|||
surfaceType = FindProperty(kSurfaceType, props); |
|||
blendMode = FindProperty(kBlendMode, props); |
|||
alphaCutoff = FindProperty(kAlphaCutoff, props); |
|||
alphaCutoffEnable = FindProperty(kAlphaCutoffEnabled, props); |
|||
doubleSidedMode = FindProperty(kDoubleSidedMode, props); |
|||
FindInputOptionProperties(props); |
|||
} |
|||
|
|||
protected void SetupMaterial(Material material) |
|||
{ |
|||
bool alphaTestEnable = material.GetFloat(kAlphaCutoffEnabled) == 1.0; |
|||
SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType); |
|||
BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode); |
|||
DoubleSidedMode doubleSidedMode = (DoubleSidedMode)material.GetFloat(kDoubleSidedMode); |
|||
|
|||
if (surfaceType == SurfaceType.Opaque) |
|||
{ |
|||
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : ""); |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); |
|||
material.SetInt("_ZWrite", 1); |
|||
material.renderQueue = alphaTestEnable ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : -1; |
|||
} |
|||
else |
|||
{ |
|||
material.SetOverrideTag("RenderType", "Transparent"); |
|||
material.SetInt("_ZWrite", 0); |
|||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; |
|||
|
|||
switch (blendMode) |
|||
{ |
|||
case BlendMode.Lerp: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); |
|||
break; |
|||
|
|||
case BlendMode.Add: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
break; |
|||
|
|||
case BlendMode.SoftAdd: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusDstColor); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
break; |
|||
|
|||
case BlendMode.Multiply: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); |
|||
break; |
|||
|
|||
case BlendMode.Premultiply: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (doubleSidedMode == DoubleSidedMode.None) |
|||
{ |
|||
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back); |
|||
} |
|||
else |
|||
{ |
|||
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off); |
|||
} |
|||
|
|||
if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingFlip) |
|||
{ |
|||
material.EnableKeyword("_DOUBLESIDED_LIGHTING_FLIP"); |
|||
material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR"); |
|||
} |
|||
else if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingMirror) |
|||
{ |
|||
material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP"); |
|||
material.EnableKeyword("_DOUBLESIDED_LIGHTING_MIRROR"); |
|||
} |
|||
else |
|||
{ |
|||
material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP"); |
|||
material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR"); |
|||
} |
|||
|
|||
SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable); |
|||
SetupInputMaterial(material); |
|||
SetupEmissionGIFlags(material); |
|||
} |
|||
|
|||
protected void SetKeyword(Material m, string keyword, bool state) |
|||
{ |
|||
if (state) |
|||
m.EnableKeyword(keyword); |
|||
else |
|||
m.DisableKeyword(keyword); |
|||
} |
|||
|
|||
public void ShaderPropertiesGUI(Material material) |
|||
{ |
|||
// Use default labelWidth
|
|||
EditorGUIUtility.labelWidth = 0f; |
|||
|
|||
// Detect any changes to the material
|
|||
EditorGUI.BeginChangeCheck(); |
|||
{ |
|||
ShaderOptionsGUI(); |
|||
EditorGUILayout.Space(); |
|||
|
|||
ShaderInputOptionsGUI(); |
|||
|
|||
EditorGUILayout.Space(); |
|||
ShaderInputGUI(); |
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
foreach (var obj in m_MaterialEditor.targets) |
|||
SetupMaterial((Material)obj); |
|||
} |
|||
} |
|||
|
|||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) |
|||
{ |
|||
FindOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
|
|||
FindInputProperties(props); |
|||
|
|||
m_MaterialEditor = materialEditor; |
|||
Material material = materialEditor.target as Material; |
|||
ShaderPropertiesGUI(material); |
|||
} |
|||
|
|||
// TODO: ? or remove
|
|||
bool HasValidEmissiveKeyword(Material material) |
|||
{ |
|||
/* |
|||
// Material animation might be out of sync with the material keyword.
|
|||
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
|
|||
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
|
|||
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION"); |
|||
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue)) |
|||
return false; |
|||
else |
|||
return true; |
|||
*/ |
|||
|
|||
return true; |
|||
} |
|||
|
|||
protected virtual void SetupEmissionGIFlags(Material material) |
|||
{ |
|||
// Setup lightmap emissive flags
|
|||
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags; |
|||
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0) |
|||
{ |
|||
if (ShouldEmissionBeEnabled(material)) |
|||
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
else |
|||
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
|
|||
material.globalIlluminationFlags = flags; |
|||
} |
|||
} |
|||
|
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
MaterialProperty surfaceType = null; |
|||
MaterialProperty alphaCutoffEnable = null; |
|||
MaterialProperty blendMode = null; |
|||
MaterialProperty alphaCutoff = null; |
|||
MaterialProperty doubleSidedMode = null; |
|||
|
|||
const string kSurfaceType = "_SurfaceType"; |
|||
const string kBlendMode = "_BlendMode"; |
|||
const string kAlphaCutoff = "_AlphaCutoff"; |
|||
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable"; |
|||
const string kDoubleSidedMode = "_DoubleSidedMode"; |
|||
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode }; |
|||
|
|||
protected abstract void FindInputProperties(MaterialProperty[] props); |
|||
protected abstract void ShaderInputGUI(); |
|||
protected abstract void ShaderInputOptionsGUI(); |
|||
protected abstract void FindInputOptionProperties(MaterialProperty[] props); |
|||
protected abstract void SetupInputMaterial(Material material); |
|||
protected abstract bool ShouldEmissionBeEnabled(Material material); |
|||
} |
|||
} // namespace UnityEditor
|
|
|||
fileFormatVersion: 2 |
|||
guid: d35c4b8ec5d49e4438d0b0ba2655c495 |
|||
timeCreated: 1480349253 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public abstract class BaseUnlitGUI : ShaderGUI |
|||
{ |
|||
public enum SurfaceType |
|||
{ |
|||
Opaque, |
|||
Transparent |
|||
} |
|||
public enum BlendMode |
|||
{ |
|||
Lerp, |
|||
Add, |
|||
SoftAdd, |
|||
Multiply, |
|||
Premultiply |
|||
} |
|||
|
|||
public enum DoubleSidedMode |
|||
{ |
|||
None, |
|||
DoubleSided |
|||
} |
|||
|
|||
protected static class Styles |
|||
{ |
|||
public static string OptionText = "Options"; |
|||
public static string SurfaceTypeText = "Surface Type"; |
|||
public static string BlendModeText = "Blend Mode"; |
|||
|
|||
public static GUIContent alphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "Threshold for alpha cutoff"); |
|||
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff"); |
|||
public static GUIContent doubleSidedModeText = new GUIContent("Double Sided", "This will render the two face of the objects (disable backface culling)"); |
|||
|
|||
public static readonly string[] surfaceTypeNames = Enum.GetNames(typeof(SurfaceType)); |
|||
public static readonly string[] blendModeNames = Enum.GetNames(typeof(BlendMode)); |
|||
|
|||
public static string InputsOptionsText = "Inputs options"; |
|||
|
|||
public static string InputsText = "Inputs"; |
|||
|
|||
public static string InputsMapText = ""; |
|||
|
|||
public static GUIContent colorText = new GUIContent("Color + Opacity", "Albedo (RGB) and Opacity (A)"); |
|||
|
|||
public static GUIContent emissiveText = new GUIContent("Emissive Color", "Emissive"); |
|||
public static GUIContent emissiveIntensityText = new GUIContent("Emissive Intensity", "Emissive"); |
|||
} |
|||
|
|||
MaterialProperty surfaceType = null; |
|||
MaterialProperty blendMode = null; |
|||
MaterialProperty alphaCutoff = null; |
|||
MaterialProperty alphaCutoffEnable = null; |
|||
MaterialProperty doubleSidedMode = null; |
|||
|
|||
protected const string kSurfaceType = "_SurfaceType"; |
|||
protected const string kBlendMode = "_BlendMode"; |
|||
protected const string kAlphaCutoff = "_AlphaCutoff"; |
|||
protected const string kAlphaCutoffEnabled = "_AlphaCutoffEnable"; |
|||
protected const string kDoubleSidedMode = "_DoubleSidedMode"; |
|||
|
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
public void FindOptionProperties(MaterialProperty[] props) |
|||
{ |
|||
surfaceType = FindProperty(kSurfaceType, props); |
|||
blendMode = FindProperty(kBlendMode, props); |
|||
alphaCutoff = FindProperty(kAlphaCutoff, props); |
|||
alphaCutoffEnable = FindProperty(kAlphaCutoffEnabled, props); |
|||
doubleSidedMode = FindProperty(kDoubleSidedMode, props); |
|||
FindInputOptionProperties(props); |
|||
} |
|||
|
|||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) |
|||
{ |
|||
FindOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
|
|||
FindInputProperties(props); |
|||
|
|||
m_MaterialEditor = materialEditor; |
|||
Material material = materialEditor.target as Material; |
|||
ShaderPropertiesGUI(material); |
|||
} |
|||
|
|||
protected void ShaderOptionsGUI() |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel); |
|||
SurfaceTypePopup(); |
|||
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent) |
|||
{ |
|||
BlendModePopup(); |
|||
} |
|||
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text); |
|||
if (alphaCutoffEnable.floatValue == 1.0) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text); |
|||
} |
|||
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text); |
|||
|
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
public void ShaderPropertiesGUI(Material material) |
|||
{ |
|||
// Use default labelWidth
|
|||
EditorGUIUtility.labelWidth = 0f; |
|||
|
|||
// Detect any changes to the material
|
|||
EditorGUI.BeginChangeCheck(); |
|||
{ |
|||
ShaderOptionsGUI(); |
|||
EditorGUILayout.Space(); |
|||
|
|||
ShaderInputOptionsGUI(); |
|||
|
|||
EditorGUILayout.Space(); |
|||
ShaderInputGUI(); |
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
foreach (var obj in m_MaterialEditor.targets) |
|||
SetupMaterial((Material)obj); |
|||
} |
|||
} |
|||
|
|||
// TODO: try to setup minimun value to fall back to standard shaders and reverse
|
|||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) |
|||
{ |
|||
base.AssignNewShaderToMaterial(material, oldShader, newShader); |
|||
} |
|||
|
|||
void SurfaceTypePopup() |
|||
{ |
|||
EditorGUI.showMixedValue = surfaceType.hasMixedValue; |
|||
var mode = (SurfaceType)surfaceType.floatValue; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
mode = (SurfaceType)EditorGUILayout.Popup(Styles.SurfaceTypeText, (int)mode, Styles.surfaceTypeNames); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type"); |
|||
surfaceType.floatValue = (float)mode; |
|||
} |
|||
|
|||
EditorGUI.showMixedValue = false; |
|||
} |
|||
|
|||
void BlendModePopup() |
|||
{ |
|||
EditorGUI.showMixedValue = blendMode.hasMixedValue; |
|||
var mode = (BlendMode)blendMode.floatValue; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode"); |
|||
blendMode.floatValue = (float)mode; |
|||
} |
|||
|
|||
EditorGUI.showMixedValue = false; |
|||
} |
|||
|
|||
protected void SetupMaterial(Material material) |
|||
{ |
|||
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
|
|||
// (MaterialProperty value might come from renderer material property block)
|
|||
|
|||
bool alphaTestEnable = material.GetFloat(kAlphaCutoffEnabled) == 1.0; |
|||
SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType); |
|||
BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode); |
|||
DoubleSidedMode doubleSidedMode = (DoubleSidedMode)material.GetFloat(kDoubleSidedMode); |
|||
|
|||
if (surfaceType == SurfaceType.Opaque) |
|||
{ |
|||
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : ""); |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); |
|||
material.SetInt("_ZWrite", 1); |
|||
material.renderQueue = alphaTestEnable ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : -1; |
|||
} |
|||
else |
|||
{ |
|||
material.SetOverrideTag("RenderType", "Transparent"); |
|||
material.SetInt("_ZWrite", 0); |
|||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; |
|||
|
|||
switch (blendMode) |
|||
{ |
|||
case BlendMode.Lerp: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); |
|||
break; |
|||
|
|||
case BlendMode.Add: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
break; |
|||
|
|||
case BlendMode.SoftAdd: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusDstColor); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
break; |
|||
|
|||
case BlendMode.Multiply: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); |
|||
break; |
|||
|
|||
case BlendMode.Premultiply: |
|||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); |
|||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (doubleSidedMode == DoubleSidedMode.None) |
|||
{ |
|||
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back); |
|||
} |
|||
else |
|||
{ |
|||
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off); |
|||
} |
|||
|
|||
SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable); |
|||
SetupInputMaterial(material); |
|||
|
|||
// Setup lightmap emissive flags
|
|||
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags; |
|||
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0) |
|||
{ |
|||
if (ShouldEmissionBeEnabled(material)) |
|||
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
else |
|||
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
|
|||
material.globalIlluminationFlags = flags; |
|||
} |
|||
} |
|||
|
|||
bool HasValidEmissiveKeyword(Material material) |
|||
{ |
|||
/* |
|||
// Material animation might be out of sync with the material keyword.
|
|||
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
|
|||
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
|
|||
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION"); |
|||
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue)) |
|||
return false; |
|||
else |
|||
return true; |
|||
*/ |
|||
|
|||
return true; |
|||
} |
|||
|
|||
protected void SetKeyword(Material m, string keyword, bool state) |
|||
{ |
|||
if (state) |
|||
m.EnableKeyword(keyword); |
|||
else |
|||
m.DisableKeyword(keyword); |
|||
} |
|||
|
|||
protected abstract void FindInputProperties(MaterialProperty[] props); |
|||
protected abstract void ShaderInputGUI(); |
|||
protected abstract void ShaderInputOptionsGUI(); |
|||
protected abstract void FindInputOptionProperties(MaterialProperty[] props); |
|||
protected abstract void SetupInputMaterial(Material material); |
|||
protected abstract bool ShouldEmissionBeEnabled(Material material); |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 11fd029bb88b2c04092b1e4d71b919c6 |
|||
timeCreated: 1480351138 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 22228a1bd982b864ea6c84db2fc11dd1, type: 3} |
|||
m_Name: basicrenderloop |
|||
m_EditorClassIdentifier: |
|
|||
fileFormatVersion: 2 |
|||
guid: f77fc78803cb35147ab3c0811feb562d |
|||
timeCreated: 1480085360 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public abstract class ScriptableRenderLoop : ScriptableObject |
|||
{ |
|||
public abstract void Render(Camera[] cameras, RenderLoop renderLoop); |
|||
public virtual void Rebuild() {} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public virtual UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures() { return new UnityEditor.SupportedRenderingFeatures(); } |
|||
#endif
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4a2689a80c91a4fb8bec214a015b9cdc |
|||
timeCreated: 1466769781 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
//@TODO: This should be moved into GraphicsSettings
|
|||
[ExecuteInEditMode] |
|||
public class ScriptableRenderLoopPicker : MonoBehaviour |
|||
{ |
|||
public ScriptableRenderLoop renderloop |
|||
{ |
|||
get { return m_RenderLoop; } |
|||
set { m_RenderLoop = value; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
private ScriptableRenderLoop m_RenderLoop; |
|||
|
|||
// TEMPORARY
|
|||
public int legacyRenderLoopMaxShaderLOD = int.MaxValue; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
RenderLoop.renderLoopDelegate += Render; |
|||
|
|||
SyncRenderingFeatures(); |
|||
} |
|||
|
|||
void OnValidate() |
|||
{ |
|||
SyncRenderingFeatures(); |
|||
} |
|||
|
|||
void SyncRenderingFeatures() |
|||
{ |
|||
if (m_RenderLoop != null && isActiveAndEnabled) |
|||
Shader.globalMaximumLOD = int.MaxValue; |
|||
|
|||
#if UNITY_EDITOR
|
|||
if (m_RenderLoop != null && isActiveAndEnabled) |
|||
UnityEditor.SupportedRenderingFeatures.active = m_RenderLoop.GetSupportedRenderingFeatures(); |
|||
else |
|||
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default; |
|||
#endif
|
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
RenderLoop.renderLoopDelegate -= Render; |
|||
Shader.globalMaximumLOD = legacyRenderLoopMaxShaderLOD; |
|||
|
|||
#if UNITY_EDITOR
|
|||
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default; |
|||
#endif
|
|||
} |
|||
|
|||
bool Render(Camera[] cameras, RenderLoop loop) |
|||
{ |
|||
if (m_RenderLoop == null) |
|||
return false; |
|||
|
|||
#if UNITY_EDITOR
|
|||
if (m_AssetVersion != s_GlobalAssetVersion) |
|||
{ |
|||
m_AssetVersion = s_GlobalAssetVersion; |
|||
m_RenderLoop.Rebuild(); |
|||
} |
|||
#endif
|
|||
|
|||
m_RenderLoop.Render(cameras, loop); |
|||
return true; |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
// Temporary hack to allow compute shader reloading
|
|||
internal class AssetReloader : UnityEditor.AssetPostprocessor |
|||
{ |
|||
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) |
|||
{ |
|||
foreach (var str in importedAssets) |
|||
{ |
|||
if (str.EndsWith(".compute")) |
|||
{ |
|||
s_GlobalAssetVersion++; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
static int s_GlobalAssetVersion = 0; |
|||
int m_AssetVersion = 0; |
|||
#endif
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 92bb16b4ee20841929b24d6bd771738d |
|||
timeCreated: 1467028218 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue