浏览代码

More progress to VR FPTL

Everything is about ready except for the deferred lighting pass
/vr_fptl_sandbox
Robert Srinivasiah 8 年前
当前提交
16072312
共有 10 个文件被更改,包括 175 次插入68 次删除
  1. 139
      Assets/ScriptableRenderPipeline/fptl/FptlLighting.cs
  2. 7
      Assets/ScriptableRenderPipeline/fptl/Internal-DeferredReflections.shader
  3. 10
      Assets/ScriptableRenderPipeline/fptl/Internal-DeferredShading.shader
  4. 18
      Assets/ScriptableRenderPipeline/fptl/LightingTemplate.hlsl
  5. 34
      Assets/ScriptableRenderPipeline/fptl/LightingUtils.hlsl
  6. 6
      Assets/ScriptableRenderPipeline/fptl/ReflectionTemplate.hlsl
  7. 6
      Assets/ScriptableRenderPipeline/fptl/TiledLightingUtils.hlsl
  8. 12
      Assets/ScriptableRenderPipeline/fptl/UnityStandardForwardNew.cginc
  9. 5
      Assets/ScriptableRenderPipeline/fptl/lightlistbuild-bigtile.compute
  10. 6
      Assets/ScriptableRenderPipeline/fptl/lightlistbuild.compute

139
Assets/ScriptableRenderPipeline/fptl/FptlLighting.cs


private static ComputeBuffer s_UnifiedLightDataBuffer; // VR
private static int s_UnifiedLightDataEyeOffset; // VR
private static ComputeBuffer s_UnifiedDirLightList; // VR
private static int s_UnifiedDirLightListEyeOffset; // VR
//private static int s_UnifiedDirLightListEyeOffset; // VR
private static float[] s_UnifiedDirLightListBaseCount; //VR
private static ComputeBuffer s_BigTileLightList; // used for pre-pass coarse culling on 64x64 tiles
private static int s_GenListPerBigTileKernel;

s_BigTileLightList = null;
m_shadowBufferID = Shader.PropertyToID("g_tShadowBuffer");
s_UnifiedDirLightListBaseCount = new float[4];
}
//static void SetupGBuffer(int width, int height, CommandBuffer cmd)

if (enableComputeLightEvaluation) //TODO: temporary workaround for "All kernels must use same constant buffer layouts"
{
// VR - none of this will work in VR...
var w = camera.pixelWidth;
var h = camera.pixelHeight;
var numTilesX = (w + 7) / 8;

static Matrix4x4 CameraToWorld(Camera camera)
{
return camera.cameraToWorldMatrix * GetFlipMatrix();
}
static Matrix4x4 StereoCameraToWorld(Camera camera, Camera.StereoscopicEye eye)
{
return camera.GetStereoViewMatrix(eye).inverse * GetFlipMatrix();
}
static Matrix4x4 CameraProjection(Camera camera)

{
loop.StopMultiEye(camera);
}
int numLights = 0, numDirLights = 0;
if (stereoDoublewide)
var projScrArr = new Matrix4x4[2];
var invProjScrArr = new Matrix4x4[2];
var viewToWorldArr = new Matrix4x4[2];
int numLights = 0, numDirLights = 0;
if (stereoDoublewide)
var unifiedLightData = new List<SFiniteLightData>();
var unifiedLightData = new List<SFiniteLightData>();
var unifiedDirLightData = new List<DirectionalLight>();
for (int eye = 0; eye < 2; eye++)
for (int eye = 0; eye < 2; eye++)
{
// camera to screen matrix (and it's inverse)
var proj = CameraStereoProjection(camera, (Camera.StereoscopicEye)eye);

var projscr = temp * proj;
var invProjscr = projscr.inverse;
// build per tile light lists
// VR - we gotta stash out each eye's light list!
numLights = GenerateSourceLightBuffers(camera, cullResults, (Camera.StereoscopicEye)eye);
projScrArr[eye] = projscr;
invProjScrArr[eye] = invProjscr;
viewToWorldArr[eye] = StereoCameraToWorld(camera, (Camera.StereoscopicEye)eye);
// build per tile light lists
// VR - we gotta stash out each eye's light list!
numLights = GenerateSourceLightBuffers(camera, cullResults, (Camera.StereoscopicEye)eye);
var generatedLightData = new SFiniteLightData[numLights];
s_LightDataBuffer.GetData(generatedLightData);
unifiedLightData.AddRange(generatedLightData);

// VR - same here, we need to double up the directional light lists
numDirLights = UpdateDirectionalLights(camera, cullResults.visibleLights);
}
var generatedDirLightData = new DirectionalLight[numDirLights];
s_DirLightList.GetData(generatedDirLightData);
unifiedDirLightData.AddRange(generatedDirLightData);
//if (0 == eye)
//{
// s_UnifiedDirLightListEyeOffset = numDirLights;
//}
s_UnifiedDirLightListBaseCount[eye * 2 + 0] = eye * s_UnifiedDirLightListBaseCount[1]; // 0 for eye=0, previous numdir for eye=1
s_UnifiedDirLightListBaseCount[eye * 2 + 1] = numDirLights;
}
s_UnifiedDirLightList.SetData(unifiedDirLightData.ToArray());
// VR - make this VR aware of course!
// Push all global params
PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights);
// VR - make this VR aware of course!
// Push all global params
//PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights);
PushGlobalParams(camera, loop, viewToWorldArr, projScrArr, invProjScrArr, numDirLights);
// pulled out async shadow maps (for now)
}
else
// pulled out async shadow maps (for now)
}
else
{
// camera to screen matrix (and it's inverse)
var proj = CameraProjection(camera);

// Push all global params
numDirLights = UpdateDirectionalLights(camera, cullResults.visibleLights);
PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights);
}
if (stereoActive)
s_UnifiedDirLightListBaseCount[0] = s_UnifiedDirLightListBaseCount[2] = 0;
s_UnifiedDirLightListBaseCount[1] = s_UnifiedDirLightListBaseCount[3] = numDirLights;
projScrArr[0] = projScrArr[1] = projscr;
invProjScrArr[0] = invProjScrArr[1]= invProjscr;
viewToWorldArr[0] = viewToWorldArr[1] = CameraToWorld(camera);
//PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights);
PushGlobalParams(camera, loop, viewToWorldArr, projScrArr, invProjScrArr, numDirLights);
}
if (stereoActive)
{
loop.StartMultiEye(camera);
}

cmd.Dispose();
}
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)
//void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4[] viewToWorld, Matrix4x4[] scrProj, Matrix4x4[] incScrProj, int numDirLights)
// VR - this is fine, but I should make this 'correct'
cmd.SetGlobalFloat("g_heightRT", (float)camera.pixelHeight);
// VR - turn these into VR enabled arrays
cmd.SetGlobalMatrix("g_mViewToWorld", viewToWorld);
cmd.SetGlobalMatrix("g_mWorldToView", viewToWorld.inverse);
cmd.SetGlobalMatrix("g_mScrProjection", scrProj);
cmd.SetGlobalMatrix("g_mInvScrProjection", incScrProj);
// VR - make sure this list is the unified light data list
cmd.SetGlobalBuffer("g_vLightData", s_LightDataBuffer);
cmd.SetGlobalFloat("g_heightRT", (float)camera.pixelHeight);
// VR - turn these into VR enabled arrays
//cmd.SetGlobalMatrix("g_mViewToWorld", viewToWorld);
//cmd.SetGlobalMatrix("g_mWorldToView", viewToWorld.inverse);
//cmd.SetGlobalMatrix("g_mScrProjection", scrProj);
//cmd.SetGlobalMatrix("g_mInvScrProjection", incScrProj);
var worldToView = new Matrix4x4[2];
worldToView[0] = viewToWorld[0].inverse;
worldToView[1] = viewToWorld[1].inverse;
cmd.SetGlobalMatrixArray("g_mViewToWorldArr", viewToWorld);
cmd.SetGlobalMatrixArray("g_mWorldToViewArr", worldToView);
cmd.SetGlobalMatrixArray("g_mScrProjectionArr", scrProj);
cmd.SetGlobalMatrixArray("g_mInvScrProjectionArr", incScrProj);
// VR - make sure this list is the unified light data list
//cmd.SetGlobalBuffer("g_vLightData", s_LightDataBuffer);
if (stereoDoublewide)
{
cmd.SetGlobalBuffer("g_vLightData", s_UnifiedLightDataBuffer);
cmd.SetGlobalFloat("g_lightDataEyeOffset", (float)s_UnifiedLightDataEyeOffset);
}
else
{
cmd.SetGlobalBuffer("g_vLightData", s_LightDataBuffer);
cmd.SetGlobalFloat("g_lightDataEyeOffset", (float)0);
}
cmd.SetGlobalTexture("_spotCookieTextures", m_CookieTexArray.GetTexCache());
cmd.SetGlobalTexture("_pointCookieTextures", m_CubeCookieTexArray.GetTexCache());

}
// VR - these needs to be VR adjusted
cmd.SetGlobalFloat("g_nNumDirLights", numDirLights);
cmd.SetGlobalBuffer("g_dirLightData", s_DirLightList);
//cmd.SetGlobalFloat("g_nNumDirLights", numDirLights);
//cmd.SetGlobalBuffer("g_dirLightData", s_DirLightList);
cmd.SetGlobalFloat("g_nNumDirLights", numDirLights); // not needed anymore
if (stereoDoublewide)
{
cmd.SetGlobalBuffer("g_dirLightData", s_UnifiedDirLightList);
}
else
{
cmd.SetGlobalBuffer("g_dirLightData", s_DirLightList);
}
cmd.SetGlobalFloatArray("g_UnifiedDirLightListBaseCount", s_UnifiedDirLightListBaseCount); // new dir light bounds
// Shadow constants
cmd.SetGlobalMatrixArray("g_matWorldToShadow", m_MatWorldToShadow);

7
Assets/ScriptableRenderPipeline/fptl/Internal-DeferredReflections.shader


float linDepth = GetLinearDepth(zbufDpth);
float3 vP = GetViewPosFromLinDepth(i.vertex.xy, linDepth);
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
//float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
//float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
float3 vPw = mul(g_mViewToWorldArr[unity_StereoEyeIndex], float4(vP, 1)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], -vP).xyz); //unity_CameraToWorld
float4 gbuffer0 = _CameraGBufferTexture0.Load( uint3(pixCoord.xy, 0) );
float4 gbuffer1 = _CameraGBufferTexture1.Load( uint3(pixCoord.xy, 0) );

10
Assets/ScriptableRenderPipeline/fptl/Internal-DeferredShading.shader


v2f vert (float4 vertex : POSITION, float2 texcoord : TEXCOORD0)
{
v2f o;
o.vertex = UnityObjectToClipPos(vertex);
o.vertex = UnityObjectToClipPos(vertex); // this does the double wide correction
o.texcoord = texcoord.xy;
return o;
}

half4 frag (v2f i) : SV_Target
{
uint2 pixCoord = ((uint2) i.vertex.xy);
uint2 pixCoord = ((uint2) i.vertex.xy); // this is corrected for VR
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
//float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
//float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
float3 vPw = mul(g_mViewToWorldArr[unity_StereoEyeIndex], float4(vP, 1)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], -vP).xyz); //unity_CameraToWorld
float4 gbuffer0 = _CameraGBufferTexture0.Load( uint3(pixCoord.xy, 0) );
float4 gbuffer1 = _CameraGBufferTexture1.Load( uint3(pixCoord.xy, 0) );

18
Assets/ScriptableRenderPipeline/fptl/LightingTemplate.hlsl


uniform uint g_nNumDirLights;
uniform int g_UnifiedDirLightListBaseCount[4];
//---------------------------------------------------------------------------------------------------------------------------------------------------------
// TODO: clean up.. -va
#define MAX_SHADOW_LIGHTS 10

float3 ints = 0;
for (int i = 0; i < g_nNumDirLights; i++)
int dirBase = g_UnifiedDirLightListBaseCount[unity_StereoEyeIndex * 2 + 0];
int dirCount = g_UnifiedDirLightListBaseCount[unity_StereoEyeIndex * 2 + 1];
//for (int i = 0; i < g_nNumDirLights; i++)
for (int i = dirBase; i < dirCount; i++)
{
DirectionalLight lightData = g_dirLightData[i];
float atten = 1;

UnityLight light;
light.color.xyz = lightData.color.xyz * atten;
light.dir.xyz = mul((float3x3) g_mViewToWorld, -lightData.lightAxisZ).xyz;
//light.dir.xyz = mul((float3x3) g_mViewToWorld, -lightData.lightAxisZ).xyz;
light.dir.xyz = mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], -lightData.lightAxisZ).xyz;
ints += EvalMaterial(light, ind);
}

UnityLight light;
light.color.xyz = lgtDat.color.xyz*atten*angularAtt.xyz;
light.dir.xyz = mul((float3x3) g_mViewToWorld, vL).xyz; //unity_CameraToWorld
//light.dir.xyz = mul((float3x3) g_mViewToWorld, vL).xyz; //unity_CameraToWorld
light.dir.xyz = mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], vL).xyz; //unity_CameraToWorld
ints += EvalMaterial(light, ind);

float3 toLight = vLp - vP;
float dist = length(toLight);
float3 vL = toLight / dist;
float3 vLw = mul((float3x3) g_mViewToWorld, vL).xyz; //unity_CameraToWorld
//float3 vLw = mul((float3x3) g_mViewToWorld, vL).xyz; //unity_CameraToWorld
float3 vLw = mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], vL).xyz; //unity_CameraToWorld
float attLookUp = dist*lgtDat.recipRange; attLookUp *= attLookUp;
float atten = tex2Dlod(_LightTextureB0, float4(attLookUp.rr, 0.0, 0.0)).UNITY_ATTEN_CHANNEL;

34
Assets/ScriptableRenderPipeline/fptl/LightingUtils.hlsl


#include "LightDefinitions.cs.hlsl"
uniform float4x4 g_mViewToWorld;
uniform float4x4 g_mWorldToView; // used for reflection only
uniform float4x4 g_mScrProjection;
uniform float4x4 g_mInvScrProjection;
//uniform float4x4 g_mViewToWorld;
//uniform float4x4 g_mWorldToView; // used for reflection only
//uniform float4x4 g_mScrProjection;
//uniform float4x4 g_mInvScrProjection;
uniform float4x4 g_mViewToWorldArr[2];
uniform float4x4 g_mWorldToViewArr[2]; // used for reflection only
uniform float4x4 g_mScrProjectionArr[2];
uniform float4x4 g_mInvScrProjectionArr[2];
uniform uint g_widthRT;
uniform uint g_heightRT;

{
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;
//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;
float fSx = g_mScrProjectionArr[unity_StereoEyeIndex][0].x;
float fCx = g_mScrProjectionArr[unity_StereoEyeIndex][0].z;
float fSy = g_mScrProjectionArr[unity_StereoEyeIndex][1].y;
float fCy = g_mScrProjectionArr[unity_StereoEyeIndex][1].z;
#if USE_LEFTHAND_CAMERASPACE
return fLinDepth*float3( ((v2ScrPos.x-fCx)/fSx), ((v2ScrPos.y-fCy)/fSy), 1.0 );

float GetLinearDepth(float zDptBufSpace) // 0 is near 1 is far
{
// todo (simplify): m22 is zero and m23 is +1/-1 (depends on left/right hand proj)
float m22 = g_mInvScrProjection[2].z, m23 = g_mInvScrProjection[2].w;
float m32 = g_mInvScrProjection[3].z, m33 = g_mInvScrProjection[3].w;
//float m22 = g_mInvScrProjection[2].z, m23 = g_mInvScrProjection[2].w;
//float m32 = g_mInvScrProjection[3].z, m33 = g_mInvScrProjection[3].w;
float m22 = g_mInvScrProjectionArr[unity_StereoEyeIndex][2].z, m23 = g_mInvScrProjectionArr[unity_StereoEyeIndex][2].w;
float m32 = g_mInvScrProjectionArr[unity_StereoEyeIndex][3].z, m33 = g_mInvScrProjectionArr[unity_StereoEyeIndex][3].w;
return (m22*zDptBufSpace+m23) / (m32*zDptBufSpace+m33);

6
Assets/ScriptableRenderPipeline/fptl/ReflectionTemplate.hlsl


{
float3 worldNormalRefl = reflect(-Vworld, vNw);
float3 vspaceRefl = mul((float3x3) g_mWorldToView, worldNormalRefl).xyz;
//float3 vspaceRefl = mul((float3x3) g_mWorldToView, worldNormalRefl).xyz;
float3 vspaceRefl = mul((float3x3) g_mWorldToViewArr[unity_StereoEyeIndex], worldNormalRefl).xyz;
float percRoughness = SmoothnessToPerceptualRoughness(smoothness);

#else
float3 volumeSpaceRefl = float3( dot(vspaceRefl, lgtDat.lightAxisX), dot(vspaceRefl, lgtDat.lightAxisY), dot(vspaceRefl, lgtDat.lightAxisZ) );
float3 vPR = BoxProjectedCubemapDirection(volumeSpaceRefl, posInReflVolumeSpace, float4(lgtDat.localCubeCapturePoint, 1.0), -boxOuterDistance, boxOuterDistance); // Volume space corrected reflection vector
sampleDir = mul( (float3x3) g_mViewToWorld, vPR.x*lgtDat.lightAxisX + vPR.y*lgtDat.lightAxisY + vPR.z*lgtDat.lightAxisZ );
//sampleDir = mul( (float3x3) g_mViewToWorld, vPR.x*lgtDat.lightAxisX + vPR.y*lgtDat.lightAxisY + vPR.z*lgtDat.lightAxisZ );
sampleDir = mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], vPR.x*lgtDat.lightAxisX + vPR.y*lgtDat.lightAxisY + vPR.z*lgtDat.lightAxisZ);
#endif
}
else

6
Assets/ScriptableRenderPipeline/fptl/TiledLightingUtils.hlsl


StructuredBuffer<SFiniteLightData> g_vLightData;
StructuredBuffer<uint> g_vLightListGlobal; // don't support Buffer yet in unity
uniform float g_lightDataEyeOffset;
uint nrTilesX = ((uint) (g_widthRT+(tileSize-1)))/tileSize; uint nrTilesY = ((uint) (g_heightRT+(tileSize-1)))/tileSize;
uint nrTilesX = ((uint) (g_widthRT+(tileSize-1)))/tileSize;
uint nrTilesY = ((uint) (g_heightRT+(tileSize-1)))/tileSize;
uint2 tileIDX = pixCoord / tileSize;
const int tileOffs = (tileIDX.y+model*nrTilesY)*nrTilesX+tileIDX.x;

12
Assets/ScriptableRenderPipeline/fptl/UnityStandardForwardNew.cginc


{
float linZ = GetLinearZFromSVPosW(i.pos.w); // matching script side where camera space is right handed.
float3 vP = GetViewPosFromLinDepth(i.pos.xy, linZ);
float3 vPw = mul(g_mViewToWorld, float4(vP,1.0)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); // not same as unity_CameraToWorld
//float3 vPw = mul(g_mViewToWorld, float4(vP,1.0)).xyz;
//float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); // not same as unity_CameraToWorld
float3 vPw = mul(g_mViewToWorldArr[unity_StereoEyeIndex], float4(vP, 1.0)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], -vP).xyz); // not same as unity_CameraToWorld
#ifdef _PARALLAXMAP
half3 tangent = i.tangentToWorldAndParallax[0].xyz;

{
float linZ = GetLinearZFromSVPosW(i.pos.w); // matching script side where camera space is right handed.
float3 vP = GetViewPosFromLinDepth(i.pos.xy, linZ);
float3 vPw = mul(g_mViewToWorld, float4(vP,1.0)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); // not same as unity_CameraToWorld
//float3 vPw = mul(g_mViewToWorld, float4(vP,1.0)).xyz;
//float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); // not same as unity_CameraToWorld
float3 vPw = mul(g_mViewToWorldArr[unity_StereoEyeIndex], float4(vP, 1.0)).xyz;
float3 Vworld = normalize(mul((float3x3) g_mViewToWorldArr[unity_StereoEyeIndex], -vP).xyz); // not same as unity_CameraToWorld
#ifdef _PARALLAXMAP
half3 tangent = i.tangentToWorldAndParallax[0].xyz;

5
Assets/ScriptableRenderPipeline/fptl/lightlistbuild-bigtile.compute


uniform int g_iNrVisibLights;
uniform uint2 g_viDimensions;
uniform float4x4 g_mInvScrProjection;
uniform float4x4 g_mScrProjection;
uniform float4x4 g_mScrProjection; // uh, I hope this doesn't conflict with LightingUtils.hlsl
uniform float g_fNearPlane;
uniform float g_fFarPlane;
uniform int g_iEye;

// VR - adjust this to offset into the correct portion of the light list
// right eye will get second half
// might not actually need to do this due to auto-sync between dispatches
int offs = tileIDX.y*nrBigTilesX + tileIDX.x + (eye * nrBigTilesX * nrBigTilesY);
int offs = tileIDX.y*nrBigTilesX + tileIDX.x + (g_iEye * nrBigTilesX * nrBigTilesY);
for(i=t; i<(iNrCoarseLights+1); i+=NR_THREADS)
g_vLightList[MAX_NR_BIGTILE_LIGHTS_PLUSONE*offs + i] = i==0 ? iNrCoarseLights : lightsListLDS[i-1];

6
Assets/ScriptableRenderPipeline/fptl/lightlistbuild.compute


uint2 uCrd = min( uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1) );
// VR - we need to fetch from the correct half of the depth texture
// for a double wide VR texture, the real width is actually double iWidth, so we can just add that
// This doesn't need to be done in a VS/PS if they use UnityObjectToClipPos, as that auto-corrects for stereo
uCrd.x += (uint)(g_iEye * iWidth);
const float fDepth = FetchDepth(g_depth_tex, uCrd);
vLinDepths[i] = GetLinearDepth(fDepth);

// in VR, we need to use eye to index into the correct half
//const int bigTileIdx = (tileIDX.y>>2)*NrBigTilesX + (tileIDX.x>>2); // map the idx to 64x64 tiles
const int bigTileIdx = (tileIDX.y >> 2)*NrBigTilesX + (tileIDX.x >> 2)
+ (eye * NrBigTilesX * NrBigTilesY); // map the idx to 64x64 tiles
+ (g_iEye * NrBigTilesX * NrBigTilesY); // map the idx to 64x64 tiles
int nrBigTileLights = g_vBigTileLightList[MAX_NR_BIGTILE_LIGHTS_PLUSONE*bigTileIdx+0];
for(int l0=(int) t; l0<(int) nrBigTileLights; l0 += NR_THREADS)
{

// write lights to global buffers
int localOffs=0;
// make sure the base index here corrects in the appropriate eye half
int offs = tileIDX.y*nrTilesX + tileIDX.x;
//int offs = tileIDX.y*nrTilesX + tileIDX.x;
int offs = tileIDX.y*nrTilesX + tileIDX.x + (g_iEye * nrTilesX * nrTilesY * NR_LIGHT_MODELS);
for(int category=0; category<NR_LIGHT_MODELS; category++)
{

正在加载...
取消
保存