public bool TryLoad(IReadOnlyFileSystem fileSystem, string path, out ISkybox skybox, out string[] imageFileRelativePaths, out ErrorInfo error) { dynamic mainFile; using (var reader = trwFactory.JsonReader(fileSystem.OpenRead(path))) mainFile = reader.ReadAsDynamic(); imageFileRelativePaths = new string[] { mainFile.Right, mainFile.Left, mainFile.Top, mainFile.Bottom, mainFile.Back, mainFile.Front }; var folderPath = Path.Combine(Path.GetDirectoryName(path)); var images = new IImage[6]; for (var i = 0; i < 6; i++) { var relPath = imageFileRelativePaths[i]; using (var stream = fileSystem.OpenRead(Path.Combine(folderPath, relPath))) if (!imageLoader.TryLoad(stream, out images[i], out error)) { skybox = null; return(false); } } var width = images[0].Size.Width; if (images.Any(x => x.Size != new IntSize2(width, width))) { error = new ErrorInfo("Skybox images are not of equal size"); skybox = null; return(false); } skybox = new Skybox(ResourceVolatility.Immutable, width, images); return(true); }
public Game( IAppConfig config, ILogger logger, ICamera camera, IWorld world, OpenGlContext context, IRenderer renderer, IRenderer ndcRenderer, IRenderer skyboxRenderer, ISkybox skybox) { _camera = camera; _logger = logger; _config = config; _title = config.WindowTitle; _context = context; ConfigureContext(); _skybox = skybox; _world = world; GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.FrontFace(FrontFaceDirection.Cw); GL.ClearColor(Color4.Green); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); _renderer = renderer; _ndcRenderer = ndcRenderer; _skyboxRenderer = skyboxRenderer; _skyboxRenderer.BeforeRender = () => { GL.DepthFunc(DepthFunction.Lequal); GL.CullFace(CullFaceMode.Front); }; _skyboxRenderer.AfterRender = () => { GL.CullFace(CullFaceMode.Back); }; _skyboxRenderer.AddToScene(skybox); _traffic = _world.Traffic; _renderer.AddToScene(_traffic); _renderer.AddToScene(_world.Renderables); _backbufferTexture = new Texture(_config.ResolutionWidth, config.ResolutionHeight); _worldRenderer = new BackBufferRenderer( _logger, _backbufferTexture, _config.ResolutionWidth, _config.ResolutionHeight, useDepthBuffer: true); _postprocessTexture = new Texture(_config.ResolutionWidth, _config.ResolutionHeight); _postprocessPipeline = new PostprocessPipeline(_logger, _config, _worldRenderer.Texture, _postprocessTexture); _fullscreenShader = new Shader("vs.vert", "fs.frag"); _fullscreenShader.SetUniformValue("tex", new IntUniform { Value = 0 }); _ndcTexture = _postprocessTexture; var fullScreenQuad = new FullScreenQuad(new[] { _ndcTexture }, _fullscreenShader); _ndcRenderer.AddToScene(fullScreenQuad); }
public SkyboxCache(IGraphicsInfra infra, ISkybox skybox) { this.skybox = skybox; this.infra = infra; isDirty = true; }
protected override void Subscribed() { if (_labyrinthData != null) { Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); return; } var assets = Resolve <IAssetManager>(); var state = Resolve <IGameState>(); var factory = Resolve <ICoreFactory>(); _labyrinthData = assets.LoadLabyrinthData(_mapData.LabDataId); if (_labyrinthData == null) { return; } _logicalMap = new LogicalMap3D(_mapData, _labyrinthData, state.TemporaryMapChanges, state.PermanentMapChanges); var properties = new TilemapRequest { Id = MapId, Width = (uint)_logicalMap.Width, Scale = _labyrinthData.TileSize, Origin = _labyrinthData.TileSize.Y / 2 * Vector3.UnitY, HorizontalSpacing = _labyrinthData.TileSize * Vector3.UnitX, VerticalSpacing = _labyrinthData.TileSize * Vector3.UnitZ, AmbientLightLevel = _labyrinthData.Lighting, FogColor = _labyrinthData.FogColor, ObjectYScaling = _labyrinthData.ObjectYScaling, Pipeline = DungeonTilemapPipeline.Normal }; _selection = AttachChild(new Selection3D()); AttachChild(new MapRenderable3D(_logicalMap, _labyrinthData, properties)); AttachChild(new ScriptManager()); AttachChild(new Collider3D(_logicalMap)); if (!_labyrinthData.BackgroundId.IsNone) { var background = assets.LoadTexture(_labyrinthData.BackgroundId); _skybox = factory.CreateSkybox(background); } var palette = assets.LoadPalette(_logicalMap.PaletteId); uint backgroundColour = palette.GetPaletteAtTime(0)[_labyrinthData.BackgroundColour]; _backgroundRed = (backgroundColour & 0xff) / 255.0f; _backgroundGreen = (backgroundColour & 0xff00 >> 8) / 255.0f; _backgroundBlue = (backgroundColour & 0xff0000 >> 16) / 255.0f; //if(_labyrinthData.CameraHeight != 0) // Debugger.Break(); //if(_labyrinthData.Unk12 != 0) // 7=1|2|4 (Jirinaar), 54=32|16|4|2, 156=128|16|8|2 (Tall town) // Debugger.Break(); // Raise(new LogEvent(LogEvent.Level.Info, $"WallHeight: {_labyrinthData.WallHeight} MaxObj: {maxObjectHeightRaw} EffWallWidth: {_labyrinthData.EffectiveWallWidth}")); foreach (var npc in _logicalMap.Npcs) { if (npc.SpriteOrGroup.IsNone) { continue; } if (npc.SpriteOrGroup.Type != AssetType.ObjectGroup) { Warn($"[3DMap] Tried to load npc with object group of incorrect type: {npc.SpriteOrGroup}"); continue; } if (npc.SpriteOrGroup.Id >= _labyrinthData.ObjectGroups.Count) { Warn($"[3DMap] Tried to load object group {npc.SpriteOrGroup.Id}, but the max group id is {_labyrinthData.ObjectGroups.Count-1}."); continue; } var objectData = _labyrinthData.ObjectGroups[npc.SpriteOrGroup.Id]; // TODO: Verify SpriteOrGroup is an ObjectGroup // TODO: Build proper NPC objects with AI, sound effects etc foreach (var subObject in objectData.SubObjects) { AttachChild(MapObject.Build(npc.Waypoints[0].X, npc.Waypoints[0].Y, _labyrinthData, subObject, properties)); } } for (int y = 0; y < _logicalMap.Height; y++) { for (int x = 0; x < _logicalMap.Width; x++) { var group = _logicalMap.GetObject(x, y); if (group == null) { continue; } foreach (var subObject in group.SubObjects) { AttachChild(MapObject.Build(x, y, _labyrinthData, subObject, properties)); } } } Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); }
protected override void Unsubscribed() { _skybox?.Dispose(); _skybox = null; base.Unsubscribed(); }
public static void SetRotation(this ISkybox skybox, System.Single rotation) => skybox.Skybox.material.SetFloat("_Rotation", rotation);
public static System.Single GetRotation(this ISkybox skybox) => skybox.Skybox.material.GetFloat("_Rotation");
public static UnityEngine.Skybox GetSkybox(this ISkybox skybox) => (skybox as UnityEngine.Component)?.GetComponent <UnityEngine.Skybox> ();