public void Clear()
 {
     for (Int32 PixelY = 0; PixelY < Height; ++PixelY)
     {
         for (Int32 PixelX = 0; PixelX < Width; ++PixelX)
         {
             Pixels[PixelY * Width + PixelX] = new H1Color(0, 0, 0, 1);
         }
     }
 }
        public H1RenderTarget(Int32 InWidth, Int32 InHeight)
        {
            Width  = InWidth;
            Height = InHeight;

            // allocate pixels in screen
            Pixels = new H1Color[Width * Height];
            // clear the render target
            Clear();
        }
        public bool Render()
        {
            H1Entity CameraObject = new H1Entity();
            H1RayTracerCameraComponent RayTracerCameraComponent = new H1RayTracerCameraComponent(CameraObject);

            Int32 ResolutionX = BackBuffer.Width;
            Int32 ResolutionY = BackBuffer.Height;

            H1Vector3 Direction = H1Vector3.Normalize(new H1Vector3(0, 1, -1));

            RayTracerCameraComponent.UpdateCamera(new H1Vector3(0, 0, 500), Direction);
            RayTracerCameraComponent.SetViewFrustum(100, 1000, (float)(30.0 / Math.PI), ResolutionX, ResolutionY);

            // test ray tracer component entity
            H1RayTracerComponent OneComponent = new H1RayTracerComponent(CameraObject);

            OneComponent.Activate();

            float Extent = 25.0f;

            OneComponent.CreateBoxBound(new H1Vector3(0, 500, 0), new H1Vector3(Extent, Extent, Extent));

            H1Ray Ray = new H1Ray(new H1Vector3(0, 0, 500), Direction);
            float T0, T1;

            bool bCollide = OneComponent.IsCollide(Ray, out T0, out T1);

            H1Ray[] Rays = RayTracerCameraComponent.GenerateRays();
            H1RayTracerSystem.Singleton.RayCast(Rays, ref BackBuffer);

            Bitmap NewBitmap = new Bitmap(ResolutionX, ResolutionY);

            for (Int32 PixelY = 0; PixelY < ResolutionY; ++PixelY)
            {
                for (Int32 PixelX = 0; PixelX < ResolutionX; ++PixelX)
                {
                    H1Color PixelColor = BackBuffer[PixelX, PixelY];
                    Color   OutColor   = Color.FromArgb(PixelColor.A, PixelColor.R, PixelColor.G, PixelColor.B);

                    NewBitmap.SetPixel(PixelX, PixelY, OutColor);
                }
            }

            NewBitmap.Save("RayTracerOutput.png", ImageFormat.Png);

            return(true);
        }
Beispiel #4
0
        public void RayCast(H1Ray[] InRays, ref H1RenderTarget OutRenderTarget)
        {
            Int32 Index = 0;

            foreach (H1Ray Ray in InRays)
            {
                float T0 = float.MaxValue;
                foreach (H1RayTracerComponent Component in RayTracerComponents)
                {
                    float CurrT0, CurrT1;
                    if (Component.IsCollide(Ray, out CurrT0, out CurrT1))
                    {
                        if (T0 > CurrT0)
                        {
                            OutRenderTarget[Index] = new H1Color(1, 0, 0, 1);
                            T0 = CurrT0;
                        }
                    }
                }

                Index++;
            }
        }