예제 #1
0
    public void Render( 
                       GraphicsContext graphics,
                       Camera camera,
                       LightModel light,
                       Model model,
                       BgModel bg
                      )
    {
        // setup a camera aligned with the  light source
        float aspect = offWidth / (float)offHeight;
        float fov = 45.0f * (float)(FMath.PI / 180.0f);
        Matrix4 proj = Matrix4.Perspective( fov,
                                            aspect,
                                            1.0f,
                                            10000.0f );
        Matrix4 view = Matrix4.LookAt( light.Position, model.Position, new Vector3( 0.0f, 1.0f, 0.0f ) );
 		Matrix4 world = model.Posture;
        Matrix4 lightVP = proj * view;

        // pass 1
        renderShadowMap( graphics, lightVP * world, model );

        // pass 2
		graphics.Clear();

        drawModel( graphics, camera, lightVP, model );
        light.Render( graphics, camera );

        // test
        texRenderer.Begin();
        int width = texShadow.Width / 2;
        int height = texShadow.Height / 2;
        texRenderer.Render( texShadow, ShaderCatalog.DspWidth - width, 0, 0, 0, width, height );
        texRenderer.End();
    }
예제 #2
0
        static void Init()
        {
            stopwatch = new Stopwatch();
            graphics  = new GraphicsContext();
            SampleDraw.Init(graphics);

            DspWidth  = graphics.Screen.Width;
            DspHeight = graphics.Screen.Height;

            sceneList = new List <IScene>();
            sceneList.Add(new SceneSimpleShader());
            sceneList.Add(new SceneVertexLightingShader());
            sceneList.Add(new SceneGouraudShader());
            sceneList.Add(new ScenePhongShader());
            sceneList.Add(new SceneGlossMapShader());
            sceneList.Add(new SceneTextureShader());
            sceneList.Add(new SceneMultiTextureShader());
            sceneList.Add(new SceneToonShader());
            sceneList.Add(new SceneFogShader());
            sceneList.Add(new SceneBumpMapShader());
            sceneList.Add(new SceneProjectionShadow());

            // graphics context
            graphics.SetViewport(0, 0, DspWidth, DspHeight);
            graphics.SetClearColor(0.0f, 0.5f, 1.0f, 1.0f);
            graphics.Enable(EnableMode.DepthTest);
            graphics.Enable(EnableMode.CullFace);
            graphics.SetCullFace(CullFaceMode.Back, CullFaceDirection.Ccw);

            // camera
            float aspect = DspWidth / (float)DspHeight;
            float fov    = FMath.Radians(45.0f);

            camera = new Camera(fov, aspect, 10.0f, 100.0f);

            // light
            light         = new LightModel();
            light.Color   = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            light.Ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);

            // model
//        model = new Model( BasicMeshFactory.CreateSphere( 4.0f, 20 ) );
            model               = new Model(BasicMeshFactory.CreateTorus(3.0f, 1.0f, 40, 12));
            model.Position      = new Vector3(0.0f, 4.0f, 0.0f);
            model.DiffuseColor  = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);
            model.AmbientColor  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            model.SpecularColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

            // Bg
            modelBg = new BgModel(40.0f, 40.0f, 10, 10);

            id = 0;
            sceneList[id].Setup(graphics, model);

            stopwatch.Start();
        }
예제 #3
0
 public void Render(
     GraphicsContext graphics,
     Camera camera,
     LightModel light,
     Model model,
     BgModel bg
     )
 {
     graphics.Clear();
     drawModel(graphics, camera, light, model);
     light.Render(graphics, camera);
     bg.Render(graphics, camera);
 }
예제 #4
0
        public void Render(
            GraphicsContext graphics,
            Camera camera,
            LightModel light,
            Model model,
            BgModel bg
            )
        {
            // offscreen rendering
            FrameBuffer oldBuffer = graphics.GetFrameBuffer();

            // render the scene
            graphics.SetFrameBuffer(sceneBuffer);
            graphics.SetViewport(0, 0, sceneBuffer.Width, sceneBuffer.Height);
            graphics.SetClearColor(0.0f, 0.5f, 1.0f, 1.0f);

            renderSimpleScene(graphics, camera, light, model, bg);

            // apply gaussian along X axis
            graphics.SetFrameBuffer(gaussianXBuffer);
            graphics.SetViewport(0, 0, gaussianXBuffer.Width, gaussianXBuffer.Height);

            renderGaussianX(graphics);

            // apply gaussian along Y axis
            graphics.SetFrameBuffer(gaussianXYBuffer);
            graphics.SetViewport(0, 0, gaussianXYBuffer.Width, gaussianXYBuffer.Height);

            renderGaussianY(graphics);

            // final draw
            {
                // restore frame buffer
                graphics.SetFrameBuffer(oldBuffer);
                graphics.SetViewport(0, 0, oldBuffer.Width, oldBuffer.Height);
                graphics.SetClearColor(0.0f, 0.5f, 1.0f, 1.0f);

                graphics.Clear();

                int width  = sceneBuffer.Width / 4;
                int height = sceneBuffer.Height / 4;

                texRenderer.Begin();
                texRenderer.Render(texGaussianXY, 0, 0, 0, 0, sceneBuffer.Width, sceneBuffer.Height);

                texRenderer.Render(texScene, 0, height * 0, 0, 0, width, height);
                texRenderer.Render(texGaussianX, 0, height * 1, 0, 0, width, height);
                texRenderer.Render(texGaussianXY, 0, height * 2, 0, 0, width, height);
                texRenderer.End();
            }
        }
예제 #5
0
        private void renderSimpleScene(
            GraphicsContext graphics,
            Camera camera,
            LightModel light,
            Model model,
            BgModel bg
            )
        {
            // rendering
            graphics.Clear();

            Matrix4 world         = model.Posture;
            Matrix4 worldViewProj = camera.Projection * camera.View * world;

            shaderTexture.SetUniformValue(shaderTexture.FindUniform("WorldViewProj"), ref worldViewProj);
            graphics.SetShaderProgram(shaderTexture);
            graphics.SetVertexBuffer(0, vbTeapot);

            graphics.SetTexture(0, texture);
            graphics.DrawArrays(model.Mesh.Prim, 0, model.Mesh.IndexCount);

            light.Render(graphics, camera);
            bg.Render(graphics, camera);
        }