浏览代码

temp fixed include issues for some .compute shaders

added metal, smoothness to decals
/prototype-decals
Paul Melamed 7 年前
当前提交
3b75ece2
共有 11 个文件被更改,包括 38 次插入74 次删除
  1. 68
      ScriptableRenderPipeline/Core/Editor/ShaderGenerator/CSharpToHLSL.cs
  2. 6
      ScriptableRenderPipeline/Core/Resources/EncodeBC6H.compute
  3. 2
      ScriptableRenderPipeline/Core/Resources/GPUCopy.compute
  4. 7
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/Decal/DecalUI.cs
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
  6. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.hlsl
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
  9. 6
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
  10. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl
  11. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl

68
ScriptableRenderPipeline/Core/Editor/ShaderGenerator/CSharpToHLSL.cs


using System;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Visitors;
using ICSharpCode.NRefactory.Ast;

s_TypeName = new Dictionary<string, ShaderTypeGenerator>();
// Iterate over assemblyList, discover all applicable types with fully qualified names
var assemblyList = AssemblyEnumerator.EnumerateReferencedAssemblies(Assembly.GetCallingAssembly());
var assemblyList = AppDomain.CurrentDomain.GetAssemblies().ToList();
foreach (var assembly in assemblyList)
{

return null;
}
}
}
// Helper class to recursively enumerate assemblies referenced by the calling assembly, including unloaded ones
static class AssemblyEnumerator
{
public static List<Assembly> EnumerateReferencedAssemblies(Assembly assembly)
{
Dictionary<string, Assembly> referenced = assembly.GetReferencedAssembliesRecursive();
referenced[GetName(assembly.FullName)] = assembly;
return referenced.Values.ToList();
}
public static Dictionary<string, Assembly> GetReferencedAssembliesRecursive(this Assembly assembly)
{
s_Assemblies = new Dictionary<string, Assembly>();
InternalGetDependentAssembliesRecursive(assembly);
// Skip assemblies from GAC (@TODO: any reason we'd want to include them?)
var keysToRemove = s_Assemblies.Values.Where(
o => o.GlobalAssemblyCache == true).ToList();
foreach (var k in keysToRemove)
{
s_Assemblies.Remove(GetName(k.FullName));
}
return s_Assemblies;
}
private static void InternalGetDependentAssembliesRecursive(Assembly assembly)
{
// Load assemblies with newest versions first.
var referencedAssemblies = assembly.GetReferencedAssemblies()
.OrderByDescending(o => o.Version);
foreach (var r in referencedAssemblies)
{
if (string.IsNullOrEmpty(assembly.FullName))
{
continue;
}
if (s_Assemblies.ContainsKey(GetName(r.FullName)))
continue;
try
{
// Ensure that the assembly is loaded
var a = Assembly.Load(r.FullName);
s_Assemblies[GetName(a.FullName)] = a;
InternalGetDependentAssembliesRecursive(a);
}
catch
{
// Missing dll, ignore.
}
}
}
static string GetName(string name)
{
return name.Split(',')[0];
}
static Dictionary<string, Assembly> s_Assemblies;
}
}

6
ScriptableRenderPipeline/Core/Resources/EncodeBC6H.compute


#include "ShaderLibrary/Common.hlsl"
#include "ShaderLibrary/BC6H.hlsl"
#include "ShaderLibrary/Sampling.hlsl"
#include "../ShaderLibrary/Common.hlsl"
#include "../ShaderLibrary/BC6H.hlsl"
#include "../ShaderLibrary/Sampling.hlsl"
TextureCube<float4> _Source;
RWTexture2DArray<uint4> _Target;

2
ScriptableRenderPipeline/Core/Resources/GPUCopy.compute


// Autogenerated file. Do not edit by hand
#include "ShaderLibrary/Common.hlsl"
#include "../ShaderLibrary/Common.hlsl"
SamplerState sampler_LinearClamp;

7
ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/Decal/DecalUI.cs


public static GUIContent baseColorText = new GUIContent("Base Color + Blend", "Albedo (RGB) and Blend Factor (A)");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))");
public static GUIContent MSHMapText = new GUIContent("Metal Smoothness Height Map", "Metal(R) Smoothness(G) Height(B) ");
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Combines with Base Color (A)");
}

protected MaterialProperty normalMap = new MaterialProperty();
protected const string kNormalMap = "_NormalMap";
protected MaterialProperty MSHMap = new MaterialProperty();
protected const string kMSHMap = "_MSHMap";
protected MaterialProperty decalBlend = new MaterialProperty();
protected const string kDecalBlend = "_DecalBlend";

{
baseColorMap = FindProperty(kBaseColorMap, props);
normalMap = FindProperty(kNormalMap, props);
MSHMap = FindProperty(kMSHMap, props);
decalBlend = FindProperty(kDecalBlend, props);
}

{
CoreUtils.SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap));
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap));
CoreUtils.SetKeyword(material, "_MSHMAP", material.GetTexture(kMSHMap));
}
protected void SetupMaterialKeywordsAndPassInternal(Material material)

m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.MSHMapText, MSHMap);
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs


// 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 RenderTextureReadWrite[] m_RTReadWrite = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear};
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32 };
static RenderTextureReadWrite[] m_RTReadWrite = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear };
static public void GetMaterialDBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite)
{

7
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.hlsl


//
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_BASE_COLOR (10000)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL_WS (10001)
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_MSH (10002)
#define DBUFFERMATERIAL_COUNT (2)
#define DBUFFERMATERIAL_COUNT (3)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData
// PackingRules = Exact

float4 normalWS;
float4 MSH;
};
//

break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL_WS:
result = decalsurfacedata.normalWS.xyz;
break;
case DEBUGVIEW_DECAL_DECALSURFACEDATA_MSH:
result = decalsurfacedata.MSH.xyz;
break;
}
}

6
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl


// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild
void EncodeIntoDBuffer( DecalSurfaceData surfaceData,
out DBufferType0 outDBuffer0,
out DBufferType1 outDBuffer1
out DBufferType1 outDBuffer1,
out DBufferType2 outDBuffer2
outDBuffer2 = surfaceData.MSH;
DBufferType2 inDBuffer2,
out DecalSurfaceData surfaceData
)
{

surfaceData.normalWS.w = inDBuffer1.w;
surfaceData.MSH = inDBuffer2;
}

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader


{
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_MSHMap("MSHMap", 2D) = "white" {}
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5
}

//-------------------------------------------------------------------------------------
#pragma shader_feature _COLORMAP
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MSHMAP
//-------------------------------------------------------------------------------------

6
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl


{
surfaceData.baseColor = float4(0,0,0,0);
surfaceData.normalWS = float4(0,0,0,0);
surfaceData.MSH = float4(0,0,0,0);
float totalBlend = _DecalBlend;
#if _COLORMAP
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy);

surfaceData.normalWS.xyz = mul((float3x3)_DecalToWorldR, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
surfaceData.normalWS.w = totalBlend;
#endif
#if _MSHMAP
surfaceData.MSH.xyz = SAMPLE_TEXTURE2D(_MSHMap, sampler_MSHMap, texCoordDS.xy);
surfaceData.MSH.w = totalBlend;
#endif
}

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl


SAMPLER2D(sampler_BaseColorMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_MSHMap);
SAMPLER2D(sampler_MSHMap);
float _DecalBlend;

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl


surfaceData.baseColor.xyz = lerp(surfaceData.baseColor.xyz, decalSurfaceData.baseColor.xyz, decalSurfaceData.baseColor.w);
surfaceData.normalWS.xyz = normalize(lerp(surfaceData.normalWS.xyz, decalSurfaceData.normalWS.xyz, decalSurfaceData.normalWS.w));
surfaceData.metallic = lerp(surfaceData.metallic, decalSurfaceData.MSH.x, decalSurfaceData.MSH.w);
surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, decalSurfaceData.MSH.y, decalSurfaceData.MSH.w);
#endif
}
正在加载...
取消
保存