private static void CreateEarthAndMoonScene(float speed, float orbitDistanceMultiplier, float planetScaleMultiplier, Renderer renderer) { // Create and setup material SimpleMaterial baseMaterial = new SimpleMaterial { VertexShaderPath = "Shaders.fx", VertexShaderEntryPoint = "VS", VertexShaderProfile = "vs_5_0", PixelShaderPath = "Shaders.fx", PixelShaderEntryPoint = "PS", PixelShaderProfile = "ps_5_0", }; baseMaterial.Initialize(renderer.device); baseMaterial.pixelShaderData.LightPos = new Vector4(5, 3, 5, 1); baseMaterial.pixelShaderData.EmissionColor = new Vector4(0.1f, 0.1f, 0.1f, 1); // Load model ModelLoader modelLoader = new ModelLoader(renderer.device); Model sphere = modelLoader.LoadRelative("Assets\\Planets\\sphere.obj"); // Create scene objects var earth = CreatePlanet(0f * speed, 0f * orbitDistanceMultiplier, 1f * planetScaleMultiplier, baseMaterial, new Vector4(0.2f, 0.2f, 0.8f, 1), sphere); CreatePlanet(1 / 0.1f * speed, 1f * orbitDistanceMultiplier, 0.4f, baseMaterial, new Vector4(0.4f, 0.4f, 0.4f, 1), sphere, earth.transform); }
public void Draw(CommandList cmdList, Camera cam) { cmdList.SetVertexBuffer(0, m_vertexBuffer); cmdList.SetIndexBuffer(m_indexBuffer, IndexFormat.UInt32); cmdList.SetPipeline(m_pipelineState); SN.Matrix4x4 transform = WorldMatrix; for (int i = 0; i < m_meshesToDraw.Count; i++) { MeshDrawCall drawParams = m_meshesToDraw[i]; MeshPart partData = m_meshesData[drawParams.MeshPartIndex]; SimpleMaterial material = m_materials[partData.MaterialIndex]; SN.Matrix4x4 w = drawParams.World * transform; SN.Matrix4x4 wvp = w * cam.ViewProjection; cmdList.UpdateBuffer(m_wvpParam, 0, ref wvp); cmdList.UpdateBuffer(m_worldParam, 0, ref w); cmdList.UpdateBuffer(m_lightPosParam, 0, LightPosition); cmdList.UpdateBuffer(m_camPosParam, 0, cam.Position); cmdList.SetGraphicsResourceSet(0, m_worldLightCBSet); cmdList.SetGraphicsResourceSet(1, material.ColorAndTexture); cmdList.DrawIndexed((uint)partData.IndexCount, 1, (uint)partData.IndexOffset, 0, 0); } }
public override void Load(BodyHandle bodyHandle, ConnectionState connectionState, Simulator simulator, ObjectState state) { base.Load(bodyHandle, connectionState, simulator, state); PhyInterval worker = new PhyInterval(1, simulator); worker.Completed += Tick; material = new SimpleMaterial { FrictionCoefficient = .97f, MaximumRecoveryVelocity = float.MaxValue, SpringSettings = new SpringSettings(1f, 1.5f) }; simulator.collidableMaterials.Allocate(bodyHandle) = material; reference = simulator.Simulation.Bodies.GetBodyReference(bodyHandle); simulator.OnContactListeners.Add(this.bodyHandle, this); SetPositionToStartPoint(); CreateBall(); CreateUser(); CreateGauntlet(); jumpState = new JumpState(this); snappedState = new SnappedState(this); notSnappedState = new Not_SnappedState(this); shotState = new ShootState(this); }
private static void CreateSolarSystemScene(float speed, float orbitDistanceMultiplier, float planetScaleMultiplier, Renderer renderer) { // Create and setup material SimpleMaterial baseMaterial = new SimpleMaterial { VertexShaderPath = "Shaders.fx", VertexShaderEntryPoint = "VS", VertexShaderProfile = "vs_5_0", PixelShaderPath = "Shaders.fx", PixelShaderEntryPoint = "PS", PixelShaderProfile = "ps_5_0", }; baseMaterial.Initialize(renderer.device); baseMaterial.pixelShaderData.LightPos = new Vector4(0, 0, 0, 1); baseMaterial.pixelShaderData.EmissionColor = new Vector4(0.1f, 0.1f, 0.1f, 1); // Load model ModelLoader modelLoader = new ModelLoader(renderer.device); Model sphere = modelLoader.LoadRelative("Assets\\Planets\\sphere.obj"); // Create scene objects // Sun SceneObject sunObject = new SceneObject(); sunObject.model = sphere; SimpleMaterial sunMaterial = baseMaterial.CreateInstanceTyped(); sunMaterial.pixelShaderData.DiffuseColor = new Vector4(0.92f, 0.72f, 0.2f, 1); sunMaterial.pixelShaderData.EmissionColor = new Vector4(0.92f, 0.8f, 0.2f, 1); sunObject.material = sunMaterial; // Mercury CreatePlanet(4f * speed, 0.36f * orbitDistanceMultiplier, 0.38f * planetScaleMultiplier, baseMaterial, new Vector4(0.7f, 0.6f, 0.5f, 1), sphere); // Venus CreatePlanet(1.3f * speed, 0.67f * orbitDistanceMultiplier, 0.95f * planetScaleMultiplier, baseMaterial, new Vector4(0.96f, 0.48f, 0.04f, 1), sphere); // Earth + Moon var earth = CreatePlanet(1f * speed, 0.93f * orbitDistanceMultiplier, 1f * planetScaleMultiplier, baseMaterial, new Vector4(0.2f, 0.2f, 0.8f, 1), sphere); CreatePlanet(1 / 0.1f * speed, 1f * orbitDistanceMultiplier, 0.8f * planetScaleMultiplier, baseMaterial, new Vector4(0.4f, 0.4f, 0.4f, 1), sphere, earth.transform); // Mars CreatePlanet(0.45f * speed, 1.41f * orbitDistanceMultiplier, 0.53f * planetScaleMultiplier, baseMaterial, new Vector4(0.73f, 0.13f, 0.04f, 1), sphere); // Jupiter CreatePlanet(1 / 11.9f * speed, 2.6f * orbitDistanceMultiplier, 11.12f * planetScaleMultiplier, baseMaterial, new Vector4(0.77f, 0.66f, 0.45f, 1), sphere); // Saturn CreatePlanet(1 / 29.5f * speed, 3.7f * orbitDistanceMultiplier, 9.45f * planetScaleMultiplier, baseMaterial, new Vector4(0.68f, 0.54f, 0.36f, 1), sphere); // Uranus CreatePlanet(1 / 84f * speed, 4.4f * orbitDistanceMultiplier, 4.00f * planetScaleMultiplier, baseMaterial, new Vector4(0.55f, 0.83f, 0.97f, 1), sphere); // Neptune CreatePlanet(1 / 165f * speed, 5.2f * orbitDistanceMultiplier, 3.88f * planetScaleMultiplier, baseMaterial, new Vector4(0.38f, 0.50f, 0.83f, 1), sphere); }
public static SimpleMaterial CreateMaterial(TwoDimensionDrawContext drawContext, BrushWidget widget) { SimpleMaterial simpleMaterial = drawContext.CreateSimpleMaterial(); Brush brush = widget.Brush; StyleLayer styleLayer; if (brush == null) { styleLayer = null; } else { Dictionary <string, StyleLayer> .ValueCollection layers = brush.GetStyleOrDefault(widget.CurrentState).Layers; styleLayer = layers?.FirstOrDefault(); } simpleMaterial.OverlayEnabled = false; simpleMaterial.CircularMaskingEnabled = false; simpleMaterial.AlphaFactor = (styleLayer?.AlphaFactor ?? 1f) * widget.Brush.GlobalAlphaFactor * widget.Context.ContextAlpha; simpleMaterial.ColorFactor = (styleLayer?.ColorFactor ?? 1f) * widget.Brush.GlobalColorFactor; simpleMaterial.HueFactor = styleLayer?.HueFactor ?? 0.0f; simpleMaterial.SaturationFactor = styleLayer?.SaturationFactor ?? 0.0f; simpleMaterial.ValueFactor = styleLayer?.ValueFactor ?? 0.0f; simpleMaterial.Color = (styleLayer?.Color ?? Color.White) * widget.Brush.GlobalColor; return(simpleMaterial); }
public RenderSystem(ICamera camera) { _camera = camera; _resourceAllocator = new ResourceAllocator(new OpenGlResourceFactory()); _simpleMaterial = new SimpleMaterial(); _simpleMaterial.Create(); _normalDebugProgram = new NormalDebugProgram(); _normalDebugProgram.Create(); }
public Terrain(IChunkedLod chunkedLod) { _tree = CreateTree(); _chunkedLod = chunkedLod; _simpleMaterial = new SimpleMaterial(); _simpleMaterial.Create(); _normalDebugProgram = new NormalDebugProgram(); _normalDebugProgram.Create(); _cache = new TerrainChunkCache(new TerrainChunkFactory(), new ResourceAllocator(new OpenGlResourceFactory())); }
public Cube() { _simpleMaterial = new SimpleMaterial(); var resourceAllocator = new ResourceAllocator(new OpenGlResourceFactory()); _simpleMaterial.Create(); var mesh = MeshCreator.CreateXZGrid(10, 10); _renderable = resourceAllocator.AllocateResourceFor(mesh); _renderable.CreateVAO(); }
protected override void OnRender(TwoDimensionContext twoDimensionContext, TwoDimensionDrawContext drawContext) { base.OnRender(twoDimensionContext, drawContext); var size = _agentMarkerSize; UpdateDrawObject2D(size, size); var materials = new SimpleMaterial[(int)AgentMarkerType.Count]; var globalPosition = Widgets.Utility.GetGlobalPosition(this); for (int i = 0; i < AgentMakers.CountOfAgentMarkers; ++i) { var agentMaker = AgentMakers.AgentMarkers[i]; var type = agentMaker.AgentMarkerType; twoDimensionContext.Draw(globalPosition.x + agentMaker.PositionInWidget.x * ScaledSuggestedWidth / Math.Max(SuggestedWidth, 1) - size * 0.5f, globalPosition.y + agentMaker.PositionInWidget.y * ScaledSuggestedHeight / Math.Max(SuggestedHeight, 1) - size * 0.5f, materials[(int)type] ??= CreateMaterial(drawContext, type), _cachedMesh, type.GetLayer()); } }
protected override void OnRender(TwoDimensionContext twoDimensionContext, TwoDimensionDrawContext drawContext) { base.OnRender(twoDimensionContext, drawContext); SimpleMaterial simpleMaterial = drawContext.CreateSimpleMaterial(); Brush brush = Brush; StyleLayer styleLayer; if (brush == null) { styleLayer = null; } else { Dictionary <string, StyleLayer> .ValueCollection layers = brush.GetStyleOrDefault(CurrentState).Layers; styleLayer = layers?.FirstOrDefault(); } simpleMaterial.OverlayEnabled = false; simpleMaterial.CircularMaskingEnabled = false; simpleMaterial.Texture = Texture; simpleMaterial.AlphaFactor = (styleLayer?.AlphaFactor ?? 1f) * Brush.GlobalAlphaFactor * Context.ContextAlpha; simpleMaterial.ColorFactor = (styleLayer?.ColorFactor ?? 1f) * Brush.GlobalColorFactor; simpleMaterial.HueFactor = styleLayer?.HueFactor ?? 0.0f; simpleMaterial.SaturationFactor = styleLayer?.SaturationFactor ?? 0.0f; simpleMaterial.ValueFactor = styleLayer?.ValueFactor ?? 0.0f; simpleMaterial.Color = (styleLayer?.Color ?? Color.White) * Brush.GlobalColor; if (CachedMesh == null || Math.Abs(CachedMesh.Width - Size.X) > 0.01f && Math.Abs(CachedMesh.Height - Size.Y) > 0.01f) { UpdateDrawObject2D(); } if (drawContext.CircularMaskEnabled) { simpleMaterial.CircularMaskingEnabled = true; simpleMaterial.CircularMaskingCenter = drawContext.CircularMaskCenter; simpleMaterial.CircularMaskingRadius = drawContext.CircularMaskRadius; simpleMaterial.CircularMaskingSmoothingRadius = drawContext.CircularMaskSmoothingRadius; } //drawContext.Draw(GlobalPosition.X, GlobalPosition.Y, simpleMaterial, CachedMesh, Size.X, Size.Y); twoDimensionContext.Draw(GlobalPosition.X, GlobalPosition.Y, simpleMaterial, CachedMesh, Layer); }
private static SceneObject CreatePlanet(float orbitRotationSpeed, float orbitDistance, float planetScale, SimpleMaterial baseMaterial, Vector4 planetColor, Model model, Transform parentTransform = null) { SceneObject planetRoot = new SceneObject(); SimpleTransformAnimationComponent animationComponent = new SimpleTransformAnimationComponent() { RotationSpeed = new Vector3(orbitRotationSpeed, 0, 0), }; planetRoot.AddComponent(animationComponent); planetRoot.animationComponent = animationComponent; planetRoot.transform.parent = parentTransform; SceneObject planet = new SceneObject(); planet.model = model; planet.transform.LocalPositionX = orbitDistance; planet.transform.LocalScale = Vector3.One * planetScale; planet.transform.parent = planetRoot.transform; SimpleMaterial planetMaterial = baseMaterial.CreateInstanceTyped(); planetMaterial.pixelShaderData.DiffuseColor = planetColor; planet.material = planetMaterial; return(planet); }