Beispiel #1
0
        unsafe public void clearJacobianMap()
        {
            if (m_fxJacobian == null)// || mSynthesiser == null)
            {
                return;
            }


            Vector4 tr = new Vector4(0, 0, (float)m_iBuffersWidth, (float)m_iBuffersHeight);


            // save render target
            D3DProtectRenderTarget locktarget = new D3DProtectRenderTarget(true);

            // set new render target
            BRenderDevice.getDevice().SetRenderTarget(0, mJacobianMapSrf);
            BRenderDevice.getDevice().SetRenderTarget(1, mJacobianMapInverseSrf);

            savedDepthSten = BRenderDevice.getDevice().DepthStencilSurface;
            BRenderDevice.getDevice().DepthStencilSurface = m_DepthStencilSurface;


            // render
            BRenderDevice.getDevice().BeginScene();
            {
                BRenderDevice.getDevice().Clear(ClearFlags.Target, Color.Black, 1, 0);


                m_fxJacobian.Technique = m_fxJacobianClearTech;
                m_fxJacobian.SetValue(m_fxJacobianGlobalScale, mExemplar == null?0:mExemplar.mSynthParams.TextureScale);
                m_fxJacobian.SetValue(m_fxJacobianSelectedJMap, (int)mJMapPattern);
                m_fxJacobian.SetValue(m_fxJacobianViewport, tr);

                m_fxJacobian.CommitChanges();
                m_fxJacobian.Begin(FX.DoNotSaveState | FX.DoNotSaveShaderState | FX.DoNotSaveSamplerState);
                m_fxJacobian.BeginPass(0);
                m_QuadDual.render();
                m_fxJacobian.EndPass();
                m_fxJacobian.End();

                BRenderDevice.getDevice().EndScene();
            }

            m_bNeedUpdate = true;

            BRenderDevice.getDevice().DepthStencilSurface = savedDepthSten;
            savedDepthSten.Dispose();
            savedDepthSten = null;

            BRenderDevice.getDevice().SetRenderTarget(1, null);
            BRenderDevice.getDevice().SetTexture(0, null);
            locktarget.destroy();
            locktarget = null;

            //   BRenderDevice.writeTextureToFile(mJacobianMap, AppDomain.CurrentDomain.BaseDirectory + "screens\\localFrames.bmp");
            //   BRenderDevice.writeTextureToFile(mJacobianMapInverse, AppDomain.CurrentDomain.BaseDirectory + "screens\\localFramesINV.bmp");
        }
Beispiel #2
0
        public void clearPaintLayer()
        {
            // save render target
            D3DProtectRenderTarget locktarget = new D3DProtectRenderTarget(true);

            // set new render target
            BRenderDevice.getDevice().SetRenderTarget(0, m_d3dPaintLayerSrf);
            savedDepthSten = BRenderDevice.getDevice().DepthStencilSurface;
            BRenderDevice.getDevice().DepthStencilSurface = m_DepthStencilSurface;

            // render
            BRenderDevice.getDevice().BeginScene();
            if (mJMapPattern == eJMapPattern.cPaint)
            {
                BRenderDevice.getDevice().Clear(ClearFlags.Target, unchecked ((int)0x0080FF00), 1.0f, 0);
            }
            else
            {
                BRenderDevice.getDevice().Clear(ClearFlags.Target, unchecked ((int)0x80808080), 1.0f, 0);
            }
            BRenderDevice.getDevice().EndScene();

            BRenderDevice.getDevice().SetTexture(0, null);

            // CLM uncomment this for advection
            //if (mJMapPattern == eJMapPattern.cVfieldPaint)
            // {
            //if (m_VectorFieldPyramid == null)
            //{
            //   m_VectorFieldPyramid = new D3DGenMipMapPyramid(AppDomain.CurrentDomain.BaseDirectory + "shaders\\vfield.pyramid.fx", m_d3dPaintLayer);
            //}
            //if (m_VectorFieldPyramid.compatible(m_d3dPaintLayer))
            //{
            //  m_VectorFieldPyramid.bind(m_d3dPaintLayer);
            //}
            //else
            //{
            //  m_VectorFieldPyramid.destroy();
            //  m_VectorFieldPyramid = null;
            //  m_VectorFieldPyramid = new D3DGenMipMapPyramid(AppDomain.CurrentDomain.BaseDirectory + "shaders\\vfield.pyramid.fx", m_d3dPaintLayer);
            //}
            //}

            if (mJMapPattern == eJMapPattern.cPaint)
            {
                m_bNeedUpdateJacobianMap = true;
            }

            BRenderDevice.getDevice().DepthStencilSurface = savedDepthSten;
            savedDepthSten.Dispose();
            savedDepthSten = null;


            // restore render target
            locktarget.destroy();
            locktarget = null;
        }
Beispiel #3
0
        void renderJacobianMapFromPaint()
        {
            if (m_fxJacobian == null)// || mSynthesiser == null)
            {
                return;
            }

            // save render target
            D3DProtectRenderTarget locktarget = new D3DProtectRenderTarget(true);

            // set new render target
            BRenderDevice.getDevice().SetRenderTarget(0, mJacobianMapSrf);
            BRenderDevice.getDevice().SetRenderTarget(1, mJacobianMapInverseSrf);

            savedDepthSten = BRenderDevice.getDevice().DepthStencilSurface;
            BRenderDevice.getDevice().DepthStencilSurface = m_DepthStencilSurface;


            // render
            BRenderDevice.getDevice().BeginScene();

            BRenderDevice.getDevice().Clear(ClearFlags.Target, Color.Black, 1, 0);


            m_fxJacobian.Technique = m_fxGeomPaintJMapTech;
            m_fxJacobian.SetValue(m_fxGeomGlobalScale, mExemplar.mSynthParams.TextureScale);
            m_fxJacobian.SetValue(m_fxGeomPaintedJMap, m_d3dPaintLayer);
            m_fxJacobian.SetValue(m_fxGeomExemplarMainDirection, m_fExemplarMainDirection);

            m_fxJacobian.CommitChanges();
            m_fxJacobian.Begin(FX.DoNotSaveState | FX.DoNotSaveShaderState | FX.DoNotSaveSamplerState);
            m_fxJacobian.BeginPass(0);
            m_QuadDual.render();
            m_fxJacobian.EndPass();
            m_fxJacobian.End();

            BRenderDevice.getDevice().EndScene();


            m_bNeedUpdate = true;

            BRenderDevice.getDevice().DepthStencilSurface = savedDepthSten;
            savedDepthSten.Dispose();
            savedDepthSten = null;

            BRenderDevice.getDevice().SetRenderTarget(1, null);
            BRenderDevice.getDevice().SetTexture(0, null);

            locktarget.destroy();
            locktarget = null;
        }
Beispiel #4
0
        void refresh()
        {
            for (int l = 1; l < numLevels(); l++)
            {
                D3DProtectRenderTarget protect = new D3DProtectRenderTarget(true);
                Surface srf = pyramidLevel(l).GetSurfaceLevel(0);
                BRenderDevice.getDevice().SetRenderTarget(0, srf);
                m_fxParentFromChildren.mShader.SetValue(m_fxChildrenTexture, pyramidLevel(l - 1));

                SurfaceDescription desc = pyramidLevel(l).GetLevelDescription(0);

                m_fxParentFromChildren.renderFull(desc.Width, desc.Height);

                protect.destroy();
                protect = null;
                srf     = null;
            }
        }
Beispiel #5
0
        public void paintAt(int mx, int my)
        {
            // save render target
            D3DProtectRenderTarget locktarget = new D3DProtectRenderTarget(true);

            float dx = (float)(mx - m_iAnchorX);
            float dy = (float)(my - m_iAnchorY);
            float l  = (float)Math.Sqrt(dx * dx + dy * dy);

            if (l < 0.01)
            {
                return;
            }
            dx /= l;      dy /= l;
            dx  = dx * 127.0f + 128.0f; dy = dy * 127.0f + 128.0f;
            int r = 0, g = 0, b = 0, a = 0;

            if (mJMapPattern == eJMapPattern.cPaint)
            {
                if (mPaintOrientation && mPaintScale)
                {
                    r = (int)(dx);
                    g = (int)(dy);
                    b = (int)(Math.Max(0.0f, Math.Min(255.0f, 255.0f * (1.0f - m_fInnerRadius))));
                }
                else if (mPaintOrientation)
                {
                    r = (int)(dx);
                    g = (int)(dy);
                    b = 0;
                }
                else if (mPaintScale)
                {
                    r = 0x80;
                    g = 0xFF;
                    b = (int)(Math.Max(0.0f, Math.Min(255.0f, 255.0f * (1.0f - m_fInnerRadius))));
                }
            }

            a = 0xff;

            Matrix mat, mattrl, matscl;
            float  tx = mx / (float)(m_iSynthWidth);  // (m_dwCreationWidth);
            float  ty = my / (float)(m_iSynthHeight); // (m_dwCreationHeight);


            mattrl = Matrix.Translation(tx - m_fInnerRadius / 2.0f,
                                        ty - m_fInnerRadius / 2.0f,
                                        0.0f);
            matscl = Matrix.Scaling(m_fInnerRadius,
                                    m_fInnerRadius,
                                    0.0f);
            mat = Matrix.Multiply(matscl, mattrl);



            BRenderDevice.getDevice().SetTransform(TransformType.View, mat);
            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true);
            BRenderDevice.getDevice().SetRenderState(RenderStates.BlendOperation, (int)BlendOperation.Add);
            BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
            BRenderDevice.getDevice().SetTexture(0, m_d3dSplat.mTexture);

            BRenderDevice.getDevice().SetRenderState(RenderStates.TextureFactor, (a << 24) + (r << 16) + (g << 8) + b);
            BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.TFactor);

            // set new render target
            BRenderDevice.getDevice().SetRenderTarget(0, m_d3dPaintLayerSrf);

            // render
            BRenderDevice.getDevice().BeginScene();
            m_Quad.render();
            BRenderDevice.getDevice().EndScene();

            // restore state
            BRenderDevice.getDevice().SetTransform(TransformType.View, Matrix.Identity);

            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false);
            BRenderDevice.getDevice().SetRenderState(RenderStates.BlendOperation, (int)BlendOperation.Add);

            BRenderDevice.getDevice().SetRenderState(RenderStates.TextureFactor, 0xFFFFFFFF);
            BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.Current);


            // restore render target
            locktarget.destroy();
            locktarget = null;
        }