浏览代码

added color swatch to decal material

/main
Paul Melamed 7 年前
当前提交
8b873a1e
共有 8 个文件被更改,包括 47 次插入23 次删除
  1. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  2. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  3. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl
  4. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  5. 12
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl
  6. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProperties.hlsl
  7. 17
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalSystem.cs
  8. 29
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl

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


protected MaterialProperty baseColorMap = new MaterialProperty();
protected const string kBaseColorMap = "_BaseColorMap";
protected MaterialProperty baseColor = new MaterialProperty();
protected const string kBaseColor = "_BaseColor";
protected MaterialProperty normalMap = new MaterialProperty();
protected const string kNormalMap = "_NormalMap";

void FindMaterialProperties(MaterialProperty[] props)
{
baseColor = FindProperty(kBaseColor, props);
baseColorMap = FindProperty(kBaseColorMap, props);
normalMap = FindProperty(kNormalMap, props);
maskMap = FindProperty(kMaskMap, props);

m_MaterialEditor.ShaderProperty(albedoMode, Styles.AlbedoModeText);
if (material.GetFloat(kAlbedoMode) == 1.0f)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText2, baseColorMap, baseColor);
}
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);

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


public Vector4 diffuseScaleBias;
public Vector4 normalScaleBias;
public Vector4 maskScaleBias;
public Vector4 baseColor;
};
}

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


float4 diffuseScaleBias;
float4 normalScaleBias;
float4 maskScaleBias;
float4 baseColor;
};
//

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


{
Properties
{
_BaseColor("_BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_MaskMap("MaskMap", 2D) = "white" {}

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


void GetSurfaceData(FragInputs input, out DecalSurfaceData surfaceData)
#endif
{
surfaceData.baseColor = float4(0,0,0,0);
surfaceData.baseColor = _BaseColor;
surfaceData.normalWS = float4(0,0,0,0);
surfaceData.mask = float4(0,0,0,0);
surfaceData.HTileMask = 0;

#endif
#if _COLORMAP
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoords);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
surfaceData.baseColor *= SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoords);
#endif
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
// outside _COLORMAP because we still have base color
#endif
#endif
#if _NORMALMAP

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


SAMPLER(sampler_MaskMap);
float _DecalBlend;
float4 _BaseColor;
#endif

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


static public TextureScaleBias[] m_DiffuseTextureScaleBias = new TextureScaleBias[kDecalBlockSize];
static public TextureScaleBias[] m_NormalTextureScaleBias = new TextureScaleBias[kDecalBlockSize];
static public TextureScaleBias[] m_MaskTextureScaleBias = new TextureScaleBias[kDecalBlockSize];
static public Vector4[] m_BaseColor = new Vector4[kDecalBlockSize];
static public int m_DecalDatasCount = 0;

return 0;
}
}
public void Initialize(Texture texture, Vector4 scaleBias)
{
m_Texture = texture;
m_ScaleBias = scaleBias;
}
}
private List<TextureScaleBias> m_TextureList = new List<TextureScaleBias>();

{
if (m_Material == null)
return;
m_Diffuse.m_Texture = m_Material.GetTexture("_BaseColorMap");
m_Normal.m_Texture = m_Material.GetTexture("_NormalMap");
m_Mask.m_Texture = m_Material.GetTexture("_MaskMap");
m_Diffuse.Initialize(m_Material.GetTexture("_BaseColorMap"), Vector4.zero);
m_Normal.Initialize(m_Material.GetTexture("_NormalMap"), Vector4.zero);
m_Mask.Initialize(m_Material.GetTexture("_MaskMap"), Vector4.zero);
m_BaseColor = m_Material.GetVector("_BaseColor");
}
public DecalSet(Material material)

{
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse;
m_DecalDatas[m_DecalDatasCount].normalToWorld = normalToWorldBatch[instanceCount];
m_DecalDatas[m_DecalDatasCount].baseColor = m_BaseColor;
// we have not allocated the textures in atlas yet, so only store references to them
m_DiffuseTextureScaleBias[m_DecalDatasCount] = m_Diffuse;

private Material m_Material;
private float m_Blend = 0;
private float m_AlbedoContribution = 0;
private Vector4 m_BaseColor;
TextureScaleBias m_Diffuse = new TextureScaleBias();
TextureScaleBias m_Normal = new TextureScaleBias();

m_DiffuseTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
m_NormalTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
m_MaskTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
m_BaseColor = new Vector4[newDecalDatasSize];
}
foreach (var pair in m_DecalSets)
{

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


matMask |= mapMask;
}
void ApplyBlendDiffuse(inout float4 dst, inout int matMask, float2 texCoords, int mapMask, inout float blend, float lod)
void ApplyBlendDiffuse(inout float4 dst, inout int matMask, float2 texCoords, float4 src, int mapMask, inout float blend, float lod, int diffuseTextureBound)
float4 src = SAMPLE_TEXTURE2D_LOD(_DecalAtlas2D, _trilinear_clamp_sampler_DecalAtlas2D, texCoords, lod);
if(diffuseTextureBound)
{
src *= SAMPLE_TEXTURE2D_LOD(_DecalAtlas2D, _trilinear_clamp_sampler_DecalAtlas2D, texCoords, lod);
}
src.w *= blend;
blend = src.w; // diffuse texture alpha affects all other channels
dst.xyz = src.xyz * src.w + dst.xyz * (1.0f - src.w);

float lodMask = ComputeTextureLOD(sampleMaskDdx, sampleMaskDdy, _DecalAtlasResolution);
float decalBlend = decalData.normalToWorld[0][3];
if((decalData.diffuseScaleBias.x > 0) && (decalData.diffuseScaleBias.y > 0))
{
ApplyBlendDiffuse(DBuffer0, mask, sampleDiffuse, DBUFFERHTILEBIT_DIFFUSE, decalBlend, lodDiffuse);
float albedoContribution = decalData.normalToWorld[1][3];
if (albedoContribution == 0.0f)
{
mask = 0; // diffuse will not get modified
}
alpha = alpha < decalBlend ? decalBlend : alpha; // use decal alpha if it is higher than transparent alpha
}
float4 src = decalData.baseColor;
int diffuseTextureBound = (decalData.diffuseScaleBias.x > 0) && (decalData.diffuseScaleBias.y > 0);
ApplyBlendDiffuse(DBuffer0, mask, sampleDiffuse, src, DBUFFERHTILEBIT_DIFFUSE, decalBlend, lodDiffuse, diffuseTextureBound);
alpha = alpha < decalBlend ? decalBlend : alpha; // use decal alpha if it is higher than transparent alpha
float albedoContribution = decalData.normalToWorld[1][3];
if (albedoContribution == 0.0f)
{
mask = 0; // diffuse will not get modified
}
if ((decalData.normalScaleBias.x > 0) && (decalData.normalScaleBias.y > 0))
{
ApplyBlendNormal(DBuffer1, mask, sampleNormal, DBUFFERHTILEBIT_NORMAL, (float3x3)decalData.normalToWorld, decalBlend, lodNormal);

正在加载...
取消
保存