sebastienlagarde
8 年前
当前提交
bfedb067
共有 20 个文件被更改,包括 883 次插入 和 193 次删除
-
17Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
6Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl
-
36Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.hlsl
-
88Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/DefaultUnlit.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/DefaultUnlit.shader.meta
-
34Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs
-
29Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs.hlsl.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs.meta
-
143Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl.meta
-
323Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitUI.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitUI.cs.meta
-
19Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForwardUnlit.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForwardUnlit.hlsl.meta
-
127Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/unlitTest.mat
-
8Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/unlitTest.mat.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.shader.meta
-
171Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.shader
|
|||
Shader "Unity/Unlit" |
|||
{ |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_ColorMap("ColorMap", 2D) = "white" {} |
|||
|
|||
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0) |
|||
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {} |
|||
_EmissiveIntensity("EmissiveIntensity", Float) = 0 |
|||
|
|||
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0 |
|||
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0 |
|||
|
|||
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend ("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend ("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite ("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
|
|||
[Enum(None, 0, DoubleSided, 1)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
|
|||
#include "UnlitCommon.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags { "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags { "LightMode" = "ForwardUnlit" } |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "UnlitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ce56194c2cab0bd4fbab7a7aba4f160d |
|||
timeCreated: 1476887321 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using System; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// structure definition
|
|||
//-----------------------------------------------------------------------------
|
|||
namespace UnityEngine.ScriptableRenderLoop |
|||
{ |
|||
namespace Unlit |
|||
{ |
|||
//-----------------------------------------------------------------------------
|
|||
// SurfaceData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
// Main structure that store the user data (i.e user input of master node in material graph)
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 1100)] |
|||
public struct SurfaceData |
|||
{ |
|||
[SurfaceDataAttributes("Color")] |
|||
public Vector3 color; |
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// BSDFData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 1130)] |
|||
public struct BSDFData |
|||
{ |
|||
public Vector3 color; |
|||
}; |
|||
} |
|||
} |
|
|||
// |
|||
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs. Please don't edit by hand. |
|||
// |
|||
|
|||
// |
|||
// UnityEngine.ScriptableRenderLoop.Unlit.SurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_UNLIT_SURFACEDATA_COLOR (1100) |
|||
|
|||
// |
|||
// UnityEngine.ScriptableRenderLoop.Unlit.BSDFData: static fields |
|||
// |
|||
#define DEBUGVIEW_UNLIT_BSDFDATA_COLOR (1130) |
|||
|
|||
// Generated from UnityEngine.ScriptableRenderLoop.Unlit.SurfaceData |
|||
// PackingRules = Exact |
|||
struct SurfaceData |
|||
{ |
|||
float3 color; |
|||
}; |
|||
|
|||
// Generated from UnityEngine.ScriptableRenderLoop.Unlit.BSDFData |
|||
// PackingRules = Exact |
|||
struct BSDFData |
|||
{ |
|||
float3 color; |
|||
}; |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 69c83587055c7b1488151841534b03e1 |
|||
timeCreated: 1476887739 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 442f2692415eb6d4ab434b389a186d4a |
|||
timeCreated: 1476887639 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#define UNITY_MATERIAL_UNLIT // Need to be define before including Material.hlsl |
|||
// no need to include lighting |
|||
#include "../Material.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
float4 _Color; |
|||
UNITY_DECLARE_TEX2D(_ColorMap); |
|||
float3 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Lighting architecture |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// TODO: Check if we will have different Varyings based on different pass, not sure about that... |
|||
|
|||
// Forward |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float2 texCoord0; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
FRONT_FACE_TYPE cullFace; |
|||
#endif |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionHS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
#endif |
|||
}; |
|||
|
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionHS = input.positionHS; |
|||
output.interpolators[0].xy = input.texCoord0.xy; |
|||
output.interpolators[0].zw = float2(0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
Varyings UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
Varyings output; |
|||
output.positionHS = input.positionHS; |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
output.cullFace = input.cullFace; |
|||
#endif |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings VertDefault(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Lighting data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
surfaceData.color = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).rgb * _Color.rgb; |
|||
float alpha = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).a * _Color.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor = UNITY_SAMPLE_TEX2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor; |
|||
#else |
|||
builtinData.emissiveColor = _EmissiveColor; |
|||
#endif |
|||
|
|||
builtinData.emissiveIntensity = _EmissiveIntensity; |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
} |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_DEPTH: |
|||
// TODO: provide a customize parameter (like a slider) |
|||
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1); |
|||
result = linearDepth.xxx; |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
// TODO: require a remap |
|||
result = float3(input.texCoord0, 0.0); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#endif // #if SHADER_STAGE_FRAGMENT |
|
|||
fileFormatVersion: 2 |
|||
guid: aef2222e32b780144af8d7e9fd2176a2 |
|||
timeCreated: 1476887321 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor |
|||
{ |
|||
internal class UnlitGUI : ShaderGUI |
|||
{ |
|||
public enum SurfaceType |
|||
{ |
|||
Opaque, |
|||
Transparent |
|||
} |
|||
public enum BlendMode |
|||
{ |
|||
Lerp, |
|||
Add, |
|||
SoftAdd, |
|||
Multiply, |
|||
Premultiply |
|||
} |
|||
|
|||
public enum DoubleSidedMode |
|||
{ |
|||
None, |
|||
DoubleSided |
|||
} |
|||
|
|||
private 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; |
|||
|
|||
MaterialProperty color = null; |
|||
MaterialProperty colorMap = null; |
|||
|
|||
MaterialProperty emissiveColor = null; |
|||
MaterialProperty emissiveColorMap = null; |
|||
MaterialProperty emissiveIntensity = null; |
|||
|
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
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 const string kEmissiveColorMap = "_EmissiveColorMap"; |
|||
|
|||
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); |
|||
} |
|||
|
|||
public void FindInputProperties(MaterialProperty[] props) |
|||
{ |
|||
color = FindProperty("_Color", props); |
|||
colorMap = FindProperty("_ColorMap", props); |
|||
emissiveColor = FindProperty("_EmissiveColor", props); |
|||
emissiveColorMap = FindProperty(kEmissiveColorMap, props); |
|||
emissiveIntensity = FindProperty("_EmissiveIntensity", 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--; |
|||
} |
|||
|
|||
protected void ShaderInputOptionsGUI() |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
protected void ShaderInputGUI() |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
|
|||
GUILayout.Label(Styles.InputsText, EditorStyles.boldLabel); |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.colorText, colorMap, color); |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor); |
|||
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); |
|||
|
|||
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 virtual void SetupKeywordsForInputMaps(Material material) |
|||
{ |
|||
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap)); |
|||
} |
|||
|
|||
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); |
|||
|
|||
SetupKeywordsForInputMaps(material); |
|||
|
|||
/* |
|||
// Setup lightmap emissive flags
|
|||
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags; |
|||
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0) |
|||
{ |
|||
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
if (!shouldEmissionBeEnabled) |
|||
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; |
|||
|
|||
material.globalIlluminationFlags = flags; |
|||
} |
|||
*/ |
|||
} |
|||
|
|||
static bool ShouldEmissionBeEnabled(Material mat, Color color) |
|||
{ |
|||
//var realtimeEmission = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.RealtimeEmissive) > 0;
|
|||
//return color.maxColorComponent > 0.1f / 255.0f || realtimeEmission;
|
|||
|
|||
return false; |
|||
} |
|||
|
|||
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); |
|||
} |
|||
} |
|||
} // namespace UnityEditor
|
|
|||
fileFormatVersion: 2 |
|||
guid: 4c48229427cd20841ada5ba240c493da |
|||
timeCreated: 1476888642 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
float4 Frag(PackedVaryings packedInput) : SV_Target |
|||
{ |
|||
Varyings input = UnpackVaryings(packedInput); |
|||
|
|||
SurfaceData surfaceData; |
|||
BuiltinData builtinData; |
|||
GetSurfaceAndBuiltinData(input, surfaceData, builtinData); |
|||
|
|||
// Not lit here (but emissive is allowed) |
|||
|
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData); |
|||
|
|||
// TODO: we must not access bsdfData here, it break the genericity of the code! |
|||
return float4(bsdfData.color, builtinData.opacity); |
|||
} |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 00c90b339432489468b14dc26ca81899 |
|||
timeCreated: 1476887321 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: unlitTest |
|||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} |
|||
m_ShaderKeywords: _EMISSION |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
m_SavedProperties: |
|||
serializedVersion: 2 |
|||
m_TexEnvs: |
|||
- first: |
|||
name: _BumpMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailAlbedoMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailMask |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailNormalMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _EmissionMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _MainTex |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _MetallicGlossMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _OcclusionMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _ParallaxMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- first: |
|||
name: _BumpScale |
|||
second: 1 |
|||
- first: |
|||
name: _Cutoff |
|||
second: 0.5 |
|||
- first: |
|||
name: _DetailNormalMapScale |
|||
second: 1 |
|||
- first: |
|||
name: _DstBlend |
|||
second: 0 |
|||
- first: |
|||
name: _GlossMapScale |
|||
second: 1 |
|||
- first: |
|||
name: _Glossiness |
|||
second: 0.5 |
|||
- first: |
|||
name: _GlossyReflections |
|||
second: 1 |
|||
- first: |
|||
name: _Metallic |
|||
second: 0 |
|||
- first: |
|||
name: _Mode |
|||
second: 0 |
|||
- first: |
|||
name: _OcclusionStrength |
|||
second: 1 |
|||
- first: |
|||
name: _Parallax |
|||
second: 0.02 |
|||
- first: |
|||
name: _SmoothnessTextureChannel |
|||
second: 0 |
|||
- first: |
|||
name: _SpecularHighlights |
|||
second: 1 |
|||
- first: |
|||
name: _SrcBlend |
|||
second: 1 |
|||
- first: |
|||
name: _UVSec |
|||
second: 0 |
|||
- first: |
|||
name: _ZWrite |
|||
second: 1 |
|||
m_Colors: |
|||
- first: |
|||
name: _Color |
|||
second: {r: 1, g: 1, b: 1, a: 1} |
|||
- first: |
|||
name: _EmissionColor |
|||
second: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: a1c297147b557ff4bb9d5e2059b70d67 |
|||
timeCreated: 1476887873 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1972af2d7b732904ab1f3d5d0f1f2ab0 |
|||
timeCreated: 1475766656 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unity/Unlit" |
|||
{ |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_ColorMap("ColorMap", 2D) = "white" {} |
|||
|
|||
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0) |
|||
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {} |
|||
_EmissiveIntensity("EmissiveIntensity", Float) = 0 |
|||
|
|||
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0 |
|||
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0 |
|||
|
|||
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend ("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend ("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite ("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
|
|||
[Enum(None, 0, DoubleSided)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
|
|||
#define UNITY_MATERIAL_UNLIT |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
|
|||
float4 _Color; |
|||
UNITY_DECLARE_TEX2D(_ColorMap); |
|||
float3 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags { "LightMode" = "ForwardUnlit" } // This will be only for transparent object based on the RenderQueue index |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment FragForward |
|||
|
|||
// Forward |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float2 texCoord0; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionHS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
|
|||
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionHS = input.positionHS; |
|||
output.interpolators[0].xy = input.texCoord0.xy; |
|||
output.interpolators[0].zw = float2(0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
Varyings UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
Varyings output; |
|||
output.positionHS = input.positionHS; |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings VertDefault(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix) |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
|
|||
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
surfaceData.color = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).rgb * _Color.rgb; |
|||
float alpha = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).a * _Color.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
builtinData.opacity = alpha; |
|||
|
|||
// Builtin Data |
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor = UNITY_SAMPLE_TEX2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor; |
|||
#else |
|||
builtinData.emissiveColor = _EmissiveColor; |
|||
#endif |
|||
|
|||
builtinData.emissiveIntensity = _EmissiveIntensity; |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
} |
|||
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
float4 FragForward(PackedVaryings packedInput) : SV_Target |
|||
{ |
|||
Varyings input = UnpackVaryings(packedInput); |
|||
|
|||
SurfaceData surfaceData; |
|||
BuiltinData builtinData; |
|||
GetSurfaceAndBuiltinData(input, surfaceData, builtinData); |
|||
|
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData); |
|||
|
|||
return float4(bsdfData.color, builtinData.opacity); |
|||
} |
|||
|
|||
#endif |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue