浏览代码
unified lighttemplate code for deferred and tiled forward with callback to material function
unified lighttemplate code for deferred and tiled forward with callback to material function
unified lighttemplate code for deferred and tiled forward with callback to material function Need to do the same for reflection next/main
mmikk
8 年前
当前提交
d62f5fd8
共有 6 个文件被更改,包括 289 次插入 和 512 次删除
-
38Assets/ScriptableRenderLoop/fptl/ClusteredUtils.h
-
57Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
456Assets/ScriptableRenderLoop/fptl/Internal-DeferredShading.shader
-
71Assets/ScriptableRenderLoop/fptl/TiledLightingTemplate.hlsl
-
17Assets/ScriptableRenderLoop/fptl/UnityStandardForwardNew.cginc
-
162Assets/ScriptableRenderLoop/fptl/TiledLightingUtils.hlsl
|
|||
#ifndef __TILEDLIGHTINGTEMPLATE_H__ |
|||
#define __TILEDLIGHTINGTEMPLATE_H__ |
|||
|
|||
uint FetchIndex(const uint tileOffs, const uint l); |
|||
uniform float4x4 g_mViewToWorld; |
|||
uniform float4x4 g_mScrProjection; |
|||
|
|||
#include "TiledLightingUtils.hlsl" |
|||
void GetLightCountAndStart(out uint uStart, out uint uNrLights, uint2 tileIDX, int nrTilesX, int nrTilesY, float linDepth); |
|||
|
|||
uniform uint g_widthRT; |
|||
uniform uint g_heightRT; |
|||
float3 ExecuteLightListTiled(uint2 pixCoord, float3 vP, float3 vPw, float3 Vworld) |
|||
float3 ExecuteLightListTiled(out uint numLightsProcessed, uint2 pixCoord, float3 vP, float3 vPw, float3 Vworld) |
|||
GetLightCountAndStart(start, numLights, tileIDX, nrTilesX, nrTilesY, vP.z); |
|||
GetCountAndStart(start, numLights, tileIDX, nrTilesX, nrTilesY, vP.z, DIRECT_LIGHT); |
|||
numLightsProcessed = numLights; // mainly for debugging/heat maps |
|||
|
|||
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 float g_fLog2NumClusters; |
|||
static int g_iLog2NumClusters; |
|||
|
|||
#include "ClusteredUtils.h" |
|||
|
|||
StructuredBuffer<uint> g_vLightListGlobal; |
|||
Buffer<uint> g_vLayeredOffsetsBuffer; |
|||
#ifdef ENABLE_DEPTH_TEXTURE_BACKPLANE |
|||
Buffer<float> g_logBaseBuffer; |
|||
#endif |
|||
|
|||
|
|||
void GetLightCountAndStart(out uint uStart, out uint uNrLights, uint2 tileIDX, int nrTilesX, int nrTilesY, float linDepth) |
|||
{ |
|||
g_iLog2NumClusters = (int) g_fLog2NumClusters; |
|||
#ifdef ENABLE_DEPTH_TEXTURE_BACKPLANE |
|||
float logBase = g_logBaseBuffer[tileIDX.y*nrTilesX + tileIDX.x]; |
|||
#else |
|||
float logBase = g_fClustBase; |
|||
#endif |
|||
int clustIdx = SnapToClusterIdx(linDepth, logBase); |
|||
|
|||
int nrClusters = (1<<g_iLog2NumClusters); |
|||
const int idx = ((DIRECT_LIGHT*nrClusters + clustIdx)*nrTilesY + tileIDX.y)*nrTilesX + tileIDX.x; |
|||
uint dataPair = g_vLayeredOffsetsBuffer[idx]; |
|||
uStart = dataPair&0x7ffffff; |
|||
uNrLights = (dataPair>>27)&31; |
|||
} |
|||
|
|||
uint FetchIndex(const uint tileOffs, const uint l) |
|||
{ |
|||
return g_vLightListGlobal[ tileOffs+l ]; |
|||
} |
|||
|
|||
|
|||
float3 GetViewPosFromLinDepth(float2 v2ScrPos, float fLinDepth) |
|||
{ |
|||
float fSx = g_mScrProjection[0].x; |
|||
//float fCx = g_mScrProjection[2].x; |
|||
float fCx = g_mScrProjection[0].z; |
|||
float fSy = g_mScrProjection[1].y; |
|||
//float fCy = g_mScrProjection[2].y; |
|||
float fCy = g_mScrProjection[1].z; |
|||
|
|||
#ifdef LEFT_HAND_COORDINATES |
|||
return fLinDepth*float3( ((v2ScrPos.x-fCx)/fSx), ((v2ScrPos.y-fCy)/fSy), 1.0 ); |
|||
#else |
|||
return fLinDepth*float3( -((v2ScrPos.x+fCx)/fSx), -((v2ScrPos.y+fCy)/fSy), 1.0 ); |
|||
#endif |
|||
} |
|||
|
|||
|
|||
|
|||
#endif |
|
|||
#ifndef __TILEDLIGHTINGUTILS_H__ |
|||
#define __TILEDLIGHTINGUTILS_H__ |
|||
|
|||
|
|||
uniform float4x4 g_mViewToWorld; |
|||
uniform float4x4 g_mScrProjection; |
|||
uniform float4x4 g_mInvScrProjection; |
|||
|
|||
|
|||
uniform uint g_widthRT; |
|||
uniform uint g_heightRT; |
|||
|
|||
StructuredBuffer<uint> g_vLightListGlobal; |
|||
|
|||
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; |
|||
|
|||
uNrLights = g_vLightListGlobal[ 16*tileOffs + 0]&0xffff; |
|||
uStart = tileOffs; |
|||
} |
|||
|
|||
uint FetchIndexOpaque(const uint tileOffs, const uint l) |
|||
{ |
|||
const uint l1 = l+1; |
|||
return (g_vLightListGlobal[ 16*tileOffs + (l1>>1)]>>((l1&1)*16))&0xffff; |
|||
} |
|||
|
|||
#ifdef OPAQUES_ONLY |
|||
|
|||
void GetCountAndStart(out uint uStart, out uint uNrLights, uint2 tileIDX, int nrTilesX, int nrTilesY, float linDepth, uint model) |
|||
{ |
|||
GetCountAndStartOpaque(uStart, uNrLights, tileIDX, nrTilesX, nrTilesY, linDepth, model); |
|||
} |
|||
|
|||
uint FetchIndex(const uint tileOffs, const uint l) |
|||
{ |
|||
return FetchIndexOpaque(tileOffs, l); |
|||
} |
|||
|
|||
#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 float g_fLog2NumClusters; |
|||
static 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) |
|||
{ |
|||
if(g_isOpaquesOnlyEnabled) |
|||
{ |
|||
GetCountAndStartOpaque(uStart, uNrLights, tileIDX, nrTilesX, nrTilesY, linDepth, model); |
|||
} |
|||
else |
|||
{ |
|||
g_iLog2NumClusters = (int) g_fLog2NumClusters; |
|||
float logBase = g_fClustBase; |
|||
if(g_isLogBaseBufferEnabled) |
|||
logBase = g_logBaseBuffer[tileIDX.y*nrTilesX + tileIDX.x]; |
|||
|
|||
int clustIdx = SnapToClusterIdxFlex(linDepth, logBase, g_isLogBaseBufferEnabled!=0); |
|||
|
|||
int nrClusters = (1<<g_iLog2NumClusters); |
|||
const int idx = ((model*nrClusters + clustIdx)*nrTilesY + tileIDX.y)*nrTilesX + tileIDX.x; |
|||
uint dataPair = g_vLayeredOffsetsBuffer[idx]; |
|||
uStart = dataPair&0x7ffffff; |
|||
uNrLights = (dataPair>>27)&31; |
|||
} |
|||
} |
|||
|
|||
uint FetchIndex(const uint tileOffs, const uint l) |
|||
{ |
|||
if(g_isOpaquesOnlyEnabled) |
|||
return FetchIndexOpaque(tileOffs, l); |
|||
else |
|||
return g_vLightListGlobal[ tileOffs+l ]; |
|||
} |
|||
|
|||
#endif |
|||
|
|||
|
|||
float3 GetViewPosFromLinDepth(float2 v2ScrPos, float fLinDepth) |
|||
{ |
|||
float fSx = g_mScrProjection[0].x; |
|||
//float fCx = g_mScrProjection[2].x; |
|||
float fCx = g_mScrProjection[0].z; |
|||
float fSy = g_mScrProjection[1].y; |
|||
//float fCy = g_mScrProjection[2].y; |
|||
float fCy = g_mScrProjection[1].z; |
|||
|
|||
#ifdef LEFT_HAND_COORDINATES |
|||
return fLinDepth*float3( ((v2ScrPos.x-fCx)/fSx), ((v2ScrPos.y-fCy)/fSy), 1.0 ); |
|||
#else |
|||
return fLinDepth*float3( -((v2ScrPos.x+fCx)/fSx), -((v2ScrPos.y+fCy)/fSy), 1.0 ); |
|||
#endif |
|||
} |
|||
|
|||
float GetLinearZFromSVPosW(float posW) |
|||
{ |
|||
#ifdef LEFT_HAND_COORDINATES |
|||
float linZ = posW; |
|||
#else |
|||
float linZ = -posW; |
|||
#endif |
|||
|
|||
return linZ; |
|||
} |
|||
|
|||
float GetLinearDepth(float zDptBufSpace) // 0 is near 1 is far |
|||
{ |
|||
float3 vP = float3(0.0f,0.0f,zDptBufSpace); |
|||
float4 v4Pres = mul(g_mInvScrProjection, float4(vP,1.0)); |
|||
return v4Pres.z / v4Pres.w; |
|||
} |
|||
|
|||
|
|||
|
|||
float3 OverlayHeatMap(uint numLights, float3 c) |
|||
{ |
|||
///////////////////////////////////////////////////////////////////// |
|||
// |
|||
const float4 kRadarColors[12] = |
|||
{ |
|||
float4(0.0,0.0,0.0,0.0), // black |
|||
float4(0.0,0.0,0.6,0.5), // dark blue |
|||
float4(0.0,0.0,0.9,0.5), // blue |
|||
float4(0.0,0.6,0.9,0.5), // light blue |
|||
float4(0.0,0.9,0.9,0.5), // cyan |
|||
float4(0.0,0.9,0.6,0.5), // blueish green |
|||
float4(0.0,0.9,0.0,0.5), // green |
|||
float4(0.6,0.9,0.0,0.5), // yellowish green |
|||
float4(0.9,0.9,0.0,0.5), // yellow |
|||
float4(0.9,0.6,0.0,0.5), // orange |
|||
float4(0.9,0.0,0.0,0.5), // red |
|||
float4(1.0,0.0,0.0,0.9) // strong red |
|||
}; |
|||
|
|||
float maxNrLightsPerTile = 31; |
|||
|
|||
|
|||
|
|||
int nColorIndex = numLights==0 ? 0 : (1 + (int) floor(10 * (log2((float)numLights) / log2(maxNrLightsPerTile))) ); |
|||
nColorIndex = nColorIndex<0 ? 0 : nColorIndex; |
|||
float4 col = nColorIndex>11 ? float4(1.0,1.0,1.0,1.0) : kRadarColors[nColorIndex]; |
|||
|
|||
return lerp(c, pow(col.xyz, 2.2), 0.3*col.w); |
|||
} |
|||
|
|||
|
|||
|
|||
#endif |
撰写
预览
正在加载...
取消
保存
Reference in new issue