コード例 #1
0
        public static Level parseModelLevel(Model.Level modLevel)
        {
            // TODO: Name einfügen
            Level level = new Level("TODO");

            foreach (Model.GameObject.Room modRoom in modLevel.Rooms)
            {
                Room room = new Room();
                room.Player = new Player(modRoom.Player.Position);

                foreach (var modLightRay in modRoom.LightRays)
                {
                    LightRay lr = new LightRay(modLightRay.Position, modLightRay.RayDirection);
                    room.AddLightRay(lr);
                }
                foreach (var modMirror in modRoom.Mirrors)
                {
                    Mirror m = new Mirror(modMirror.RailStart, modMirror.RailEnd, modMirror.InitAngle, modMirror.StartingRelativePosition);
                    room.AddMirror(m);
                }
            }
            //  var room = new Room();
            //   room.Player = new Fledermaus.GameObjects.Player(modLevel.Player.InitialPosition);
            //  room.Exit = new Fledermaus.GameObjects.RectangularGameObject();


            return(level);
        }
コード例 #2
0
        private void DrawLightRay(LightRay lightRay)
        {
            SetColor(BasicGraphics.Colors.LightRay);
            DrawBounds(lightRay, 0.004f);

            if (lightRay.GetLines().ToList().Count < 1)
            {
                return;
            }

            Line lastLine = lightRay.GetLines().ToList().Last();

            Vector2 oppositeDirection = lastLine.GetDirectionVector() * -1;

            oppositeDirection.Normalize();

            Vector2 arrowVector1 = Util.GetRotatedVector(oppositeDirection, 0.9f);
            Vector2 arrowVector2 = Util.GetRotatedVector(oppositeDirection, -0.9f);

            Line arrowLine1 = Line.CreateParameterized(lastLine.Point2, arrowVector1, 0.04f);
            Line arrowLine2 = Line.CreateParameterized(lastLine.Point2, arrowVector2, 0.04f);

            IBounded arrowLines = Util.CreateBoundsFromList(new List <Line>()
            {
                arrowLine1, arrowLine2
            });

            DrawBounds(arrowLines, 0.004f);
        }
コード例 #3
0
 private void GetBody(PixelBody wallBody, MultipixelObject obsticle)
 {
     foreach (Pixel wall in wallBody.Pixels)
     {
         LightRay ray = new  LightRay(source, wall, obsticle, Shape, Color);
         Body.rays.Add(ray);
     }
 }
コード例 #4
0
 // Use this for initialization
 void Start()
 {
     lightSource  = GetComponent <LightRay>();
     maxRadius    = lightSource.lightRadius;
     isDecreasing = true;
     target       = minRadius;
     radiusNow    = maxRadius;
     StartCoroutine("LightDelay", waitSeconds);
 }
コード例 #5
0
        public CrepuscularRays(Game game, Vector3 lightSourcePos, string lightSourceImage, float lightSourceSize, float density, float decay, float weight, float exposure, float brightThreshold)
            : base(game)
        {
            lsMask = new LightSourceMask(game, lightSourcePos, lightSourceImage, lightSourceSize);
            mask = new LightSceneMask(game, lightSourcePos);
            rays = new LightRay(game, lightSourcePos, density, decay, weight, exposure);
            bp = new BrightPass(game, brightThreshold);
            blend = new SceneBlend(game);

            AddPostProcess(lsMask);
            AddPostProcess(mask);
            AddPostProcess(rays);
            AddPostProcess(bp);
            AddPostProcess(blend);
        }
コード例 #6
0
ファイル: Crystal.cs プロジェクト: sketchycode/Traveler67093
 public void LightRayIlluminated(LightRay lightRay, bool isIlluminating)
 {
     if (isIlluminating)
     {
         if (illuminatingRays.Contains(lightRay))
         {
             return;
         }
         illuminatingRays.Add(lightRay);
         Debug.Log("crystal getting light, now at " + illuminatingRays.Count + ", isActive: " + IsCrystalActivated);
     }
     else if (!isIlluminating)
     {
         illuminatingRays.Remove(lightRay);
     }
 }
コード例 #7
0
    internal void LightRayIlluminated(LightRay lightRay, bool isIlluminating)
    {
        if (isIlluminating)
        {
            if (illuminatingRays.Contains(lightRay))
            {
                return;
            }
            illuminatingRays.Add(lightRay);
        }
        else if (!isIlluminating)
        {
            illuminatingRays.Remove(lightRay);
        }

        IsReceptacleActive = isWantingLight ? illuminatingRays.Count > 0 : illuminatingRays.Count == 0;
    }
コード例 #8
0
    void Start()
    {
        PlayerInteractable playerInteractable = GetComponent <PlayerInteractable>();

        playerInteractable.PlayerInteractedAction = (player) => {
            if (player.IsHoldingACrystal)
            {
                var oldMountedCrystal = mountedCrystal;
                player.SetCrystalInMount(this);

                if (oldMountedCrystal)
                {
                    player.PickUpCrystal(oldMountedCrystal);
                }
            }
            else
            {
                player.PickUpCrystal(mountedCrystal);
                mountedCrystal = null;
            }
        };

        playerInteractable.CanPlayerInteract = (player) => {
            return(player.IsHoldingACrystal || mountedCrystal);
        };

        activatedLightRay = GetComponentInChildren <LightRay>(true);
        activatedLightRay.transform.position = LightRayOrigin;
        activatedLightRay.transform.rotation = LightRayRotation;

        activatedLightRay.gameObject.SetActive(false);

        if (mountedCrystal)
        {
            AcceptCrystal(mountedCrystal);
        }
    }
コード例 #9
0
 // Use this for initialization
 void Start()
 {
     LightDirectionVector   = this.transform.TransformDirection(transform.forward);
     lightRay               = new LightRay();
     lightRayInstantiateRay = (GameObject)Instantiate(lightRayPrefab, this.transform.position, lightRayPrefab.transform.rotation);
 }
コード例 #10
0
 protected override void Awake()
 {
     base.Awake();
     LightOnMaterial = ResourceHolder.Instance.Light_Yellow_Signal_Mat;
     LightRay.GetComponent <MeshRenderer> ().material = ResourceHolder.Instance.Ray_Yellow_Signal_Mat;
 }
コード例 #11
0
    private void DrawIllumination()
    {
        RaycastHit2D[] hits = null;
        _source.GetHits(ref hits);
        if (hits.Length == 0)
        {
            return;
        }

        // pre-calc some values
        int rayCount  = 4 * hits.Length;        // 4 rays per hit
        int vertCount = rayCount + 1;           // 1 vert per ray, +1 for centre
        var rays      = new LightRay[rayCount];
        var verts     = new Vector3[vertCount];
        var uv        = new Vector2[verts.Length];
        var indices   = new int[3 * rayCount];

        verts[0] = _source.Position;

        int ri = 0;

        for (int i = 0; i < hits.Length; i++)
        {
            var collider = hits[i].collider as CircleCollider2D;
            _source.GetRays(ref rays, ri, collider);
            ri += 4;
        }

        System.Array.Sort(rays, _comparer);

        for (int i = 0; i < rays.Length; i++)
        {
            verts[i + 1] = rays[i].end;
        }

        // verts[0] is mesh centre
        for (int i = 0; i < rayCount - 1; i++)
        {
            int ti = 3 * i;

            indices[ti]     = 0;
            indices[ti + 1] = i + 1;
            indices[ti + 2] = i + 2;
        }
        var li = indices.Length;

        indices[li - 3] = 0;
        indices[li - 2] = vertCount - 1;
        indices[li - 1] = 1;

        _mesh.Clear();
        _mesh.vertices  = verts;
        _mesh.triangles = indices;
        _mesh.RecalculateNormals();
        _mesh.RecalculateBounds();
        var size = _source.range * 2;

        for (int i = 0; i < verts.Length; i++)
        {
            var tv = (Vector2)verts[i] - _source.Position;

            uv[i].x = tv.x / size;
            uv[i].y = tv.y / size;
        }
        _mesh.uv = uv;
    }
コード例 #12
0
ファイル: Room.cs プロジェクト: eric1338/FledermausSpiel
 public void AddLightRay(LightRay lightRay)
 {
     LightRays.Add(lightRay);
 }
コード例 #13
0
 protected virtual void Awake()
 {
     NoLightMaterial = ResourceHolder.Instance.Light_No_Signal_Mat;
     LightRay        = GetComponentInChildren <LightRay> ();
 }
コード例 #14
0
        public void Calculate( IList<CalculationPointDLE> points )
        {
            // главный цикл по лучам
            for ( var iteration = 0; iteration < NRays; iteration++ )
            {
                // определяем источник
                var light = this.RouletteLight();

                // розыгрыш луча от источника
                var ray = light.RandomRay();


                // DEBUG
                // [0,000 ms] - Ray.From = x = 0,06968741, y = 0,1730685, z = 4,9, Ray.To = x = -2,499, y = 0,1456028, z = 2,175853
                // [0,000 ms] - Ray.From = x = 0,7848736, y = -2,312128, z = 0,0009999275, Ray.To = x = 0,785834, y = -0,3403686, z = 1,224729
                //ray = new LightRay(ray.From, new Vector( -0.1f, -0.25f, -1, true ), ray.Illuminance );
                //ray.To = new Point3D()


                var wMinFact = ray.Illuminance.ValueMax * WMin;

                // основной блуждания луча
                int rayIteration = 0;
                while ( ray.Illuminance.ValueMax > wMinFact && rayIteration < 8 )
                {
                    rayIteration++;

                    // ищем пересечение с элементом сцены
                    var intersection = this.RayTracer.Trace( ray.From, ray.Direction, Constants.Epsilon );
                    while ( intersection != null && intersection.Face.Material.Reflectance == null )
                    {
                        if ( intersection.Face.Material.Mirror != null )
                        {
                            var mirrorRay = Vector.Reflect( ray.Direction, intersection.Face.Normal );
                            mirrorRay.Normalize();
                            ray.From = intersection.Point;
                            ray.Direction = mirrorRay;
                            intersection = this.RayTracer.Trace( ray.From, ray.Direction, Constants.Epsilon );
                        }
                        else
                            throw new NotImplementedException();
                    }
                    if ( intersection == null )
                        break;

                    //RayDebugStaticCollection.Add( new Ray( ray.From, intersection.Point ), Color.Blue );
                    //this.Log.Message( string.Format( "Ray.From = {0}, Ray.To = {1}", ray.From, intersection.Point ) );

                    var intersectionNormal = intersection.Face.Normal;
                    var intesectionPointOcclude = intersection.Point + intersectionNormal * Constants.Epsilon;

                    // для всех расчетных точек производимы вычисления
                    foreach ( var point in points )
                    {
                        var renderPointNormal = point.Face.Normal;


                        //if (point.Obj.Name == "Box2")
                        //{
                        //    point.Illuminance = new Spectrum(1f, 0, 0);
                        //    continue;
                        //}

                        if ( Vector.Dot( intersectionNormal, renderPointNormal ) > Constants.Epsilon )
                        {
                            point.CounterVisibleNormals++;
                            continue;
                        }


                        var pointOcclude = point.Position;

                        // направление от точки до точки рендеринга
                        var r2 = Point3D.LenghtSquared( intesectionPointOcclude, pointOcclude );

                        var coreDirection = new Vector( intesectionPointOcclude, pointOcclude, true );
                        //var occludeRayLength = (float)Math.Sqrt( r2 ) - Constants.Epsilon;

                        //r2 = Point3D.LenghtSquared(intesectionPointOcclude, point.Position );
                        var occludeRayLength = (float)Math.Sqrt( r2 ) - Constants.Epsilon;


                        if ( this.RayTracer.Occluded( intesectionPointOcclude, coreDirection, 0, occludeRayLength ) )
                        {
                            point.CounterOccluded++;
                            continue;
                        }



                        //if ( this.RayTracer.Occluded( intersection.Point, coreDirection, Constants.Epsilon, occludeRayLength ) )
                        //    continue;

                        var cos1 = ( Vector.Dot( coreDirection, intersectionNormal ) );
                        var cos2 = Math.Abs( Vector.Dot( coreDirection, renderPointNormal ) );

                        if ( cos1 < Constants.Epsilon2 )
                            point.CounterRaysCos1Zero++;
                        if ( cos2 < Constants.Epsilon )
                            point.CounterRaysCos2Zero++;

                        cos1 = Math.Abs( cos1 );
                        cos2 = Math.Abs( cos2 );

                        var sigma1 = intersection.Face.Material.Reflectance.BRDF( ray.Direction, intersectionNormal,
                            coreDirection );

                        var kernel1 = sigma1 * cos1 * cos2 / r2;
                        //var kernel1 = intersection.Face.Material.BRDF( ray.Direction, intersection.Face.Normal,
                        //    core1Direction );

                        //var kernel1 = new Spectrum( sigma1 );

                        //kernel1.Multiplication( cos1 * cos2 / r2 );

                        // Ядро 2. Переход из суб. точки в искомое направление
                        var sigma2 = point.Face.Material.Reflectance.BRDF( coreDirection, renderPointNormal,
                            point.Direction );

                        var kernel2 = sigma2;

                        point.Illuminance += ray.Illuminance * kernel1 * kernel2;

                    }

                    var newDirection = intersection.Face.Material.Reflectance.RandomReflectedDirection( ray.Direction,
                            intersectionNormal );
                    var brdf = intersection.Face.Material.Reflectance.BRDF( ray.Direction, intersectionNormal, newDirection );

                    ray = new LightRay( intersection.Point, newDirection, ray.Illuminance * brdf );

                    /*
                    if (rayIteration == 1)
                        ray = new LightRay(ray.From, new Vector(1f, 0, 1f), ray.Illuminance);
                    else if ( rayIteration == 2 )
                        ray = new LightRay( ray.From, new Vector( -0.85f, 1.5f, 1.5f, true ), ray.Illuminance );
                    
                     * */
                }

                if ( iteration % 100 == 0 )
                    this.Log.Message( string.Format( "Render {0} rays", iteration ), 1 );

            }


            const float norm = 4 * Constants.PI;
            foreach ( var point in points )
            {
                point.Illuminance *= ( norm / ( NRays * Constants.PI * Constants.PI ) );
            }
        }
コード例 #15
0
 public LightRay(LightRay ray) : this(ray._ray, ray._intensity, ray._wavelen)
 {
 }
コード例 #16
0
        public void Calculate()
        {
            // главный цикл по лучам
            for (var iteration = 0; iteration < NRays; iteration++)
            {
                // определяем источник
                var light = this.RouletteLight();

                // розыгрыш луча от источника
                var ray = light.RandomRay();

                //ray = new LightRay( light.Position, new Vector( -0f, -0f, -1.0f, true ), new Spectrum( 1f ) );

                var wMinFact = ray.Illuminance.ValueMax * WMin;

                // основной блуждания луча
                int rayIteration = 0;
                while (ray.Illuminance.ValueMax > wMinFact && rayIteration < 8)
                {
                    rayIteration++;

                    // ищем пересечение с элементом сцены
                    var intersection = RayTracer.Trace(ray.From, ray.Direction, Constants.Epsilon);
                    while (intersection != null && intersection.Face.Material.Reflectance == null)
                    {
                        if (intersection.Face.Material.Mirror != null)
                        {
                            var mirrorRay = Vector.Reflect(ray.Direction, intersection.Face.Normal);
                            mirrorRay.Normalize();
                            ray.From      = intersection.Point;
                            ray.Direction = mirrorRay;
                            intersection  = this.RayTracer.Trace(ray.From, ray.Direction, Constants.Epsilon);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    if (intersection == null)
                    {
                        break;
                    }

                    //RayDebugStaticCollection.Add( new Ray( ray.From, intersection.Point ), Color.Blue );
                    //this.Log.Message( string.Format( "Ray.From = {0}, Ray.To = {1}", ray.From, intersection.Point ) );

                    var intersectionNormal      = intersection.Face.Normal;
                    var intesectionPointOcclude = intersection.Point + intersectionNormal * Constants.Epsilon;

                    // для всех расчетных точек производимы вычисления
                    foreach (var obj in Scene.Objects)
                    {
                        foreach (var vertex in obj.Vertices)
                        {
                            var renderPointNormal = vertex.Face.Normal;

                            if (vertex.Face == intersection.Face)
                            {
                                continue;
                            }

                            var dnormals = intersection.Face.Normal - renderPointNormal;
                            if (Math.Abs(dnormals.X) < Constants.Epsilon && Math.Abs(dnormals.Y) < Constants.Epsilon && Math.Abs(dnormals.Z) < Constants.Epsilon)
                            {
                                continue;
                            }


                            var mr = (new Vector(intersection.Point, vertex.Point).Reflect(vertex.Face.Normal));
                            //RayDebugStaticCollection.Add( new Ray( intersection.Point, vertex.Point ), Color.Green );
                            //RayDebugStaticCollection.Add( new Ray( vertex.Point,mr  ), Color.Red );

                            //if (point.Obj.Name == "Box2")
                            //{
                            //    point.Illuminance = new Spectrum(1f, 0, 0);
                            //    continue;
                            //}

                            //if ( Vector.Dot( intersectionNormal, renderPointNormal ) > Constants.Epsilon )
                            //{
                            //    vertex.CounterVisibleNormals++;
                            //    continue;
                            //}


                            var pointOcclude = vertex.Point;

                            // направление от точки до точки рендеринга
                            var r2 = Point3D.LenghtSquared(intesectionPointOcclude, pointOcclude);

                            var coreDirection = new Vector(intesectionPointOcclude, pointOcclude, true);
                            //var occludeRayLength = (float)Math.Sqrt( r2 ) - Constants.Epsilon;

                            //r2 = Point3D.LenghtSquared(intesectionPointOcclude, point.Position );
                            var occludeRayLength = (float)Math.Sqrt(r2) - Constants.Epsilon;


                            if (this.RayTracer.Occluded(intesectionPointOcclude, coreDirection, 0, occludeRayLength))
                            {
                                //vertex.CounterOccluded++;
                                continue;
                            }



                            //if ( this.RayTracer.Occluded( intersection.Point, coreDirection, Constants.Epsilon, occludeRayLength ) )
                            //    continue;

                            var cos1 = (Vector.Dot(coreDirection, intersectionNormal));
                            var cos2 = Math.Abs(Vector.Dot(coreDirection, renderPointNormal));

                            /*
                             * if ( cos1 < Constants.Epsilon2 )
                             *  vertex.CounterRaysCos1Zero++;
                             * if ( cos2 < Constants.Epsilon )
                             *  vertex.CounterRaysCos2Zero++;
                             */

                            cos1 = Math.Abs(cos1);
                            cos2 = Math.Abs(cos2);

                            var sigma1 = intersection.Face.Material.Reflectance.BRDF(ray.Direction, intersectionNormal, coreDirection);

                            if (sigma1.ValueMax > 0)
                            {
                                cos1 = Math.Abs(cos1);
                            }

                            var kernel1 = sigma1 * cos1 * cos2 / r2;
                            //var kernel1 = intersection.Face.Material.BRDF( ray.Direction, intersection.Face.Normal,
                            //    core1Direction );

                            //var kernel1 = new Spectrum( sigma1 );

                            //kernel1.Multiplication( cos1 * cos2 / r2 );

                            // Ядро 2. Переход из суб. точки в искомое направление
                            for (int i = 0; i < vertex.IlluminanceAngles.Directions.Count; i++)
                            {
                                var sigma2 = vertex.Face.Material.Reflectance.BRDF(coreDirection, renderPointNormal, vertex.IlluminanceAngles.Directions[i]);

                                var kernel2 = sigma2;
                                var q       = ray.Illuminance * kernel1 * kernel2;
                                if (float.IsNaN(q.R) || float.IsNaN(q.G) || float.IsNaN(q.B))
                                {
                                    q = new Spectrum( );
                                }

                                vertex.IlluminanceIndirect[i] += q;
                            }
                        }
                    }

                    var newDirection = intersection.Face.Material.Reflectance.RandomReflectedDirection(ray.Direction,
                                                                                                       intersectionNormal);
                    var brdf = intersection.Face.Material.Reflectance.BRDF(ray.Direction, intersectionNormal, newDirection);

                    ray = new LightRay(intersection.Point, newDirection, ray.Illuminance * brdf);

                    /*
                     * if (rayIteration == 1)
                     *  ray = new LightRay(ray.From, new Vector(1f, 0, 1f), ray.Illuminance);
                     * else if ( rayIteration == 2 )
                     *  ray = new LightRay( ray.From, new Vector( -0.85f, 1.5f, 1.5f, true ), ray.Illuminance );
                     *
                     * */
                }

                if (iteration % 10 == 0)
                {
                    Log.Message(string.Format("Render {0} rays", iteration), 1);
                }
            }


            const float XXXX = 0.25f;
            const float norm = 4 * Constants.PI * XXXX;

            foreach (var obj in Scene.Objects)
            {
                foreach (var vertex in obj.Vertices)
                {
                    for (int i = 0; i < vertex.IlluminanceAngles.Directions.Count; i++)
                    {
                        vertex.IlluminanceIndirect[i] *= (norm / (NRays * Constants.PI * Constants.PI));
                    }
                }
            }
        }