浏览代码

working spotlight cookies in transperencies

/classicDeferredMobile
Filip Iliescu 8 年前
当前提交
4dcc5cff
共有 2 个文件被更改,包括 54 次插入17 次删除
  1. 52
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs
  2. 19
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/UnityStandardForwardMobile.cginc

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


private Matrix4x4[] m_LightMatrix = new Matrix4x4[k_MaxLights];
private Matrix4x4[] m_WorldToLightMatrix = new Matrix4x4[k_MaxLights];
[NonSerialized]
private int m_shadowBufferID;
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
[NonSerialized]
private TextureCache2D m_CookieTexArray;
//private TextureCacheCubemap m_CubeCookieTexArray;
//private TextureCacheCubemap m_CubeReflTexArray;
private int m_shadowBufferID;
private static int s_GBufferAlbedo;
private static int s_GBufferSpecRough;

if (m_ReflectionNearClipMaterial) DestroyImmediate (m_ReflectionNearClipMaterial);
if (m_ReflectionNearAndFarClipMaterial) DestroyImmediate (m_ReflectionNearAndFarClipMaterial);
m_CookieTexArray.Release();
//m_CubeCookieTexArray.Release();
//m_CubeReflTexArray.Release();
DeinitShadowSystem();
}

m_ReflectionNearAndFarClipMaterial.SetInt("_CullMode", (int)CullMode.Off);
m_ReflectionNearAndFarClipMaterial.SetInt("_CompareFunc", (int)CompareFunction.Always);
m_CookieTexArray = new TextureCache2D();
//m_CubeCookieTexArray = new TextureCacheCubemap();
//m_CubeReflTexArray = new TextureCacheCubemap();
m_CookieTexArray.AllocTextureArray(8, m_TextureSettings.spotCookieSize, m_TextureSettings.spotCookieSize, TextureFormat.RGBA32, true);
//m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
//m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHdrCompressedTextureFormat, true);
//shadows
m_MatWorldToShadow = new Matrix4x4[k_MaxLights * k_MaxShadowmapPerLights];
m_DirShadowSplitSpheres = new Vector4[k_MaxDirectionalSplit];

m_shadowBufferID = Shader.PropertyToID("g_tShadowBuffer");
}
void NewFrame()
{
// update texture caches
m_CookieTexArray.NewFrame();
//m_CubeCookieTexArray.NewFrame();
//m_CubeReflTexArray.NewFrame();
}
public void Render(ScriptableRenderContext context, IEnumerable<Camera> cameras)
{
foreach (var camera in cameras) {

void ExecuteRenderLoop(Camera camera, CullResults cullResults, ScriptableRenderContext loop)
{
NewFrame ();
UpdateShadowConstants (camera, cullResults);
m_ShadowMgr.RenderShadows( m_FrameId, loop, cullResults, cullResults.visibleLights );

{
for (int i = 0; i < k_MaxLights; ++i)
{
m_LightData [i] = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
m_LightData [i] = new Vector4(0.0f, 0.0f, -1.0f, 0.0f);
m_LightColors[i] = Vector4.zero;
m_LightDirections[i] = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
m_LightPositions[i] = Vector4.zero;

if (light.lightType == LightType.Point) {
m_LightData[i].x = SPHERE_LIGHT;
//RenderPointLight (light, cmd, props, renderAsQuad, intersectsNear, true);
// 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;

Matrix4x4 temp3 = PerspectiveCotanMatrix (chsa, 0.0f, range);
m_LightMatrix[i] = temp2 * temp1 * temp3 * worldToLight;
if (light.light.cookie != null)
m_LightData [i].z = m_CookieTexArray.FetchSlice (light.light.cookie);
else
m_LightData [i].z = m_CookieTexArray.FetchSlice (m_DefaultSpotCookie);
} else if (light.lightType == LightType.Directional) {
m_LightData[i].x = DIRECTIONAL_LIGHT;

cmd.SetGlobalMatrixArray("gLightMatrix", m_LightMatrix);
cmd.SetGlobalMatrixArray("gWorldToLightMatrix", m_WorldToLightMatrix);
cmd.SetGlobalVector("gLightData", new Vector4(totalLightCount, 0, 0, 0));
cmd.SetGlobalTexture("_spotCookieTextures", m_CookieTexArray.GetTexCache());
//cmd.SetGlobalTexture("_pointCookieTextures", m_CubeCookieTexArray.GetTexCache());
//cmd.SetGlobalTexture("_reflCubeTextures", m_CubeReflTexArray.GetTexCache());
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();

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


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

float att = dot(toLight, toLight) * gLightPos[lightIndex].w;
float atten = tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;
// float4 cookieColor = float4(1,1,1,1);
// const bool bHasCookie = (lgtDat.flags&HAS_COOKIE_TEXTURE)!=0;
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

}
UnityLight light;
light.color.xyz = gLightColor[lightIndex].xyz*atten; //*cookieColor.xyz;
light.color.xyz = gLightColor[lightIndex].xyz*atten*cookieColor.xyz;
light.dir.xyz = vLw;
ints += EvalMaterial(light, ind);

float d0 = 0.65;
float4 angularAtt = float4(1,1,1,smoothstep(0.0, 1.0-d0, 1.0-length(2*cookCoord-1)));
// [branch]if(bHasCookie)
// {
// angularAtt = UNITY_SAMPLE_TEX2DARRAY_LOD(_spotCookieTextures, float3(cookCoord, lgtDat.sliceIndex), 0.0);
// }
const bool bHasCookie = gPerLightData[lightIndex].z > 0;
[branch]if(bHasCookie)
{
angularAtt = UNITY_SAMPLE_TEX2DARRAY_LOD(_spotCookieTextures, float3(cookCoord, gPerLightData[lightIndex].z), 0.0);
}
atten *= angularAtt.w*(-uvCookie.w>0.0); // finally apply this to the dist att.
int shadowIdx = asint(gPerLightData[lightIndex].y);

}
UnityLight light;
light.color.xyz = gLightColor[lightIndex].xyz*atten; //*angularAtt.xyz;
light.color.xyz = gLightColor[lightIndex].xyz*atten*angularAtt.xyz;
light.dir.xyz = vLw.xyz; //unity_CameraToWorld
ints += EvalMaterial(light, ind);

正在加载...
取消
保存