浏览代码

added code to bind shadow resources to compute shaders

/RenderPassXR_Sandbox
runes 7 年前
当前提交
3c1116f3
共有 4 个文件被更改,包括 38 次插入22 次删除
  1. 4
      Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  2. 8
      Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs
  3. 4
      Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs
  4. 44
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs

4
Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs


m_ShadowCtxt.SyncData();
}
public override void BindResources(CommandBuffer cmd)
public override void BindResources(CommandBuffer cmd, ComputeShader computeShader, int computeKernel)
{
foreach (var sm in m_Shadowmaps)
{

m_ShadowCtxt.BindResources(cmd);
m_ShadowCtxt.BindResources(cmd, computeShader, computeKernel);
cmd.EndSample("Bind resources to GPU");
}

8
Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs


public class ShadowContext : ShadowContextStorage
{
public delegate void SyncDel( ShadowContext sc );
public delegate void BindDel( ShadowContext sc, CommandBuffer cb );
public delegate void BindDel( ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel);
public struct CtxtInit
{
public Init storage;

// delegate that takes care of syncing data to the GPU
public void SyncData() { m_DataSyncerDel( this ); }
// delegate that takes care of binding textures, buffers and samplers to shaders just before rendering
public void BindResources( CommandBuffer cb ) { m_ResourceBinderDel( this, cb ); }
public void BindResources( CommandBuffer cb, ComputeShader computeShader, int computeKernel) { m_ResourceBinderDel( this, cb, computeShader, computeKernel); }
// the following functions are to be used by the bind and sync delegates
public void GetShadowDatas( out ShadowData[] shadowDatas, out uint offset, out uint count ) { shadowDatas = m_ShadowDatas.AsArray( out offset, out count ); }

// Synchronize data with GPU buffers
void SyncData();
// Binds resources to shader stages just before rendering the lighting pass
void BindResources( CommandBuffer cmd );
void BindResources( CommandBuffer cmd, ComputeShader computeShader, int computeKernel);
// Fixes up some parameters within the cullResults
void UpdateCullingParameters( ref ScriptableCullingParameters cullingParams );

public abstract void DisplayShadow(CommandBuffer cmd, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void DisplayShadowMap(CommandBuffer cmd, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void SyncData();
public abstract void BindResources( CommandBuffer cmd );
public abstract void BindResources( CommandBuffer cmd, ComputeShader computeShader, int computeKernel);
public abstract void UpdateCullingParameters( ref ScriptableCullingParameters cullingParams );
// sort the shadow requests in descending priority - may only modify shadowRequests
protected abstract void PrioritizeShadowCasters( Camera camera, List<VisibleLight> lights, uint shadowRequestsCount, int[] shadowRequests );

4
Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs


};
// binding code. This needs to be in sync with ShadowContext.hlsl
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb) =>
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel) =>
{
// bind buffers
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);

CommandBuffer cmdShadow = CommandBufferPool.Get();
m_ShadowMgr.RenderShadows( m_FrameId, loop, cmdShadow, cullResults, cullResults.visibleLights );
m_ShadowMgr.SyncData();
m_ShadowMgr.BindResources( cmdShadow );
m_ShadowMgr.BindResources( cmdShadow, null, 0 );
loop.ExecuteCommandBuffer(cmdShadow);
CommandBufferPool.Release(cmdShadow);

44
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


};
// binding code. This needs to be in sync with ShadowContext.hlsl
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb) =>
{
// bind buffers
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);
cb.SetGlobalBuffer("_ShadowPayloads", s_ShadowPayloadBuffer);
// bind textures
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel) =>
{
sc.GetTex2DArrays( out tex, out offset, out count );
cb.SetGlobalTexture( "_ShadowmapExp_VSM_0", tex[0] );
cb.SetGlobalTexture( "_ShadowmapExp_VSM_1", tex[1] );
cb.SetGlobalTexture( "_ShadowmapExp_VSM_2", tex[2] );
cb.SetGlobalTexture( "_ShadowmapExp_PCF" , tex[3] );
sc.GetTex2DArrays(out tex, out offset, out count);
if(computeShader)
{
// bind buffers
cb.SetComputeBufferParam(computeShader, computeKernel, "_ShadowDatasExp", s_ShadowDataBuffer);
cb.SetComputeBufferParam(computeShader, computeKernel, "_ShadowPayloads", s_ShadowPayloadBuffer);
// bind textures
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_0", tex[0]);
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_1", tex[1]);
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_2", tex[2]);
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_PCF", tex[3]);
}
else
{
// bind buffers
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);
cb.SetGlobalBuffer("_ShadowPayloads", s_ShadowPayloadBuffer);
// bind textures
cb.SetGlobalTexture("_ShadowmapExp_VSM_0", tex[0]);
cb.SetGlobalTexture("_ShadowmapExp_VSM_1", tex[1]);
cb.SetGlobalTexture("_ShadowmapExp_VSM_2", tex[2]);
cb.SetGlobalTexture("_ShadowmapExp_PCF", tex[3]);
}
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
};

s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
}
private void BindGlobalParams(CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, Camera camera)
private void BindGlobalParams(CommandBuffer cmd, Camera camera)
m_ShadowMgr.BindResources(cmd);
m_ShadowMgr.BindResources(cmd, activeComputeShader, activeComputeKernel);
SetGlobalBuffer("g_vLightListGlobal", !usingFptl ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)

m_ShadowMgr.SyncData();
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd);
BindGlobalParams(cmd, computeShader, kernelIndex, camera);
BindGlobalParams(cmd, camera);
SetGlobalPropertyRedirect(null, 0, null);
}
}

正在加载...
取消
保存