示例#1
0
        private void OnNewDevice()
        {
            if (outSettings != null)
            {
                outSettings.CreateDevice(panel1, out device, out pParams);
            }

            if (device != null)
            {
                pipeline = new GraphicsFixedPipeline3D(device);
                //deviceFont = new Microsoft.DirectX.Direct3D.Font(device, Font);

                if (previewObj != null)
                {
                    previewObj.Dispose();
                }
                previewObj = Mesh.Sphere(device, 2, 32, 32);

                lightObj = Mesh.Sphere(device, 1, 4, 4);

                CreateOrbitLine();

                OnResize(null);
            }
            else
            {
            }
        }
示例#2
0
        public override void UpdateFrameData(BufferedGeometryData[] geomData, GraphicsPipeline3D pipeline)
        {
            PointVertex[] blobPoints = (PointVertex[])geomData[0].vBuffers[0].Buffer.Lock(0, LockFlags.None);
            numPoints = blobPoints.Length;

            if (needsReset)
            {
                OnReset();
            }

            FillBlobVB(pipeline.WorldMatrix * pipeline.ViewMatrix, pipeline.ProjectionMatrix, ref blobPoints);

            geomData[0].vBuffers[0].Buffer.Unlock();
        }
        public override void RenderFrame(GraphicsPipeline3D pipeline, MoleculeRenderingScheme scheme, bool alphaPass)
        {
            Matrix wvp = pipeline.WorldMatrix * pipeline.ViewMatrix * pipeline.ProjectionMatrix;

            effect.SetValue("worldViewProj", wvp);

            // do passes
            effect.Technique = technique;
            effect.Begin(FX.None);
            effect.BeginPass(0);

            // render everything from the scheme
            scheme.RenderAtoms(false, false);
            scheme.RenderBonds(false, false);

            effect.EndPass();
            effect.End();
        }
示例#4
0
        private void OnNewDevice()
        {
            if (outSettings != null)
            {
                outSettings.CreateDevice(this, out device, out pParams);
            }

            if (device != null)
            {
                pipeline   = new GraphicsFixedPipeline3D(device);
                deviceFont = new Microsoft.DirectX.Direct3D.Font(device, Font);

                sceneManger = new MoleculeSceneManager(device, outSettings);
            }
            else
            {
            }
        }
        protected override void InitializeEnvironment(CommonDeviceInterface cdi)
        {
            base.InitializeEnvironment(cdi);

            pipeline = new GraphicsFixedPipeline3D(device);//new GraphicsProgramablePipeline3D(device);

            ChemSymbolTextures.GraphicsDevice = device;

            sceneManager = new MoleculeSceneManager(device, outSettings);

            selectionLine           = new Line(device);
            selectionLine.Antialias = false;
            selectionArea           = new Vector2[5];

            molControlLayer = new MoleculeControlLayer(devIf, new Point(), new Size());
            molControlLayer.Show(false);
            molControlLayer.LoadResources();
            layers.InsertLayer(molControlLayer, uint.MaxValue);
        }
示例#6
0
        private void OnNewDevice()
        {
            if (outSettings != null)
            {
                outSettings.CreateDevice(this, out device, out pParams);
            }

            if (device != null)
            {
                pipeline   = new GraphicsFixedPipeline3D(device);
                deviceFont = new Microsoft.DirectX.Direct3D.Font(device, Font);

                sceneManger = new MoleculeSceneManager(device, outSettings);
                BallAndStickRenderingScheme scheme = new BallAndStickRenderingScheme(device);
                sceneManger.SetScheme(scheme);
                sceneManger.SetOutputDesc(latestCoDesc);
                sceneManger.OnNewDataSource(atoms, null, new Vector3(), new Bounds3D(new Vector3(), new Vector3(), 3));
            }
            else
            {
            }
        }
示例#7
0
        public override void RenderFrame(GraphicsPipeline3D pipeline)
        {
            pEffect.SetValue("g_mWorldViewProjection", pipeline.ProjectionMatrix);

            Surface[] apSurfOldRenderTarget = new Surface[2];
            Surface   pSurfOldDepthStencil  = null;

            Surface[] pGBufSurf = new Surface[4];

            // Clear the render target and the zbuffer
            //device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(0, 45, 50, 170), 1.0f, 0);
            device.BeginScene();

            // Get the initial device surfaces
            apSurfOldRenderTarget[0] = device.GetRenderTarget(0);  // Only RT 0 should've been set.
            pSurfOldDepthStencil     = device.DepthStencilSurface;

            // Turn off Z
            device.RenderState.ZBufferEnable = false;
            device.DepthStencilSurface       = null;

            // Clear the blank texture
            Surface pSurfBlank = pTexScratch.GetSurfaceLevel(0);

            device.SetRenderTarget(0, pSurfBlank);
            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            pSurfBlank.Dispose();

            // clear temp textures
            for (int i = 0; i < 2; i++)
            {
                pGBufSurf[i] = pTexGBuffer[i].GetSurfaceLevel(0);
                device.SetRenderTarget(0, pGBufSurf[i]);
                device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            }

            for (int i = 2; i < 4; i++)
            {
                pGBufSurf[i] = pTexGBuffer[i].GetSurfaceLevel(0);
            }

            device.SetStreamSource(0, pBlobVB, 0, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ScreenVertex)));
            device.VertexFormat = ScreenVertexFormat;

            // Render the blobs
            pEffect.Technique = hBlendTech;
            int nNumPasses;

            for (int i = 0; i < numPoints; i++)
            {
                // Copy bits off of render target into scratch surface [for blending].
                pEffect.SetValue("g_tSourceBlob", pTexScratch);
                pEffect.SetValue("g_tNormalBuffer", pTexGBuffer[0]);
                pEffect.SetValue("g_tColorBuffer", pTexGBuffer[1]);

                nNumPasses = pEffect.Begin(FX.None);
                for (int iPass = 0; iPass < nNumPasses; iPass++)
                {
                    for (int rt = 0; rt < nRtUsed; rt++)
                    {
                        device.SetRenderTarget(rt, aRTSet[iPass].apCopyRT[rt]);
                    }

                    pEffect.BeginPass(iPass);

                    device.DrawPrimitives(PrimitiveType.TriangleList, i * 6, 2);
                    pEffect.EndPass();
                }
                pEffect.End();

                // Render the blob
                pEffect.SetValue("g_tSourceBlob", pTexBlob);
                pEffect.SetValue("g_tNormalBuffer", pTexGBuffer[2]);
                pEffect.SetValue("g_tColorBuffer", pTexGBuffer[3]);

                nNumPasses = pEffect.Begin(FX.None);
                for (int iPass = 0; iPass < nNumPasses; iPass++)
                {
                    for (int rt = 0; rt < nRtUsed; rt++)
                    {
                        device.SetRenderTarget(rt, aRTSet[iPass].apBlendRT[rt]);
                    }

                    pEffect.BeginPass(iPass);

                    device.DrawPrimitives(PrimitiveType.TriangleList, i * 6, 2);
                    pEffect.EndPass();
                }

                pEffect.End();
            }

            // Restore initial device surfaces
            device.DepthStencilSurface = pSurfOldDepthStencil;

            for (int rt = 0; rt < nRtUsed; rt++)
            {
                device.SetRenderTarget(rt, apSurfOldRenderTarget[rt]);
            }

            // Light and composite blobs into backbuffer
            pEffect.Technique = "BlobLight";

            nNumPasses = pEffect.Begin(FX.None);

            for (int iPass = 0; iPass < nNumPasses; iPass++)
            {
                pEffect.BeginPass(iPass);

                for (int i = 0; i < numPoints; i++)
                {
                    pEffect.SetValue("g_tSourceBlob", pTexGBuffer[0]);
                    pEffect.SetValue("g_tColorBuffer", pTexGBuffer[1]);
                    pEffect.SetValue("g_tEnvMap", pEnvMap);
                    pEffect.CommitChanges();

                    RenderFullScreenQuad(1.0f);
                }
                pEffect.EndPass();
            }

            pEffect.End();
            device.EndScene();

            for (int rt = 0; rt < nRtUsed; rt++)
            {
                if (apSurfOldRenderTarget[rt] != null)
                {
                    apSurfOldRenderTarget[rt].Dispose();
                }
            }
            pSurfOldDepthStencil.Dispose();

            for (int i = 0; i < 4; i++)
            {
                pGBufSurf[i].Dispose();
            }
        }
示例#8
0
 public abstract void RenderFrame(GraphicsPipeline3D pipeline);
示例#9
0
 public virtual void UpdateFrameData(BufferedGeometryData[] geomData, GraphicsPipeline3D pipeline)
 {
 }
示例#10
0
//        public abstract bool DesiredGeomDataFields(out DataFields[] fields, bool exclusive);
        public abstract void RenderFrame(GraphicsPipeline3D pipeline, MoleculeRenderingScheme scheme, bool alphaPass);
示例#11
0
 public override void UpdateFrameViewData(GraphicsPipeline3D pipeline)
 {
 }
示例#12
0
 public abstract void UpdateFrameViewData(GraphicsPipeline3D pipeline);
示例#13
0
        public override void RenderFrame(GraphicsPipeline3D pipeline, MoleculeRenderingScheme scheme, bool alphaPass)
        {
            Surface rt0 = device.GetRenderTarget(0);
            Surface ds0 = device.DepthStencilSurface;

            // draw shadow to rt1 and ds1
            rt1 = new Texture(device, 1024, 1024, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            Surface ds1 = device.CreateDepthStencilSurface(1024, 1024, DepthFormat.D16, MultiSampleType.None, 0, true);

            device.SetRenderTarget(0, rt1.GetSurfaceLevel(0));
            device.DepthStencilSurface = ds1;

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1, 0);

            effect.Technique = renderShadow;

            // calc projection needed for scene
            float   radius   = scheme.SceneRadius + 0.3f;
            Vector3 lightDir = new Vector3(-0.3f, -1, 0);
            float   distance = (float)(radius / Math.Tan(Math.PI / 4)) * 2;
            Vector3 lightPos = (-lightDir * distance) + scheme.SceneOrigin;

            Matrix lightProj = Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                                                       (float)rt0.Description.Width / (float)rt0.Description.Height,
                                                       distance - radius, distance + radius);
            Matrix lightView = Matrix.LookAtLH(lightPos, scheme.SceneOrigin, new Vector3(0, 1, 0));
            Matrix lightViewProjectionMatrix = /*Matrix.Invert(pipeline.WorldMatrix * pipeline.ViewMatrix) **/ lightView * lightProj;

            effect.SetValue("xWorldViewProjection", pipeline.WorldMatrix * pipeline.ViewMatrix * pipeline.ProjectionMatrix);
            effect.SetValue("xWorld", Matrix.Identity);
            effect.SetValue("xMaxDepth", distance + radius);
            effect.SetValue("xLightPos", new Vector4(lightPos.X, lightPos.Y, lightPos.Z, 1));
            effect.SetValue("xLightDir", new Vector4(lightDir.X, lightDir.Y, lightDir.Z, 1));
            effect.SetValue("xLightWorldViewProjection", lightViewProjectionMatrix);
            effect.SetValue("g_fCosTheta", (float)Math.PI / 4);

            Matrix iv = Matrix.Invert(pipeline.WorldMatrix * pipeline.ViewMatrix);

            effect.SetValue("viewInverse", iv);

            /*effect.SetValue("g_mWorldView", lightView);
             * effect.SetValue("g_mProj", lightProj);*/


            //device.Clear(ClearFlags.ZBuffer, 0x000000ff, 1, 0);
            //device.RenderState.CullMode = Cull.Clockwise;
            device.RenderState.ZBufferEnable = true;

            effect.Begin(FX.None);
            effect.BeginPass(0);

            // render everything from the scheme
            scheme.RenderAtoms(false, true);
            //scheme.RenderBonds(false, true);

            /*CustomVertex.PositionNormal[] floor = new CustomVertex.PositionNormal[4];
             * floor[0] = new CustomVertex.PositionNormal(new Vector3(6, -3, 6), new Vector3(0, 1, 0));
             * floor[2] = new CustomVertex.PositionNormal(new Vector3(-6, -3, 6), new Vector3(0, 1, 0));
             * floor[1] = new CustomVertex.PositionNormal(new Vector3(6, -3, -6), new Vector3(0, 1, 0));
             * floor[3] = new CustomVertex.PositionNormal(new Vector3(-6, -3, -6), new Vector3(0, 1, 0));*/

            /*device.VertexFormat = CustomVertex.PositionNormal.Format;
             * device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, floor);*/

            effect.EndPass();
            effect.End();

            device.SetRenderTarget(0, rt0);
            device.DepthStencilSurface = ds0;


            // render scene mapped with shadow
            //device.RenderState.CullMode = Cull.CounterClockwise;
            effect.Technique = renderScene;
            effect.SetValue("xShadowMap", rt1);

            /*effect.SetValue("xWorld", pipeline.WorldMatrix);
             * effect.SetValue("xLightWorldViewProjection", pipeline.WorldMatrix * lightViewProjectionMatrix);*/

            /*effect.SetValue("g_mWorldView", pipeline.WorldMatrix * pipeline.ViewMatrix);
             * effect.SetValue("g_mProj", pipeline.ProjectionMatrix);
             * effect.SetValue("g_mViewToLightProj", lightViewProjectionMatrix);
             * effect.SetValue("g_vLightPos", new Vector4(lightPos.X, lightPos.Y, lightPos.Z, 1));
             * effect.SetValue("g_vLightDir", new Vector4(lightDir.X, lightDir.Y, lightDir.Z, 1));
             * effect.SetValue("g_fCosTheta", (float)Math.PI / 4);*/

            effect.Begin(FX.None);
            effect.BeginPass(0);

            // render everything from the scheme
            scheme.RenderAtoms(false, true);

            if (scheme.LightBonds)
            {
                scheme.RenderBonds(false, false);
            }

            // draw floor

            /*device.VertexFormat = CustomVertex.PositionNormal.Format;
             * device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, floor);*/

            effect.EndPass();
            effect.End();

            effect.Technique = renderLines;

            effect.Begin(FX.None);
            effect.BeginPass(0);

            scheme.RenderBonds(false, true);

            effect.EndPass();
            effect.End();

            //TextureLoader.Save("c:/shadow.dds", ImageFileFormat.Dds, rt1);

            rt1.Dispose();
            ds1.Dispose();
        }
        public override void RenderFrame(GraphicsPipeline3D pipeline, MoleculeRenderingScheme scheme, bool alphaPass)
        {
            Effect cEffect;

            if (lod == 0)
            {
                cEffect = effect1;
            }
            else if (lod == 1)
            {
                cEffect = effect2;
            }
            else
            {
                return;
            }

            Matrix wvp = pipeline.WorldMatrix * pipeline.ViewMatrix * pipeline.ProjectionMatrix;
            Matrix iv  = Matrix.Invert(pipeline.ViewMatrix);

            cEffect.SetValue("worldViewProj", wvp);
            cEffect.SetValue("viewInverse", iv);
            cEffect.SetValue("worldInverseTranspose", Matrix.TransposeMatrix(iv));
            cEffect.SetValue("shininess", 3);
            cEffect.SetValue("diffuseTexture", testTexture);

            if (alphaPass)
            {
                cEffect.Technique = alphaTechnique;
                cEffect.Begin(FX.None);
                cEffect.BeginPass(0);

                scheme.RenderAtoms(false, false);

                cEffect.EndPass();
                cEffect.End();
            }
            else
            {
                // do light passes
                cEffect.Technique = technique;
                cEffect.Begin(FX.None);
                cEffect.BeginPass(0);
                //effect.SetValue("diffuseTexture", texture);
                foreach (NuGenSVisualLib.Rendering.Lighting.Light light in setup.lights)
                {
                    if (!light.Enabled)
                    {
                        continue;
                    }
                    if (light is DirectionalLight)
                    {
                        DirectionalLight dLight = (DirectionalLight)light;
                        cEffect.SetValue("lightDir", new Vector4(dLight.Direction.X, dLight.Direction.Y, dLight.Direction.Z, 1.0f));
                        cEffect.SetValue("lightColor", ColorValue.FromColor(dLight.Clr));

                        // render everything from the scheme
                        scheme.RenderAtoms(false, false);
                        if (scheme.LightBonds)
                        {
                            scheme.RenderBonds(false, false);
                        }
                    }
                }
                cEffect.EndPass();
                cEffect.End();
            }
            //if (!scheme.LightBonds)
            //{
            //    effect.Technique = lineTechnique;
            //    effect.Begin(FX.None);
            //    effect.BeginPass(0);

            //    scheme.RenderBonds();

            //    effect.EndPass();
            //    effect.End();
            //}

            //device.SetTexture(0, null);
        }
示例#15
0
 public abstract void RenderSceneFrame(GraphicsPipeline3D pipeline, int width, int height);
示例#16
0
        public override void RenderSceneFrame(GraphicsPipeline3D pipeline, int width, int height)
        {
            //pipeline.PushAll();

            //pipeline.PopAll();

            //pipeline.ProjectionMatrix = Matrix.OrthoLH(width, height, 0f, 2f);
            //pipeline.ViewMatrix = Matrix.Identity;
            //pipeline.WorldMatrix = Matrix.Identity;

            if (ppEffect != null)
            {
                // do alpha pass first
                ppEffect.PreFramePass(-1);
                if (ppEffect.RenderScene(-1))
                {
                    // render scene w/effect
                    device.RenderState.Lighting = false;
                    // update frame data
                    scheme.UpdateFrameViewData(pipeline);
                    if (effect != null)
                    {
                        if (effect is GeometryRenderingEffect)
                        {
                            GeometryRenderingEffect gEffect = (GeometryRenderingEffect)effect;
                            gEffect.RenderFrame(pipeline, scheme, true);
                        }

                        /*else if (effect is ScreenSpaceRenderingEffect)
                         * {
                         *  ScreenSpaceRenderingEffect sEffect = (ScreenSpaceRenderingEffect)effect;
                         *  sEffect.UpdateFrameData(scheme.atomsBufferData, pipeline);
                         *
                         *  sEffect.RenderFrame(pipeline);
                         *  return;
                         * }*/
                    }

                    /*device.RenderState.Lighting = false;
                     * scheme.RenderAtoms(true, effect == null);
                     * scheme.RenderBonds(true, (effect == null || !scheme.LightBonds));*/
                }
                ppEffect.PostFramePass(-1);

                for (int i = 0; i < ppEffect.NumPassesRequired; i++)
                {
                    ppEffect.PreFramePass(i);
                    if (ppEffect.RenderScene(i))
                    {
                        // render scene w/effect
                        device.RenderState.Lighting = true;
                        // update frame data
                        scheme.UpdateFrameViewData(pipeline);
                        if (effect != null)
                        {
                            if (effect is GeometryRenderingEffect)
                            {
                                GeometryRenderingEffect gEffect = (GeometryRenderingEffect)effect;
                                gEffect.RenderFrame(pipeline, scheme, false);
                            }
                            else if (effect is ScreenSpaceRenderingEffect)
                            {
                                ScreenSpaceRenderingEffect sEffect = (ScreenSpaceRenderingEffect)effect;
                                sEffect.UpdateFrameData(scheme.atomsBufferData, pipeline);

                                sEffect.RenderFrame(pipeline);
                                return;
                            }
                        }
                        device.RenderState.Lighting = false;
                        scheme.RenderAtoms(true, effect == null);
                        scheme.RenderBonds(true, (effect == null || !scheme.LightBonds));
                    }
                    ppEffect.PostFramePass(i);
                }
            }
            else
            {
                device.RenderState.Lighting = true;

                // update frame data
                scheme.UpdateFrameViewData(pipeline);

                if (effect != null)
                {
                    if (effect is GeometryRenderingEffect)
                    {
                        GeometryRenderingEffect gEffect = (GeometryRenderingEffect)effect;
                        gEffect.RenderFrame(pipeline, scheme, false);
                    }
                    else if (effect is ScreenSpaceRenderingEffect)
                    {
                        ScreenSpaceRenderingEffect sEffect = (ScreenSpaceRenderingEffect)effect;
                        sEffect.UpdateFrameData(scheme.atomsBufferData, pipeline);

                        sEffect.RenderFrame(pipeline);
                        return;
                    }
                    //else if (effect.EfxType == RenderingEffect.EffectType.ScreenSpace)
                    //{
                    //    // TODO: Check for matrix changes for update check
                    //    effect.UpdateFrameData(scheme.atomsBufferData, pipeline);
                    //    effect.RenderFrame(pipeline, scheme);
                    //}
                }

                // render as fixed pipeline (/ do FP pass)

                // TODO: Setup lights

                device.RenderState.Lighting = false;

                scheme.RenderAtoms(true, effect == null);
                scheme.RenderBonds(true, (effect == null || !scheme.LightBonds));
            }

            // render post-scene world entities
            foreach (IEntity entity in postSceneWorldEntities)
            {
                entity.Render();
            }

            Matrix wvMat = pipeline.WorldMatrix * pipeline.ViewMatrix;

            foreach (ViewSpaceEntity entity in postSceneViewEntities)
            {
                entity.UpdateView(pipeline.WorldMatrix, pipeline.ViewMatrix);
                // z-compare
                float z = 1000 - Vector3.Transform(entity.BoundingBox.Centre, wvMat).Z;
                try
                {
                    zCompareViewEntities.Add(z, entity);
                }
                catch { zCompareViewEntities.Add(z - 0.001f, entity); } // TODO: more robust feature?
            }

            foreach (KeyValuePair <float, ViewSpaceEntity> entity in zCompareViewEntities)
            {
                entity.Value.Render();
            }
            zCompareViewEntities.Clear();

            // render post-scene screen entities
            foreach (IScreenSpaceEntity entity in screenEntities)
            {
                // TODO: Detect matrix changes
                entity.Update(pipeline.WorldMatrix, pipeline.ViewMatrix, pipeline.ProjectionMatrix);
                entity.Render();
            }
        }