Ejemplo n.º 1
0
        public void ShadowPass(List <VisibleLight> visibleLights, ref ScriptableRenderContext context, ref LightData lightData, CullResults cullResults, int unsortedIndex, Color backgroundColor)
        {
            m_ShadowMapRT = null;
            if (m_Asset.AreShadowsEnabled() && lightData.mainLightIndex != -1)
            {
                VisibleLight mainLight = visibleLights[lightData.mainLightIndex];

                if (mainLight.light.shadows != LightShadows.None)
                {
                    if (!LightweightUtils.IsSupportedShadowType(mainLight.lightType))
                    {
                        Debug.LogWarning("Only directional and spot shadows are supported by LightweightPipeline.");
                        Shadows = false;
                        return;
                    }

                    // There's no way to map shadow light indices. We need to pass in the original unsorted index.
                    // If no additional lights then no light sorting is performed and the indices match.
                    int  shadowOriginalIndex = (lightData.totalAdditionalLightsCount > 0) ? unsortedIndex : lightData.mainLightIndex;
                    bool shadowsRendered     = RenderShadows(ref cullResults, ref mainLight, shadowOriginalIndex, ref context, backgroundColor);
                    if (shadowsRendered)
                    {
                        lightData.shadowMapSampleType = (m_Asset.ShadowSetting != ShadowType.SOFT_SHADOWS) ? LightShadows.Hard : mainLight.light.shadows;

                        // In order to avoid shader variants explosion we only do hard shadows when sampling shadowmap in the lit pass.
                        // GLES2 platform is forced to hard single cascade shadows.
                        if (!m_ShadowSettings.screenSpace)
                        {
                            lightData.shadowMapSampleType = LightShadows.Hard;
                        }
                    }
                    else
                    {
                        lightData.shadowMapSampleType = LightShadows.None;
                    }

                    Shadows = shadowsRendered;
                    return;
                }
            }

            Shadows = false;
            return;
        }
Ejemplo n.º 2
0
        // How main light is decided:
        // If shadows enabled, main light is always a shadow casting light. Directional has priority over local lights.
        // Otherwise directional lights have priority based on cookie support and intensity
        private int GetMainLight(List <VisibleLight> visibleLights)
        {
            int  totalVisibleLights = visibleLights.Count;
            bool shadowsEnabled     = m_Asset.AreShadowsEnabled();

            if (totalVisibleLights == 0 || m_Asset.MaxPixelLights == 0)
            {
                return(-1);
            }

            int brighestDirectionalIndex = -1;

            for (int i = 0; i < totalVisibleLights; ++i)
            {
                VisibleLight currLight = visibleLights[i];

                // Particle system lights have the light property as null. We sort lights so all particles lights
                // come last. Therefore, if first light is particle light then all lights are particle lights.
                // In this case we either have no main light or already found it.
                if (currLight.light == null)
                {
                    break;
                }

                // Shadow lights are sorted by type (directional > puctual) and intensity
                // The first shadow light we find in the list is the main light
                if (shadowsEnabled && currLight.light.shadows != LightShadows.None && LightweightUtils.IsSupportedShadowType(currLight.lightType))
                {
                    return(i);
                }

                // In case no shadow light is present we will return the brightest directional light
                if (currLight.lightType == UnityEngine.LightType.Directional && brighestDirectionalIndex == -1)
                {
                    brighestDirectionalIndex = i;
                }
            }

            return(brighestDirectionalIndex);
        }