コード例 #1
0
        /// <summary>
        /// Vergleicht zwei Lichter miteinander
        /// </summary>
        /// <param name="obj">Zu vergleichendes Licht</param>
        /// <returns>1, -1</returns>
        public int CompareTo(object obj)
        {
            LightObject light = (LightObject)obj;

            //return light.IsShadowCaster && !this.IsShadowCaster ? 1 : -1;
            return(light.IsShadowCaster ? 1 : -1);
        }
コード例 #2
0
        internal static void PrepareLightsForRenderPass(List <LightObject> lights, ref float[] colors, ref float[] targets, ref float[] positions, ref int count, ref int shadowLight)
        {
            int countTemp = 0;
            IEnumerator <LightObject> enumerator = lights.GetEnumerator();

            enumerator.Reset();
            for (int i = 0, arraycounter = 0; i < lights.Count; i++)
            {
                enumerator.MoveNext();
                LightObject l           = enumerator.Current;
                bool        isInFrustum =
                    KWEngine.CurrentWindow.Frustum.SphereVsFrustum(l.Position, l.Type == LightType.DirectionalShadow ? l.DistanceMultiplier * 100 : l.DistanceMultiplier * 10);

                if (isInFrustum)
                {
                    if (l.Type == LightType.DirectionalShadow)
                    {
                        shadowLight = i;
                    }

                    colors[arraycounter + 0] = l.Color.X;
                    colors[arraycounter + 1] = l.Color.Y;
                    colors[arraycounter + 2] = l.Color.Z;
                    colors[arraycounter + 3] = l.Color.W; // Intensity of color

                    targets[arraycounter + 0] = l.Target.X;
                    targets[arraycounter + 1] = l.Target.Y;
                    targets[arraycounter + 2] = l.Target.Z;
                    targets[arraycounter + 3] = l.Type == LightType.Directional || l.Type == LightType.DirectionalShadow ? 1 : -1;

                    positions[arraycounter + 0] = l.Position.X;
                    positions[arraycounter + 1] = l.Position.Y;
                    positions[arraycounter + 2] = l.Position.Z;
                    positions[arraycounter + 3] = l.DistanceMultiplier;

                    countTemp++;
                    arraycounter += 4;
                }
            }

            count = countTemp;
        }
コード例 #3
0
        internal static void PrepareLightsForRenderPass(List <LightObject> lights, ref float[] colors, ref float[] targets, ref float[] positions, ref float[] meta, ref float[] nearFar, ref int count)
        {
            int countTemp = 0;
            IEnumerator <LightObject> enumerator = lights.GetEnumerator();

            enumerator.Reset();

            Vector3 viewDirection;
            Vector3 camPosition;

            if (KWEngine.CurrentWorld.IsFirstPersonMode)
            {
                viewDirection = HelperCamera.GetLookAtVector();
                camPosition   = KWEngine.CurrentWorld.GetFirstPersonObject().Position;
            }
            else
            {
                viewDirection = KWEngine.CurrentWorld.GetCameraLookAtVector();
                camPosition   = KWEngine.CurrentWorld.GetCameraPosition();
            }

            for (int i = 0, twocounter = 0, threecounter = 0, arraycounter = 0; i < lights.Count; i++)
            {
                bool isInFrustum = true;
                enumerator.MoveNext();
                LightObject l = enumerator.Current;

                Vector3 cameraToLight          = Vector3.NormalizeFast(l.Position - camPosition);
                float   dotProductViewAndLight = Vector3.Dot(viewDirection, cameraToLight);

                if (dotProductViewAndLight < -0.125f && (camPosition - l.Position).LengthFast > (l.Type != LightType.Sun ? l._zFar * 5 : (KWEngine.CurrentWorld.ZFar * 5)))
                {
                    isInFrustum = false;
                }

                if (isInFrustum)
                {
                    colors[arraycounter + 0] = l.Color.X;
                    colors[arraycounter + 1] = l.Color.Y;
                    colors[arraycounter + 2] = l.Color.Z;
                    colors[arraycounter + 3] = l.Color.W; // Intensity of color

                    targets[arraycounter + 0] = l.Target.X;
                    targets[arraycounter + 1] = l.Target.Y;
                    targets[arraycounter + 2] = l.Target.Z;
                    if (l.Type == LightType.Point)
                    {
                        targets[arraycounter + 3] = 0; // Point
                    }
                    else if (l.Type == LightType.Directional)
                    {
                        targets[arraycounter + 3] = 1; // Directional
                    }
                    else
                    {
                        targets[arraycounter + 3] = -1; // Sun
                    }

                    positions[arraycounter + 0] = l.Position.X;
                    positions[arraycounter + 1] = l.Position.Y;
                    positions[arraycounter + 2] = l.Position.Z;
                    positions[arraycounter + 3] = l._zFar;

                    meta[threecounter]     = l._shadowMapBiasCoefficient;
                    meta[threecounter + 1] = l.IsShadowCaster ? 1 : 0;
                    meta[threecounter + 2] = l._shadowHardness;

                    nearFar[twocounter]     = l._zNear;
                    nearFar[twocounter + 1] = l._zFar;

                    countTemp++;
                    arraycounter += 4;
                    threecounter += 3;
                    twocounter   += 2;
                }
            }

            count = countTemp;
        }