Julien Ignace 8 年前
当前提交
faec4157
共有 8 个文件被更改,包括 196 次插入1028 次删除
  1. 1001
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  2. 10
      Assets/ScriptableRenderLoop/fptl/TiledLightingTemplate.hlsl
  3. 29
      Assets/ScriptableRenderLoop/fptl/TiledLightingUtils.hlsl
  4. 11
      Assets/ScriptableRenderLoop/fptl/TiledReflectionTemplate.hlsl
  5. 9
      Assets/ScriptableRenderLoop/fptl/renderloopfptl.asset
  6. 146
      Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute
  7. 9
      Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute.meta
  8. 9
      Assets/Shaders.meta

1001
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
文件差异内容过多而无法显示
查看文件

10
Assets/ScriptableRenderLoop/fptl/TiledLightingTemplate.hlsl


return ExecuteLightList(start, numLights, vP, vPw, Vworld);
}
float3 ExecuteLightListTile(out uint numLightsProcessed, uint2 tileIDX, float3 vP, float3 vPw, float3 Vworld)
{
uint nrTilesX = (g_widthRT + 15) / 16; uint nrTilesY = (g_heightRT + 15) / 16;
uint start = 0, numLights = 0;
GetCountAndStart(start, numLights, tileIDX, nrTilesX, nrTilesY, vP.z, DIRECT_LIGHT);
numLightsProcessed = numLights; // mainly for debugging/heat maps
return ExecuteLightList(start, numLights, vP, vPw, Vworld);
}
#endif

29
Assets/ScriptableRenderLoop/fptl/TiledLightingUtils.hlsl


StructuredBuffer<SFiniteLightData> g_vLightData;
Buffer<uint> g_vLightListGlobal;
uniform float g_fClustScale;
uniform float g_fClustBase;
uniform float g_fNearPlane;
uniform float g_fFarPlane;
uniform int g_iLog2NumClusters; // We need to always define these to keep constant buffer layouts compatible
#include "ClusteredUtils.h"
Buffer<uint> g_vLayeredOffsetsBuffer;
Buffer<float> g_logBaseBuffer;
uniform uint g_isLogBaseBufferEnabled;
uniform uint g_isOpaquesOnlyEnabled;
void GetCountAndStartOpaque(out uint uStart, out uint uNrLights, uint2 tileIDX, int nrTilesX, int nrTilesY, float linDepth, uint model)
{
const int tileOffs = (tileIDX.y+model*nrTilesY)*nrTilesX+tileIDX.x;

}
#else
uniform float g_fClustScale;
uniform float g_fClustBase;
uniform float g_fNearPlane;
uniform float g_fFarPlane;
//uniform int g_iLog2NumClusters; // numClusters = (1<<g_iLog2NumClusters)
uniform int g_iLog2NumClusters;
#include "ClusteredUtils.h"
Buffer<uint> g_vLayeredOffsetsBuffer;
Buffer<float> g_logBaseBuffer;
uniform uint g_isLogBaseBufferEnabled;
uniform uint g_isOpaquesOnlyEnabled;
void GetCountAndStart(out uint uStart, out uint uNrLights, uint2 tileIDX, int nrTilesX, int nrTilesY, float linDepth, uint model)
{

11
Assets/ScriptableRenderLoop/fptl/TiledReflectionTemplate.hlsl


return ExecuteReflectionList(start, numReflectionProbes, vP, vNw, Vworld, smoothness);
}
float3 ExecuteReflectionListTile(out uint numReflectionProbesProcessed, uint2 tileIDX, float3 vP, float3 vNw, float3 Vworld, float smoothness)
{
uint nrTilesX = (g_widthRT + 15) / 16; uint nrTilesY = (g_heightRT + 15) / 16;
uint start = 0, numReflectionProbes = 0;
GetCountAndStart(start, numReflectionProbes, tileIDX, nrTilesX, nrTilesY, vP.z, REFLECTION_LIGHT);
numReflectionProbesProcessed = numReflectionProbes; // mainly for debugging/heat maps
return ExecuteReflectionList(start, numReflectionProbes, vP, vNw, Vworld, smoothness);
}
#endif

9
Assets/ScriptableRenderLoop/fptl/renderloopfptl.asset


deferredShader: {fileID: 4800000, guid: 1c102a89f3460254a8c413dbdcd63a2a, type: 3}
deferredReflectionShader: {fileID: 4800000, guid: 3899e06d641c2cb4cbff794df0da536b,
type: 3}
deferredComputeShader: {fileID: 7200000, guid: 6994e4f8a80d87b428cca7242cb32a0e,
type: 3}
finalPassShader: {fileID: 4800000, guid: 5590f54ad211f594da4e687b698f2258, type: 3}
debugLightBoundsShader: {fileID: 4800000, guid: 33f2a444e9120d34396d41e40795d712,
type: 3}

type: 3}
buildPerVoxelLightListShader: {fileID: 7200000, guid: 4c2d6eb0553e2514bba3ea9a85d8c53c,
type: 3}
enableClustered: 0
disableFptlWhenClustered: 0
enableClustered: 1
disableFptlWhenClustered: 1
enableDrawLightBoundsDebug: 0
enableDrawLightBoundsDebug: 1
enableComputeLightEvaluation: 1

146
Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute


#pragma kernel ShadeDeferred_Fptl SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=0
#pragma kernel ShadeDeferred_Clustered SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=0 //TODO: disabled clustered permutations so far as it leads to the error "All kernels must use same constant buffer layouts"
#pragma kernel ShadeDeferred_Fptl_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl_Debug USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=1
#pragma kernel ShadeDeferred_Clustered_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered_Debug USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=1
#define TILE_SIZE 8
// Hacks to get the header to compile in compute
#define SHADER_TARGET 50
#define UNITY_PBS_USE_BRDF1
#define fixed4 float4
#include "UnityLightingCommon.cginc"
#undef fixed4
float3 EvalMaterial(UnityLight light, UnityIndirect ind);
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind);
// uses the optimized single layered light list for opaques only
#ifdef USE_FPTL_LIGHTLIST
#define OPAQUES_ONLY
#endif
#include "TiledLightingTemplate.hlsl"
#include "TiledReflectionTemplate.hlsl"
Texture2D _CameraDepthTexture;
Texture2D _CameraGBufferTexture0;
Texture2D _CameraGBufferTexture1;
Texture2D _CameraGBufferTexture2;
Texture2D _CameraGBufferTexture3;
RWTexture2D<float4> uavOutput : register(u0);
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
v2f vert(float4 vertex : POSITION, float2 texcoord : TEXCOORD0)
{
v2f o;
o.vertex = UnityObjectToClipPos(vertex);
o.texcoord = texcoord.xy;
return o;
}
struct StandardData
{
float3 specularColor;
float3 diffuseColor;
float3 normalWorld;
float smoothness;
float occlusion;
float3 emission;
};
struct LocalDataBRDF
{
StandardData gbuf;
// extras
float oneMinusReflectivity;
float3 Vworld;
};
static LocalDataBRDF g_localParams;
StandardData UnityStandardDataFromGbufferAux(float4 gbuffer0, float4 gbuffer1, float4 gbuffer2, float4 gbuffer3)
{
StandardData data;
data.normalWorld = normalize(2 * gbuffer2.xyz - 1);
data.smoothness = gbuffer1.a;
data.diffuseColor = gbuffer0.xyz; data.specularColor = gbuffer1.xyz;
data.occlusion = gbuffer0.a;
data.emission = gbuffer3.xyz;
return data;
}
half3 BRDF3_Direct2(half3 diffColor, half3 specColor, half rlPow4, half smoothness)
{
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp
// Lookup texture to save instructions
half specular = tex2Dlod(unity_NHxRoughness, half4(rlPow4, SmoothnessToPerceptualRoughness(smoothness), 0, 0)).UNITY_ATTEN_CHANNEL * LUT_RANGE;
#if defined(_SPECULARHIGHLIGHTS_OFF)
specular = 0.0;
#endif
return diffColor + specular * specColor;
}
float3 EvalMaterial(UnityLight light, UnityIndirect ind)
{
StandardData data = g_localParams.gbuf;
return UNITY_BRDF_PBS(data.diffuseColor, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind);
}
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind)
{
StandardData data = g_localParams.gbuf;
return data.occlusion * UNITY_BRDF_PBS(0, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind).rgb;
}
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
void SHADE_DEFERRED_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)
{
uint2 pixCoord = dispatchThreadId;
float zbufDpth = FetchDepth(_CameraDepthTexture, pixCoord.xy).x;
float linDepth = GetLinearDepth(zbufDpth);
float3 vP = GetViewPosFromLinDepth(pixCoord, linDepth);
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
float4 gbuffer0 = _CameraGBufferTexture0.Load(uint3(pixCoord.xy, 0));
float4 gbuffer1 = _CameraGBufferTexture1.Load(uint3(pixCoord.xy, 0));
float4 gbuffer2 = _CameraGBufferTexture2.Load(uint3(pixCoord.xy, 0));
float4 gbuffer3 = _CameraGBufferTexture3.Load(uint3(pixCoord.xy, 0));
StandardData data = UnityStandardDataFromGbufferAux(gbuffer0, gbuffer1, gbuffer2, gbuffer3);
g_localParams.gbuf = data;
g_localParams.oneMinusReflectivity = 1.0 - SpecularStrength(data.specularColor.rgb);
g_localParams.Vworld = Vworld;
uint2 tileCoord = groupId >> 1;
uint numLightsProcessed = 0;
float3 c = data.emission + ExecuteLightListTile(numLightsProcessed, tileCoord, vP, vPw, Vworld);
uint numReflectionsProcessed = 0;
c += ExecuteReflectionListTile(numReflectionsProcessed, tileCoord, vP, data.normalWorld, Vworld, data.smoothness);
#if ENABLE_DEBUG
c = OverlayHeatMap(pixCoord & 15, numLightsProcessed, c);
#endif
uavOutput[pixCoord] = float4(c, 1.0);
}

9
Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute.meta


fileFormatVersion: 2
guid: 6994e4f8a80d87b428cca7242cb32a0e
timeCreated: 1478685321
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/Shaders.meta


fileFormatVersion: 2
guid: f449d3af78d5535459739664d3d41d1e
folderAsset: yes
timeCreated: 1476191704
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存