浏览代码

implement point and directional cookies for forward path

/main
Filip Iliescu 8 年前
当前提交
748bcdd2
共有 2 个文件被更改,包括 35 次插入25 次删除
  1. 16
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs
  2. 44
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/UnityStandardForwardMobile.cginc

16
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs


[NonSerialized]
private TextureCache2D m_CookieTexArray;
//private TextureCacheCubemap m_CubeCookieTexArray;
private TextureCacheCubemap m_CubeCookieTexArray;
private TextureCacheCubemap m_CubeReflTexArray;
private int m_shadowBufferID;

s_LightDataBuffer.Release();
m_CookieTexArray.Release();
//m_CubeCookieTexArray.Release();
m_CubeCookieTexArray.Release();
m_CubeReflTexArray.Release();
DeinitShadowSystem();

m_ReflectionNearAndFarClipMaterial.SetInt("_CompareFunc", (int)CompareFunction.Always);
m_CookieTexArray = new TextureCache2D();
//m_CubeCookieTexArray = new TextureCacheCubemap();
m_CubeCookieTexArray = new TextureCacheCubemap();
//m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHdrCompressedTextureFormat, true);
// TODO: decide on better max reflection probes

{
// update texture caches
m_CookieTexArray.NewFrame();
//m_CubeCookieTexArray.NewFrame();
m_CubeCookieTexArray.NewFrame();
m_CubeReflTexArray.NewFrame();
}

if (light.lightType == LightType.Point) {
m_LightData[i].x = SPHERE_LIGHT;
// if (light.light.cookie != null)
// m_LightData[i].z = m_CubeCookieTexArray.FetchSlice(light.light.cookie);
if (light.light.cookie != null)
m_LightData[i].z = m_CubeCookieTexArray.FetchSlice(light.light.cookie);
} else if (light.lightType == LightType.Spot) {
m_LightData[i].x = SPOT_LIGHT;

cmd.SetGlobalVector("gLightData", new Vector4(totalLightCount, finalProbeCount, 0, 0));
cmd.SetGlobalTexture("_spotCookieTextures", m_CookieTexArray.GetTexCache());
//cmd.SetGlobalTexture("_pointCookieTextures", m_CubeCookieTexArray.GetTexCache());
cmd.SetGlobalTexture("_pointCookieTextures", m_CubeCookieTexArray.GetTexCache());
cmd.SetGlobalTexture("_reflCubeTextures", m_CubeReflTexArray.GetTexCache());
cmd.SetGlobalBuffer("g_vProbeData", s_LightDataBuffer);

44
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/UnityStandardForwardMobile.cginc


sampler2D _LightTextureB0;
UNITY_DECLARE_TEX2DARRAY(_spotCookieTextures);
//UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_pointCookieTextures);
UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_pointCookieTextures);
static FragmentCommonData gdata;
static float occlusion;

}
float4 cookieColor = float4(1,1,1,1);
// float4 uvCookie = mul (gLightMatrix[lightIndex], float4(vPw,1));
// float2 cookCoord = uvCookie.xy / uvCookie.w;
// const bool bHasCookie = gPerLightData[lightIndex].z >= 0;
// [branch]if(bHasCookie)
// {
// cookieColor *= UNITY_SAMPLE_TEX2DARRAY_LOD(_spotCookieTextures, float3(cookCoord, gPerLightData[lightIndex].z), 0.0);
// atten *= (-cookieColor.w>0.0);
// }
float4 uvCookie = mul (gLightMatrix[lightIndex], float4(vPw,1));
float2 cookCoord = uvCookie.xy / uvCookie.w;
const bool bHasCookie = gPerLightData[lightIndex].z >= 0;
[branch]if(bHasCookie)
{
cookieColor = UNITY_SAMPLE_TEX2DARRAY_LOD(_spotCookieTextures, float3(cookCoord, gPerLightData[lightIndex].z), 0.0);
atten *= cookieColor.w;
}
[branch]if(_useLegacyCookies)
{
cookieColor.xyz = 1;
}
light.color.xyz = gLightColor[lightIndex].xyz*atten*cookieColor.xyz;
light.color.xyz = gLightColor[lightIndex].xyz*atten*cookieColor.xyz;
light.dir.xyz = -gLightDirection[lightIndex].xyz;
ints += EvalMaterial(light, ind);

float atten = tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;
float4 cookieColor = float4(1,1,1,1);
// const bool bHasCookie = gPerLightData[lightIndex].z >= 0;
// [branch]if(bHasCookie)
// {
// float3 cookieCoord = -float3(dot(vL, lgtDat.lightAxisX.xyz), dot(vL, lgtDat.lightAxisY.xyz), dot(vL, lgtDat.lightAxisZ.xyz)); // negate to make vL a fromLight vector
// cookieColor = UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(_pointCookieTextures, float4(cookieCoord, lgtDat.sliceIndex), 0.0);
// atten *= cookieColor.w;
// }
const bool bHasCookie = gPerLightData[lightIndex].z >= 0;
[branch]if(bHasCookie)
{
float4 uvCookie = mul (gLightMatrix[lightIndex], float4(vLw,1));
float3 cookieCoord = -uvCookie.xyz / uvCookie.w;
cookieColor = UNITY_SAMPLE_ABSTRACT_CUBE_ARRAY_LOD(_pointCookieTextures, float4(cookieCoord, gPerLightData[lightIndex].z), 0.0);
atten *= cookieColor.w;
}
[branch]if(_useLegacyCookies)
{
cookieColor.xyz = 1;
}
int shadowIdx = asint(gPerLightData[lightIndex].y);
[branch]

正在加载...
取消
保存