Ejemplo n.º 1
0
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                _lensFlare.ReadString(reader);
                for (x = 0; (x < _fog.Count); x = (x + 1))
                {
                    Fog.Add(new SkyLightFogBlockBlock());
                    Fog[x].Read(reader);
                }
                for (x = 0; (x < _fog.Count); x = (x + 1))
                {
                    Fog[x].ReadChildData(reader);
                }
                for (x = 0; (x < _fogOpposite.Count); x = (x + 1))
                {
                    FogOpposite.Add(new SkyLightFogBlockBlock());
                    FogOpposite[x].Read(reader);
                }
                for (x = 0; (x < _fogOpposite.Count); x = (x + 1))
                {
                    FogOpposite[x].ReadChildData(reader);
                }
                for (x = 0; (x < _radiosity.Count); x = (x + 1))
                {
                    Radiosity.Add(new SkyRadiosityLightBlockBlock());
                    Radiosity[x].Read(reader);
                }
                for (x = 0; (x < _radiosity.Count); x = (x + 1))
                {
                    Radiosity[x].ReadChildData(reader);
                }
            }
Ejemplo n.º 2
0
        public static void CalculateLightmaps(LightmapSpecs specs)
        {
            if (_currentRoom != null && _currentLightmaps != null)
            {
                Radiosity.Init(new Radiosity.RenderDelegate(renderRadiosityCallback));

                _calculatingRadiosity = true;
                CurrentFilterMode     = TextureFilterMode.None;
                LightmapsEnabled      = true;
                CurrentShadeMode      = ShadeMode.Flat;
                DoubleLightmapValues  = false;
                Graphics.Camera   originalCamera   = CurrentCamera;
                Graphics.Viewport originalViewport = Graphics.RendererManager.CurrentRenderer.Viewport;

                RadiosityMaps radiosityMaps = _currentRoom.GenerateMemoryTextures(specs);

                // generate the omni lights
                _omniLightInfo = new List <OmniInfo>();
                foreach (LightmapSpecs.OmniLight light in specs.OmniLights)
                {
                    OmniInfo o;
                    o.Info = light;
                    Radiosity.GenerateOmniLight((int)light.Radius, light.Color, out o.MemTex, out o.AlphaMask);

                    _omniLightInfo.Add(o);
                }

                Graphics.RendererManager.CurrentRenderer.CullMode = Graphics.CullMode.None;


                Graphics.TextureResource skyboxTop          = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxFront        = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxBack         = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxLeft         = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxRight        = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxBottom       = Radiosity.GenerateMemoryTexture(16, 16, 0, 0, 0);
                Graphics.BitmapSurface   skyboxTopPixels    = new Graphics.BitmapSurface(skyboxTop);
                Graphics.BitmapSurface   skyboxFrontPixels  = new Graphics.BitmapSurface(skyboxFront);
                Graphics.BitmapSurface   skyboxBackPixels   = new Graphics.BitmapSurface(skyboxBack);
                Graphics.BitmapSurface   skyboxLeftPixels   = new Graphics.BitmapSurface(skyboxLeft);
                Graphics.BitmapSurface   skyboxRightPixels  = new Graphics.BitmapSurface(skyboxRight);
                Graphics.BitmapSurface   skyboxBottomPixels = new Graphics.BitmapSurface(skyboxBottom);

                // Graphics.SkyBox.AddSun(specs.SunDirection, specs.SunColor, 0.125f, skyboxFrontPixels, skyboxBackPixels, skyboxLeftPixels, skyboxRightPixels, skyboxTopPixels, true);

                Graphics.SkyBox originalSkybox = _currentSkybox;
                if (_currentSkybox != null)
                {
                    _currentSkybox = new Graphics.SkyBox("box", skyboxFrontPixels, skyboxBackPixels, skyboxLeftPixels, skyboxRightPixels, skyboxTopPixels, skyboxBottomPixels, 0);

                    _currentSkybox.AddSun(specs.SunDirection, specs.SunColor, true);
                }

                Graphics.LightmapResource oldLightmaps = _currentLightmaps;
                _currentLightmaps = radiosityMaps.CreateBigMemoryTexture(_currentLightmaps.Name);
                _currentRoom.CalcRadiosityPass(_currentLightmaps, radiosityMaps);

                Radiosity.Shutdown();

                _currentRoom.FinalizeVertices(_currentLightmaps, true);
                _currentLightmaps = radiosityMaps.ConvertToLightmap(_currentLightmaps.Name, 0.02f);

                Graphics.RendererManager.CurrentRenderer.CullMode = Graphics.CullMode.CounterClockwise;
                Graphics.RendererManager.CurrentRenderer.Viewport = originalViewport;
                CurrentCamera  = originalCamera;
                _currentSkybox = originalSkybox;

                _calculatingRadiosity = false;
            }
        }
Ejemplo n.º 3
0
        public static PhysicalObject Read(Reader reader, Pointer offset, SuperObject so = null, Radiosity radiosity = null)
        {
            PhysicalObject po = new PhysicalObject(offset, so);

            //MapLoader.Loader.print("PO @ " + offset);
            // Header
            po.off_visualSet            = Pointer.Read(reader);
            po.off_collideSet           = Pointer.Read(reader);
            po.off_visualBoundingVolume = Pointer.Read(reader);
            if (Settings.s.engineVersion > Settings.EngineVersion.TT && Settings.s.game != Settings.Game.LargoWinch)
            {
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    po.off_collideBoundingVolume = po.off_visualBoundingVolume;
                    reader.ReadUInt32();
                }
                else
                {
                    po.off_collideBoundingVolume = Pointer.Read(reader);
                }
            }

            // Parse visual set
            Pointer.DoAt(ref reader, po.off_visualSet, () => {
                ushort numberOfLOD = 1;
                po.visualSetType   = 0;
                if (Settings.s.game == Settings.Game.LargoWinch)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = null;
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    po.visualSet                = new VisualSetLOD[1];
                    po.visualSet[0]             = new VisualSetLOD();
                    po.visualSet[0].obj         = MapLoader.Loader.meshObjects.FirstOrDefault(p => p.offset == po.off_visualSet);
                    po.visualSet[0].off_data    = po.off_visualSet;
                    po.visualSet[0].LODdistance = 5f;
                }
                else
                {
                    if (Settings.s.platform != Settings.Platform.DC)
                    {
                        reader.ReadUInt32();                         // 0
                        numberOfLOD = reader.ReadUInt16();
                        //if (numberOfLOD > 1) MapLoader.Loader.print("Found a PO with " + numberOfLOD + " levels of detail @ " + offset);
                        po.visualSetType = reader.ReadUInt16();
                        if (numberOfLOD > 0)
                        {
                            Pointer off_LODDistances   = Pointer.Read(reader);
                            Pointer off_LODDataOffsets = Pointer.Read(reader);
                            reader.ReadUInt32();                             // always 0? RLI table offset
                            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                            {
                                reader.ReadUInt32();                                                                                         // always 0? number of RLI
                            }
                            po.visualSet = new VisualSetLOD[numberOfLOD];
                            for (uint i = 0; i < numberOfLOD; i++)
                            {
                                po.visualSet[i] = new VisualSetLOD();
                            }
                            Pointer.DoAt(ref reader, off_LODDistances, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    // if distance > the float at this offset, game engine uses next LOD if there is one
                                    po.visualSet[i].LODdistance = reader.ReadSingle();
                                }
                            });
                            Pointer.DoAt(ref reader, off_LODDataOffsets, () => {
                                for (uint i = 0; i < numberOfLOD; i++)
                                {
                                    po.visualSet[i].off_data = Pointer.Read(reader);
                                }
                            });
                        }
                    }
                    else
                    {
                        // Platform = Dreamcast
                        Pointer.Read(reader);                        // Material pointer?
                        Pointer off_data = Pointer.Read(reader);
                        reader.ReadUInt32();                         // always 0?
                        reader.ReadUInt32();                         // always 0?
                        po.visualSet                = new VisualSetLOD[1];
                        po.visualSet[0].off_data    = off_data;
                        po.visualSet[0].LODdistance = 5f;
                    }
                }
                int radiosityLODIndex = 0;
                for (uint i = 0; i < numberOfLOD; i++)
                {
                    Pointer.DoAt(ref reader, po.visualSet[i].off_data, () => {
                        switch (po.visualSetType)
                        {
                        case 0:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = GeometricObject.Read(reader, po.visualSet[i].off_data, radiosity: radiosity?.lod?[radiosityLODIndex++]);
                            }
                            break;

                        case 1:
                            if (po.visualSet[i].obj == null)
                            {
                                po.visualSet[i].obj = PatchGeometricObject.Read(reader, po, po.visualSet[i].off_data);
                            }
                            break;

                        default:
                            MapLoader.Loader.print("unknown type " + po.visualSetType + " at offset: " + offset);
                            break;
                        }
                    });
                }
            });

            // Parse collide set
            Pointer.DoAt(ref reader, po.off_collideSet, () => {
                if (Settings.s.game == Settings.Game.R2Revolution)
                {
                    // Read collide mesh object here directly
                    po.collideMesh = GeometricObjectCollide.Read(reader, po.off_collideSet);
                }
                else
                {
                    // Read collide set containing collide mesh
                    uint u1         = reader.ReadUInt32();             // 0, zdm
                    uint u2         = reader.ReadUInt32();             // 0, zdd
                    uint u3         = reader.ReadUInt32();             // 0, zde
                    Pointer off_zdr = Pointer.Read(reader);
                    Pointer.DoAt(ref reader, off_zdr, () => {
                        po.collideMesh = GeometricObjectCollide.Read(reader, off_zdr);
                    });
                }
            });
            MapLoader.Loader.physicalObjects.Add(po);
            return(po);
        }