public override void Initialize() { base.Initialize(); // setup screen that fits our map based on the bg size SetDesignResolution(137 * 9, 89 * 9, SceneResolutionPolicy.ShowAllPixelPerfect); Screen.SetSize(137 * 9, 89 * 9); ClearColor = Color.DarkGray; // add our renderer setting the renderLayers we will use for lights and for renderables var deferredRenderer = AddRenderer(new DeferredLightingRenderer(0, LightLayer, RenderablesLayer)) .SetClearColor(Color.DarkGray); deferredRenderer.EnableDebugBufferRender = false; // prep our textures. we have diffuse and normal maps to interact with the lights. var moonTex = Content.LoadTexture(Nez.Content.DeferredLighting.Moon); var moonNorm = Content.LoadTexture(Nez.Content.DeferredLighting.MoonNorm); var orangeTexture = Content.LoadTexture(Nez.Content.DeferredLighting.Orange); var orangeNormalMap = Content.LoadTexture(Nez.Content.DeferredLighting.OrangeNorm); var bgTexture = Content.LoadTexture(Nez.Content.DeferredLighting.Bg); var bgNormalMap = Content.LoadTexture(Nez.Content.DeferredLighting.BgNorm); // prep our Materials. Deferred lighting requires a Material that is normal map aware. We can also leave our Material null and // a default Material will be used that is diffuse lighting only (no normal map). var moonMaterial = new DeferredSpriteMaterial(moonNorm); var orangeMaterial = new DeferredSpriteMaterial(orangeNormalMap); var bgMaterial = new DeferredSpriteMaterial(bgNormalMap); // create some Entities. When we add the Renderable (Sprite in this case) we need to be sure to set the renderLayer and Material var bgEntity = CreateEntity("bg"); bgEntity.SetPosition(Screen.Center).SetScale(9); bgEntity.AddComponent(new SpriteRenderer(bgTexture)).SetRenderLayer(RenderablesLayer).SetMaterial(bgMaterial) .SetLayerDepth(1); bgEntity.AddComponent(new DeferredLightingController()); var orangeEntity = CreateEntity("orange"); orangeEntity.SetPosition(Screen.Center).SetScale(0.5f); orangeEntity.AddComponent(new SpriteRenderer(orangeTexture)).SetRenderLayer(RenderablesLayer) .SetMaterial(orangeMaterial); orangeEntity.AddComponent(new SpotLight()).SetRenderLayer(LightLayer); var moonEntity = CreateEntity("moon"); moonEntity.SetPosition(new Vector2(100, 400)); moonEntity.AddComponent(new SpriteRenderer(moonTex)).SetRenderLayer(RenderablesLayer).SetMaterial(moonMaterial); moonEntity.AddComponent(new DirLight(Color.Red)).SetRenderLayer(LightLayer).SetEnabled(true); var clone = orangeEntity.Clone(new Vector2(200, 200)); AddEntity(clone); var mouseFollowEntity = CreateEntity("mouse-follow"); mouseFollowEntity.AddComponent(new MouseFollow()); mouseFollowEntity.AddComponent(new PointLight(new Color(0.8f, 0.8f, 0.9f))).SetRadius(200).SetIntensity(2) .SetRenderLayer(LightLayer); }
public override void initialize() { base.initialize(); // setup screen that fits our map based on the bg size setDesignResolution(137, 89, Scene.SceneResolutionPolicy.ShowAllPixelPerfect); Screen.setSize(137 * 6, 89 * 6); //clearColor = Color.DarkGray; // add our renderer setting the renderLayers we will use for lights and for renderables var deferredRenderer = addRenderer(new DeferredLightingRenderer(100, LIGHT_LAYER, RENDERABLES_LAYER)); deferredRenderer.enableDebugBufferRender = false; // prep our textures. we have diffuse and normal maps to interact with the lights. var moonTex = contentManager.Load <Texture2D>("DeferredLighting/moon"); var moonNorm = contentManager.Load <Texture2D>("DeferredLighting/moonNorm"); var orangeTexture = contentManager.Load <Texture2D>("DeferredLighting/orange"); var orangeNormalMap = contentManager.Load <Texture2D>("DeferredLighting/orangeNorm"); var bgTexture = contentManager.Load <Texture2D>("DeferredLighting/bg"); var bgNormalMap = contentManager.Load <Texture2D>("DeferredLighting/bgNorm"); // prep our Materials. Deferred lighting requires a Material that is normal map aware. We can also leave our Material null and // a default Material will be used that is diffuse lighting only (no normal map). var moonMaterial = new DeferredSpriteMaterial(moonNorm); var orangeMaterial = new DeferredSpriteMaterial(orangeNormalMap); var bgMaterial = new DeferredSpriteMaterial(bgNormalMap); orangeMaterial = null; moonMaterial = null; // create some Entities. When we add the Renderable (Sprite in this case) we need to be sure to set the renderLayer and Material var bgEntity = createEntity("bg"); bgEntity.transform.setPosition(new Vector2(0, 0)).setScale(1); bgEntity.addComponent(new Sprite(bgTexture)).setRenderLayer(RENDERABLES_LAYER); bgEntity.addComponent(new DeferredLightingController()); var orangeEntity = createEntity("orange"); orangeEntity.transform.setPosition(new Vector2(0, 0)).setScale(1f); orangeEntity.addComponent(new Sprite(orangeTexture)).setRenderLayer(RENDERABLES_LAYER).setMaterial(orangeMaterial); orangeEntity.addComponent(new SpotLight()).setRenderLayer(LIGHT_LAYER); var moonEntity = createEntity("moon"); moonEntity.transform.setPosition(new Vector2(100, 400)); moonEntity.addComponent(new Sprite(moonTex)).setRenderLayer(RENDERABLES_LAYER).setMaterial(moonMaterial); moonEntity.addComponent(new DirLight(Color.Red)).setRenderLayer(LIGHT_LAYER).setEnabled(true); var clone = orangeEntity.clone(new Vector2(200, 200)); addEntity(clone); var mouseFollowEntity = createEntity("mouse-follow"); mouseFollowEntity.addComponent(new MouseFollow()); mouseFollowEntity.addComponent(new PointLight(new Color(0.8f, 0.8f, 0.9f))).setRadius(200).setIntensity(2) .setRenderLayer(LIGHT_LAYER); }
public void Generate(DungeonMapGeneratorSettings settings) { _mapWidth = settings.Width; _mapHeight = settings.Height; _generator = new DungeonMapGenerator(settings); _generator.Generate(); var result = _generator.Result; TileLayers = new List <Tile[, ]>(); var normalMap = Core.Content.Load <Texture2D>(Content.Textures.Tileset_subtiles_test_normal); var material = new DeferredSpriteMaterial(normalMap); foreach (var tileGroup in result.Tiles) { var layer = new Tile[_mapWidth, _mapHeight]; layer.Initialize(); foreach (var tile in tileGroup) { layer[tile.TilePosition.X, tile.TilePosition.Y] = tile; } TileLayers.Add(layer); var layerRenderer = new DungeonMapLayerRenderer(); var renderLayer = DetermineRenderLayerForGroup(tileGroup.Key); layerRenderer.SetRenderLayer(renderLayer); layerRenderer.SetMaterial(material); layerRenderer.SetTiles(layer); AddComponent(layerRenderer); } foreach (var Entity in result.Entities) { Core.Scene.AddEntity(Entity); } foreach (var colliderBounds in result.ColliderBounds) { AddComponent(new BoxCollider(colliderBounds)); } Spawn = result.Entities.First(e => e is Spawn) as Spawn; Exit = result.Entities.First(e => e is Exit) as Exit; }
public DeferredLightingRenderer( int renderOrder, int lightLayer, params int[] renderLayers ) : base( renderOrder ) { // make sure we have a workable Material for our lighting system material = new DeferredSpriteMaterial( nullNormalMapTexture ); _lightLayer = lightLayer; Array.Sort( renderLayers ); Array.Reverse( renderLayers ); this.renderLayers = renderLayers; _lightEffect = new DeferredLightEffect(); // meshes used for light volumes _quadMesh = new QuadMesh( Core.graphicsDevice ); _polygonMesh = PolygonMesh.createSymmetricalPolygon( 10 ); _quadPolygonMesh = PolygonMesh.createRectangle(); // set some sensible defaults setAmbientColor( new Color( 0.2f, 0.2f, 0.2f ) ) .setClearColor( Color.CornflowerBlue ); }