public List <IHittable> Generate() { var tex = new NoiseTexture(Vec3.One, Vec3.Zero, 4); var mat = new Lambertian(tex); var toReturn = new List <IHittable>(); toReturn.Add(new Sphere { Center = new Vec3(0, -1000, 0), Radius = 1000, Material = mat }); toReturn.Add(new Sphere { Center = new Vec3(0, 2, 0), Radius = 2, Material = mat }); var diffLight = new DiffuseLight(new Vec3(4, 4, 4)); toReturn.Add(new RectXY(3, 5, 1, 3, -2, diffLight)); toReturn.Add(new Sphere { Center = new Vec3(0, 7, 0), Radius = 2, Material = diffLight }); return(toReturn); }
//Calculate density values based on a Perlin Noise 3D float[,,] calcualteNoiseValues3D() { float[,,] _returnValues = new float[TerrainSize, TerrainSize, TerrainSize]; NoiseTexture.NoiseScale = NoiseScale; NoiseTexture.Offset = Offset; Texture3D noiseTexture = NoiseTexture.generateTexture3D_GPU(textureWidth, textureHeight, textureDepth); float gridStepSizeX = textureWidth / TerrainSize; float gridStepSizeY = textureHeight / TerrainSize; float gridStepSizeZ = textureDepth / TerrainSize; for (int _x = 0; _x < TerrainSize; _x++) { for (int _y = 0; _y < TerrainSize; _y++) { for (int _z = 0; _z < TerrainSize; _z++) { _returnValues[_x, _y, _z] = noiseTexture.GetPixel((int)(_x * gridStepSizeX), (int)(_y * gridStepSizeY), (int)(_z * gridStepSizeZ)).grayscale; } } } return(_returnValues); }
private void addServer(String name, String motd1, String motd2, int current, int max) { HBoxContainer hBoxContainer = new HBoxContainer { Name = name }; // TODO server icon TextureRect icon = new TextureRect(); NoiseTexture texture = new NoiseTexture { Width = 64, Height = 64, Noise = new OpenSimplexNoise { Seed = (int)random.Randi() } }; icon.Texture = texture; Label label = new Label { Text = name + " (" + current + "/" + max + ")\n" + motd1 + "\n" + motd2 }; hBoxContainer.AddChild(icon); hBoxContainer.AddChild(label); serverList.AddChild(hBoxContainer); hBoxContainer.Connect("gui_input", this, nameof(serverInput), new Array { name }); }
private void InitScene() { int width = 2000; int height = 1000; bool isSky = false; Vector3D lookFrom = new Vector3D(13, 15, 25); Vector3D lookAt = new Vector3D(0, 0, 0); float diskToFocus = (lookFrom - lookAt).Length(); float aperture = 0; Camera camera = new Camera(lookFrom, lookAt, new Vector3D(0, 1, 0), 20, (float)width / (float)height, aperture, 0.7f * diskToFocus, 0, 1); HitableList world = new HitableList(); List <Hitable> list = new List <Hitable>(); Texture perText = new NoiseTexture(5f); list.Add(new Sphere(new Vector3D(0, -1000, 0), 1000, new Lambertian(perText))); list.Add(new Sphere(new Vector3D(0, 2, 0), 2, new Lambertian(perText))); list.Add(new Sphere(new Vector3D(0, 7, 0), 2, new DiffuseLight(new ConstantTexture(new Vector3D(10, 10, 10))))); list.Add(new XYRect(3, 5, 1, 3, -2, new DiffuseLight(new ConstantTexture(new Vector3D(10, 10, 10))))); world.list = list; scene = new Scene(width, height, world, isSky, camera, 0, true); //使用直接光源采样 //HitableList lightShapeList = new HitableList(); //lightShapeList.list.Add(new Sphere(new Vector3D(0, 7, 0), 2, null)); //lightShapeList.list.Add(new XYRect(3, 5, 1, 3, -2, null)); //scene = new Scene(width, height, world, isSky, camera, 1, false, lightShapeList); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { NoiseTexture noiseTexture = target as NoiseTexture; Texture2D texture = noiseTexture.GetTexture(); if (texture != null) { Rect previewRect = new Rect(r); float textureAspectRatio = noiseTexture.resolution.x / noiseTexture.resolution.y; float previewAspectRatio = r.width / r.height; if (textureAspectRatio >= previewAspectRatio) { float scale = noiseTexture.resolution.x / r.width; float newHeight = noiseTexture.resolution.y / scale; previewRect.width = r.width; previewRect.height = newHeight; previewRect.y = (r.height / 2.0f) - (newHeight / 2.0f); } else { float scale = noiseTexture.resolution.y / r.height; float newWidth = noiseTexture.resolution.x / scale; previewRect.width = newWidth; previewRect.height = r.height; previewRect.x = (r.width / 2.0f) - (newWidth / 2.0f); } EditorGUI.DrawPreviewTexture(previewRect, texture); } }
public HitableList GetSceneWorld() { var perlinTexture = new NoiseTexture(1f); return(new HitableList() { new Sphere(new Vector3(0, -1000, 0), 1000, new Lambertian(perlinTexture)), new Sphere(new Vector3(0, 2, 0), 2, new Lambertian(perlinTexture)) }); }
public override Hitable GetObjects() { Texture perlin = new NoiseTexture(5.0); List <Hitable> list = new List <Hitable>(); list.Add(new Sphere(new Vec3(0.0, -1000.0, 0), 1000, new Lambertian(perlin))); list.Add(new Sphere(new Vec3(0.0, 2.0, 0.0), 2, new Lambertian(perlin))); return((Hitable) new HitableList(list)); }
private HitableList TwoPerlinSpheres() { Texture pertext = new NoiseTexture(5); List <IHitable> list = new List <IHitable>(); list.Add(new Sphere(new Vector3D(0, -1000, 0), 1000, new Lambertian(pertext))); list.Add(new Sphere(new Vector3D(0, 2, 0), 2, new Lambertian(pertext))); return(new HitableList(list, list.Count)); }
internal static IHitTarget GenerateTwoLargeSphereBvhScene() { var returnList = new List <IHitTarget>(); var perlinTexture = new NoiseTexture(new Color(0.8, 0.8, 0.8), 4.0, NoiseTypes.MARBLE, 0.5, 10.0, 15); returnList.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(perlinTexture))); returnList.Add(new Sphere(new Vec3(0, 1, 0), 1.0, new Lambertian(perlinTexture))); return(new BvhNode(returnList, 0.0, 1.0)); }
private HitableList SimpleLight() { Texture perText = new NoiseTexture(4); List <IHitable> list = new List <IHitable>(); list.Add(new Sphere(new Vector3D(0, -1000, 0), 1000, new Lambertian(perText))); list.Add(new Sphere(new Vector3D(0, 2, 0), 2, new Lambertian(perText))); list.Add(new Sphere(new Vector3D(0, 7, 0), 2, new DiffuseLight(new ConstantTexture(new Vector3D(4, 4, 4))))); list.Add(new XYRect(3, 5, 1, 3, -2, new DiffuseLight(new ConstantTexture(new Vector3D(4, 4, 4))))); return(new HitableList(list, list.Count)); }
public override Hitable GetObjects() { Texture per = new NoiseTexture(4.0); var list = new List <Hitable>(); list.Add(new Sphere(new Vec3(0.0, -1000.0, 0.0), 1000, new Lambertian(per))); list.Add(new Sphere(new Vec3(0.0, 2.0, 0.0), 2.0, new Lambertian(per))); list.Add(new Sphere(new Vec3(0.0, 7.0, 0.0), 2.0, new DiffuseLight(new ConstantTexture(new Vec3(4.0, 4.0, 4.0))))); list.Add(new XYRect(3.0, 5.0, 1.0, 3.0, -2.0, new DiffuseLight(new ConstantTexture(new Vec3(4.0, 4.0, 4.0))))); return((Hitable) new HitableList(list)); }
public HitableList GetSceneWorld() { var perlinTexture = new NoiseTexture(1f); var lightTexture = new DiffuseLight(new ConstantTexture(new Vector3(4, 4, 4))); return(new HitableList() { new Sphere(new Vector3(0, -1000, 0), 1000, new Lambertian(perlinTexture)), new Sphere(new Vector3(0, 2, 0), 2, new Lambertian(perlinTexture)), new XYRectangle(3, 1, -2, 2, 2, lightTexture), new Sphere(new Vector3(0, 8, 0), 3, lightTexture) }); }
internal static IHitTarget GenerateSimpleAreaLightBvhScene() { var perlinTexture = new NoiseTexture(new Color(0.8, 0.8, 0.8), 4, NoiseTypes.MARBLE, 0.5, 10, 0); var returnList = new List <IHitTarget>(); returnList.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(perlinTexture))); returnList.Add(new Sphere(new Vec3(0, 2, 0), 2, new Lambertian(perlinTexture))); returnList.Add(new Sphere(new Vec3(0, 7, 0), 2, new Emission(new ConstantTexture(new Color(1, 1, 1)), 4))); returnList.Add(new XYAlignedRectangle(3, 5, 1, 3, -2, new Emission(new ConstantTexture(new Color(1, 1, 1)), 4))); return(new BvhNode(returnList, 0.0, 1.0)); }
public NoiseTextureScene(double aspect) { var perlin_texture = NoiseTexture.Create(1, NoiseTexture.Type.SIN_Z); IHitable[] hitables = { new Sphere(Vec3.Create(0, -1000, 0), 1000, new Lambertian(perlin_texture)), new Sphere(Vec3.Create(0, 2, 0), 2, new Lambertian(perlin_texture)) }; World = new BVHNode(hitables, 0, 1); var lookFrom = Vec3.Create(13, 2, 3); var lookAt = Vec3.Create(0, 0, 0); double dist_to_focus = 10; double aderpture = 0; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), 20, aspect, aderpture, dist_to_focus); }
public SimpleLightScene(double aspect) { var perlin_texture = NoiseTexture.Create(4, NoiseTexture.Type.SIN_Z); IHitable[] hitables = { new Sphere(Vec3.Create(0, -1000, 0), 1000, new Lambertian(perlin_texture)), new Sphere(Vec3.Create(0, 2, 0), 2, new Lambertian(perlin_texture)), new Sphere(Vec3.Create(0, 7, 0), 2, new DiffuseLight(ConstantTexture.Create(4, 4, 4))), new XYRect(3, 5, 1, 3, -2,new DiffuseLight(ConstantTexture.Create(4, 4, 4))) }; World = new BVHNode(hitables, 0, 1); var lookFrom = Vec3.Create(25, 4, 5); var lookAt = Vec3.Create(0, 2, 0); double dist_to_focus = 10; double aderpture = 0; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), 20, aspect, aderpture, dist_to_focus); }
internal static IHitTarget GenerateRandomBvhScene() { var rng = new Random(); var returnList = new List <IHitTarget>(); var checkerTexture = new CheckerTexture(new ConstantTexture(new Color(0.2, 0.3, 0.1)), new ConstantTexture(new Color(0.9, 0.9, 0.9))); var perlinTexture = new NoiseTexture(new Color(1, 1, 1), 10.0, NoiseTypes.TURBULENCE); returnList.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(perlinTexture))); for (var i = -11; i < 11; ++i) { for (var j = -11; j < 11; ++j) { var materialPicker = rng.NextDouble(); var center = new Vec3(i + 0.9 * rng.NextDouble(), 0.2, j + 0.9 * rng.NextDouble()); if (!((center - new Vec3(4, 0.2, 0)).GetLength() > 0.9)) { continue; } if (materialPicker < 0.7) { returnList.Add(new Sphere(center, 0.2, new Lambertian(new ConstantTexture(new Color(rng.NextDouble() * rng.NextDouble(), rng.NextDouble() * rng.NextDouble(), rng.NextDouble() * rng.NextDouble()))))); } else if (materialPicker < 0.8) { returnList.Add(new Sphere(center, 0.2, new Glossy(new Color(0.5 * (1 + rng.NextDouble()), 0.5 * (1 + rng.NextDouble()), 0.5 * (1 + rng.NextDouble())), 0.5 * rng.NextDouble()))); } else { returnList.Add(new Sphere(center, 0.2, new Dielectric(new Color(1, 1, 1), 1.5))); } } } returnList.Add(new Sphere(new Vec3(0, 1, 0), 1.0, new Dielectric(new Color(1, 1, 1), 1.5))); returnList.Add(new Sphere(new Vec3(-4, 1, 0), 1.0, new Lambertian(new ConstantTexture(new Color(0.4, 0.2, 0.1))))); returnList.Add(new Sphere(new Vec3(4, 1, 0), 1.0, new Glossy(new Color(0.7, 0.6, 0.5), 0.05))); return(new BvhNode(returnList, 0.0, 1.0)); }
internal static IHitTarget GenerateEarthLampBvhScene() { var returnList = new List <IHitTarget>(); var perlinTexture = new NoiseTexture(new Color(0.8, 0.8, 0.8), 4.0, NoiseTypes.MARBLE, 0.5, 10.0, 15); returnList.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(perlinTexture))); var loader = new ImageReader(); using (var stream = File.Open("earthMap.jpg", FileMode.Open)) { var image = loader.Read(stream, StbImage.STBI_rgb); var material = new Emission(new ImageTexture(image.Data, image.Width, image.Height), 10); returnList.Add(new Sphere(new Vec3(0, 1, 0), 1.0, material)); } return(new BvhNode(returnList, 0.0, 1.0)); }
public List <IHittable> Generate() { var toReturn = new List <IHittable>(); var perTex = new NoiseTexture(4); toReturn.Add(new Sphere { Center = new Vec3(0, -1000, 0), Radius = 1000, Material = new Lambertian(perTex) }); toReturn.Add(new Sphere { Center = new Vec3(0, 2, 0), Radius = 2, Material = new Lambertian(perTex) }); return(toReturn); }
float[,] generateNoiseValues() { NoiseTexture.NoiseScale = noiseScale; NoiseTexture.Offset = Offset; Texture2D noiseTexture = NoiseTexture.generateTexture2D_GPU(textureWidth, textureHeight); float[,] _returnList = new float[caveWidth, caveHeight]; float gridStepSizeX = textureWidth / caveWidth; float gridStepSizeY = textureHeight / caveHeight; for (int x = 0; x < caveWidth; x++) { for (int y = 0; y < caveHeight; y++) { _returnList[x, y] = noiseTexture.GetPixel((int)(x * gridStepSizeX), (int)(y * gridStepSizeY)).grayscale; } } return(_returnList); }
/// <summary> /// Pdf 2, perlin noise /// </summary> private void CreateScene4() { // Set up camera this.hFovDeg = 35; var lookFrom = new Vec3(13, 2, 3); var lookAt = new Vec3(0, 0, 0); var lookUp = new Vec3(0, 1, 0); float focusDist = 10; float aperture = 0; this.camera = new CartesianCamera(this.rows, this.columns, this.hFovDeg, lookFrom, lookAt, lookUp, aperture, focusDist); // Add items var hitables = new List <Hitable>(); var perlinTexture = new NoiseTexture(); hitables.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(perlinTexture))); hitables.Add(new Sphere(new Vec3(0, 2, 0), 2, new Lambertian(perlinTexture))); this.world = new HitableList(hitables); }
public override void OnInspectorGUI() { NoiseTexture noiseTexture = target as NoiseTexture; DrawDefaultInspector(); serializedObject.Update(); EditorGUILayout.PropertyField(frequency); if (noiseTexture.noiseType == NoiseTexture.NoiseType.Perlin || noiseTexture.noiseType == NoiseTexture.NoiseType.Billow || noiseTexture.noiseType == NoiseTexture.NoiseType.RidgedMultifractal) { EditorGUILayout.PropertyField(lacunarity); } if (noiseTexture.noiseType == NoiseTexture.NoiseType.Perlin || noiseTexture.noiseType == NoiseTexture.NoiseType.Billow) { EditorGUILayout.PropertyField(persistence); } if (noiseTexture.noiseType == NoiseTexture.NoiseType.Voronoi) { EditorGUILayout.PropertyField(displacement); } if (noiseTexture.noiseType == NoiseTexture.NoiseType.Perlin || noiseTexture.noiseType == NoiseTexture.NoiseType.Billow || noiseTexture.noiseType == NoiseTexture.NoiseType.RidgedMultifractal) { //Large octave values can lag or crash Unity, so be careful... EditorGUILayout.IntSlider(octaves, 1, 16); } if (noiseTexture.noiseType == NoiseTexture.NoiseType.Voronoi) { EditorGUILayout.PropertyField(distance); } if (GUILayout.Button("Generate Texture") == true) { noiseTexture.CreateTexture(); } serializedObject.ApplyModifiedProperties(); }
private void InitScene() { int width = 2000; int height = 1000; bool isSky = true; Vector3D lookFrom = new Vector3D(13, 2, 0); Vector3D lookAt = new Vector3D(0, 0, 0); float diskToFocus = (lookFrom - lookAt).Length(); float aperture = 0; Camera camera = new Camera(lookFrom, lookAt, new Vector3D(0, 1, 0), 20, (float)width / (float)height, aperture, 0.7f * diskToFocus, 0, 1); HitableList world = new HitableList(); List <Hitable> list = new List <Hitable>(); Texture perText = new NoiseTexture(5f); list.Add(new Sphere(new Vector3D(0, -1000, 0), 1000, new Lambertian(perText))); list.Add(new Sphere(new Vector3D(0, 1, 0), 1, new Lambertian(perText))); world.list = list; scene = new Scene(width, height, world, isSky, camera, 0, true); }
public List <IHittable> Generate() { var tex = new NoiseTexture(Vec3.One, Vec3.Zero, 4); var mat = new Lambertian(tex); var toReturn = new List <IHittable>(); toReturn.Add(new Sphere { Center = new Vec3(0, -1000, 0), Radius = 1000, Material = mat }); toReturn.Add(new Sphere { Center = new Vec3(0, 2, 0), Radius = 2, Material = mat }); toReturn.Add( new RectXY(0, 5, 0, 5, -2, new Lambertian(new Vec3(1, 0, 1)))); return(toReturn); }
public List <IHittable> Generate() { var toReturn = new List <IHittable>(); var ground = new Lambertian(new Vec3(0.48, 0.83, 0.53)); const int boxesPerSide = 20; var boxes1 = new List <IHittable>(); for (var i = 0; i < boxesPerSide; i++) { for (var j = 0; j < boxesPerSide; j++) { var w = 100.0; var x0 = -1000 + i * w; var z0 = -1000 + j * w; var y0 = 0; var x1 = x0 + w; var y1 = MathUtils.RandDouble(1, 101); var z1 = z0 + w; boxes1.Add(new Box( new Vec3(x0, y0, z0), new Vec3(x1, y1, z1), ground)); } } toReturn.Add(new BvhNode(boxes1, 0, boxes1.Count, 0, 1)); var light = new DiffuseLight(new Vec3(7, 7, 7)); toReturn.Add(new RectXZ(123, 423, 147, 412, 554, light)); var c1 = new Vec3(400, 400, 200); var c2 = c1 + new Vec3(30, 0, 0); var movingSphereMat = new Lambertian(new Vec3(0.7, 0.3, 0.1)); toReturn.Add(new MovingSphere { Center0 = c1, Center1 = c2, Radius = 50, Time0 = 0, Time1 = 1, Material = movingSphereMat }); toReturn.Add(new Sphere { Center = new Vec3(260, 150, 45), Radius = 50, Material = new Dielectric { RefractionIndex = 1.5 } }); toReturn.Add(new Sphere { Center = new Vec3(0, 150, 145), Radius = 50, Material = new Metal { Albedo = new Vec3(0.8, 0.8, 0.9), Fuzz = 1.0 } }); var boundary = new Sphere { Center = new Vec3(360, 150, 145), Radius = 70, Material = new Dielectric { RefractionIndex = 1.5 } }; toReturn.Add(boundary); toReturn.Add(new ConstantMedium(boundary, 0.2, new Vec3(0.2, 0.4, 0.9))); boundary = new Sphere { Center = Vec3.Zero, Radius = 5000, Material = new Dielectric { RefractionIndex = 1.5 } }; toReturn.Add(new ConstantMedium(boundary, 0.0001, Vec3.One)); var emat = new Lambertian(new ImageTexture("../../Data/earthmap.jpg")); toReturn.Add(new Sphere { Center = new Vec3(400, 200, 400), Radius = 100, Material = emat }); var pertex = new NoiseTexture(0.1); toReturn.Add(new Sphere { Center = new Vec3(220, 280, 300), Radius = 80, Material = new Lambertian(pertex) }); var boxes2 = new List <IHittable>(); var white = new Lambertian(new Vec3(0.73, 0.73, 0.73)); var ns = 1000; for (int j = 0; j < ns; j++) { boxes2.Add(new Sphere { Center = Vec3.Random(0, 165), Radius = 10, Material = white }); } toReturn.Add(new Translate( new RotateY( new BvhNode(boxes2, 0, boxes2.Count, 0, 1), 15 ), new Vec3(-100, 270, 395) )); return(toReturn); }
public override void _Ready() { var env = GetNode <WorldEnvironment>("sky").Environment; env.BackgroundColor = new Color(Lib.Node.BackgroundColorHtmlCode); env.BackgroundMode = Godot.Environment.BGMode.Sky; env.BackgroundSky = new PanoramaSky() { Panorama = ((Texture)GD.Load("res://assets/stars.hdr")) }; env.BackgroundSkyRotationDegrees = new Vector3(0, 0, 0); env.BackgroundEnergy = 0.5f; env.BackgroundSkyCustomFov = 130; env.DofBlurFarEnabled = true; env.GlowEnabled = true; env.GlowIntensity = 0.45f; env.GlowStrength = 0.9f; env.GlowBlendMode = Godot.Environment.GlowBlendModeEnum.Additive; env.GlowHdrThreshold = 0; env.GlowBicubicUpscale = true; InitSound(); AddChild(Audio); GetNode <CSGTorus>("PlanetPivot5/Planet/Rings").MaterialOverride = new SpatialMaterial() { AlbedoColor = Color.FromHsv(GD.Randf(), 0.5f, 1) }; for (int i = 1; i <= 5; i++) { GetNode <Spatial>("PlanetPivot" + i).RotateY(Mathf.Deg2Rad((float)GD.RandRange(-180, 180))); var planetMesh = GetNode <Spatial>("PlanetPivot" + i).GetNode("Planet").GetNode <MeshInstance>("Star"); var randCol = Color.FromHsv(GD.Randf(), 0.5f, 1); var randNoise = new OpenSimplexNoise() { Period = 40, Persistence = 0, Lacunarity = 0.1f, }; var randNoiseTx = new NoiseTexture() { Noise = randNoise }; var randNoiseTxBm = new NoiseTexture() { Noise = randNoise, AsNormalmap = true, BumpStrength = 1 }; planetMesh.MaterialOverride = new SpatialMaterial() { AlbedoColor = randCol, AlbedoTexture = randNoiseTx, NormalEnabled = true, NormalTexture = randNoiseTxBm, EmissionEnabled = true, Emission = randCol, DepthEnabled = true, DepthTexture = randNoiseTx, DepthScale = 0.5f, EmissionEnergy = 0.02f }; } }
static void Window() { NoiseTexture window = (NoiseTexture)EditorWindow.GetWindow(typeof(NoiseTexture), false, "Noise"); window.Show(); }
private void InitScene() { int width = 512; int height = 512; bool isSky = false; Vector3D lookFrom = new Vector3D(500, 300, -600); Vector3D lookAt = new Vector3D(278, 278, 0); float diskToFocus = 10; float aperture = 0; float vfov = 40; Camera camera = new Camera(lookFrom, lookAt, new Vector3D(0, 1, 0), vfov, (float)width / (float)height, aperture, diskToFocus, 0, 1); List <Hitable> list = new List <Hitable>(); List <Hitable> boxList = new List <Hitable>(); List <Hitable> boxList2 = new List <Hitable>(); int nb = 20; Material white = new Lambertian(new ConstantTexture(new Vector3D(0.73f, 0.73f, 0.73f))); Material ground = new Lambertian(new ConstantTexture(new Vector3D(0.48f, 0.83f, 0.53f))); Material light = new DiffuseLight(new ConstantTexture(new Vector3D(7, 7, 7))); for (int i = 0; i < nb; i++) { for (int j = 0; j < nb; j++) { float w = 100; float x0 = -1000 + i * w; float z0 = -1000 + j * w; float y0 = 0; float x1 = x0 + w; float y1 = 100 * (Mathf.Randomfloat() + 0.01f); float z1 = z0 + w; boxList.Add(new Box(new Vector3D(x0, y0, z0), new Vector3D(x1, y1, z1), ground)); } } list.Add(new BVHNode(boxList, boxList.Count, 0, 1)); list.Add(new FlipNormals(new XZRect(123, 423, 147, 412, 554, light))); Vector3D center = new Vector3D(400, 400, 200); list.Add(new MovingSphere(center, center + new Vector3D(30, 0, 0), 0, 1, 50, new Lambertian(new ConstantTexture(new Vector3D(0.7f, 0.3f, 0.1f))))); list.Add(new Sphere(new Vector3D(260, 150, 45), 50, new Dielectric(1.5f))); list.Add(new Sphere(new Vector3D(0, 150, 145), 50, new Metal( new Vector3D(0.8f, 0.8f, 0.9f), 10))); Hitable boundary = new Sphere(new Vector3D(360, 150, 145), 70, new Dielectric(1.5f)); list.Add(boundary); list.Add(new ConstantMedium(boundary, 0.2f, new ConstantTexture(new Vector3D(0.2f, 0.4f, 0.9f)))); boundary = new Sphere(new Vector3D(0, 0, 0), 5000, new Dielectric(1.5f)); list.Add(new ConstantMedium(boundary, 0.0001f, new ConstantTexture(new Vector3D(1, 1, 1)))); Material emat = new Lambertian(new Imagetexture("Earth.jpg")); list.Add(new Sphere(new Vector3D(400, 200, 400), 100, emat)); Texture pertext = new NoiseTexture(1f); list.Add(new Sphere(new Vector3D(220, 280, 300), 80, new Lambertian(pertext))); int ns = 1000; for (int j = 0; j < ns; j++) { boxList2.Add(new Sphere(new Vector3D(165 * Mathf.Randomfloat(), 165 * Mathf.Randomfloat(), 165 * Mathf.Randomfloat()), 10, white)); } list.Add(new Translate(new RotateY(new BVHNode(boxList2, ns, 0, 1), 15), new Vector3D(-100, 270, 395))); BVHNode b = new BVHNode(list, list.Count, 0, 1); HitableList world = new HitableList(); world.list.Add(b); HitableList lightShapeList = new HitableList(); Hitable lightShape = new XZRect(123, 423, 147, 412, 554, null); lightShapeList.list.Add(lightShape); scene = new Scene(width, height, world, isSky, camera, 0.5f, false, lightShapeList); }
public void Init(int seed, int width, int height) { if (LandBitmap != null && width != LandBitmap.Width) { LandBitmap.ResizeImage(width, height, false); } if (MountainBitmap != null && width != MountainBitmap.Width) { MountainBitmap.ResizeImage(width, height, false); } float delta = width / 3072.0f; delta *= ZoomMultiplier; DivNoise = delta; // Rand.SetSeed(seed); baseWaterTerrain.Frequency = 2.0; baseLandTerrain.Frequency = (2.0); ScaleBiasOutput flatTerrain = new ScaleBiasOutput(baseLandTerrain); flatTerrain.Scale = 0.005; flatTerrain.Bias = seaLevel;//SeaLevel; MinLandFreq = 0.2f; MaxLandFreq = 1f; if (LandBitmap != null) { MinLandFreq = 0.7f; } ScaleBiasOutput hillTerrain = new ScaleBiasOutput(baseLandTerrain); hillTerrain.Scale = 0.09; hillTerrain.Bias = seaLevel + 0.2;//SeaLevel; ScaleBiasOutput waterTerrain = new ScaleBiasOutput(baseWaterTerrain); waterTerrain.Bias = -0.33f;//SeaLevel; waterTerrain.Scale = 0.001; Perlin waterLandType = new Perlin(); float landFreq = Rand.Next((int)(MinLandFreq * 10000), (int)(MaxLandFreq * 10000)) / 10000.0f; waterLandType.Persistence = 0.45; waterLandType.Frequency = landFreq; //waterLandType.OctaveCount = 12; waterLandType.Seed = Rand.Next(1000000); Select waterLandSelector = new Select(waterLandType, waterTerrain, flatTerrain); if (LandBitmap != null) { waterLandSelector = new BitmapSelect(waterLandType, waterTerrain, flatTerrain, DivNoise, LandBitmap); } waterLandSelector.EdgeFalloff = (0.145); waterLandSelector.SetBounds(-0.0, 1000);; Select landHillSelector = new Select(waterLandType, waterLandSelector, hillTerrain); if (LandBitmap != null) { landHillSelector = new BitmapSelect(waterLandType, waterLandSelector, hillTerrain, DivNoise, LandBitmap); } landHillSelector.EdgeFalloff = (0.45); landHillSelector.SetBounds(0.25f, 1000);; terrainType.Persistence = 0.3; terrainType.Frequency = 0.3; terrainType.Seed = Rand.Next(10000000); var clamp = new ClampOutput(terrainType); clamp.SetBounds(0, 1); // mountainTerrain.Frequency /= 1.5f; mountainTerrain.Lacunarity = 35; mountainTerrain.Frequency = 3.2; mountainTerrain.Seed = Rand.Next(10000000); MultiplyPositive mul = new MultiplyPositive(waterLandType, waterLandType); ScaleOutput scaled = new ScaleOutput(mul, 0.00001); Add add = new Add(new BiasOutput(mountainTerrain, 0.8 + seaLevel), landHillSelector); MultiplyPositive mul2 = new MultiplyPositive(add, add); MultiplyPositive mul3 = new MultiplyPositive(clamp, mul); Select terrainSelector = new Select(mul3, landHillSelector, add); if (MountainBitmap != null) { terrainSelector = new BitmapSelect(mul3, landHillSelector, add, DivNoise, MountainBitmap); } terrainSelector.EdgeFalloff = (7.925); terrainSelector.SetBounds(0.3, 1000); Turbulence finalTerrain = new Turbulence(terrainSelector); finalTerrain.Frequency = 4; finalTerrain.Power = 0.075; Width = width; Height = height; // ResultBitmap2 = new NoiseTexture(width, height, clamp); // System.Console.Out.WriteLine("Left: " + ResultBitmap2.minRange + " - " + ResultBitmap2.maxRange); // ResultBitmap2 = new NoiseTexture(width, height, finalTerrain, DivNoise, 1.25f, -0.66f); // System.Console.Out.WriteLine("Left: " + ResultBitmap2.minRange + " - " + ResultBitmap2.maxRange); ResultBitmap = new NoiseTexture(width, height, finalTerrain, DivNoise, 1.25f, -0.66f); System.Console.Out.WriteLine("Right: " + ResultBitmap.minRange + " - " + ResultBitmap.maxRange); }
public void InitO(int seed, int width, int height) { float delta = width / 3072.0f; delta *= ZoomMultiplier; DivNoise = delta; // Rand.SetSeed(seed); baseWaterTerrain.Frequency = 2.0; baseLandTerrain.Frequency = (2.0); ScaleBiasOutput flatTerrain = new ScaleBiasOutput(baseLandTerrain); flatTerrain.Scale = 0.005; flatTerrain.Bias = seaLevel;//SeaLevel; ScaleBiasOutput hillTerrain = new ScaleBiasOutput(baseLandTerrain); hillTerrain.Scale = 0.065; hillTerrain.Bias = seaLevel + 0.2;//SeaLevel; ScaleBiasOutput waterTerrain = new ScaleBiasOutput(baseWaterTerrain); waterTerrain.Bias = -0.73f;//SeaLevel; waterTerrain.Scale = 0.05; Perlin waterLandType = new Perlin(); waterLandType.Persistence = 0.45; waterLandType.Frequency = 0.5; //waterLandType.OctaveCount = 12; waterLandType.Seed = Rand.Next(1000000); Select waterLandSelector = new Select(waterLandType, waterTerrain, flatTerrain); waterLandSelector.EdgeFalloff = (0.045); waterLandSelector.SetBounds(-0.0, 1000);; Select landHillSelector = new Select(waterLandType, waterLandSelector, hillTerrain); landHillSelector.EdgeFalloff = (0.15); landHillSelector.SetBounds(0.4, 1000);; terrainType.Persistence = 0.3; terrainType.Frequency = 0.3; terrainType.Seed = Rand.Next(10000000); var clamp = new ClampOutput(terrainType); clamp.SetBounds(0, 1); // mountainTerrain.Frequency /= 1.5f; mountainTerrain.Lacunarity = 30; mountainTerrain.Frequency = 1.3; MultiplyPositive mul = new MultiplyPositive(waterLandType, waterLandType); ScaleOutput scaled = new ScaleOutput(mul, 0.00001); Add add = new Add(new BiasOutput(mountainTerrain, 1 + seaLevel), landHillSelector); MultiplyPositive mul2 = new MultiplyPositive(mul, mul); MultiplyPositive mul3 = new MultiplyPositive(clamp, mul); Select terrainSelector = new Select(mul3, landHillSelector, add); terrainSelector.EdgeFalloff = (0.425); terrainSelector.SetBounds(0.3, 1000); Turbulence finalTerrain = new Turbulence(terrainSelector); finalTerrain.Frequency = 4; finalTerrain.Power = 0.075; Width = width; Height = height; // ResultBitmap2 = new NoiseTexture(width, height, clamp); // System.Console.Out.WriteLine("Left: " + ResultBitmap2.minRange + " - " + ResultBitmap2.maxRange); ResultBitmap = new NoiseTexture(width, height, finalTerrain, DivNoise, 1.25f, -0.66f); System.Console.Out.WriteLine("Range: " + ResultBitmap.minRange + " - " + ResultBitmap.maxRange); }
public void doStuff() { //CPU Based Perlin Noise var watch = System.Diagnostics.Stopwatch.StartNew(); NoiseTexture.Offset = Offset; NoiseTexture.NoiseScale = NoiseScale; Texture2D cpuTex = NoiseTexture.generateTexture2D(size, size); cpuPrefab.GetComponent <Renderer>().material.mainTexture = cpuTex; watch.Stop(); Debug.Log("CPU Based: " + watch.ElapsedMilliseconds); //GPU Based Perlin Noise watch.Reset(); watch = System.Diagnostics.Stopwatch.StartNew(); ComputeShader cs = (ComputeShader)Resources.Load("PerlinNoise"); int kernel = cs.FindKernel("NoiseTexture2D"); RenderTexture result = new RenderTexture(size, size, 24); result.enableRandomWrite = true; result.format = RenderTextureFormat.ARGB32; result.Create(); ComputeBuffer buffer = new ComputeBuffer(size * size, sizeof(float)); cs.SetBuffer(kernel, "noiseValues", buffer); cs.SetFloat("noiseScale", NoiseTexture.NoiseScale); cs.SetInts("size", new int[3] { size, size, 1 }); cs.SetFloats("offset", new float[3] { Offset.x, Offset.y, Offset.z }); cs.Dispatch(kernel, size / 16, size / 16, 1); Texture2D gpuTex = new Texture2D(size, size, TextureFormat.ARGB32, false); float[] colors = new float[size * size]; buffer.GetData(colors); buffer.Dispose(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float sample = colors[i * size + j]; Color color = new Color(sample, sample, sample, 1.0f); gpuTex.SetPixel(i, j, color); } } gpuTex.Apply(); gpuPrefab.GetComponent <Renderer>().material.mainTexture = gpuTex; watch.Stop(); Debug.Log("GPU Based: " + watch.ElapsedMilliseconds); }