private void setbumpmap2(Entity entity, Texture texture, float sizeX = 1, float sizeY = 1, float strength = 1) { try { if (entity is Cylinder) { Cylinder cylinder = entity as Cylinder; cylinder.Bumpmap2 = texture; cylinder.Bumpmap2Size = new Vector2f(1 / sizeX, 1 / sizeY); cylinder.Bumpmap2Strength = strength; } else if (entity is Tube) { Tube tube = entity as Tube; tube.Bumpmap2 = texture; tube.Bumpmap2Size = new Vector2f(1 / sizeX, 1 / sizeY); tube.Bumpmap2Strength = strength; } else { throw new NullReferenceException(); } } catch (Exception ex) { RuntimeError("setbumpmap2", ex); } }
private void setinnerradius(Tube tube, float innerRadius) { try { tube.InnerRadius = innerRadius; } catch (Exception ex) { RuntimeError("setinnerradius", ex); } }
private void render(Camera camera) { try { if (!IsStopped) { LiterayCore.Initialize(); LiterayCore.SetGlobal( RenderProperties.ScreenWidth, RenderProperties.ScreenHeight, RenderProperties.MaximumRecursion, RenderProperties.ActualShadowSamples, RenderProperties.ActualAntiAliasMask.SubPixels.Length, RenderProperties.ActualAntiAliasMask.SubPixels, camera.Position, camera.Angle, camera.Zoom, camera.ClsColor, camera.AmbientColor, camera.FogEnabled, camera.FogRange); foreach (RaytracingObject raytracingObject in RaytracingObject.AllRaytracingObjects) { if (raytracingObject is Texture) { Texture texture = raytracingObject as Texture; LiterayCore.LoadTexture(texture.Handle, texture.Width, texture.Height, texture.Buffer); } if (raytracingObject is Light) { Light light = raytracingObject as Light; LiterayCore.CreateLight(light.Position, light.Size, light.Brightness, light.Color); } else if (raytracingObject is Plane) { Plane plane = raytracingObject as Plane; LiterayCore.CreatePlane( plane.Normal, plane.D, plane.Color, plane.Reflection, plane.SpecularPower, plane.SpecularIntensity, plane.Texture == null ? 0 : plane.Texture.Handle, plane.Texture2 == null ? 0 : plane.Texture2.Handle, plane.Bumpmap == null ? 0 : plane.Bumpmap.Handle, plane.Bumpmap2 == null ? 0 : plane.Bumpmap2.Handle, plane.TextureSize, plane.Texture2Size, plane.BumpmapSize, plane.Bumpmap2Size, plane.BumpmapStrength, plane.Bumpmap2Strength); } else if (raytracingObject is Cube) { Cube cube = raytracingObject as Cube; LiterayCore.CreateCube( cube.Position, cube.Size, cube.Color, cube.Reflection, cube.SpecularPower, cube.SpecularIntensity, cube.Texture == null ? 0 : cube.Texture.Handle, cube.Texture2 == null ? 0 : cube.Texture2.Handle, cube.Bumpmap == null ? 0 : cube.Bumpmap.Handle, cube.Bumpmap2 == null ? 0 : cube.Bumpmap2.Handle, cube.TextureSize, cube.Texture2Size, cube.BumpmapSize, cube.Bumpmap2Size, cube.BumpmapStrength, cube.Bumpmap2Strength); } else if (raytracingObject is Sphere) { Sphere sphere = raytracingObject as Sphere; LiterayCore.CreateSphere( sphere.Position, sphere.Radius, sphere.Color, sphere.Reflection, sphere.SpecularPower, sphere.SpecularIntensity, sphere.Texture == null ? 0 : sphere.Texture.Handle, sphere.Texture2 == null ? 0 : sphere.Texture2.Handle, sphere.Bumpmap == null ? 0 : sphere.Bumpmap.Handle, sphere.Bumpmap2 == null ? 0 : sphere.Bumpmap2.Handle, sphere.TextureSize, sphere.Texture2Size, sphere.BumpmapSize, sphere.Bumpmap2Size, sphere.BumpmapStrength, sphere.Bumpmap2Strength); } else if (raytracingObject is Cylinder) { Cylinder cylinder = raytracingObject as Cylinder; LiterayCore.CreateCylinder( cylinder.Position, cylinder.Radius, cylinder.Height, cylinder.Color, cylinder.Reflection, cylinder.SpecularPower, cylinder.SpecularIntensity, cylinder.Texture == null ? 0 : cylinder.Texture.Handle, cylinder.Texture2 == null ? 0 : cylinder.Texture2.Handle, cylinder.Bumpmap == null ? 0 : cylinder.Bumpmap.Handle, cylinder.Bumpmap2 == null ? 0 : cylinder.Bumpmap2.Handle, cylinder.TextureSize, cylinder.Texture2Size, cylinder.BumpmapSize, cylinder.Bumpmap2Size, cylinder.BumpmapStrength, cylinder.Bumpmap2Strength); } else if (raytracingObject is Tube) { Tube tube = raytracingObject as Tube; LiterayCore.CreateTube( tube.Position, tube.Radius, tube.InnerRadius, tube.Height, tube.Color, tube.Reflection, tube.SpecularPower, tube.SpecularIntensity, tube.Texture == null ? 0 : tube.Texture.Handle, tube.Texture2 == null ? 0 : tube.Texture2.Handle, tube.Bumpmap == null ? 0 : tube.Bumpmap.Handle, tube.Bumpmap2 == null ? 0 : tube.Bumpmap2.Handle, tube.TextureSize, tube.Texture2Size, tube.BumpmapSize, tube.Bumpmap2Size, tube.BumpmapStrength, tube.Bumpmap2Strength); } } Window = new WindowRenderer(RenderProperties.ScreenWidth, RenderProperties.ScreenHeight, FileName); Window.Closed += Window_Closed; Window.Title = FileName; Window.Show(); DateTime startTime = DateTime.Now; CurrentLine = 0; Pixels = new int[RenderProperties.ScreenWidth * RenderProperties.ScreenHeight]; for (int y = 0, pixelOffset = 0; y < RenderProperties.ScreenHeight; y++) { for (int x = 0; x < RenderProperties.ScreenWidth; x++) { Pixels[pixelOffset++] = ((y / 12) & 1) == 1 ^ ((x / 12) & 1) == 1 ? 0xffffff : 0xafafaf; } } Window.Bitmap.WritePixels(new Int32Rect(0, 0, RenderProperties.ScreenWidth, RenderProperties.ScreenHeight), Pixels, RenderProperties.ScreenWidth * 4, 0); Threads = new Thread[RenderProperties.ThreadCount]; for (int i = 0; i < RenderProperties.ThreadCount; i++) { int j = i; Threads[i] = new Thread(new ThreadStart(delegate { RenderThread(j); })); Threads[i].Priority = ThreadPriority.Lowest; Threads[i].Start(); } bool finished = false; while (!finished) { finished = true; foreach (Thread thread in Threads) { if (thread.IsAlive) { finished = false; break; } } Window.Bitmap.WritePixels(new Int32Rect(0, 0, RenderProperties.ScreenWidth, RenderProperties.ScreenHeight), Pixels, RenderProperties.ScreenWidth * 4, 0); Window.SetProgress((int)CurrentLine * 1f / RenderProperties.ScreenHeight); Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); Thread.Sleep(100); } TimeSpan timeUsed = DateTime.Now - startTime; LiterayCore.Destroy(); Window.Title += " - " + Math.Round(timeUsed.TotalSeconds, 3) + " s"; Window.SetProgress(1); HasRenderedAtLeastOnce = true; if (RenderProperties.AutoSave) { using (MemoryStream memoryStream = new MemoryStream()) { BitmapEncoder bitmapEncoder = new BmpBitmapEncoder(); bitmapEncoder.Frames.Add(BitmapFrame.Create(Window.Bitmap)); bitmapEncoder.Save(memoryStream); using (Bitmap bitmap = new Bitmap(memoryStream)) { string path = RenderProperties.AutoSavePath; Directory.CreateDirectory(path); bitmap.Save(Path.Combine(path, DateTime.Now.ToString("yyyy.MM.dd HH.mm.ss.fff", CultureInfo.InvariantCulture) + " - " + Path.GetFileNameWithoutExtension(FileName) + ".png"), ImageFormat.Png); } } } if (RenderProperties.AutoClose) { Window.AutoClose(); } } } catch (Exception ex) { RuntimeError("render", ex); } }