浏览代码

intermediate commit for decal height map

/prototype-decals
Paul Melamed 7 年前
当前提交
e2add901
共有 7 个文件被更改,包括 117 次插入44 次删除
  1. 38
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/Decal/DecalUI.cs
  2. 74
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
  3. 18
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
  4. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl
  5. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
  6. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl

38
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 maskMapText = new GUIContent("Mask Map - M(R), AO(G), D(B), S(A)", "Mask map");
public static GUIContent heightMapText = new GUIContent("Height Map (R)", "Height Map.\nFor floating point textures, min, max and base value should be 0, 1 and 0.");
public static GUIContent heightMapCenterText = new GUIContent("Height Map Base", "Base of the heightmap in the texture (between 0 and 1)");
public static GUIContent heightMapMinText = new GUIContent("Height Min (cm)", "Minimum value in the heightmap (in centimeters)");
public static GUIContent heightMapMaxText = new GUIContent("Height Max (cm)", "Maximum value in the heightmap (in centimeters)");
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Whole decal blend");
}

protected MaterialProperty maskMap = new MaterialProperty();
protected const string kMaskMap = "_MaskMap";
protected MaterialProperty heightMap = new MaterialProperty();
protected const string kHeightMap = "_HeightMap";
protected MaterialProperty heightAmplitude = new MaterialProperty();
protected const string kHeightAmplitude = "_HeightAmplitude";
protected MaterialProperty heightCenter = new MaterialProperty();
protected const string kHeightCenter = "_HeightCenter";
protected MaterialProperty heightMin = new MaterialProperty();
protected const string kHeightMin = "_HeightMin";
protected MaterialProperty heightMax = new MaterialProperty();
protected const string kHeightMax = "_HeightMax";
decalBlend = FindProperty(kDecalBlend, props);
heightMap = FindProperty(kHeightMap, props);
heightAmplitude = FindProperty(kHeightAmplitude, props);
heightCenter = FindProperty(kHeightCenter, props);
heightMin = FindProperty(kHeightMin, props);
heightMax = FindProperty(kHeightMax, props);
decalBlend = FindProperty(kDecalBlend, props);
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
static public void SetupMaterialKeywordsAndPass(Material material)
{

CoreUtils.SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap));
}
protected void SetupMaterialKeywordsAndPassInternal(Material material)

public void ShaderPropertiesGUI(Material material)
{

m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap);
if ((!heightMap.hasMixedValue) && (heightMap.textureValue != null))
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(heightMin, Styles.heightMapMinText);
m_MaterialEditor.ShaderProperty(heightMax, Styles.heightMapMaxText);
m_MaterialEditor.ShaderProperty(heightCenter, Styles.heightMapCenterText);
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;
}
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
EditorGUI.indentLevel--;

// We should always do this call at the end
m_MaterialEditor.serializedObject.ApplyModifiedProperties();
}
}
}

74
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset


m_EditorClassIdentifier:
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7,
type: 2}
defaultFrameSettings:
lightingSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
renderSettings:
enableForwardRenderingOnly: 1
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableMaterialDisplayDebug: 0
enableShadowMask: 0
serializedFrameSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableObjectMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 0
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

enableBigTilePrepass: 1
isFptlEnabled: 1
m_globalFrameSettings: {fileID: 0}
m_sssSettings: {fileID: 0}
renderPipelineSettings:
supportShadowMask: 1
supportSSR: 1
supportSSAO: 1
supportSSSAndTransmission: 1
supportDBuffer: 1
supportMSAA: 0
supportAsyncCompute: 0
lightLoopSettings:
spotCookieSize: 128
cookieTexArraySize: 16
pointCookieSize: 512
cubeCookieTexArraySize: 16
reflectionProbeCacheSize: 128
reflectionCubemapSize: 128
reflectionCacheCompressed: 0
shadowInitParams:
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
sssSettings: {fileID: 0}
m_DefaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17,
type: 2}
m_DefaultShader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}

18
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs


[SurfaceDataAttributes("Normal", true)]
public Vector4 normalWS;
[SurfaceDataAttributes("Mask", true)]
public Vector4 mask;
public Vector4 mask;
[GenerateHLSL(PackingRules.Exact, false, true, 10001)]
public struct DecalSurfaceDataVS
{
[SurfaceDataAttributes("Height", true)]
public float height;
}
{
// 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
};
//-----------------------------------------------------------------------------

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

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl


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

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

surfaceData.mask = inDBuffer2;
}
void DecodeFromDBufferVS(
DBufferType3 inDBuffer3,
out DecalSurfaceDataVS surfaceData
)
{
ZERO_INITIALIZE(DecalSurfaceDataVS, surfaceData);
surfaceData.height = inDBuffer3;
}

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader


_BaseColorMap("BaseColorMap", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_MaskMap("MaskMap", 2D) = "white" {}
_HeightMap("HeightMap", 2D) = "white" {}
// Caution: Default value of _HeightAmplitude must be (_HeightMax - _HeightMin) * 0.01
[HideInInspector] _HeightAmplitude("Height Amplitude", Float) = 0.02 // In world units. This will be computed in the UI.
_HeightMin("Heightmap Min", Float) = -1
_HeightMax("Heightmap Max", Float) = 1
_HeightCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5
}

#pragma shader_feature _COLORMAP
#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _HEIGHTMAP
//-------------------------------------------------------------------------------------

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


surfaceData.normalWS.w *= surfaceData.mask.z;
surfaceData.mask.z *= totalBlend;
#endif
}
void GetSurfaceDataVS(float2 texCoordDS, out DecalSurfaceDataVS surfaceData)
{
surfaceData.height = 0;
#if _HEIGHTMAP
surfaceData.mask = SAMPLE_TEXTURE2D(_HeightMap, sampler_HeightMap, texCoordDS.xy);
#endif
}

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


SAMPLER(sampler_NormalMap);
TEXTURE2D(_MaskMap);
SAMPLER(sampler_MaskMap);
TEXTURE2D(_HeightMap);
SAMPLER(sampler_HeightMap);
float _DecalBlend;

正在加载...
取消
保存