浏览代码

Decals work with master and trunk

/Add-support-for-light-specular-color-tint
Paul Melamed 7 年前
当前提交
dd2f4c60
共有 10 个文件被更改,包括 20 次插入31 次删除
  1. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
  3. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
  7. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl
  9. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  10. 9
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl

2
ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl


#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r

3
ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs


internal HashSet<DecalProjectorComponent> m_Decals = new HashSet<DecalProjectorComponent>();
Mesh m_CubeMesh;
private static readonly int m_WorldToDecal = Shader.PropertyToID("_WorldToDecal");
private static readonly int m_DecalToWorldR = Shader.PropertyToID("_DecalToWorldR");
public DecalSystem()
{
CreateCubeMesh();

9
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


for (int dbufferIndex = 0; dbufferIndex < dbufferCount; ++dbufferIndex)
{
cmd.ReleaseTemporaryRT(HDShaderIDs._DBufferTexture[dbufferIndex]);
cmd.GetTemporaryRT(HDShaderIDs._DBufferTexture[dbufferIndex], width, height, 0, FilterMode.Point, rtFormat[dbufferIndex], rtReadWrite[dbufferIndex]);
m_RTIDs[dbufferIndex] = new RenderTargetIdentifier(HDShaderIDs._DBufferTexture[dbufferIndex]);
}

}
ConfigureForShadowMask(enableBakeShadowMask, cmd);
InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
RenderDepthPrepass(m_CullResults, camera, renderContext, cmd, true);
InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, true);
RenderDBuffer(hdCamera.cameraPos, renderContext, cmd);
RenderDBuffer(hdCamera.cameraPos, renderContext, cmd);
RenderGBuffer(m_CullResults, hdCamera, renderContext, cmd);

{
Color clearColor = new Color(0,0,0,0);
CoreUtils.SetRenderTarget(cmd, m_DbufferManager.GetDBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.Color, clearColor);
cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, GetDepthTexture());
cmd.SetGlobalTexture(HDShaderIDs._MainDepthTexture, GetDepthTexture());
DecalSystem.instance.Render(renderContext, cameraPos, cmd);
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs


// DBuffer management
//-----------------------------------------------------------------------------
// should this be rolled into common class shared with Lit.cs???
// should this be combined into common class shared with Lit.cs???
static public void GetMaterialDBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite)
{

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl


{
ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
surfaceData.baseColor = inDBuffer0;
surfaceData.normalWS = inDBuffer1 * float4(2.0f, 2.0f, 2.0f, 1.0f) - float4(1.0f, 1.0f, 1.0f, 0.0f);
surfaceData.normalWS.xyz = inDBuffer1.xyz * 2.0f - 1.0f;
surfaceData.normalWS.w = inDBuffer1.w;
}

9
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader


// Include
//-------------------------------------------------------------------------------------
#include "../../../Core/ShaderLibrary/Common.hlsl"
#include "../../../Core/ShaderLibrary/Wind.hlsl"
#include "ShaderLibrary/Common.hlsl"
#include "ShaderLibrary/Wind.hlsl"
#include "../../ShaderPass/FragInputs.hlsl"
#include "../../ShaderPass/ShaderPass.cs.hlsl"

Name "DBuffer" // Name is not used
Tags { "LightMode" = "dBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull Back
// need to optimize this and use proper Cull and ZTest modes for cases when decal geometry is clipped by camera
Cull Off
ZTest LEqual
ZTest Always
HLSLPROGRAM

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


//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function
//-------------------------------------------------------------------------------------
#include "../../../Core/ShaderLibrary/Packing.hlsl"
#include "../../../Core/ShaderLibrary/SampleUVMapping.hlsl"
#include "ShaderLibrary/Packing.hlsl"
#include "ShaderLibrary/SampleUVMapping.hlsl"
void GetSurfaceData(float2 texCoordDS, out DecalSurfaceData surfaceData)
{

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


SAMPLER2D(sampler_BaseColorMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
float _DecalBlend;

7
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


#include "ShaderLibrary/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
#include "../../../Core/ShaderLibrary/SampleUVMapping.hlsl"
#include "ShaderLibrary/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
#include "../Decal/DecalUtilities.hlsl"

// Caution: surfaceData must be fully initialize before calling GetBuiltinData
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData);
AddDecalContribution(posInput.unPositionSS, surfaceData);
AddDecalContribution(posInput.positionSS, surfaceData);
}
#include "LitDataMeshModification.hlsl"

9
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl


OUTPUT_DBUFFER(outDBuffer)
)
{
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
PositionInputs posInput = GetPositionInput(packedInput.vmesh.positionCS, _ScreenSize.zw);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, posInput.positionSS.xy);
UpdatePositionInput(d, _InvViewProjMatrix, _ViewProjMatrix, posInput);
float d = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x;
UpdatePositionInput(d, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput);
float3 positionWS = posInput.positionWS;
float3 positionDS = mul(_WorldToDecal, float4(positionWS, 1.0f)).xyz;

正在加载...
取消
保存