浏览代码

Added lightweight unlit and its shader GUI

/RenderPassXR_Sandbox
Felipe Lira 8 年前
当前提交
53105986
共有 14 个文件被更改,包括 1055 次插入292 次删除
  1. 18
      Assets/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/LDPipe_Shader/LDPipe_UnlitMat.mat
  2. 3
      Assets/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/LDPipe_Shader/LDPipe_UnlitMatTexture.mat
  3. 83
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs
  4. 999
      ImageTemplates/LightweightPipeline/Scenes/Shaders/LDPipe_LitShaderMaps.unity.png
  5. 53
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs
  6. 12
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta
  7. 9
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI.meta
  8. 81
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader
  9. 9
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader.meta
  10. 68
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs
  11. 12
      Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs.meta
  12. 0
      /Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightPipelineMaterialEditor.cs.meta
  13. 0
      /Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightPipelineMaterialEditor.cs

18
Assets/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/LDPipe_Shader/LDPipe_UnlitMat.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: LDPipe_UnlitMat
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _EMISSION _NORMALMAP _SPECGLOSSMAP_BASE_ALPHA
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords: _ALPHABLEND_ON _NORMALMAP _SPECGLOSSMAP_BASE_ALPHA
m_CustomRenderQueue: -1
stringTagMap: {}
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3

- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlend: 10
- _Mode: 0
- _Mode: 2
- _OcclusionStrength: 1
- _Parallax: 0.02
- _ReflectionSource: 0

- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlend: 5
- _ZWrite: 1
- _ZWrite: 0
- _MainColor: {r: 1, g: 0, b: 0, a: 1}
- _ReflectColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}

3
Assets/GraphicsTests/RenderPipeline/LightweightPipeline/Assets/LDPipe_Shader/LDPipe_UnlitMatTexture.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: LDPipe_UnlitMatTexture
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords: _EMISSION _NORMALMAP _SPECGLOSSMAP_BASE_ALPHA
m_LightmapFlags: 4
m_EnableInstancingVariants: 0

m_Colors:
- _Color: {r: 0.9264706, g: 0.095371954, b: 0.095371954, a: 1}
- _EmissionColor: {r: 0.20663926, g: 0.24034719, b: 0.28676468, a: 1}
- _MainColor: {r: 1, g: 1, b: 1, a: 1}
- _ReflectColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}

83
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs


public static void UpdateMaterialKeywords(Material material)
{
UpdateMaterialBlendMode(material);
LightweightShaderHelper.SetMaterialBlendMode(material);
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
SetKeyword(material, "_CUBEMAP_REFLECTION", material.GetTexture("_Cube"));
SetKeyword(material, "_EMISSION", material.GetTexture("_EmissionMap"));
}
private static void UpdateMaterialBlendMode(Material material)
{
UpgradeBlendMode mode = (UpgradeBlendMode)material.GetFloat("_Mode");
switch (mode)
{
case UpgradeBlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = -1;
break;
case UpgradeBlendMode.Cutout:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", true);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = (int)RenderQueue.AlphaTest;
break;
case UpgradeBlendMode.Alpha:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", true);
material.renderQueue = (int)RenderQueue.Transparent;
break;
}
LightweightShaderHelper.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
LightweightShaderHelper.SetKeyword(material, "_CUBEMAP_REFLECTION", material.GetTexture("_Cube"));
LightweightShaderHelper.SetKeyword(material, "_EMISSION", material.GetTexture("_EmissionMap"));
}
private static void UpdateMaterialSpecularSource(Material material)

{
SetKeyword(material, "_SPECGLOSSMAP", false);
SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", false);
}
else if (specSource == SpecularSource.SpecularTextureAndColor && material.GetTexture("_SpecGlossMap"))
{

SetKeyword(material, "_SPECGLOSSMAP", false);
SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", true);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", true);
SetKeyword(material, "_SPECGLOSSMAP", true);
SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", true);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", false);
SetKeyword(material, "_SPECGLOSSMAP", false);
SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
SetKeyword(material, "_SPECULAR_COLOR", true);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", true);
SetKeyword(material, "_REFLECTION_CUBEMAP", false);
SetKeyword(material, "_REFLECTION_PROBE", false);
LightweightShaderHelper.SetKeyword(material, "_REFLECTION_CUBEMAP", false);
LightweightShaderHelper.SetKeyword(material, "_REFLECTION_PROBE", false);
SetKeyword(material, "_REFLECTION_CUBEMAP", true);
LightweightShaderHelper.SetKeyword(material, "_REFLECTION_CUBEMAP", true);
SetKeyword(material, "_REFLECTION_PROBE", true);
LightweightShaderHelper.SetKeyword(material, "_REFLECTION_PROBE", true);
}
private static void SetKeyword(Material material, string keyword, bool enable)
{
if (enable)
material.EnableKeyword(keyword);
else
material.DisableKeyword(keyword);
}
}

999
ImageTemplates/LightweightPipeline/Scenes/Shaders/LDPipe_LitShaderMaps.unity.png
文件差异内容过多而无法显示
查看文件

53
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs


using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public static class LightweightShaderHelper
{
public static void SetMaterialBlendMode(Material material)
{
UpgradeBlendMode mode = (UpgradeBlendMode) material.GetFloat("_Mode");
switch (mode)
{
case UpgradeBlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = -1;
break;
case UpgradeBlendMode.Cutout:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", true);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = (int) RenderQueue.AlphaTest;
break;
case UpgradeBlendMode.Alpha:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", true);
material.renderQueue = (int) RenderQueue.Transparent;
break;
}
}
public static void SetKeyword(Material material, string keyword, bool enable)
{
if (enable)
material.EnableKeyword(keyword);
else
material.DisableKeyword(keyword);
}
}
}

12
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta


fileFormatVersion: 2
guid: 673aad8cdc228cf499f7974fb673fa10
timeCreated: 1496821330
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI.meta


fileFormatVersion: 2
guid: c8b417f54d2314549995022591d5454f
folderAsset: yes
timeCreated: 1496821940
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

81
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader


Shader "ScriptableRenderPipeline/LightweightPipeline/Unlit"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_MainColor("MainColor", Color) = (1, 1, 1, 1)
_Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5
// BlendMode
[HideInInspector] _Mode("Mode", Float) = 0.0
[HideInInspector] _SrcBlend("Src", Float) = 1.0
[HideInInspector] _DstBlend("Dst", Float) = 0.0
[HideInInspector] _ZWrite("ZWrite", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipe" "Lightmode" = "LightweightForward" }
LOD 100
Blend [_SrcBlend][_DstBlend]
ZWrite [_ZWrite]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
half4 _MainColor;
half _Cutoff;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed alpha = texColor.a * _MainColor.a;
fixed3 color = texColor.rgb * _MainColor.rgb;
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif
UNITY_APPLY_FOG(i.fogCoord, color);
#ifdef _ALPHABLEND_ON
return fixed4(color, alpha);
#else
return fixed4(color, 1.0);
#endif
}
ENDCG
}
}
CustomEditor "LightweightUnlitGUI"
}

9
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader.meta


fileFormatVersion: 2
guid: 650dd9526735d5b46b79224bc6e94025
timeCreated: 1496762173
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

68
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs


using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
public class LightweightUnlitGUI : ShaderGUI
{
private MaterialProperty blendModeProp = null;
private MaterialProperty mainTexProp = null;
private MaterialProperty mainColorProp = null;
private MaterialProperty alphaCutoffProp = null;
private MaterialEditor m_MaterialEditor = null;
private static class Styles
{
public static GUIContent[] mainTexLabels =
{
new GUIContent("MainTex (RGB)", "Base Color"),
new GUIContent("MainTex (RGB) Alpha (A)", "Base Color and Alpha")
};
public static readonly string[] blendNames = Enum.GetNames(typeof(UpgradeBlendMode));
public static string renderingModeLabel = "Rendering Mode";
public static string alphaCutoffLabel = "Alpha Cutoff";
}
private void FindMaterialProperties(MaterialProperty[] properties)
{
blendModeProp = FindProperty("_Mode", properties);
mainTexProp = FindProperty("_MainTex", properties);
mainColorProp = FindProperty("_MainColor", properties);
alphaCutoffProp = FindProperty("_Cutoff", properties);
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
Material material = materialEditor.target as Material;
m_MaterialEditor = materialEditor;
FindMaterialProperties(properties);
int modeValue = (int)blendModeProp.floatValue;
EditorGUI.BeginChangeCheck();
modeValue = EditorGUILayout.Popup(Styles.renderingModeLabel, modeValue, Styles.blendNames);
if (EditorGUI.EndChangeCheck())
blendModeProp.floatValue = modeValue;
GUIContent mainTexLabel = Styles.mainTexLabels[Math.Min(modeValue, 1)];
m_MaterialEditor.TexturePropertySingleLine(mainTexLabel, mainTexProp, mainColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(mainTexProp);
if ((UpgradeBlendMode) modeValue == UpgradeBlendMode.Cutout)
m_MaterialEditor.RangeProperty(alphaCutoffProp, Styles.alphaCutoffLabel);
EditorGUILayout.Space();
EditorGUILayout.Space();
materialEditor.RenderQueueField();
LightweightShaderHelper.SetMaterialBlendMode(material);
EditorGUILayout.Space();
EditorGUILayout.Space();
}
}

12
Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs.meta


fileFormatVersion: 2
guid: 3be3f3707c329b043b5816855ee127fd
timeCreated: 1487767801
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineMaterialEditor.cs.meta → /Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightPipelineMaterialEditor.cs.meta

/Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineMaterialEditor.cs → /Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightPipelineMaterialEditor.cs

正在加载...
取消
保存