浏览代码

Intermediate work

/main
Paul Melamed 6 年前
当前提交
e000418f
共有 7 个文件被更改,包括 88 次插入9 次删除
  1. 53
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  2. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs
  3. 11
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl
  5. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.hlsl
  6. 19
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  7. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl

53
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


public static GUIContent AlbedoModeText = new GUIContent("Albedo contribution", "Base color + Blend, Blend only");
}
enum NormalPerPixelBlendSource
{
AlbedoMapAlpha,
MaskMapBlue
}
protected string[] normalPerPixelBlendSourceNames = Enum.GetNames(typeof(NormalPerPixelBlendSource));
enum MaskPerPixelBlendSource
{
Zero,
AlbedoMapAlpha,
MaskMapBlue
}
protected string[] maskPerPixelBlendSourceNames = Enum.GetNames(typeof(MaskPerPixelBlendSource));
protected MaterialProperty baseColorMap = new MaterialProperty();
protected const string kBaseColorMap = "_BaseColorMap";

protected MaterialProperty albedoMode = new MaterialProperty();
protected const string kAlbedoMode = "_AlbedoMode";
protected MaterialProperty normalPerPixelBlend = new MaterialProperty();
protected const string kNormalPerPixelBlend = "_NormalPerPixelBlend";
protected MaterialProperty metalnessPerPixelBlend = new MaterialProperty();
protected const string kMetalnessPerPixelBlend = "_MetalnessPerPixelBlend";
protected MaterialProperty AOPerPixelBlend = new MaterialProperty();
protected const string kAOPerPixelBlend = "_AOPerPixelBlend";
protected MaterialProperty smoothnessPerPixelBlend = new MaterialProperty();
protected const string kSmoothnessPerPixelBlend = "_SmoothnessPerPixelBlend";
protected MaterialEditor m_MaterialEditor;
// This is call by the inspector

maskMap = FindProperty(kMaskMap, props);
decalBlend = FindProperty(kDecalBlend, props);
albedoMode = FindProperty(kAlbedoMode, props);
normalPerPixelBlend = FindProperty(kNormalPerPixelBlend, props);
metalnessPerPixelBlend = FindProperty(kMetalnessPerPixelBlend, props);
AOPerPixelBlend = FindProperty(kAOPerPixelBlend, props);
smoothnessPerPixelBlend = FindProperty(kSmoothnessPerPixelBlend, props);
// always instanced
SerializedProperty instancing = m_MaterialEditor.serializedObject.FindProperty("m_EnableInstancingVariants");
instancing.boolValue = true;

{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
float normalPerPixelBlendValue = normalPerPixelBlend.floatValue;
float metalnessPerPixelBlendValue = metalnessPerPixelBlend.floatValue;
float AOPerPixelBlendValue = AOPerPixelBlend.floatValue;
float smoothnessPerPixelBlendValue = smoothnessPerPixelBlend.floatValue;
EditorGUI.showMixedValue = normalPerPixelBlend.hasMixedValue;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{

{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap, baseColor);
}
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
normalPerPixelBlendValue = EditorGUILayout.Popup( "Normal Per Pixel Blend", (int)normalPerPixelBlendValue, normalPerPixelBlendSourceNames);
metalnessPerPixelBlendValue = EditorGUILayout.Popup( "Metalness Per Pixel Blend", (int)metalnessPerPixelBlendValue, maskPerPixelBlendSourceNames);
smoothnessPerPixelBlendValue = EditorGUILayout.Popup( "Smoothness Per Pixel Blend", (int)smoothnessPerPixelBlendValue, maskPerPixelBlendSourceNames);
EditorGUILayout.Space();
AOPerPixelBlendValue = EditorGUILayout.Popup( "AO Per Pixel Blend", (int)AOPerPixelBlendValue, maskPerPixelBlendSourceNames);
EditorGUILayout.Space();
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;
}

m_MaterialEditor.RegisterPropertyChangeUndo( "Normal Per Pixel Blend");
normalPerPixelBlend.floatValue = normalPerPixelBlendValue;
m_MaterialEditor.RegisterPropertyChangeUndo( "Metalness Per Pixel Blend");
metalnessPerPixelBlend.floatValue = metalnessPerPixelBlendValue;
m_MaterialEditor.RegisterPropertyChangeUndo( "AO Per Pixel Blend");
AOPerPixelBlend.floatValue = AOPerPixelBlendValue;
m_MaterialEditor.RegisterPropertyChangeUndo( "Smoothness Per Pixel Blend");
smoothnessPerPixelBlend.floatValue = smoothnessPerPixelBlendValue;
EditorGUI.showMixedValue = false;
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)

2
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DBufferManager.cs


Color clearColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
Color clearColorNormal = new Color(0.5f, 0.5f, 0.5f, 1.0f); // for normals 0.5 is neutral
Color clearColorAOSBlend = new Color(1.0f, 1.0f, 1.0f, 1.0f);
HDUtils.SetRenderTarget(cmd, camera, m_RTs[3], ClearFlag.Color, clearColorAOSBlend);
HDUtils.SetRenderTarget(cmd, camera, m_HTile, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

11
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs


public Vector4 normalWS;
[SurfaceDataAttributes("Mask", true)]
public Vector4 mask;
[SurfaceDataAttributes("AOSBlend", true)]
public Vector2 AOSBlend;
[SurfaceDataAttributes("HTileMask")]
public uint HTileMask;
};

{
// Note: This count doesn't include the velocity buffer. On shader and csharp side the velocity buffer will be added by the framework
Count = 3
{
Count = 4
};
[GenerateHLSL(PackingRules.Exact)]

// should this be combined into common class shared with Lit.cs???
static public int GetMaterialDBufferCount() { return (int)DBufferMaterial.Count; }
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32 };
static bool[] m_sRGBFlags = { true, false, false };
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.RG16 };
static bool[] m_sRGBFlags = { true, false, false, false };
static public void GetMaterialDBufferDescription(out RenderTextureFormat[] RTFormat, out bool[] sRGBFlags)
{

3
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl


//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferMaterial: static fields
//
#define DBUFFERMATERIAL_COUNT (3)
#define DBUFFERMATERIAL_COUNT (4)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferHTileBit: static fields

float4 baseColor;
float4 normalWS;
float4 mask;
float2 AOSBlend;
uint HTileMask;
};

8
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.hlsl


#define DBufferType0 float4
#define DBufferType1 float4
#define DBufferType2 float4
#define DBufferType3 float4
#define DBufferType3 float2
#ifdef DBUFFERMATERIAL_COUNT

void EncodeIntoDBuffer( DecalSurfaceData surfaceData,
out DBufferType0 outDBuffer0,
out DBufferType1 outDBuffer1,
out DBufferType2 outDBuffer2
out DBufferType2 outDBuffer2,
out DBufferType3 outDBuffer3
outDBuffer3 = surfaceData.AOSBlend;
}
void DecodeFromDBuffer(

DBufferType3 inDBuffer3,
out DecalSurfaceData surfaceData
)
{

surfaceData.normalWS.w = inDBuffer1.w;
surfaceData.mask = inDBuffer2;
surfaceData.AOSBlend = inDBuffer3;
}

19
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


_MaskMap("MaskMap", 2D) = "white" {}
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5
[ToggleUI] _AlbedoMode("_AlbedoMode", Range(0.0, 1.0)) = 1.0
[HideInInspector] _NormalPerPixelBlend("_NormalPerPixelBlend", Float) = 0.0
[HideInInspector] _MetalnessPerPixelBlend("_MetalnessPerPixelBlend", Float) = 1.0
[HideInInspector] _AOPerPixelBlend("_AOPerPixelBlend", Float) = 1.0
[HideInInspector] _SmoothnessPerPixelBlend("_SmoothnessPerPixelBlend", Float) = 1.0
}
HLSLINCLUDE

#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _ALBEDOCONTRIBUTION
#pragma shader_feature _NORMAL_BLEND_ALBEDO_A
#pragma shader_feature _NORMAL_BLEND_MASK_B
#pragma shader_feature _METALNESS_BLEND_ZERO
#pragma shader_feature _METALNESS_BLEND_ALBEDO_A
#pragma shader_feature _METALNESS_BLEND_MASK_B
#pragma shader_feature _AO_BLEND_ZERO
#pragma shader_feature _AO_BLEND_ALBEDO_A
#pragma shader_feature _AO_BLEND_MASK_B
#pragma shader_feature _SMOOTHNESS_BLEND_ZERO
#pragma shader_feature _SMOOTHNESS_BLEND_ALBEDO_A
#pragma shader_feature _SMOOTHNESS_BLEND_MASK_B
#pragma multi_compile_instancing
//-------------------------------------------------------------------------------------

1
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl


surfaceData.baseColor = _BaseColor;
surfaceData.normalWS = float4(0,0,0,0);
surfaceData.mask = float4(0,0,0,0);
surfaceData.AOSBlend = float2(0, 0);
surfaceData.HTileMask = 0;
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
float totalBlend = clamp(normalToWorld[0][3], 0.0f, 1.0f);

正在加载...
取消
保存