public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(278, 278, 800), new Vector3(278, 278, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 40; camera.Aperture = 0.0f; camera.FocusDistance = 10.0f; camera.ControlSpeed = 500.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(0); camera.SkyColor2 = new Vector4(0); var sphere = Model.CreateSphere(new Vector3(555 - 130, 165.0f, -165.0f / 2 - 65), 80.0f, Material.Dielectric(1.5f), true); var lucy0 = Model.LoadModel("./assets/models/lucy.obj"); lucy0.TransformVertices( (Matrix4x4.CreateScale(new Vector3(.6f)) * Matrix4x4.CreateTranslation(new Vector3(555 - 300 - 165 / 2, -9, -295 - 165 / 2))) .RotateBy(new Vector3(0, MathExtensions.ToRadians(75), 0))); Models.Add(Model.CreateCornellBox(555)); Models.Add(sphere); Models.Add(lucy0); }
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(278, 278, 800), new Vector3(278, 278, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 40; camera.Aperture = 0.0f; camera.FocusDistance = 10.0f; camera.ControlSpeed = 500.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(0); camera.SkyColor2 = new Vector4(0); var white = Material.Lambertian(new Vector3(0.73f, 0.73f, 0.73f)); var box0 = Model.CreateBox(new Vector3(0, 0, -165), new Vector3(165, 165, 0), white); var box1 = Model.CreateBox(new Vector3(0, 0, -165), new Vector3(165, 330, 0), white); box0.TransformVertices( Matrix4x4.CreateTranslation(new Vector3(555 - 130 - 165, 0, -65)) .RotateBy(new Vector3(0, MathExtensions.ToRadians(-18), 0))); box1.TransformVertices( Matrix4x4.CreateTranslation(new Vector3(555 - 265 - 165, 0, -295)) .RotateBy(new Vector3(0, MathExtensions.ToRadians(15), 0))); Models.Add(Model.CreateCornellBox(555)); Models.Add(box0); Models.Add(box1); }
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); // Final scene from Ray Tracing In One Weekend book. camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(13, 2, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 20; camera.Aperture = 0.1f; camera.FocusDistance = 10.0f; camera.ControlSpeed = 5.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(1); camera.SkyColor2 = new Vector4(.5f, .7f, 1f, 1f); const bool isProc = true; var random = new Random(42); Models.Add(Model.CreateSphere(new Vector3(0, -1000, 0), 1000, Material.Lambertian(new Vector3(0.5f, 0.5f, 0.5f)), isProc)); for (int a = -11; a < 11; ++a) { for (int b = -11; b < 11; ++b) { float chooseMat = (float)random.NextDouble(); var center = new Vector3(a + 0.9f * (float)random.NextDouble(), 0.2f, b + 0.9f * (float)random.NextDouble()); if ((center - new Vector3(4, 0.2f, 0)).Length() > 0.9) { if (chooseMat < 0.8f) // Diffuse { Models.Add(Model.CreateSphere(center, 0.2f, Material.Lambertian(new Vector3( (float)random.NextDouble() * (float)random.NextDouble(), (float)random.NextDouble() * (float)random.NextDouble(), (float)random.NextDouble() * (float)random.NextDouble())), isProc)); } else if (chooseMat < 0.95f) // Metal { Models.Add(Model.CreateSphere(center, 0.2f, Material.Metallic( new Vector3(0.5f * (1 + (float)random.NextDouble()), 0.5f * (1 + (float)random.NextDouble()), 0.5f * (1 + (float)random.NextDouble())), 0.5f * (float)random.NextDouble()), isProc)); } else // Glass { Models.Add(Model.CreateSphere(center, 0.2f, Material.Dielectric(1.5f), isProc)); } } } } Models.Add(Model.CreateSphere(new Vector3(0, 1, 0), 1.0f, Material.Dielectric(1.5f), isProc)); Models.Add(Model.CreateSphere(new Vector3(-4, 1, 0), 1.0f, Material.Lambertian(new Vector3(0.4f, 0.2f, 0.1f)), isProc)); Models.Add(Model.CreateSphere(new Vector3(4, 1, 0), 1.0f, Material.Metallic(new Vector3(0.7f, 0.6f, 0.5f), 0.0f), isProc)); }
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(3.5f, 3, 1.5f), new Vector3(-15, 1.0f, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 20; camera.Aperture = 0.01f; camera.FocusDistance = 20.0f; camera.ControlSpeed = 5.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(1); camera.SkyColor2 = new Vector4(.5f, .7f, 1f, 1f); Models.Add(Model.CreateGroundRect(new Vector3(0, 0, 0), 80, 80, Material.Metallic(new Vector3(.4f, .4f, .5f), .002f), 10f)); var mirror1 = Model.CreateGroundRect(new Vector3(0, 0, 0), 6, 10, Material.Metallic(new Vector3(1), 0), 1); mirror1.Transform = Matrix4x4.CreateTranslation(5, 5.05f, 0).RotateBy(new Vector3(MathExtensions.ToRadians(90), MathExtensions.ToRadians(-90), 0)); Models.Add(mirror1); var mirror1Frame = Model.CreateGroundRect(new Vector3(0, 0, 0), 6.1f, 10.1f, Material.Lambertian(new Vector3(0), 0), 1); mirror1Frame.Transform = Matrix4x4.CreateTranslation(5.01f, 5.05f, 0).RotateBy(new Vector3(MathExtensions.ToRadians(90), MathExtensions.ToRadians(-90), 0)); Models.Add(mirror1Frame); var mirror2 = Model.CreateGroundRect(new Vector3(0, 0, 0), 6, 10, Material.Metallic(new Vector3(1), 0), 1); mirror2.Transform = Matrix4x4.CreateTranslation(-5, 5, 0).RotateBy(new Vector3(MathExtensions.ToRadians(-90), MathExtensions.ToRadians(-90), 0)); Models.Add(mirror2); var mirror2Frame = Model.CreateGroundRect(new Vector3(0, 0, 0), 6.1f, 10.1f, Material.Lambertian(new Vector3(0), 0), 1); mirror2Frame.Transform = Matrix4x4.CreateTranslation(-5.01f, 5.05f, 0).RotateBy(new Vector3(MathExtensions.ToRadians(-90), MathExtensions.ToRadians(-90), 0)); Models.Add(mirror2Frame); var lucy = Model.LoadModel("./assets/models/lucy.obj"); lucy.TransformVertices( (Matrix4x4.CreateScale(new Vector3(0.0035f)) * Matrix4x4.CreateTranslation(new Vector3(0, -0.08f, 0))) .RotateBy(new Vector3(0, MathExtensions.ToRadians(0), 0))); lucy.SetMaterial(Material.Lambertian(new Vector3(0.2f, 0.4f, 0.2f))); Models.Add(lucy); }
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); // Basic test scene. camera.ModelView = Matrix4x4.CreateTranslation(new Vector3(0, 0, -2)); camera.FieldOfView = 90; camera.Aperture = 0.05f; camera.FocusDistance = 2.0f; camera.ControlSpeed = 2.0f; camera.GammaCorrection = false; camera.SkyColor1 = new Vector4(1); camera.SkyColor2 = new Vector4(.5f, .7f, 1f, 1f); Models.Add(Model.LoadModel("./assets/models/cube_multi.obj")); Models.Add(Model.CreateSphere(new Vector3(1, 0, 0), 0.5f, Material.Metallic(new Vector3(0.7f, 0.5f, 0.8f), 0.2f), true)); Models.Add(Model.CreateSphere(new Vector3(-1, 0, 0), 0.5f, Material.Dielectric(1.5f), true)); Models.Add(Model.CreateSphere(new Vector3(0, 1, 0), 0.5f, Material.Lambertian(new Vector3(1.0f), 0), true)); Textures.Add(Texture.LoadTexture("./assets/textures/land_ocean_ice_cloud_2048.png")); }
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(-10, 5, 12) * 2, new Vector3(-5, 5, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 40; camera.Aperture = 0.0f; camera.FocusDistance = 10.0f; camera.ControlSpeed = 5.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(.6f, .7f, .9f, 1); camera.SkyColor2 = new Vector4(.6f, .7f, .9f, 1); // Initialize physics _bufferPool = new BufferPool(); var targetThreadCount = Math.Max(1, Environment.ProcessorCount > 4 ? Environment.ProcessorCount - 2 : Environment.ProcessorCount - 1); _threadDispatcher = new SimpleThreadDispatcher(targetThreadCount); _simulation = Simulation.Create(_bufferPool, new DemoNarrowPhaseCallbacks(), new DemoPoseIntegratorCallbacks(new Vector3(0, -9.8f, 0)), new PositionFirstTimestepper()); var random = new Random(42); // Add a floor const float groundDim = 400; Textures.Add(Texture.LoadTexture(@"./assets/textures/laminate.jpg")); var floor = Model.CreateGroundRect(new Vector3(0, 0, 0), groundDim, groundDim, Material.Dielectric(5.5f, Textures.Count - 1), groundDim / 16f); Models.Add(floor); _simulation.Statics.Add(new StaticDescription(new Vector3(0, -.5f, 0), new CollidableDescription(_simulation.Shapes.Add(new Box(groundDim, 1, groundDim)), 0.1f))); // Create pyramid const float boxDim = 1; const float marbleRadius = boxDim / 2f; var boxShape = new Box(boxDim, boxDim, boxDim); boxShape.ComputeInertia(.1f, out var boxInertia); var boxIndex = _simulation.Shapes.Add(boxShape); var marbleShape = new BepuPhysics.Collidables.Sphere(marbleRadius); var boxTemplate = Model.CreateBox(new Vector3(-(boxDim / 2)), new Vector3(boxDim / 2), default); const int pyramidSize = 20; const float offset = -(pyramidSize / 2f) * boxDim; for (int y = 0; ; y++) { int startIndex = y; int endIndex = pyramidSize - y; if (startIndex >= endIndex) { break; } for (int x = startIndex; x < endIndex; x++) { for (int z = startIndex; z < endIndex; z++) { var box = boxTemplate.Clone(); box.SetMaterial(Material.Lambertian(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) / 1f)); box.Transform = Matrix4x4.CreateTranslation(new Vector3(x * boxDim + offset, y * boxDim + (boxDim / 2), z * boxDim + offset)); Models.Add(box); var quat = box.Transform.ToQuaternion(); var bodyHandle = _simulation.Bodies.Add( BodyDescription.CreateDynamic( new RigidPose { Position = box.Transform.Translation, Orientation = new Quaternion(quat.X, quat.Y, quat.Z, quat.W) }, boxInertia, new CollidableDescription(boxIndex, 0.1f), new BodyActivityDescription(0.01f))); _bodyHandleToModelIndex[bodyHandle] = Models.Count - 1; // Put some marbles on top of the pyramid if ((x == startIndex || x == endIndex - 1) || (z == startIndex || z == endIndex - 1)) { Models.Add(Model.CreateSphere(default, marbleRadius, Material.Metallic(
public void Reset(CameraInitialState camera) { Models.Clear(); Textures.Clear(); // Same as RayTracingInOneWeekend but using the Lucy 3D model. camera.ModelView = Matrix4x4.CreateLookAt(new Vector3(13, 2, 3), new Vector3(0, 1.0f, 0), new Vector3(0, 1, 0)); camera.FieldOfView = 20; camera.Aperture = 0.05f; camera.FocusDistance = 10.0f; camera.ControlSpeed = 5.0f; camera.GammaCorrection = true; camera.SkyColor1 = new Vector4(1); camera.SkyColor2 = new Vector4(.5f, .7f, 1f, 1f); const bool isProc = true; var random = new Random(42); Models.Add(Model.CreateSphere(new Vector3(0, -1000, 0), 1000, Material.Lambertian(new Vector3(0.5f, 0.5f, 0.5f)), isProc)); for (int a = -11; a < 11; ++a) { for (int b = -11; b < 11; ++b) { float chooseMat = (float)random.NextDouble(); var center = new Vector3(a + 0.9f * (float)random.NextDouble(), 0.2f, b + 0.9f * (float)random.NextDouble()); if ((center - new Vector3(4, 0.2f, 0)).Length() > 0.9) { if (chooseMat < 0.8f) // Diffuse { Models.Add(Model.CreateSphere(center, 0.2f, Material.Lambertian(new Vector3( (float)random.NextDouble() * (float)random.NextDouble(), (float)random.NextDouble() * (float)random.NextDouble(), (float)random.NextDouble() * (float)random.NextDouble())), isProc)); } else if (chooseMat < 0.95f) // Metal { Models.Add(Model.CreateSphere(center, 0.2f, Material.Metallic( new Vector3(0.5f * (1 + (float)random.NextDouble()), 0.5f * (1 + (float)random.NextDouble()), 0.5f * (1 + (float)random.NextDouble())), 0.5f * (float)random.NextDouble()), isProc)); } else // Glass { Models.Add(Model.CreateSphere(center, 0.2f, Material.Dielectric(1.5f), isProc)); } } } } var lucy0 = Model.LoadModel("./assets/models/lucy.obj"); var lucy1 = lucy0.Clone(); var lucy2 = lucy0.Clone(); const float scaleFactor = 0.0035f; lucy0.TransformVertices( (Matrix4x4.CreateScale(new Vector3(scaleFactor)) * Matrix4x4.CreateTranslation(new Vector3(0, -0.08f, 0))) .RotateBy(new Vector3(0, MathExtensions.ToRadians(90), 0))); lucy1.TransformVertices( (Matrix4x4.CreateScale(new Vector3(scaleFactor)) * Matrix4x4.CreateTranslation(new Vector3(-4, -0.08f, 0))) .RotateBy(new Vector3(0, MathExtensions.ToRadians(90), 0))); lucy2.TransformVertices( (Matrix4x4.CreateScale(new Vector3(scaleFactor)) * Matrix4x4.CreateTranslation(new Vector3(4, -0.08f, 0))) .RotateBy(new Vector3(0, MathExtensions.ToRadians(90), 0))); lucy0.SetMaterial(Material.Dielectric(1.5f)); lucy1.SetMaterial(Material.Lambertian(new Vector3(0.4f, 0.2f, 0.1f))); lucy2.SetMaterial(Material.Metallic(new Vector3(0.7f, 0.6f, 0.5f), 0.05f)); Models.Add(lucy0); Models.Add(lucy1); Models.Add(lucy2); }