浏览代码

HDRenderLoop: Updating inspector + shaders parameters

- Move alpha test to be able to enable it for transparent as an
optimization
- Change stuff to map a bit Untiy standard shaders and rename mettalic
to Mask map.
/main
sebastienlagarde 8 年前
当前提交
279a61e5
共有 3 个文件被更改,包括 204 次插入153 次删除
  1. 263
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs
  2. 34
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  3. 60
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl

263
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs


public enum SurfaceType
{
Opaque,
Cutout,
Transparent
}
public enum BlendMode

Premultiply
}
public enum SmoothnessMapChannel
{
MaskAlpha,
AlbedoAlpha,
}
public enum EmissiveColorMode
{
UseEmissiveColor,
UseEmissiveMask,
}
public enum DoubleSidedMode
{
None,
DoubleSided,
DoubleSidedLightingFlip,
DoubleSidedLightingMirror,
}
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 doubleSidedText = new GUIContent("Double Sided", "This will render the two face of the objects (disable backface culling)");
public static GUIContent doubleSidedLightingText = new GUIContent("Double Sided Lighting", "Enable lighting on both side of the objects (flip normal)");
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 GUIContent baseColorText = new GUIContent("Base Color", "Base Color scale factor");
public static GUIContent baseColorMapText = new GUIContent("Base Color Map", "Albedo (RGB) and Transparency (A)");
public static GUIContent ambientOcclusionText = new GUIContent("Ambient Occlusion", "Ambient Occlusion (R)");
public static string InputsOptionsText = "Inputs options";
public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel");
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", "Albedo (RGB) and Smoothness (A)");
public static GUIContent baseColorSmoothnessText = new GUIContent("Base Color + Smoothness", "Albedo (RGB) and Smoothness (A)");
public static GUIContent mettalicMapText = new GUIContent("Mettalic Map", "Mettalic Map");
public static GUIContent smoothnessMapText = new GUIContent("Smoothness Map", "Base Color scale factor");
public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map", "Specular Occlusion Map");
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 heightScaleText = new GUIContent("Height Scale", "eight Map");
public static GUIContent heightBiasText = new GUIContent("Height Bias", "eight Map");
public static GUIContent emissiveColorMapText = new GUIContent("Emissive Color Map", "Emissive");
public static string SurfaceTypeText = "Surface Type";
public static string BlendModeText = "Blend Mode";
public static string InputsText = "Inputs";
public static readonly string[] surfaceTypeNames = Enum.GetNames(typeof(SurfaceType));
public static readonly string[] blendModeNames = Enum.GetNames(typeof(BlendMode));
MaterialProperty doubleSided = null;
MaterialProperty doubleSidedLighting = null;
MaterialProperty alphaCutoffEnable = null;
MaterialProperty doubleSidedMode = null;
MaterialProperty smoothnessMapChannel = null;
MaterialProperty emissiveColorMode = null;
MaterialProperty ambientOcclusionMap = null;
MaterialProperty mettalicMap = null;
MaterialProperty smoothnessMap = null;
MaterialProperty maskMap = null;
MaterialProperty specularOcclusionMap = null;
MaterialProperty normalMap = null;
MaterialProperty heightMap = null;

surfaceType = FindProperty("_SurfaceType", props);
blendMode = FindProperty("_BlendMode", props);
alphaCutoff = FindProperty("_Cutoff", props);
doubleSided = FindProperty("_DoubleSided", props);
doubleSidedLighting = FindProperty("_DoubleSidedLigthing", props);
alphaCutoffEnable = FindProperty("_AlphaCutoffEnable", props);
doubleSidedMode = FindProperty("_DoubleSidedMode", props);
smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props);
emissiveColorMode = FindProperty("_EmissiveColorMode", props);
ambientOcclusionMap = FindProperty("_AmbientOcclusionMap", props);
mettalicMap = FindProperty("_MettalicMap", props);
smoothnessMap = FindProperty("_SmoothnessMap", props);
maskMap = FindProperty("_MaskMap", props);
specularOcclusionMap = FindProperty("_SpecularOcclusionMap", props);
normalMap = FindProperty("_NormalMap", props);
heightMap = FindProperty("_HeightMap", props);

{
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
SurfaceTypePopup();
BlendModePopup();
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text);
if (alphaCutoffEnable.floatValue == 1.0)
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text);
}
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
}
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text);
GUILayout.Label(Styles.InputsOptionsText, EditorStyles.boldLabel);
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText.text);
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText.text);
bool isAlbedoAlpha = (SmoothnessMapChannel)smoothnessMapChannel.floatValue == SmoothnessMapChannel.AlbedoAlpha;
bool useEmissiveMask = (EmissiveColorMode)emissiveColorMode.floatValue == EmissiveColorMode.UseEmissiveMask;
m_MaterialEditor.TexturePropertySingleLine(isAlbedoAlpha ? Styles.baseColorSmoothnessText : Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(mettalic, Styles.mettalicText);
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
/*
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightMap.textureValue != null ? heigtMapScale : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.occlusionText, occlusionMap, occlusionMap.textureValue != null ? occlusionStrength : null);
DoEmissionArea(material);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMaskText, detailMask);
EditorGUI.BeginChangeCheck();
m_MaterialEditor.TextureScaleOffsetProperty(albedoMap);
if (EditorGUI.EndChangeCheck())
emissionMap.textureScaleAndOffset = albedoMap.textureScaleAndOffset; // Apply the main texture scale and offset to the emission texture as well, for Enlighten's sake
if (isAlbedoAlpha && useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapESText, maskMap);
else if (useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapEText, maskMap);
else if (isAlbedoAlpha)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSText, maskMap);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
EditorGUILayout.Space();
m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap);
// Secondary properties
GUILayout.Label(Styles.secondaryMapsText, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailAlbedoText, detailAlbedoMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, detailNormalMap, detailNormalMapScale);
m_MaterialEditor.TextureScaleOffsetProperty(detailAlbedoMap);
m_MaterialEditor.ShaderProperty(uvSetSecondary, Styles.uvSetLabel.text);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
// Third properties
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightScale, heightBias);
if (highlights != null)
m_MaterialEditor.ShaderProperty(highlights, Styles.highlightsText);
if (reflections != null)
m_MaterialEditor.ShaderProperty(reflections, Styles.reflectionsText);
*/
if (!useEmissiveMask)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
}
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
//foreach (var obj in blendMode.targets)
// MaterialChanged((Material)obj, m_WorkflowMode);
foreach (var obj in blendMode.targets)
MaterialChanged((Material)obj);
}
}

EditorGUI.showMixedValue = false;
}
public static void SetupMaterialWithBlendMode(Material material, SurfaceType surfaceType, BlendMode blendMode)
public void SetupMaterialWithBlendMode(Material material, bool alphaTestEnable, SurfaceType surfaceType, BlendMode blendMode, DoubleSidedMode doubleSidedMode)
if (alphaTestEnable)
material.EnableKeyword("_ALPHATEST_ON");
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
}
else if (surfaceType == SurfaceType.Cutout)
{
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
material.renderQueue = alphaTestEnable ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : -1;
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_ZWrite", 0);
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
case BlendMode.Lerp:
material.SetOverrideTag("RenderType", "Transparent");
case BlendMode.Lerp:
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
if (doubleSidedMode == DoubleSidedMode.DoubleSided)
{
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
}
else if (doubleSidedMode == DoubleSidedMode.DoubleSided)
{
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
material.EnableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
}
else
{
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
material.EnableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
}
}
static bool ShouldEmissionBeEnabled(Material mat, Color color)

return false;
}
static void SetMaterialKeywords(Material material)
void SetMaterialKeywords(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)
SetKeyword (material, "_NORMALMAP", material.GetTexture ("_BumpMap") || material.GetTexture ("_DetailNormalMap"));
if (workflowMode == WorkflowMode.Specular)
SetKeyword (material, "_SPECGLOSSMAP", material.GetTexture ("_SpecGlossMap"));
else if (workflowMode == WorkflowMode.Metallic)
SetKeyword (material, "_METALLICGLOSSMAP", material.GetTexture ("_MetallicGlossMap"));
SetKeyword (material, "_PARALLAXMAP", material.GetTexture ("_ParallaxMap"));
SetKeyword (material, "_DETAIL_MULX2", material.GetTexture ("_DetailAlbedoMap") || material.GetTexture ("_DetailNormalMap"));
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material, material.GetColor("_EmissionColor"));
SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
if (material.HasProperty("_SmoothnessTextureChannel"))
{
SetKeyword (material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha);
}
// 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)
SetKeyword(material, "_NORMALMAP", material.GetTexture("_NormalMap"));
SetKeyword(material, "_MASKMAP", material.GetTexture("_MaskMap"));
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture("_SpecularOcclusionMap"));
SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat("_SmoothnessTextureChannel")) == SmoothnessMapChannel.AlbedoAlpha);
SetKeyword(material, "_EMISSIVE_COLOR", ((EmissiveColorMode)material.GetFloat("_EmissiveColorMode")) == EmissiveColorMode.UseEmissiveColor);
/*
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)

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))

else
return true;
*/
*/
return true;
return true;
static void MaterialChanged(Material material)
void MaterialChanged(Material material)
SetupMaterialWithBlendMode(material, (SurfaceType)material.GetFloat("_SurfaceType"), (BlendMode)material.GetFloat("_BlendMode"));
SetupMaterialWithBlendMode(material, alphaCutoffEnable.floatValue == 1.0, (SurfaceType)surfaceType.floatValue, (BlendMode)blendMode.floatValue, (DoubleSidedMode)doubleSidedMode.floatValue);
static void SetKeyword(Material m, string keyword, bool state)
void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword (keyword);

34
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader


// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_AmbientOcclusionMap("AmbientOcclusion", 2D) = "white" {}
_MettalicMap("MettalicMap", 2D) = "white" {}
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_SmoothnessMap("SmoothnessMap", 2D) = "white" {}
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_MaskMap("MaskMap", 2D) = "white" {}
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {}

// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
[ToggleOff] _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleOff] _DoubleSided("Double Sided", Float) = 1.0
[ToggleOff] _DoubleSidedLigthing("Double Sided Lighting", Float) = 1.0
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0

[HideInInspector] _CullMode("__cullmode", Float) = 2.0 // Back by default: MEGA WARNING - if we override this, how it work with MIRROR ? (to check if the engine correctly flip stuff)
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0
[HideInInspector] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 1
}
CGINCLUDE

#pragma vertex VertDefault
#pragma fragment FragForward
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#include "TemplateDisneyGGX.hlsl"

#pragma vertex VertDefault
#pragma fragment FragDeferred
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#include "TemplateDisneyGGX.hlsl"
void FragDeferred( PackedVaryings packedInput,

}
}
// CustomEditor "DisneyGGXGUI"
CustomEditor "DisneyGGXGUI"
}

60
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl


// Set of users variables
float4 _BaseColor;
sampler2D _BaseColorMap;
sampler2D _AmbientOcclusionMap;
sampler2D MettalicMap;
sampler2D _SmoothnessMap;
sampler2D _MaskMap;
sampler2D _SpecularOcclusionMap;
sampler2D _NormalMap;

SurfaceData data;
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;
#else
#endif
data.ambientOcclusion = tex2D(_AmbientOcclusionMap, input.texCoord0).r;
float mettalic = tex2D(MettalicMap, input.texCoord0).r * _Mettalic;
data.perceptualSmoothness = tex2D(_SmoothnessMap, input.texCoord0).r * _Smoothness;
data.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).r;
// MaskMap is Mettalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
#ifdef _MASKMAP
float mettalic = tex2D(_MaskMap, input.texCoord0).r;
data.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
#else
float mettalic = 1.0f;
data.ambientOcclusion = 1.0;
#endif
mettalic *= _Mettalic;
data.diffuseColor = baseColor * (1.0f - mettalic);
data.diffuseColor = baseColor * (1.0f - mettalic);
data.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
data.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
data.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
#elif _MASKMAP
data.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
#else
data.perceptualSmoothness = 1.0;
#endif
data.perceptualSmoothness *= _Smoothness;
#if _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
data.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
#else
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//data.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//data.specularOcclusion *= data.specularOcclusion;
data.specularOcclusion = 1.0;
#endif
#if 1 //_USE_NORMAL_MAP
#if _NORMAL_MAP
#if 1 //_USE_NORMAL_MAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));

#endif
#else
data.normalWS = normalize(input.tangentToWorld[2].xyz);
#endif

// Note that data input above can be use to sample into lightmap (like normal)
data.diffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
data.emissiveIntensity = _EmissiveIntensity;
#elif _MASKMAP // If we have a MaskMap, use emissive slot as a mask on baseColor
data.emissiveColor = data.baseColor * tex2D(_MaskMap, uv).b;
#else
data.emissiveColor = float3(0.0f, 0.0f, 0.0f);
#endif
data.emissiveIntensity = _EmissiveIntensity;
data.subSurfaceRadius = tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
data.subSurfaceRadius = 1.0f; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
// TODO
/*

正在加载...
取消
保存