//Load our default setup! private void SetUpEditorScene(GraphicsDevice graphics) { //////////////////////////////////////////////////////////////////////// // Camera //Set up our starting camera position // NOTE: Coordinate system depends on Camera.up, // Right now z is going up, it's not depth! Camera = new Camera(position: new Vector3(-88, -11f, 4), lookat: new Vector3(38, 8, 32)); EnvironmentSample = new EnvironmentSample(new Vector3(-45, -5, 5)); VolumeTexture = new VolumeTextureEntity("Content/Sponza/sponza_sdf.sdff", graphics, new Vector3(-7, 0, 63), new Vector3(200, 100, 100)) { NeedsUpdate = true }; _sdfGenerator = new SDFGenerator(); //////////////////////////////////////////////////////////////////////// // GUI //////////////////////////////////////////////////////////////////////// // Static geometry // NOTE: If you don't pass a materialEffect it will use the default material from the object BasicEntity testEntity = AddEntity(model: _assets.SponzaModel, position: Vector3.Zero, angleX: Math.PI / 2, angleY: 0, angleZ: 0, scale: 0.1f, hasStaticPhysics: false);//CHANGE BACK //AddEntity(model: _assets.CloneTrooper, // position: new Vector3(20, 0, 10), // angleX: Math.PI / 2, // angleY: 0, // angleZ: 0, // scale: 10.4f); for (int x = -5; x <= 5; x++) { for (int y = -5; y <= 5; y++) { AddEntity(model: _assets.Plane, materialEffect: ((x + 5 + y + 5) % 2 == 1) ? _assets.MirrorMaterial : _assets.MetalRough03Material, position: new Vector3(30 + x * 4, y * 4 + 4, 0), angleX: 0, angleY: 0, angleZ: 0, scale: 2); } } AddEntity(model: _assets.StanfordDragon, materialEffect: _assets.BaseMaterial, position: new Vector3(40, -10, 0), angleX: Math.PI / 2, angleY: 0, angleZ: 0, scale: 10); //////////////////////////////////////////////////////////////////////// // Dynamic geometry // NOTE: We first have to create a physics object and then apply said object to a rendered model // BEPU could use non-default meshes, but that is much much more expensive so I am using just default ones right now // ... so -> spheres, boxes etc. // For dynamic meshes I could use the same way i have static meshes, but use - MobileMesh - instead // NOTE: Our physics entity's position will be overwritten, so it doesn't matter // NOTE: If a physics object has mass it will move, otherwise it is static Entity physicsEntity; //Just a ground box where nothing should fall through //_physicsSpace.Add(new Box(new BEPUutilities.Vector3(0, 0, -0.5f), 1000, 1000, 1)); _physicsSpace.Add(physicsEntity = new Sphere(position: BEPUutilities.Vector3.Zero, radius: 5, mass: 50)); AddEntity(model: _assets.IsoSphere, materialEffect: _assets.AlphaBlendRim, position: new Vector3(20, 0, 10), angleX: Math.PI / 2, angleY: 0, angleZ: 0, scale: 5, PhysicsEntity: physicsEntity); testEntity.ApplyTransformation(); _sdfGenerator.Generate(testEntity); for (int i = 0; i < 10; i++) { MaterialEffect test = _assets.SilverMaterial.Clone(); test.Roughness = i / 9.0f + 0.1f; test.Metallic = 1; _physicsSpace.Add(physicsEntity = new Sphere(position: BEPUutilities.Vector3.Zero, radius: 5, mass: 50)); AddEntity(model: _assets.IsoSphere, materialEffect: test, position: new Vector3(30 + i * 10, 0, 10), angleX: Math.PI / 2, angleY: 0, angleZ: 0, scale: 5, PhysicsEntity: physicsEntity); } //////////////////////////////////////////////////////////////////////// // Decals Decals.Add(new Decal(_assets.IconDecal, new Vector3(-6, 22, 15), 0, -Math.PI / 2, 0, Vector3.One * 10)); //////////////////////////////////////////////////////////////////////// // Dynamic lights AddPointLight(position: new Vector3(-61, 0, 107), radius: 150, color: new Color(104, 163, 223), intensity: 20, castShadows: false, shadowResolution: 1024, staticShadow: false, isVolumetric: true); AddPointLight(position: new Vector3(15, 0, 107), radius: 150, color: new Color(104, 163, 223), intensity: 30, castShadows: false, shadowResolution: 1024, staticShadow: false, isVolumetric: true); AddPointLight(position: new Vector3(66, 0, 40), radius: 120, color: new Color(255, 248, 232), intensity: 120, castShadows: true, shadowResolution: 1024, softShadowBlurAmount: 0, staticShadow: false, isVolumetric: false); //volumetric light! //AddPointLight(position: new Vector3(-4, 40, 66), // radius: 80, // color: Color.White, // intensity: 50, // castShadows: true, // shadowResolution: 1024, // staticShadow: false, // isVolumetric: true, // volumetricDensity: 3); // Spawn a lot of lights to test performance //int sides = 4; //float distance = 20; //Vector3 startPosition = new Vector3(-30, 30, 1); ////amount of lights is sides*sides* sides*2 //for (int x = 0; x < sides * 2; x++) // for (int y = 0; y < sides; y++) // for (int z = 0; z < sides; z++) // { // Vector3 position = new Vector3(x, -y, z) * distance + startPosition; // AddPointLight(position, distance, FastRand.NextColor(), 50, false, false, 0.9f); // } //AddDirectionalLight(direction: new Vector3(0.2f, 0.2f, -1), // intensity: 100, // color: Color.White, // position: Vector3.UnitZ * 2, // drawShadows: true, // shadowWorldSize: 450, // shadowDepth: 180, // shadowResolution: 1024, // shadowFilteringFiltering: DirectionalLightSource.ShadowFilteringTypes.SoftPCF3x, // screenspaceShadowBlur: false); }
public void Draw(MeshMaterialLibrary meshMat, List <Decal> decals, List <PointLight> pointLights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix viewProjection, Matrix view, EditorLogic.EditorSendData editorData, bool mouseMoved) { if (editorData.GizmoTransformationMode) { _graphicsDevice.SetRenderTarget(_idRenderTarget2D); _graphicsDevice.Clear(Color.Black); return; } if (mouseMoved) { DrawIds(meshMat, decals, pointLights, dirLights, envSample, debug, viewProjection, view, editorData); } if (GameSettings.e_drawoutlines) { DrawOutlines(meshMat, viewProjection, mouseMoved, HoveredId, editorData, mouseMoved); } }
public void DrawIds(MeshMaterialLibrary meshMat, List <Decal> decals, List <PointLight> pointLights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix viewProjection, Matrix view, EditorLogic.EditorSendData editorData) { _graphicsDevice.SetRenderTarget(_idRenderTarget2D); _graphicsDevice.BlendState = BlendState.Opaque; _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; _graphicsDevice.DepthStencilState = DepthStencilState.Default; meshMat.Draw(MeshMaterialLibrary.RenderType.IdRender, viewProjection); //Now onto the billboards DrawBillboards(decals, pointLights, dirLights, envSample, debug, viewProjection, view); //Now onto the gizmos DrawGizmos(viewProjection, editorData, _assets); Rectangle sourceRectangle = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1); Color[] retrievedColor = new Color[1]; try { if (sourceRectangle.X >= 0 && sourceRectangle.Y >= 0 && sourceRectangle.X < _idRenderTarget2D.Width - 2 && sourceRectangle.Y < _idRenderTarget2D.Height - 2) { _idRenderTarget2D.GetData(0, sourceRectangle, retrievedColor, 0, 1); } } catch { //nothing } HoveredId = IdGenerator.GetIdFromColor(retrievedColor[0]); }
/// <summary> /// Main Logic for the editor part /// </summary> /// <param name="gameTime"></param> /// <param name="entities"></param> /// <param name="data"></param> public void Update(GameTime gameTime, List <BasicEntity> entities, List <Decal> decals, List <PointLight> pointLights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debugEntities, EditorReceivedData data, MeshMaterialLibrary meshMaterialLibrary) { if (!GameSettings.e_enableeditor) { return; } if (!DebugScreen.ConsoleOpen) { if (Input.WasKeyPressed(Keys.R)) { GameStats.e_gizmoMode = GizmoModes.Rotation; } if (Input.WasKeyPressed(Keys.T)) { GameStats.e_gizmoMode = GizmoModes.Translation; } if (Input.WasKeyPressed(Keys.Z)) { GameStats.e_gizmoMode = GizmoModes.Scale; } } _gizmoMode = GameStats.e_gizmoMode; int hoveredId = data.HoveredId; if (_gizmoTransformationMode) { if (Input.mouseState.LeftButton == ButtonState.Pressed) { GizmoControl(_gizmoId, data); } else { _gizmoTransformationMode = false; } } else if (Input.WasLMBClicked() && !GUIControl.UIWasUsed) { previousMouseX = Input.mouseState.X; previousMouseY = Input.mouseState.Y; //Gizmos if (hoveredId >= 1 && hoveredId <= 3) { _gizmoId = hoveredId; GizmoControl(_gizmoId, data); return; } if (hoveredId <= 0) { SelectedObject = null; return; } bool foundnew = false; //Get the selected entity! for (int index = 0; index < entities.Count; index++) { var VARIABLE = entities[index]; if (VARIABLE.Id == hoveredId) { SelectedObject = VARIABLE; foundnew = true; break; } } if (foundnew == false) { for (int index = 0; index < decals.Count; index++) { Decal decal = decals[index]; if (decal.Id == hoveredId) { SelectedObject = decal; break; } } for (int index = 0; index < pointLights.Count; index++) { PointLight pointLight = pointLights[index]; if (pointLight.Id == hoveredId) { SelectedObject = pointLight; break; } } for (int index = 0; index < dirLights.Count; index++) { DirectionalLight directionalLight = dirLights[index]; if (directionalLight.Id == hoveredId) { SelectedObject = directionalLight; break; } } { if (envSample.Id == hoveredId) { SelectedObject = envSample; } } for (int index = 0; index < debugEntities.Count; index++) { DirectionalLight debugEntity = dirLights[index]; if (debugEntity.Id == hoveredId) { SelectedObject = debugEntity; break; } } } } //Controls if (Input.WasKeyPressed(Keys.Delete)) { //Find object if (SelectedObject is BasicEntity) { entities.Remove((BasicEntity)SelectedObject); meshMaterialLibrary.DeleteFromRegistry((BasicEntity)SelectedObject); SelectedObject = null; } else if (SelectedObject is Decal) { decals.Remove((Decal)SelectedObject); SelectedObject = null; } else if (SelectedObject is PointLight) { pointLights.Remove((PointLight)SelectedObject); SelectedObject = null; } else if (SelectedObject is DirectionalLight) { dirLights.Remove((DirectionalLight)SelectedObject); SelectedObject = null; } } if (Input.WasKeyPressed(Keys.Insert) || (Input.keyboardState.IsKeyDown(Keys.LeftControl) && Input.WasKeyPressed(Keys.C))) { if (SelectedObject is BasicEntity) { BasicEntity copy = (BasicEntity)SelectedObject.Clone; copy.RegisterInLibrary(meshMaterialLibrary); entities.Add(copy); } else if (SelectedObject is Decal) { Decal copy = (Decal)SelectedObject.Clone; decals.Add(copy); } else if (SelectedObject is PointLight) { PointLight copy = (PointLight)SelectedObject.Clone; pointLights.Add(copy); } else if (SelectedObject is DirectionalLight) { DirectionalLight copy = (DirectionalLight)SelectedObject.Clone; dirLights.Add(copy); } } }
public void DrawBillboards(List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debugEntities, Matrix staticViewProjection, Matrix view) { _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; _graphicsDevice.SetVertexBuffer(_billboardBuffer.VBuffer); _graphicsDevice.Indices = (_billboardBuffer.IBuffer); Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconLight); Shaders.BillboardEffect.CurrentTechnique = Shaders.BillboardEffectTechnique_Id; for (int index = 0; index < decals.Count; index++) { var decal = decals[index]; Matrix world = Matrix.CreateTranslation(decal.Position); DrawBillboard(world, view, staticViewProjection, decal.Id); } for (int index = 0; index < lights.Count; index++) { var light = lights[index]; Matrix world = Matrix.CreateTranslation(light.Position); DrawBillboard(world, view, staticViewProjection, light.Id); } for (int index = 0; index < dirLights.Count; index++) { var light = dirLights[index]; Matrix world = Matrix.CreateTranslation(light.Position); DrawBillboard(world, view, staticViewProjection, light.Id); } Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconEnvmap); { Matrix world = Matrix.CreateTranslation(envSample.Position); DrawBillboard(world, view, staticViewProjection, envSample.Id); } for (int index = 0; index < debugEntities.Count; index++) { var debug = debugEntities[index]; Matrix world = Matrix.CreateTranslation(debug.Position); DrawBillboard(world, view, staticViewProjection, debug.Id); } }
public void DrawEnvironmentMap(GraphicsDevice graphicsDevice, Matrix view, FullScreenTriangle fullScreenTriangle, EnvironmentSample envSample, bool fireflyReduction, float ffThreshold) { FireflyReduction = fireflyReduction; FireflyThreshold = ffThreshold; SpecularStrength = envSample.SpecularStrength; DiffuseStrength = envSample.DiffuseStrength; graphicsDevice.DepthStencilState = DepthStencilState.None; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; _paramTransposeView.SetValue(Matrix.Transpose(view)); _passBasic.Apply(); fullScreenTriangle.Draw(graphicsDevice); }
public void DrawEnvironmentMap(GraphicsDevice graphicsDevice, Camera camera, Matrix view, FullScreenTriangle fullScreenTriangle, EnvironmentSample envSample, GameTime gameTime, bool fireflyReduction, float ffThreshold) { FireflyReduction = fireflyReduction; FireflyThreshold = ffThreshold; SpecularStrength = envSample.SpecularStrength; DiffuseStrength = envSample.DiffuseStrength; CameraPositionWS = camera.Position; Time = (float)gameTime.TotalGameTime.TotalSeconds % 1000; graphicsDevice.DepthStencilState = DepthStencilState.None; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; UseSDFAO = envSample.UseSDFAO; _paramTransposeView.SetValue(Matrix.Transpose(view)); _passBasic.Apply(); fullScreenTriangle.Draw(graphicsDevice); }
public void DrawBillboards(List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData sendData) { _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; _graphicsDevice.SetVertexBuffer(_billboardBuffer.VBuffer); _graphicsDevice.Indices = (_billboardBuffer.IBuffer); Shaders.BillboardEffect.CurrentTechnique = Shaders.BillboardEffectTechnique_Billboard; Shaders.BillboardEffectParameter_IdColor.SetValue(Color.Gray.ToVector3()); //Decals Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconDecal); for (int index = 0; index < decals.Count; index++) { var decal = decals[index]; DrawBillboard(decal, staticViewProjection, view, sendData); } //Lights Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconLight); for (int index = 0; index < lights.Count; index++) { var light = lights[index]; DrawBillboard(light, staticViewProjection, view, sendData); } //DirectionalLights for (var index = 0; index < dirLights.Count; index++) { DirectionalLight light = dirLights[index]; DrawBillboard(light, staticViewProjection, view, sendData); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position + Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position - Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position + Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position - Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position + Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black, light.Color); HelperGeometryManager.GetInstance() .AddLineStartDir(light.Position - Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black, light.Color); if (light.CastShadows) { BoundingFrustum boundingFrustumShadow = new BoundingFrustum(light.LightViewProjection); HelperGeometryManager.GetInstance().CreateBoundingBoxLines(boundingFrustumShadow); } } //EnvMap Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconEnvmap); DrawBillboard(envSample, staticViewProjection, view, sendData); //Dbg for (int index = 0; index < debug.Count; index++) { var dbgEntity = debug[index]; DrawBillboard(dbgEntity, staticViewProjection, view, sendData); } }
public void DrawEditorElements(MeshMaterialLibrary meshMaterialLibrary, List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData editorData) { _graphicsDevice.SetRenderTarget(null); _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; _graphicsDevice.DepthStencilState = DepthStencilState.Default; _graphicsDevice.BlendState = BlendState.Opaque; DrawGizmo(staticViewProjection, editorData); DrawBillboards(decals, lights, dirLights, envSample, debug, staticViewProjection, view, editorData); }
public void DrawIds(MeshMaterialLibrary meshMaterialLibrary, List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData editorData) { _idAndOutlineRenderer.Draw(meshMaterialLibrary, decals, lights, dirLights, envSample, debug, staticViewProjection, view, editorData, _mouseMovement); }