Apply pixel shader to video using DirectX

I need to apply a pixel shader to this code (full screen quad). I have an FX file. What is the procedure? (EDIT completed: code works)

public int CompositeImage(IntPtr pD3DDevice, IntPtr pddsRenderTarget, AMMediaType pmtRenderTarget, long rtStart, long rtEnd, int dwClrBkGnd, VMR9VideoStreamInfo[] pVideoStreamInfo, int cStreams)
        {
            try
            {
                if (udevice != pD3DDevice)
                {
                    InitCompositionDevice(pD3DDevice);
                }

                // will be creating managed object from those so increment ref count
                Marshal.AddRef(pddsRenderTarget);
                Marshal.AddRef(pVideoStreamInfo[0].pddsVideoSurface);

                device.Clear(ClearFlags.Target, Color.Red, 1f, 0);
                device.BeginScene();

                // here the video frame will be stored
                Texture capturedVideoTexture = null;

                // this is the output surface
                Surface renderTarget = new Surface(pddsRenderTarget);

                // get the surface for the input video
                Surface videoSurface = new Surface(pVideoStreamInfo[0].pddsVideoSurface);

                // will use this rect for calculations
                Rectangle videoSurfaceRect = new Rectangle(0, 0, videoSurface.Description.Width, videoSurface.Description.Height);

                // create single layer texture from input video
                capturedVideoTexture = new Texture(device, videoSurfaceRect.Width, videoSurfaceRect.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

                // get its surface
                Surface textureSurface = capturedVideoTexture.GetSurfaceLevel(0);

                // will use this rect for calculations
                Rectangle textureSurfaceRect = new Rectangle(0, 0, textureSurface.Description.Width, textureSurface.Description.Height);

                // copy the whole video surface into the texture surface
                device.StretchRectangle(videoSurface, videoSurfaceRect, textureSurface, textureSurfaceRect, TextureFilter.Linear);

                // identity matreices for world projection and view
                device.Transform.World = Matrix.Identity;
                device.Transform.Projection = Matrix.Identity;
                device.Transform.View = Matrix.Identity;

                // setup viewport
                Viewport view = new Viewport();
                view.X = 0;
                view.Y = 0;
                view.Width = 1920;
                view.Height = 1080;
                view.MinZ = 0;
                view.MaxZ = 1;
                device.Viewport = view;

                // writing will go to output surface
                device.SetRenderTarget(0, renderTarget);

                // nothing fancy of a vertex shader
                device.VertexFormat = CustomVertex.PositionTextured.Format;

                // use the texture while rendering
                device.SetTexture(0, capturedVideoTexture);

                //Bind our Vertex Buffer
                device.SetStreamSource(0, vb, 0);

                // setup and apply shader
                ps.Begin(FX.None);
                ps.BeginPass(0);
                ps.SetValue("ScreenTexture", capturedVideoTexture);

                //Render from our Vertex Buffer
                device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

                ps.EndPass();
                ps.End();

                device.EndScene();

                videoSurface.Dispose();
                textureSurface.Dispose();
                capturedVideoTexture.Dispose();
                renderTarget.Dispose();

                videoSurface = null;
                renderTarget = null;
                capturedVideoTexture = null;

            }

            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            return 0;

        }

This is the final effect: Sepia on VMR9 video:

http://img825.imageshack.us/img825/9207/sepiag.png

Now anaglyph shaders code for 3D content remains :)

+3
source share
1 answer

Create your texture from the video frame, then LockRect and copy the data. You now have the data in the D3D9 texture.

Loading a pixel shader is very simple. Use D3DXCreateEffectFromFile .

The rendering of ATVs with a texture on it can be easily found by looking at any textbook on the Internet. Try the following:

http://www.drunkenhyena.com/cgi-bin/view_cpp_article.pl?chapter=2;article=30

, .

: , , . .

-, . , , , - . , "" -1 1 ( ).

:

ver[0] = new CustomVertex.PositionTextured(-1, 1, 0, 0, 0);
ver[1] = new CustomVertex.PositionTextured(1, 1, 0, 1, 0);
ver[2] = new CustomVertex.PositionTextured(-1, -1, 0, 0, 1);
ver[3] = new CustomVertex.PositionTextured(1, 1, 0, 1, 0);
ver[4] = new CustomVertex.PositionTextured(1, -1, 0, 1, 1);
ver[5] = new CustomVertex.PositionTextured(-1, -1, 0, 0, 1);

( ++ Viewport, #):

D3DVIEWPORT9 vp;
vp.X = 0;
vp.Y = 0;
vp.Width = 1920;
vp.Height = 1080;
vp.MinZ   = 0.0f;
vp.MaxZ   = 1.0f;
pDevice->SetViewport( &vp );

.

Btw Im , SetTextureStageState... " Arg1". D3DTA_TEXTURE COLOR ARG 1?

+2

All Articles