浏览代码

change names of decal #defines to reflect functionality of dbuffer passes

store scale/bias of texture atlas allocations after they have been allocated
/main
Paul Melamed 7 年前
当前提交
aa31195d
共有 7 个文件被更改,包括 44 次插入22 次删除
  1. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  2. 12
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl
  3. 30
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalSystem.cs
  4. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderPass/DecalSharePass.hlsl
  5. 4
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs
  6. 4
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs.hlsl
  7. 10
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassDBuffer.hlsl

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


HLSLPROGRAM
#define SHADERPASS SHADERPASS_DBUFFER
#define SHADERPASS SHADERPASS_DBUFFER_PROJECTOR
#include "../../ShaderVariables.hlsl"
#include "Decal.hlsl"
#include "ShaderPass/DecalSharePass.hlsl"

HLSLPROGRAM
#define SHADERPASS SHADERPASS_MESHDECALS
#define SHADERPASS SHADERPASS_DBUFFER_MESH
#include "../../ShaderVariables.hlsl"
#include "Decal.hlsl"
#include "ShaderPass/DecalSharePass.hlsl"

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


#include "CoreRP/ShaderLibrary/EntityLighting.hlsl"
#include "../MaterialUtilities.hlsl"
#if (SHADERPASS == SHADERPASS_DBUFFER)
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
#elif (SHADERPASS == SHADERPASS_DBUFFER_MESH)
void GetSurfaceData(FragInputs input, out DecalSurfaceData surfaceData)
#endif
{

surfaceData.HTileMask = 0;
#if (SHADERPASS == SHADERPASS_DBUFFER)
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
#elif (SHADERPASS == SHADERPASS_DBUFFER_MESH)
float totalBlend = _DecalBlend;
float2 texCoords = input.texCoord0;
#endif

#if _NORMALMAP
float3 normalTS = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords));
#if (SHADERPASS == SHADERPASS_DBUFFER)
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
#elif (SHADERPASS == SHADERPASS_DBUFFER_MESH)
float3 normalWS;
GetNormalWS(input, 0, normalTS, normalWS);
#endif

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


static public DecalData[] m_DecalDatas = new DecalData[kDecalBlockSize];
static public SFiniteLightBound[] m_Bounds = new SFiniteLightBound[kDecalBlockSize];
static public LightVolumeData[] m_LightVolumes = new LightVolumeData[kDecalBlockSize];
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 int m_DecalDatasCount = 0;
static public float[] m_BoundingDistances = new float[1];

{
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse;
m_DecalDatas[m_DecalDatasCount].normalToWorld = normalToWorldBatch[instanceCount];
m_DecalDatas[m_DecalDatasCount].diffuseScaleBias = m_Diffuse.m_ScaleBias;
m_DecalDatas[m_DecalDatasCount].normalScaleBias = m_Normal.m_ScaleBias;
m_DecalDatas[m_DecalDatasCount].maskScaleBias = m_Mask.m_ScaleBias;
// we have not allocated the textures in atlas yet, so only store references to them
m_DiffuseTextureScaleBias[m_DecalDatasCount] = m_Diffuse;
m_NormalTextureScaleBias[m_DecalDatasCount] = m_Normal;
m_MaskTextureScaleBias[m_DecalDatasCount] = m_Mask;
GetDecalVolumeDataAndBound(decalToWorldBatch[instanceCount], worldToView);
m_DecalDatasCount++;
anyAffectTransparency = true;

}
}
// only add if any projectors in this decal set affect transparency
// only add if any projectors in this decal set affect transparency, doesn't actually allocate textures in the atlas yet, this is because we want all the textures in the list so we can optimize the packing
if( anyAffectTransparency)
{
AddToTextureList(ref instance.m_TextureList);

}
}
private void UpdateDecalDatasWithAtlasInfo()
{
for (int decalDataIndex = 0; decalDataIndex < m_DecalDatasCount; decalDataIndex++)
{
m_DecalDatas[decalDataIndex].diffuseScaleBias = m_DiffuseTextureScaleBias[decalDataIndex].m_ScaleBias;
m_DecalDatas[decalDataIndex].normalScaleBias = m_NormalTextureScaleBias[decalDataIndex].m_ScaleBias;
m_DecalDatas[decalDataIndex].maskScaleBias = m_MaskTextureScaleBias[decalDataIndex].m_ScaleBias;
}
}
public void UpdateTextureAtlas(CommandBuffer cmd)
{
m_AllocationSuccess = true;

}
}
m_PrevAllocationSuccess = m_AllocationSuccess;
// now that textures have been stored in the atlas we can update their location info in decal data
UpdateDecalDatasWithAtlasInfo();
}
public void CreateDrawData()

m_DecalDatas = new DecalData[newDecalDatasSize];
m_Bounds = new SFiniteLightBound[newDecalDatasSize];
m_LightVolumes = new LightVolumeData[newDecalDatasSize];
m_DiffuseTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
m_NormalTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
m_MaskTextureScaleBias = new TextureScaleBias[newDecalDatasSize];
}
foreach (var pair in m_DecalSets)
{

2
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderPass/DecalSharePass.hlsl


#error Undefine_SHADERPASS
#endif
#if (SHADERPASS == SHADERPASS_MESHDECALS)
#if (SHADERPASS == SHADERPASS_DBUFFER_MESH)
#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_NEED_TANGENT // Always present as we require it also in case of anisotropic lighting
#define ATTRIBUTES_NEED_TEXCOORD0

4
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs


SubsurfaceScattering,
VolumeVoxelization,
VolumetricLighting,
DBuffer,
MeshDecals
DbufferProjector,
DbufferMesh
}
}

4
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs.hlsl


#define SHADERPASS_SUBSURFACE_SCATTERING (9)
#define SHADERPASS_VOLUME_VOXELIZATION (10)
#define SHADERPASS_VOLUMETRIC_LIGHTING (11)
#define SHADERPASS_DBUFFER (12)
#define SHADERPASS_MESHDECALS (13)
#define SHADERPASS_DBUFFER_PROJECTOR (12)
#define SHADERPASS_DBUFFER_MESH (13)
#endif

10
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassDBuffer.hlsl


#if (SHADERPASS != SHADERPASS_DBUFFER) && (SHADERPASS != SHADERPASS_MESHDECALS)
#if (SHADERPASS != SHADERPASS_DBUFFER_PROJECTOR) && (SHADERPASS != SHADERPASS_DBUFFER_MESH)
#error SHADERPASS_is_not_correctly_define
#endif

FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
DecalSurfaceData surfaceData;
#if (SHADERPASS == SHADERPASS_DBUFFER)
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, input.positionSS.xy).x;
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
// Transform from world space to decal space (DS) to clip the decal.

clip(1.0 - positionDS); // Clip value above one
float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(matrix, _NormalToWorld);
GetSurfaceData(positionDS.xz, normalToWorld, surfaceData);\
GetSurfaceData(positionDS.xz, normalToWorld, surfaceData);
#elif (SHADERPASS == SHADERPASS_MESHDECALS)
#elif (SHADERPASS == SHADERPASS_DBUFFER_MESH)
GetSurfaceData(input, surfaceData);
#endif
uint oldVal = UnpackByte(_DecalHTile[input.positionSS.xy / 8]);

#if (SHADERPASS == SHADERPASS_DBUFFER)
#if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR)
}
#endif
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
正在加载...
取消
保存