static void Main(string[] args) { Bootstrapper.Configure(); var viewer = SimpleViewer.Create("Hello Veldrid Scene Graph"); viewer.SetCameraManipulator(TrackballManipulator.Create()); var root = Group.Create(); var geometry = Geometry <VertexPositionColor> .Create(); VertexPositionColor[] quadVertices = { new VertexPositionColor(new Vector2(-.75f, .75f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f)), new VertexPositionColor(new Vector2(.75f, .75f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f)), new VertexPositionColor(new Vector2(-.75f, -.75f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)), new VertexPositionColor(new Vector2(.75f, -.75f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f)) }; geometry.VertexData = quadVertices; uint[] quadIndices = { 0, 1, 2, 3 }; geometry.IndexData = quadIndices; geometry.VertexLayout = new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4)); var pSet = DrawElements <VertexPositionColor> .Create( geometry, PrimitiveTopology.TriangleStrip, (uint)geometry.IndexData.Length, 1, 0, 0, 0); geometry.PrimitiveSets.Add(pSet); geometry.PipelineState.VertexShaderDescription = Vertex2Color4Shader.Instance.VertexShaderDescription; geometry.PipelineState.FragmentShaderDescription = Vertex2Color4Shader.Instance.FragmentShaderDescription; var geode = Geode.Create(); geode.AddDrawable(geometry); root.AddChild(geode); viewer.SetSceneData(root); viewer.ViewAll(); viewer.Run(); }
public static IGroup Build() { var root = Group.Create(); var path = Path.Create(new Vector3[] { new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(1.0f, -1.0f, 0.0f), new Vector3(2.0f, -2.0f, 2.0f), }); var hints = TessellationHints.Create(); hints.SetDetailRatio(4f); hints.SetRadius(0.1f); var pathDrawable = ShapeDrawable <Position3Texture2Color3Normal3> .Create(path, hints); var redMaterial = PhongMaterial.Create( PhongMaterialParameters.Create( new Vector3(1.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f), new Vector3(1.0f, 1.0f, 1.0f), 5f), PhongHeadlight.Create(PhongLightParameters.Create( new Vector3(0.1f, 0.1f, 0.1f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 1f, 0)), true); var pathGeode = Geode.Create(); pathGeode.AddDrawable(pathDrawable); pathGeode.PipelineState = redMaterial.CreatePipelineState(); pathGeode.PipelineState.RasterizerStateDescription = new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, false); root.AddChild(pathGeode); return(root); }
static void Main(string[] args) { Bootstrapper.Configure(); var viewer = SimpleViewer.Create("Text Rendering Demo"); viewer.SetCameraManipulator(TrackballManipulator.Create()); var root = Group.Create(); var textNode = TextNode.Create("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"); var geode = Geode.Create(); geode.AddDrawable(textNode); root.AddChild(geode); viewer.SetSceneData(root); viewer.ViewAll(); viewer.Run(); }
public static IGroup Build() { var root = Group.Create(); var model = CreateDragonModel(); var geometryFactory = GeometryFactory.Create(); var cube = geometryFactory.CreateCube(VertexType.Position3Texture2Color3Normal3, TopologyType.IndexedTriangleList); // Shape Drawables var cubeShape = Box.Create(Vector3.Zero, 0.5f * Vector3.One); var hints = TessellationHints.Create(); hints.NormalsType = NormalsType.PerVertex; hints.ColorsType = ColorsType.ColorPerVertex; var freq = (float)(2 * System.Math.PI / 9); var cubeColors = MakeColorGradient(freq, freq, freq, 0, 2, 4, 8); var cubeDrawable = ShapeDrawable <Position3Texture2Color3Normal3> .Create( cubeShape, hints, cubeColors.ToArray()); var cube2 = Geode.Create(); cube2.AddDrawable(cubeDrawable); var sphereShape = Sphere.Create(Vector3.Zero, 0.5f); var sphereHints = TessellationHints.Create(); sphereHints.SetDetailRatio(1.6f); var sphereDrawable = ShapeDrawable <Position3Texture2Color3Normal3> .Create( sphereShape, sphereHints, new Vector3[] { new Vector3(1.0f, 0.0f, 0.0f) }); var sphere = Geode.Create(); sphere.AddDrawable(sphereDrawable); var cubeXForm = MatrixTransform.Create(Matrix4x4.CreateScale(10f, 10f, 10f)); cubeXForm.AddChild(sphere); var cubeXForm2 = MatrixTransform.Create(Matrix4x4.CreateScale(10f, 10f, 10f)); cubeXForm2.AddChild(cube2); var leftTop = MatrixTransform.Create(Matrix4x4.CreateTranslation(-10f, 10f, 0f)); var rightTop = MatrixTransform.Create(Matrix4x4.CreateTranslation(10f, 10f, 0f)); var leftBottom = MatrixTransform.Create(Matrix4x4.CreateTranslation(-10f, -10f, 0f)); var rightBottom = MatrixTransform.Create(Matrix4x4.CreateTranslation(10f, -10f, 0f)); leftTop.AddChild(model); rightTop.AddChild(model); leftBottom.AddChild(cubeXForm); rightBottom.AddChild(cubeXForm2); var flatYellowMaterial = PhongMaterial.Create( PhongMaterialParameters.Create( new Vector3(1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 1.0f), 20), PhongPositionalLight.Create(new Vector4(0, 100, 0, 1), PhongLightParameters.Create( new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0.2f, 0.2f, 0.2f), new Vector3(1.0f, 1.0f, 1.0f), 300f, 1))); var shinyRedGoldMaterial = PhongMaterial.Create( PhongMaterialParameters.Create( new Vector3(1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 1.0f), 5), PhongHeadlight.Create(PhongLightParameters.Create( new Vector3(0.1f, 0.1f, 0.1f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 30f, 1)), false); var cubeMaterial = PhongMaterial.Create( PhongMaterialParameters.Create( new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 50f), PhongHeadlight.Create(PhongLightParameters.Create( new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 1f, 0)), false); var sphereMaterial = PhongMaterial.Create( PhongMaterialParameters.Create( new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 5f), PhongPositionalLight.Create(new Vector4(0, 10, 0, 1), PhongLightParameters.Create( new Vector3(0.1f, 0.1f, 0.1f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 10000f, 2)), true); leftTop.PipelineState = flatYellowMaterial.CreatePipelineState(); rightTop.PipelineState = shinyRedGoldMaterial.CreatePipelineState(); sphere.PipelineState = sphereMaterial.CreatePipelineState(); cube2.PipelineState = cubeMaterial.CreatePipelineState(); // rightTop.PipelineState = CreateHeadlightState( // new Vector3(1.0f, 1.0f, 0.0f), // 50, // Vector3.One, // 5); var sceneGroup = Group.Create(); sceneGroup.AddChild(leftTop); sceneGroup.AddChild(rightTop); sceneGroup.AddChild(leftBottom); sceneGroup.AddChild(rightBottom); root.AddChild(sceneGroup); return(root); }
internal static IGeode CreatePosition3Texture2Color3Normal3_IndexedTriangleList() { var geometry = Geometry <Position3Texture2Color3Normal3> .Create(); var nl = 1f / (float)System.Math.Sqrt(3f); var vertices = new[] { // Top new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(0, 0), new Vector3(1, 0, 0), new Vector3(-nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(1, 0), new Vector3(1, 0, 0), new Vector3(nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(1, 1), new Vector3(1, 0, 0), new Vector3(nl, nl, nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(0, 1), new Vector3(1, 0, 0), new Vector3(-nl, nl, nl)), // Bottom new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(0, 0), new Vector3(1, 1, 0), new Vector3(-nl, -nl, nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(1, 0), new Vector3(1, 1, 0), new Vector3(nl, -nl, nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(1, 1), new Vector3(1, 1, 0), new Vector3(nl, -nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(0, 1), new Vector3(1, 1, 0), new Vector3(-nl, -nl, -nl)), // Left new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(0, 0), new Vector3(0, 1, 0), new Vector3(-nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(1, 0), new Vector3(0, 1, 0), new Vector3(-nl, nl, nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(1, 1), new Vector3(0, 1, 0), new Vector3(-nl, -nl, nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(0, 1), new Vector3(0, 1, 0), new Vector3(-nl, -nl, -nl)), // Right new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(0, 0), new Vector3(0, 1, 1), new Vector3(nl, nl, nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(1, 0), new Vector3(0, 1, 1), new Vector3(nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(1, 1), new Vector3(0, 1, 1), new Vector3(nl, -nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(0, 1), new Vector3(0, 1, 1), new Vector3(nl, -nl, nl)), // Back new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(0, 0), new Vector3(0, 0, 1), new Vector3(nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(1, 0), new Vector3(0, 0, 1), new Vector3(-nl, nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(1, 1), new Vector3(0, 0, 1), new Vector3(-nl, -nl, -nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(0, 1), new Vector3(0, 0, 1), new Vector3(nl, -nl, -nl)), // Front new Position3Texture2Color3Normal3(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(0, 0), new Vector3(1, 0, 1), new Vector3(-nl, nl, nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(1, 0), new Vector3(1, 0, 1), new Vector3(nl, nl, nl)), new Position3Texture2Color3Normal3(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(1, 1), new Vector3(1, 0, 1), new Vector3(nl, -nl, nl)), new Position3Texture2Color3Normal3(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(0, 1), new Vector3(1, 0, 1), new Vector3(-nl, -nl, nl)), }; uint[] indices = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23, }; geometry.VertexData = vertices; geometry.IndexData = indices; geometry.VertexLayout = Position3Texture2Color3Normal3.VertexLayoutDescription; var pSet = DrawElements <Position3Texture2Color3Normal3> .Create( geometry, PrimitiveTopology.TriangleList, (uint)geometry.IndexData.Length, 1, 0, 0, 0); geometry.PrimitiveSets.Add(pSet); var geode = Geode.Create(); geode.AddDrawable(geometry); return(geode); }