浏览代码

HDRenderLoop: Make shader feature worknig for DisneyGGX.shader

/main
sebastienlagarde 8 年前
当前提交
06523005
共有 4 个文件被更改,包括 194 次插入49 次删除
  1. 62
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs
  2. 35
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  3. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  4. 135
      Assets/TestScenes/HDTest/Rock/rcgRock012/Materials/rcgRock012Material.mat

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


DoubleSidedLightingMirror,
}
public enum NormalMapSpace
{
TangentSpace,
ObjectSpace,
}
public enum HeightmapMode
{
Parallax,
Displacement,
}
private static class Styles
{
public static string OptionText = "Options";

public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map (RGBA)", "Specular Occlusion Map");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC5) - DXT5 for test");
public static GUIContent normalMapSpaceText = new GUIContent("Normal Map space", "");
public static GUIContent heightMapModeText = new GUIContent("Height Map Mode", "");
// public static GUIContent diffuseLightingMapText = new GUIContent("DiffuseLightingMap", "Lightmap/Lightprobe data (fill by system is not done");

MaterialProperty maskMap = null;
MaterialProperty specularOcclusionMap = null;
MaterialProperty normalMap = null;
MaterialProperty normalMapSpace = null;
MaterialProperty heightMapMode = null;
// MaterialProperty diffuseLightingMap = null;
MaterialProperty emissiveColor = null;
MaterialProperty emissiveColorMap = null;

MaterialEditor m_MaterialEditor;
ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, 99f, 1/99f, 3f);
bool m_FirstTimeApply = true;
MaterialEditor m_MaterialEditor;
alphaCutoff = FindProperty("_Cutoff", props);
alphaCutoff = FindProperty("_AlphaCutoff", props);
alphaCutoffEnable = FindProperty("_AlphaCutoffEnable", props);
doubleSidedMode = FindProperty("_DoubleSidedMode", props);
smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props);

maskMap = FindProperty("_MaskMap", props);
specularOcclusionMap = FindProperty("_SpecularOcclusionMap", props);
normalMap = FindProperty("_NormalMap", props);
normalMapSpace = FindProperty("_NormalMapSpace", props);
heightMapMode = FindProperty("_HeightMapMode", props);
// diffuseLightingMap = FindProperty("_DiffuseLightingMap", props);
emissiveColor = FindProperty("_EmissiveColor", props);
emissiveColorMap = FindProperty("_EmissiveColorMap", props);

EditorGUI.BeginChangeCheck();
{
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
SurfaceTypePopup();
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
}
}
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
}
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text);

m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText.text);
m_MaterialEditor.ShaderProperty(heightMapMode, Styles.heightMapModeText.text);
if (!useEmissiveMask)
{

EditorGUI.showMixedValue = false;
}
public void SetupMaterialWithBlendMode(Material material, bool alphaTestEnable, SurfaceType surfaceType, BlendMode blendMode, DoubleSidedMode doubleSidedMode)
static public void SetupMaterialWithBlendMode(Material material, bool alphaTestEnable, SurfaceType surfaceType, BlendMode blendMode, DoubleSidedMode doubleSidedMode)
{
if (alphaTestEnable)
material.EnableKeyword("_ALPHATEST_ON");

}
}
if (doubleSidedMode == DoubleSidedMode.DoubleSided)
if (doubleSidedMode != DoubleSidedMode.None)
else if (doubleSidedMode == DoubleSidedMode.DoubleSided)
if (doubleSidedMode == DoubleSidedMode.DoubleSided)
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
}
}
}
static bool ShouldEmissionBeEnabled(Material mat, Color color)

return false;
}
void SetMaterialKeywords(Material material)
static void SetMaterialKeywords(Material material)
SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", (NormalMapSpace)material.GetFloat("_NormalMapSpace") == NormalMapSpace.TangentSpace);
SetKeyword(material, "_HEIGHTMAP", material.GetTexture("_HeightMap"));
SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", (HeightmapMode)material.GetFloat("_HeightMapMode") == HeightmapMode.Displacement);
/*
// Setup lightmap emissive flags

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

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


_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {}
[Enum(TangentSpace, 0, ObjectSpace, 1)] _MaterialID("NormalMap space", Float) = 0
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0
[Enum(Parallax, 0, Displacement, 1)] _MaterialID("Heightmap usage", Float) = 0
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)

// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[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] _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

CGINCLUDE
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _NORMALMAP
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _MASKMAP
#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT
ENDCG
SubShader

#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"

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


float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#endif
#if defined(_ALPHATEST_ON)
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif

#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
data.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
#elif _MASKMAP
#elif defined(_MASKMAP)
data.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
#else
data.perceptualSmoothness = 1.0;

#if _SPECULAROCCLUSIONMAP
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
data.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
#else

#endif
// TODO: think about using BC5
#if _NORMAL_MAP
#if 1 //_USE_NORMAL_MAP_TANGENT_SPACE
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
data.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)

135
Assets/TestScenes/HDTest/Rock/rcgRock012/Materials/rcgRock012Material.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: rcgRock012Material
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _METALLICGLOSSMAP _NORMALMAP
m_LightmapFlags: 5
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _DOUBLESIDEDLIGTHING_OFF _DOUBLESIDED_OFF _EMISSION _METALLICGLOSSMAP
_NORMALMAP
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:

name: _AmbientOcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BaseColorMap
second:
m_Texture: {fileID: 2800000, guid: d734753529ca78148a43944515a64bc5, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BumpMap
second:
m_Texture: {fileID: 2800000, guid: 11f99173903c31f49b05339fc71c7919, type: 3}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseLightingMap
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}

name: _EmissiveColorMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _HeightMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MaskMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MettalicMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NormalMap
second:
m_Texture: {fileID: 2800000, guid: 11f99173903c31f49b05339fc71c7919, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 2800000, guid: fe2ed6aee0b5acd42bc15ee53e939e03, type: 3}

m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SmoothnessMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecularOcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SubSurfaceRadiusMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
name: _AlphaCutoffEnable
second: 0
- first:
name: _BlendMode
second: 1
- first:
name: _CullMode
second: 0
- first:
second: 0.5
second: 1
- first:
name: _CutoffEnable
second: 0
name: _DoubleSided
second: 0
- first:
name: _DoubleSidedLigthing
second: 0
- first:
name: _DoubleSidedMode
second: 1
- first:
name: _EmissiveColorMode
second: 1
- first:
name: _EmissiveColorUsage
second: 1
- first:
name: _EmissiveIntensity
second: 0
- first:
name: _GlossMapScale
second: 1
- first:

name: _GlossyReflections
second: 1
- first:
name: _HeightBias
second: 0
- first:
name: _HeightScale
second: -1.07
- first:
name: _MaterialID
second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Mettalic
second: 0
- first:
name: _Mode
second: 0
- first:

name: _Parallax
second: 0.02
- first:
name: _Smoothness
second: 0
- first:
name: _SmoothnessTextureChannel
second: 0

name: _SrcBlend
second: 1
- first:
name: _SubSurfaceRadius
second: 0
- first:
name: _SurfaceType
second: 0
- first:
name: _UVSec
second: 0
- first:

- first:
name: _BaseColor
second: {r: 1, g: 1, b: 1, a: 1}
- first:
- first:
name: _EmissiveColor
second: {r: 0, g: 0, b: 0, a: 1}
正在加载...
取消
保存