浏览代码

mesh decals somewhat working

/main
Paul Melamed 6 年前
当前提交
6459cbb2
共有 8 个文件被更改,包括 83 次插入11 次删除
  1. 7
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipeline.cs
  2. 2
      com.unity.render-pipelines.high-definition/HDRP/HDStringConstants.cs
  3. 23
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  4. 29
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalData.hlsl
  5. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderPass/DecalSharePass.hlsl
  6. 3
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs
  7. 1
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPass.cs.hlsl
  8. 21
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassDBuffer.hlsl

7
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipeline.cs


return;
using (new ProfilingSample(cmd, "DBufferRender", CustomSamplerId.DBufferRender.GetSampler()))
{
{
// We need to copy depth buffer texture if we want to bind it at this stage
CopyDepthBufferIfNeeded(cmd);

HDUtils.SetRenderTarget(cmd, hdCamera, m_DbufferManager.GetBuffersRTI(), m_CameraDepthStencilBuffer); // do not clear anymore
m_DbufferManager.SetHTile(m_DbufferManager.bufferCount, cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
DrawRendererSettings drawSettings = new DrawRendererSettings(hdCamera.camera, HDShaderPassNames.s_EmptyName)
{
rendererConfiguration = 0,

};
renderContext.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterRenderersSettings);
// DecalSystem.instance.RenderIntoDBuffer(cmd);
DecalSystem.instance.RenderIntoDBuffer(cmd);
m_DbufferManager.UnSetHTile(cmd);
m_DbufferManager.SetHTileTexture(cmd); // mask per 8x8 tile used for optimization when looking up dbuffer values
}

2
com.unity.render-pipelines.high-definition/HDRP/HDStringConstants.cs


public static readonly string s_TransparentDepthPostpassStr = "TransparentDepthPostpass";
public static readonly string s_MetaStr = "Meta";
public static readonly string s_ShadowCasterStr = "ShadowCaster";
public static readonly string s_MeshDecalsStr = "DBuffer";
public static readonly string s_MeshDecalsStr = "MeshDecals";
// ShaderPass name
public static readonly ShaderPassName s_EmptyName = new ShaderPassName(s_EmptyStr);

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


ENDHLSL
}
Pass
{
Name "MeshDecals" // Name is not used
Tags{"LightMode" = "MeshDecals"} // This will be only for opaque object based on the RenderQueue index
Cull Back
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html
Blend SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
HLSLPROGRAM
#define SHADERPASS SHADERPASS_MESHDECALS
#include "../../ShaderVariables.hlsl"
#include "Decal.hlsl"
#include "ShaderPass/DecalSharePass.hlsl"
#include "DecalData.hlsl"
#include "../../ShaderPass/ShaderPassDBuffer.hlsl"
ENDHLSL
}
}
CustomEditor "Experimental.Rendering.HDPipeline.DecalUI"
}

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


#include "CoreRP/ShaderLibrary/Packing.hlsl"
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#if (SHADERPASS == SHADERPASS_DBUFFER)
void GetSurfaceData(float2 texCoordDS, float4x4 normalToWorld, out DecalSurfaceData surfaceData)
{
surfaceData.baseColor = float4(0,0,0,0);

surfaceData.HTileMask |= DBUFFERHTILEBIT_MASK;
#endif
}
#endif
#if (SHADERPASS == SHADERPASS_MESHDECALS)
void GetSurfaceData(float2 texCoordDS, out DecalSurfaceData surfaceData)
{
surfaceData.baseColor = float4(0, 0, 0, 0);
surfaceData.normalWS = float4(0, 0, 0, 0);
surfaceData.mask = float4(0, 0, 0, 0);
surfaceData.HTileMask = 0;
float totalBlend = 1.0f;
#if _COLORMAP
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy);
surfaceData.baseColor.w *= totalBlend;
totalBlend = surfaceData.baseColor.w; // base alpha affects all other channels;
surfaceData.HTileMask |= DBUFFERHTILEBIT_DIFFUSE;
#endif
#if _NORMALMAP
surfaceData.normalWS.xyz = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoordDS)) * 0.5f + 0.5f;
surfaceData.normalWS.w = totalBlend;
surfaceData.HTileMask |= DBUFFERHTILEBIT_NORMAL;
#endif
#if _MASKMAP
surfaceData.mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, texCoordDS.xy);
surfaceData.mask.z = surfaceData.mask.w;
surfaceData.mask.w = totalBlend;
surfaceData.HTileMask |= DBUFFERHTILEBIT_MASK;
#endif
}
#endif

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


#error Undefine_SHADERPASS
#endif
#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_NEED_TANGENT // Always present as we require it also in case of anisotropic lighting
#define ATTRIBUTES_NEED_TEXCOORD0
#define VARYINGS_NEED_POSITION_WS
#define VARYINGS_NEED_TANGENT_TO_WORLD
#define VARYINGS_NEED_TEXCOORD0
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

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


SubsurfaceScattering,
VolumeVoxelization,
VolumetricLighting,
DBuffer
DBuffer,
MeshDecals
}
}

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


#define SHADERPASS_VOLUME_VOXELIZATION (10)
#define SHADERPASS_VOLUMETRIC_LIGHTING (11)
#define SHADERPASS_DBUFFER (12)
#define SHADERPASS_MESHDECALS (13)
#endif

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


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

)
{
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
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);
DecalSurfaceData surfaceData;
#if (SHADERPASS == SHADERPASS_DBUFFER)
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.
// For this we must use absolute position.
// There is no lose of precision here as it doesn't involve the camera matrix

clip(positionDS); // clip negative value
clip(1.0 - positionDS); // Clip value above one
DecalSurfaceData surfaceData;
float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(matrix, _NormalToWorld);
GetSurfaceData(positionDS.xz, normalToWorld, surfaceData);

oldVal |= surfaceData.HTileMask;
_DecalHTile[posInput.positionSS.xy / 8] = PackByte(oldVal);
}
#endif
#if (SHADERPASS == SHADERPASS_MESHDECALS)
GetSurfaceData(input.texCoord0, surfaceData);
uint oldVal = UnpackByte(_DecalHTile[input.positionSS.xy / 8]);
oldVal |= surfaceData.HTileMask;
_DecalHTile[input.positionSS.xy / 8] = PackByte(oldVal);
#endif
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
}
正在加载...
取消
保存