Esempio n. 1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            model = dragon;
            modelWorld = dragonWorld; 

            var depthState = new DepthStencilState();
            depthState.DepthBufferEnable = true;
            depthState.DepthBufferWriteEnable = true;
            GraphicsDevice.DepthStencilState = depthState;

            GraphicsDevice.SetRenderTarget(normalOut);

            GraphicsDevice.Clear(Color.Black);
            depthEffect.CurrentTechnique = depthEffect.Techniques["WorldPos"];
            depthEffect.Parameters["modelToWorld"].SetValue(modelWorld);
            depthEffect.Parameters["modelToWorldNormal"].SetValue(Matrix.Transpose(Matrix.Invert(modelWorld)));
            depthEffect.Parameters["eyeToClip"].SetValue(cam.GetViewProjection());
            depthEffect.Parameters["eye"].SetValue(cam.GetEye());
            depthEffect.Parameters["forward"].SetValue(cam.GetForward());
            model.Draw(depthEffect);

            GraphicsDevice.SetRenderTarget(depthOut);

            GraphicsDevice.Clear(Color.Black);
            depthEffect.CurrentTechnique = depthEffect.Techniques["DepthPlusNormal"];
            depthEffect.Parameters["modelToWorld"].SetValue(modelWorld);
            depthEffect.Parameters["modelToWorldNormal"].SetValue(Matrix.Transpose(Matrix.Invert(modelWorld)));
            depthEffect.Parameters["eyeToClip"].SetValue(cam.GetViewProjection());
            depthEffect.Parameters["eye"].SetValue(cam.GetEye());
            depthEffect.Parameters["forward"].SetValue(cam.GetForward());
            model.Draw(depthEffect);

            GraphicsDevice.SetRenderTarget(noiseOut);

            if (recorder.IsRecording() && iFrame % 3 == 0)
                recorder.RecordFrame(depthOut, cam.GetView());

            GraphicsDevice.Clear(Color.Black);
            billboardEffect.CurrentTechnique = billboardEffect.Techniques["AddNoise"];
            billboardEffect.Parameters["depth"].SetValue(depthOut);
            billboardEffect.Parameters["normal"].SetValue(normalOut);
            billboardEffect.Parameters["iFrame"].SetValue(iFrame);
            billboardEffect.Parameters["eye"].SetValue(cam.GetEye());
            billboardEffect.Parameters["forward"].SetValue(cam.GetForward());
            billboard.Draw(billboardEffect);

            GraphicsDevice.SetRenderTarget(medianOut);

            GraphicsDevice.Clear(Color.Black);
            billboardEffect.CurrentTechnique = billboardEffect.Techniques["ComputeMedian"];
            billboardEffect.Parameters["depth"].SetValue(noiseOut);
            billboard.Draw(billboardEffect);

            GraphicsDevice.SetRenderTarget(null);

#if false
            GraphicsDevice.Clear(Color.Black);
            billboardEffect.CurrentTechnique = billboardEffect.Techniques["Depth2Color"];
            billboardEffect.Parameters["depth"].SetValue(medianOut);
            billboardEffect.Parameters["eye"].SetValue(cam.GetEye());
            billboardEffect.Parameters["forward"].SetValue(cam.GetForward());
            billboard.Draw(billboardEffect);       
#else
            if (iFrame == 0)
            {
                double bestE = double.MaxValue;

                float a = 0.0f;
                float b = 10.0f;
                float step = 1.0f;

                for (int i = 0; i < 3; i++)
                {
                    float minD = a;
                    for (; minD < b; minD += step)
                    {
                        medianOut.GetData<Vector4>(tmpPCL);
                        pcl.Integrate(tmpPCL, cam.GetViewProjection(), cam.GetEye(), minD);

                        depthOut.GetData<Vector4>(tmpPCL);
                        double e = pcl.MSE(tmpPCL, cam.GetViewProjection(), cam.GetEye());

                        pcl.Clear();

                        if (e < bestE)
                        {
                            bestE = e;
                            bestD = minD;
                        }
                    }

                    a = MathHelper.Max(0.0f, bestD - 0.5f * step);
                    b = a + step;
                    step /= 10;
                }

            }

            medianOut.GetData<Vector4>(tmpPCL);
            pcl.Integrate(tmpPCL, cam.GetViewProjection(), cam.GetEye(), bestD);

            depthOut.GetData<Vector4>(tmpPCL);
            double mse = pcl.MSE(tmpPCL, cam.GetViewProjection(), cam.GetEye());

            render.Render(pcl, cam.GetViewProjection(), cam.GetEye(), cam.GetForward(), rgba);

            rgbaTex.SetData<Vector4>(rgba);

            GraphicsDevice.SetRenderTarget(null);

            GraphicsDevice.Clear(Color.Black);
            billboardEffect.CurrentTechnique = billboardEffect.Techniques["RenderTex"];
            billboardEffect.Parameters["color"].SetValue(rgbaTex);
            billboard.Draw(billboardEffect);
#endif

            //if (iFrame > 100)
                cam.Orbit();

            debugInfo.Begin(SpriteSortMode.Deferred, BlendState.Opaque);
            debugInfo.DrawString(debugInfoFont, bestD.ToString(), new Vector2(10, 10), Color.White);
            debugInfo.End();

            base.Draw(gameTime);

            iFrame++;
        }
Esempio n. 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            depthEffect = Content.Load<Effect>("Depth");
            billboardEffect = Content.Load<Effect>("billboardViz");
            
            temple = new AnimatedFBX
            (
                Content,
                "house"
            );
            templeWorld = Matrix.CreateScale(0.075f) * Matrix.CreateTranslation(0.0f, -0.75f, -0.37f) * Matrix.CreateRotationY(-0.3f);

            f15 = new AnimatedFBX
            (
                Content,
                "f15"
            );
            f15World = Matrix.CreateScale(0.0015f) * Matrix.CreateTranslation(new Vector3(0.0f, -0.3f, 0.0f)) * Matrix.CreateRotationY(1.3f);

            dragon = new AnimatedFBX
            (
                Content,
                "dragon"
            );
            dragonWorld = Matrix.CreateScale(0.05f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(-0.8f) * Matrix.CreateTranslation(new Vector3(0.0f, -0.8f, 0.0f));

            billboard = new AnimatedFBX
            (
                Content,
                "billboard"
            );

            debugInfoFont = Content.Load<SpriteFont>("SpriteFont1");
        }