protected override void OnLoad() { inputManager = new InputManager3D(InputContext) { CameraMoveSpeed = 2.5f }; Span <VertexColor> crossLines = stackalloc VertexColor[] { new VertexColor(new Vector3(0, 0, 0), Color4b.Lime), new VertexColor(new Vector3(0, 1, 0), Color4b.Lime), new VertexColor(new Vector3(0, 0, 0), Color4b.Red), new VertexColor(new Vector3(1, 0, 0), Color4b.Red), new VertexColor(new Vector3(0, 0, 0), Color4b.Blue), new VertexColor(new Vector3(0, 0, 1), Color4b.Blue), }; crossBuffer = new VertexBuffer <VertexColor>(graphicsDevice, crossLines, BufferUsage.StaticDraw); Span <VertexPosition> cube = stackalloc VertexPosition[] { new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f), }; cubeBuffer = new VertexBuffer <VertexPosition>(graphicsDevice, cube, BufferUsage.StaticDraw); skyProgram = ShaderProgram.FromFiles <VertexPosition>(graphicsDevice, "skyVs.glsl", "skyFs.glsl", "vPosition"); VertexColor[] linesArray = CreateLines(); linesBuffer = new VertexBuffer <VertexColor>(graphicsDevice, linesArray, BufferUsage.StaticDraw); linesProgram = SimpleShaderProgram.Create <VertexColor>(graphicsDevice); VertexNormal[] dragonModel = OBJLoader.FromFile <VertexNormal>("dragon.obj"); dragonBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, dragonModel, BufferUsage.StaticDraw); VertexNormal[] donutModel = OBJLoader.FromFile <VertexNormal>("donut.obj"); donutBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, donutModel, BufferUsage.StaticDraw); VertexNormal[] sphereModel = OBJLoader.FromFile <VertexNormal>("sphere.obj"); sphereBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, sphereModel, BufferUsage.StaticDraw); modelsProgram = SimpleShaderProgram.Create <VertexNormal>(graphicsDevice, 1, 1); lampTexture = Texture2DExtensions.FromFile(graphicsDevice, "lamp_texture.png"); VertexNormalTexture[] lampModel = OBJLoader.FromFile <VertexNormalTexture>("lamp.obj"); lampBuffer = new VertexBuffer <VertexNormalTexture>(graphicsDevice, lampModel, BufferUsage.StaticDraw); lampProgram = SimpleShaderProgram.Create <VertexNormalTexture>(graphicsDevice); lampProgram.Texture = lampTexture; lampProgram.Color = new Vector4(3, 3, 3, 1); Vector3 sunlightDir = new Vector3(-1, -1.5f, -1); Vector3 sunColor = new Vector3(0.6f, 0.1f, 1.0f); modelsProgram.DirectionalLights[0].Direction = sunlightDir; modelsProgram.DirectionalLights[0].DiffuseColor = sunColor; modelsProgram.DirectionalLights[0].SpecularColor = sunColor; modelsProgram.PositionalLights[0].AttenuationConfig = new Vector3(0, 0.3f, 0.45f); modelsProgram.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.3f); modelsProgram.SpecularPower = 8; skyProgram.Uniforms["sunDirection"].SetValueVec3(Vector3.Normalize(-sunlightDir)); skyProgram.Uniforms["sunColor"].SetValueVec3(sunColor); lampPosition = new Vector3(2.5f, 1, -1.7f); modelsProgram.PositionalLights[0].Position = lampPosition; lampProgram.World = Matrix4x4.CreateScale(0.015f) * Matrix4x4.CreateTranslation(lampPosition.X, lampPosition.Y - 0.85f, lampPosition.Z); graphicsDevice.DepthState = DepthState.Default; graphicsDevice.BlendingEnabled = false; stopwatch = Stopwatch.StartNew(); }