Jump to content
  • Advertisement
Sign in to follow this  
w17chm4n

[D3D9] Multiple Render Targets - again

This topic is 3428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all I`d like to say Hi - I`m new here ;) Well here`s my problem - I`m developing an GPU ray tracer and I need to produce two textures out of my PS shader. I`ve googled for some examples, showing how to use MRTs in managed D3D9 and I came out with this (one RT for now, just for testing): //-------------------------------------------------// struct pixel { float4 color : COLOR0; }; pixel create_primary_rays(pixelshader_input IN) { pixel OUT = (pixel)0; Ray r; r.origin = float3(0,0,5); r.direction = raydir(IN.screenCoord.xy); OUT.color = float4(r.direction.xyz, 1); return OUT; } //-------------------------------------------------// RenderTexture = new Texture(device, RenderSurfaceSize, RenderSurfaceSize, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); RenderSurface = RenderTexture.GetSurfaceLevel(0); //-------------------------------------------------// private void renderToGBuffer() { device.BeginScene(); using (Surface oldBuffer = device.GetBackBuffer(0,0,BackBufferType.Mono)) { device.SetRenderTarget(0, RenderSurface); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0); rayGeneratorKernel.addParameter("rayDirMatrix", camera.rayDirMatrix); rayGeneratorKernel.execute("primaryrays"); device.SetRenderTarget(0, oldBuffer); } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0); texturingKernel.addParameter("myTexture", RenderTexture); texturingKernel.execute("texturing"); using (Sprite spriteobject = new Sprite(device)) { spriteobject.Begin(SpriteFlags.DoNotSaveState); spriteobject.Transform = Matrix.Scaling(0.4f, 0.4f, 0.4f); spriteobject.Draw(RenderTexture, new Rectangle(0, 0, RenderSurfaceSize, RenderSurfaceSize), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.White); spriteobject.End(); } device.EndScene(); device.Present(); this.Invalidate(); } //-------------------------------------------------// But it generates black screen (and black sprite). The code works fine when I use RenderToSurface class, though I cannot achieve MRTs with it (or am I wrong ?) //-------------------------------------------------// protected override void OnPaint(PaintEventArgs e) { RtsHelper.BeginScene(RenderSurface); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0); rayGeneratorKernel.addParameter("rayDirMatrix", camera.rayDirMatrix); rayGeneratorKernel.execute("primaryrays"); RtsHelper.EndScene(Filter.None); device.BeginScene(); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0); texturingKernel.addParameter("myTexture", RenderTexture); texturingKernel.execute("texturing"); using (Sprite spriteobject = new Sprite(device)) { spriteobject.Begin(SpriteFlags.DoNotSaveState); spriteobject.Transform = Matrix.Scaling(0.4f, 0.4f, 0.4f); spriteobject.Draw(RenderTexture, new Rectangle(0, 0, RenderSurfaceSize, RenderSurfaceSize), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.White); spriteobject.End(); } UpdateFramerate(); device.EndScene(); device.Present(); this.Invalidate(); } //-------------------------------------------------// So, what am I doing wrong? Why doesn`t MRT work ??

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!