浏览代码

Added missing files from initial commit.

/main
uygar 8 年前
当前提交
2a8f7eaa
共有 10 个文件被更改,包括 216 次插入6 次删除
  1. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  2. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs
  3. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl
  4. 177
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
  6. 17
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  7. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
  8. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  9. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl
  10. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl

3
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


}
else
{
ShadowOutput shadows;
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{

using (new Utilities.ProfilingSample("Build Light list", renderContext))
{
m_lightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera, ref shadows);
m_lightLoop.RenderShadows(renderContext, cullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
}

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void NewFrame() {}
public virtual void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput) { }
public virtual void RenderShadows( ScriptableRenderContext renderContext, CullResults cullResults ) { }
// TODO: this should not be part of the interface but for now make something working
public virtual void BuildGPULightLists(Camera camera, ScriptableRenderContext loop, RenderTargetIdentifier cameraDepthBufferRT) { }

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl


#define HAS_LIGHTLOOP // Allow to not define LightLoop related function in Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/Shadow.hlsl"
#if defined(LIGHTLOOP_SINGLE_PASS) || defined(LIGHTLOOP_TILE_PASS)
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl"

#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/Shadow.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"
// LightLoop use evaluation BSDF function for light type define in Material.hlsl

177
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


#define SHADOWS_ENABLED
#define SHADOWS_FIXSHADOWIDX
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering.HDPipeline
{
#if SHADOWS_ENABLED
using ShadowExp;
#endif
namespace TilePass
{
//-----------------------------------------------------------------------------

const int k_TileSize = 16;
private readonly HDRenderPipeline m_Parent;
#if (SHADOWS_ENABLED)
// shadow related stuff
const int k_MaxShadowDataSlots = 64;
const int k_MaxPayloadSlotsPerShadowData = 16;
FrameId m_frameId;
ShadowmapBase m_Shadowmap;
IShadowManager m_ShadowMgr;
static ComputeBuffer s_ShadowDataBuffer;
static ComputeBuffer s_ShadowPayloadBuffer;
uint m_ShadowDatasCount;
ShadowExp.ShadowData[] m_ShadowDatas;
uint m_ShadowPayloadsCount;
int[] m_ShadowPayloads;
List<int> m_ShadowRequests = new List<int>();
Dictionary<int, int> m_ShadowIndices = new Dictionary<int,int>();
void InitShadowSystem( ShadowSettings shadowSettings )
{
s_ShadowDataBuffer = new ComputeBuffer( k_MaxShadowDataSlots, System.Runtime.InteropServices.Marshal.SizeOf( typeof( ShadowExp.ShadowData ) ) );
s_ShadowPayloadBuffer = new ComputeBuffer( k_MaxShadowDataSlots * k_MaxPayloadSlotsPerShadowData, System.Runtime.InteropServices.Marshal.SizeOf( typeof( int ) ) );
ShadowAtlas.AtlasInit atlasInit;
atlasInit.baseInit.width = (uint) shadowSettings.shadowAtlasWidth;
atlasInit.baseInit.height = (uint) shadowSettings.shadowAtlasHeight;
atlasInit.baseInit.slices = 1;
atlasInit.baseInit.shadowmapBits = 32;
atlasInit.baseInit.shadowmapFormat = RenderTextureFormat.Shadowmap;
atlasInit.baseInit.clearColor = new Vector4( 0.0f, 0.0f, 0.0f, 0.0f );
atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.shaderKeyword = null;
atlasInit.cascadeCount = shadowSettings.directionalLightCascadeCount;
atlasInit.cascadeRatios = shadowSettings.directionalLightCascades;
m_Shadowmap = new ShadowExp.ShadowAtlas( ref atlasInit );
ShadowContext.SyncDel syncer = (ShadowContext sc) =>
{
// update buffers
uint offset, count;
ShadowExp.ShadowData[] sds;
sc.GetShadowDatas( out sds, out offset, out count );
s_ShadowDataBuffer.SetData( sds ); // unfortunately we can't pass an offset or count to this function
int[] payloads;
sc.GetPayloads( out payloads, out offset, out count );
payloads[0] = 5;
s_ShadowPayloadBuffer.SetData(payloads);
};
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb ) =>
{
// bind buffers
cb.SetGlobalBuffer( "_ShadowDatasExp", s_ShadowDataBuffer );
cb.SetGlobalBuffer( "_ShadowPayloads", s_ShadowPayloadBuffer );
// bind textures
uint offset, count;
RenderTargetIdentifier[] tex;
sc.GetTex2DArrays( out tex, out offset, out count );
cb.SetGlobalTexture( "_ShadowmapExp", tex[0] );
//cb.SetGlobalTexture( "_ShadowmapMomentum", tex[1] );
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
};
ShadowContext.CtxtInit scInit;
scInit.storage.maxShadowDataSlots = k_MaxShadowDataSlots;
scInit.storage.maxPayloadSlots = k_MaxShadowDataSlots * k_MaxPayloadSlotsPerShadowData;
scInit.storage.maxTex2DArraySlots = 4;
scInit.storage.maxTexCubeArraySlots = 1;
scInit.storage.maxComparisonSamplerSlots = 1;
scInit.storage.maxSamplerSlots = 1;
scInit.dataSyncer = syncer;
scInit.resourceBinder = binder;
m_ShadowMgr = new ShadowExp.ShadowManager(shadowSettings, ref scInit, m_Shadowmap);
}
void DeinitShadowSystem()
{
if( m_Shadowmap != null )
{
(m_Shadowmap as ShadowAtlas).Dispose();
m_Shadowmap = null;
}
m_ShadowMgr = null;
Utilities.SafeRelease( s_ShadowDataBuffer );
Utilities.SafeRelease( s_ShadowPayloadBuffer );
}
#endif
int GetNumTileX(Camera camera)
{

#if UNITY_EDITOR
UnityEditor.SceneView.onSceneGUIDelegate -= OnSceneGUI;
UnityEditor.SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
#if (SHADOWS_ENABLED)
InitShadowSystem(ShadowSettings.Default);
#endif
}

if (cullResults.visibleLights.Length == 0 && cullResults.visibleReflectionProbes.Length == 0)
return;
#if (SHADOWS_ENABLED)
// 0. deal with shadows
{
m_frameId.frameCount++;
// get the indices for all lights that want to have shadows
m_ShadowRequests.Clear();
m_ShadowRequests.Capacity = cullResults.visibleLights.Length;
int lcnt = cullResults.visibleLights.Length;
for( int i = 0; i < lcnt; ++i )
{
if( cullResults.visibleLights[i].light.shadows != LightShadows.None )
m_ShadowRequests.Add( i );
}
// pass this list to a routine that assigns shadows based on some heuristic
uint shadowRequestCount = (uint) m_ShadowRequests.Count;
int[] shadowRequests = m_ShadowRequests.ToArray();
int[] shadowDataIndices;
uint originalRequestCount = shadowRequestCount;
m_ShadowMgr.ProcessShadowRequests( m_frameId, cullResults, camera, cullResults.visibleLights,
ref shadowRequestCount, shadowRequests, out shadowDataIndices );
// update the visibleLights with the shadow information
m_ShadowIndices.Clear();
for( uint i = 0; i < shadowRequestCount; i++ )
{
m_ShadowIndices.Add( shadowRequests[i], shadowDataIndices[i] );
}
}
#endif
// 1. Count the number of lights and sort all light by category, type and volume
int directionalLightcount = 0;
int punctualLightcount = 0;

}
}
#if (SHADOWS_ENABLED)
uint shadow = m_ShadowIndices.ContainsKey( lightIndex ) ? 1u : 0;
// 5 bit (0x1F) light category, 5 bit (0x1F) GPULightType, 5 bit (0x1F) lightVolume, 1 bit for shadow casting, 16 bit index
sortKeys[sortCount++] = (uint)lightCategory << 27 | (uint)gpuLightType << 22 | (uint)lightVolumeType << 17 | shadow << 16 | (uint)lightIndex;
#else
#endif
}
Array.Sort(sortKeys);

uint sortKey = sortKeys[sortIndex];
LightCategory lightCategory = (LightCategory)((sortKey >> 27) & 0x1F);
GPULightType gpuLightType = (GPULightType)((sortKey >> 22) & 0x1F);
#if (SHADOWS_ENABLED)
LightVolumeType lightVolumeType = (LightVolumeType)((sortKey >> 17) & 0x1F);
#else
#endif
int lightIndex = (int)(sortKey & 0xFFFF);
var light = cullResults.visibleLights[lightIndex];

{
GetDirectionalLightData(shadowSettings, gpuLightType, light, additionalData, lightIndex, ref shadowOutput, ref directionalShadowcount);
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information (TODO: Directional bails early, need to fix up that one as well)
int shadowIdxDir;
if( m_ShadowIndices.TryGetValue( lightIndex, out shadowIdxDir ) )
{
var lightData = m_lightList.directionalLights[m_lightList.directionalLights.Count-1];
lightData.shadowIndex = shadowIdxDir;
m_lightList.directionalLights[m_lightList.directionalLights.Count-1] = lightData;
}
#endif
continue;
}

GetLightVolumeDataAndBound(lightCategory, gpuLightType, lightVolumeType, light, m_lightList.lights[m_lightList.lights.Count - 1], worldToView);
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information (TODO: Directional bails early, need to fix up that one as well)
int shadowIdx;
if( m_ShadowIndices.TryGetValue( lightIndex, out shadowIdx ) )
{
var lightData = m_lightList.lights[m_lightList.lights.Count-1];
lightData.shadowIndex = shadowIdx;
m_lightList.lights[m_lightList.lights.Count-1] = lightData;
}
#endif
}
// Sanity check

{
var probe = cullResults.visibleReflectionProbes[probeIndex];
if (envLightCount >= k_MaxEnvLightsOnScreen)
// probe.texture can be null when we are adding a reflection probe in the editor
if (probe.texture == null || envLightCount >= k_MaxEnvLightsOnScreen)
continue;
// TODO: Support LightVolumeType.Sphere, currently in UI there is no way to specify a sphere influence volume

private void BindGlobalParams(CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, Camera camera, ScriptableRenderContext loop)
{
#if (SHADOWS_ENABLED)
m_ShadowMgr.BindResources(loop);
#endif
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd);
SetGlobalTexture("_CookieTextures", m_CookieTexArray.GetTexCache());

s_ConvexBoundsBuffer.SetData(m_lightList.bounds.ToArray());
s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes.ToArray());
#if (SHADOWS_ENABLED)
// Shadows
m_ShadowMgr.SyncData();
#endif
BindGlobalParams(cmd, null, 0, camera, loop);
SetGlobalPropertyRedirect(null, 0, null);

m_mousePosition = Event.current.mousePosition;
}
#endif
public override void RenderShadows( ScriptableRenderContext renderContext, CullResults cullResults )
{
#if (SHADOWS_ENABLED)
// kick off the shadow jobs here
m_ShadowMgr.RenderShadows( m_frameId, renderContext, cullResults, cullResults.visibleLights );
#endif
}
public override void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT)
{

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl


{
int sampleShadow;
int sampleReflection;
#ifdef SHADOWS_USE_SHADOWCTXT
ShadowContext shadowContext;
#endif
#ifndef SHADOWS_USE_SHADOWCTXT
//-----------------------------------------------------------------------------
// Shadow sampling function
// ----------------------------------------------------------------------------

return uint(4.0 - dot(weights, float4(4.0, 3.0, 2.0, 1.0)));
}
float GetDirectionalShadowAttenuation(LightLoopContext lightLoopContext, float3 positionWS, int index, float3 L, float2 unPositionSS)
{

return flSum;
}
#endif
//-----------------------------------------------------------------------------
// Cookie sampling functions

17
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


out float3 specularLighting)
{
LightLoopContext context;
#ifndef SHADOWS_USE_SHADOWCTXT
#else
context.sampleShadow = 0;
context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
#endif
diffuseLighting = float3(0.0, 0.0, 0.0);
specularLighting = float3(0.0, 0.0, 0.0);

uint punctualLightStart;
uint punctualLightCount;
GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, punctualLightStart, punctualLightCount);
for (i = 0; i < punctualLightCount; ++i)
for (i = 0; i < punctualLightCount; ++i)
{
float3 localDiffuseLighting, localSpecularLighting;

out float3 specularLighting)
{
LightLoopContext context;
ZERO_INITIALIZE(LightLoopContext, context);
#ifndef SHADOWS_USE_SHADOWCTXT
ZERO_INITIALIZE(LightLoopContext, context);
#else
context.sampleShadow = 0;
context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
#endif
diffuseLighting = float3(0.0, 0.0, 0.0);
specularLighting = float3(0.0, 0.0, 0.0);

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl


[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0)
{
#ifdef SHADOWS_USE_SHADOWCTXT
float shadowAttenuation = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, lightData.shadowIndex, L, posInput.unPositionSS);
#else
#endif
illuminance *= shadowAttenuation;
}

[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0)
{
float3 offset = float3(0.0, 0.0, 0.0); // GetShadowPosOffset(nDotL, normal);
float shadowAttenuation = GetPunctualShadowAttenuation(lightLoopContext, lightData.lightType, positionWS + offset, lightData.shadowIndex, L, posInput.unPositionSS);
#ifdef SHADOWS_USE_SHADOWCTXT
float shadowAttenuation = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS + offset, lightData.shadowIndex, L, posInput.unPositionSS);
#else
float shadowAttenuation = GetPunctualShadowAttenuation(lightLoopContext, lightData.lightType, positionWS + offset, lightData.shadowIndex, L, posInput.unPositionSS);
#endif
shadowAttenuation = lerp(1.0, shadowAttenuation, lightData.shadowDimmer);
illuminance *= shadowAttenuation;

1
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord3).xyz, (coord3).w)
#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D

1
Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl


#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord3).xyz, (coord3).w)
#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D

1
Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl


#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord3).xyz, (coord3).w)
#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D

正在加载...
取消
保存