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();
        }
示例#2
0
        public void SetScheme(MoleculeRenderingScheme scheme, CompleteOutputDescription coDesc)
        {
            latestCoDesc = new CompleteOutputDescription(coDesc);
            sceneManger.SetScheme(scheme);
            sceneManger.SetOutputDesc(coDesc);

            scheme.device = device;
            // build preview via thread
            if (generatorThread.ThreadState == ThreadState.Running)
            {
                // abort thread
                generatorThread.Abort();
                generatorThread.Join();
            }
            generatorThread = new Thread(GeneratePreviewProcess);
            generatorThread.Start();

            wantPreview = true;
        }
示例#3
0
//        public abstract bool DesiredGeomDataFields(out DataFields[] fields, bool exclusive);
        public abstract void RenderFrame(GraphicsPipeline3D pipeline, MoleculeRenderingScheme scheme, bool alphaPass);
        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);
        }
示例#6
0
 public void SetScheme(MoleculeRenderingScheme scheme)
 {
     this.scheme = scheme;
 }