浏览代码

Fixed rendering issues when no realtime lights were present.

/Branch_batcher
Felipe Lira 8 年前
当前提交
dd4cded2
共有 3 个文件被更改,包括 43 次插入44 次删除
  1. 21
      Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs
  2. 49
      Assets/LowEndMobilePipeline/Shaders/LowEndMobilePipeline.shader
  3. 17
      Assets/LowEndMobilePipeline/Shaders/LowEndMobilePipelineCore.cginc

21
Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs


int pixelLightsCount, vertexLightsCount;
GetMaxSupportedLights(visibleLights.Length, out pixelLightsCount, out vertexLightsCount);
// TODO: handle shader keywords when no lights are present
SortLights(ref visibleLights, pixelLightsCount);
// TODO: Add remaining lights to SH

vertexLightsCount = (m_Asset.SupportsVertexLight) ? Mathf.Min(lightsCount - pixelLightsCount, kMaxVertexLights) : 0;
}
private void InitializeLightData()
{
for (int i = 0; i < kMaxLights; ++i)
{
m_LightPositions[i] = Vector4.zero;
m_LightColors[i] = Vector4.zero;
m_LightAttenuations[i] = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
m_LightSpotDirections[i] = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
}
}
if (lights.Length <= 0)
return;
InitializeLightData();
for (int i = 0; i < totalLightCount; ++i)
{

cmd.SetGlobalVectorArray("globalLightAtten", m_LightAttenuations);
cmd.SetGlobalVectorArray("globalLightSpotDir", m_LightSpotDirections);
cmd.SetGlobalVector("globalLightCount", new Vector4(pixelLightCount, totalLightCount, 0.0f, 0.0f));
SetShaderKeywords(cmd);
SetShaderKeywords(cmd, vertexLightCount > 0);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

setupShadow.Dispose();
}
void SetShaderKeywords(CommandBuffer cmd)
void SetShaderKeywords(CommandBuffer cmd, bool vertexLightSupport)
if (m_Asset.SupportsVertexLight)
if (vertexLightSupport)
cmd.EnableShaderKeyword("_VERTEX_LIGHTS");
else
cmd.DisableShaderKeyword("_VERTEX_LIGHTS");

49
Assets/LowEndMobilePipeline/Shaders/LowEndMobilePipeline.shader


o.normal = normal;
#endif
#if _VERTEX_LIGHTS
#if defined(_VERTEX_LIGHTS)
half4 diffuseAndSpecular = half4(1.0, 1.0, 1.0, 1.0);
for (int lightIndex = globalLightCount.x; lightIndex < globalLightCount.y; ++lightIndex)
{

half4 specularGloss;
SpecularGloss(i.uv01.xy, diffuse, alpha, specularGloss);
// Indirect Light Contribution
half3 indirect;
Indirect(i, diffuse, normal, alpha, indirect);
half3 emissionColor;
Emission(i, emissionColor);
// Compute direct contribution from main directional light.
// Only a single directional shadow caster is supported.
LightInput mainLight;
INITIALIZE_LIGHT(mainLight, 0);
half3 viewDir = i.viewDir.xyz;
half3 directColor = EvaluateOneLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir);
directColor *= ComputeShadowAttenuation(i);
half shadowAttenuation = ComputeShadowAttenuation(i);
#else
half shadowAttenuation = 1.0f;
half3 viewDir = i.viewDir.xyz;
// Compute direct contribution from additional lights.
for (int lightIndex = 1; lightIndex < globalLightCount.x; ++lightIndex)
// TODO: Restrict pixel lights by 4. This way we can keep moderate constrain for most LD project
// and can benefit from better data layout/avoid branching by doing vec math.
half3 color = half3(0, 0, 0);
for (int lightIndex = 0; lightIndex < globalLightCount.x; ++lightIndex)
directColor += EvaluateOneLight(additionalLight, diffuse, specularGloss, normal, i.posWS, viewDir);
color += EvaluateOneLight(additionalLight, diffuse, specularGloss, normal, i.posWS, viewDir);
if (lightIndex == 0)
color *= shadowAttenuation;
half3 color = directColor + indirect + emissionColor;
half3 emissionColor;
Emission(i, emissionColor);
color += emissionColor;
#if defined(LIGHTMAP_ON)
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse;
#elif defined(_VERTEX_LIGHTS) || defined(_VERTEX_AND_PIXEL_LIGHTS)
color += i.fogCoord.yzw * diffuse;
#endif
#if _CUBEMAP_REFLECTION
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
color += texCUBE(_Cube, reflectVec).rgb * _ReflectColor.rgb * specularGloss.rgb;
#endif
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);

17
Assets/LowEndMobilePipeline/Shaders/LowEndMobilePipelineCore.cginc


#define DEBUG_CASCADES 0
#define MAX_SHADOW_CASCADES 4
#define MAX_LIGHTS 8

emission = tex2D(_EmissionMap, i.uv01.xy) * _EmissionColor;
#else
emission = _EmissionColor;
#endif
}
inline void Indirect(v2f i, half3 diffuse, half3 normal, half glossiness, out half3 indirect)
{
#ifdef LIGHTMAP_ON
indirect = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse;
#else
indirect = i.fogCoord.yzw * diffuse;
#endif
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection
#ifdef _CUBEMAP_REFLECTION
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half3 indirectSpecular = texCUBE(_Cube, reflectVec) * _ReflectColor * glossiness;
indirect += indirectSpecular;
#endif
}

正在加载...
取消
保存