浏览代码

separate out resolution dependent allocations

separate out resolution dependent allocations
/main
mmikk 8 年前
当前提交
d062497d
共有 1 个文件被更改,包括 42 次插入8 次删除
  1. 50
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs

50
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


static private ComputeBuffer lightList;
static private ComputeBuffer m_dirLightList;
static private int m_WidthOnRecord;
static private int m_HeightOnRecord;
Matrix4x4[] g_matWorldToShadow = new Matrix4x4[MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS];
Vector4[] g_vDirShadowSplitSpheres = new Vector4[MAX_DIRECTIONAL_SPLIT];
Vector4[] g_vShadow3x3PCFTerms = new Vector4[4];

if (m_lightDataBuffer != null)
m_lightDataBuffer.Release();
if (lightList != null)
lightList.Release();
ReleaseResolutionDependentBuffers();
if (m_dirLightList != null)
m_dirLightList.Release();

m_convexBoundsBuffer = new ComputeBuffer(gMaxNumLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightBound)));
m_lightDataBuffer = new ComputeBuffer(gMaxNumLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightData)));
m_dirLightList = new ComputeBuffer(gMaxNumDirLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLight)));
lightList = new ComputeBuffer(LightDefinitions.NR_LIGHT_MODELS * 1024 * 1024, sizeof(uint)); // enough list memory for a 4k x 4k display
m_BuildScreenAABBShader.SetBuffer(kGenAABBKernel, "g_data", m_convexBoundsBuffer);
//m_BuildScreenAABBShader.SetBuffer(kGenAABBKernel, "g_vBoundsBuffer", m_aabbBoundsBuffer);

m_aabbBoundsBuffer.Release();
m_convexBoundsBuffer.Release();
m_lightDataBuffer.Release();
lightList.Release();
ReleaseResolutionDependentBuffers();
m_dirLightList.Release();
}

void ExecuteRenderLoop(Camera camera, CullResults cullResults, RenderLoop loop)
{
int iW = camera.pixelWidth;
int iH = camera.pixelHeight;
ResizeIfNecessary(iW, iH);
// do anything we need to do upon a new frame.
NewFrame();

temp.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
Matrix4x4 projh = temp * proj;
Matrix4x4 invProjh = projh.inverse;
int iW = camera.pixelWidth;
int iH = camera.pixelHeight;
temp.SetRow(0, new Vector4(0.5f * iW, 0.0f, 0.0f, 0.5f * iW));
temp.SetRow(1, new Vector4(0.0f, 0.5f * iH, 0.0f, 0.5f * iH));

m_DeferredMaterial.SetTexture("_pointCookieTextures", m_cubeCookieTexArray.GetTexCache());
m_DeferredReflectionMaterial.SetTexture("_reflCubeTextures", m_cubeReflTexArray.GetTexCache());
}
void ResizeIfNecessary(int curWidth, int curHeight)
{
if(curWidth!=m_WidthOnRecord || curHeight!=m_HeightOnRecord)
{
if(m_WidthOnRecord>0 && m_HeightOnRecord>0)
ReleaseResolutionDependentBuffers();
AllocResolutionDependentBuffers(curWidth, curHeight);
// update recorded window resolution
m_WidthOnRecord = curWidth;
m_HeightOnRecord = curHeight;
}
}
void ReleaseResolutionDependentBuffers()
{
if (lightList != null)
lightList.Release();
}
void AllocResolutionDependentBuffers(int width, int height)
{
int nrTilesX = (width+15)/16;
int nrTilesY = (height+15)/16;
int nrTiles = nrTilesX*nrTilesY;
const int capacityUShortsPerTileFPTL = 32;
const int nrDWordsPerTileFPTL = (capacityUShortsPerTileFPTL + 1)>>1; // room for 31 lights and a nrLights value.
lightList = new ComputeBuffer(LightDefinitions.NR_LIGHT_MODELS * nrDWordsPerTileFPTL * nrTiles, sizeof(uint)); // enough list memory for a 4k x 4k display
}
}
}
正在加载...
取消
保存