浏览代码

Create LightCullUtils.hlsl to manage light index generation

We use our light index, stereo eye index, and number of lights to generate various indices into our light cull buffers.  Instead of re-calculating stuff in every shader, we should have a common place to do these calculations!
/main
Robert Srinivasiah 7 年前
当前提交
ca84b696
共有 3 个文件被更改,包括 50 次插入6 次删除
  1. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/scrbound.compute
  2. 35
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightCullUtils.hlsl
  3. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightCullUtils.hlsl.meta

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/scrbound.compute


#include "CoreRP/ShaderLibrary/common.hlsl"
#include "LightLoop.cs.hlsl"
#include "LightCullUtils.hlsl"
#pragma only_renderers d3d11 ps4 xboxone vulkan metal

const int lgtIndex = subLigt+(int) g*8;
const int sideIndex = (int) (t%8);
const int eyeAdjustedLgtIndex = lgtIndex + (eyeIndex * g_iNrVisibLights);
const int eyeAdjustedLgtIndex = GenerateLightCullDataIndex(lgtIndex, g_iNrVisibLights, eyeIndex);
SFiniteLightBound lgtDat = g_data[eyeAdjustedLgtIndex];
const float3 boxX = lgtDat.boxAxisX.xyz;

// Each light's AABB is represented by two float3s, the min and max of the box.
// And for stereo, we have two sets of lights. Therefore, each eye has a set of mins, followed by
// a set of maxs, and each set is equal to g_iNrVisibLights.
const int eyeBaseIndex = eyeIndex * g_iNrVisibLights * 2;
const int minIndex = eyeBaseIndex + lgtIndex + 0;
const int maxIndex = eyeBaseIndex + lgtIndex + (int)g_iNrVisibLights;
g_vBoundsBuffer[minIndex] = float3(0.5*vMin.x + 0.5, 0.5*vMin.y + 0.5, vMin.z*VIEWPORT_SCALE_Z);
g_vBoundsBuffer[maxIndex] = float3(0.5*vMax.x + 0.5, 0.5*vMax.y + 0.5, vMax.z*VIEWPORT_SCALE_Z);
const ScreenSpaceBoundsIndices boundsIndices = GenerateScreenSpaceBoundsIndices(lgtIndex, g_iNrVisibLights, eyeIndex);
g_vBoundsBuffer[boundsIndices.min] = float3(0.5*vMin.x + 0.5, 0.5*vMin.y + 0.5, vMin.z*VIEWPORT_SCALE_Z);
g_vBoundsBuffer[boundsIndices.max] = float3(0.5*vMax.x + 0.5, 0.5*vMax.y + 0.5, vMax.z*VIEWPORT_SCALE_Z);
}
}
}

35
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightCullUtils.hlsl


#ifndef __LIGHTCULLUTILS_H__
#define __LIGHTCULLUTILS_H__
// Used to index into our SFiniteLightBound (g_data) and
// LightVolumeData (_LightVolumeData) buffers.
int GenerateLightCullDataIndex(int lightIndex, uint numVisibleLights, uint eyeIndex)
{
// For monoscopic, there is just one set of light cull data structs.
// In stereo, all of the left eye structs are first, followed by the right eye structs.
const int perEyeBaseIndex = (int)eyeIndex * (int)numVisibleLights;
return (perEyeBaseIndex + lightIndex);
}
struct ScreenSpaceBoundsIndices
{
int min;
int max;
};
// The returned values are used to index into our AABB screen space bounding box buffer
// Usually named g_vBoundsBuffer. The two values represent the min/max indices.
ScreenSpaceBoundsIndices GenerateScreenSpaceBoundsIndices(int lightIndex, uint numVisibleLights, uint eyeIndex)
{
// In the monoscopic mode, there is one set of bounds (min,max -> 2 * g_iNrVisibLights)
// In stereo, there are two sets of bounds (leftMin, leftMax, rightMin, rightMax -> 4 * g_iNrVisibLights)
const int eyeRelativeBase = (int)eyeIndex * 2 * (int)numVisibleLights;
ScreenSpaceBoundsIndices indices;
indices.min = eyeRelativeBase + lightIndex;
indices.max = eyeRelativeBase + lightIndex + (int)numVisibleLights;
return indices;
}
#endif //__LIGHTCULLUTILS_H__

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightCullUtils.hlsl.meta


fileFormatVersion: 2
guid: 1c2274cd4aa7374419016ddf7360a620
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存