Skip to main content
GameDev.net gamedev.net
🔒 Locked

ChangeRenderTarget

Started by nes8bit Mar 26, 2000 at 8:54 PM 4 replies 450+ views
Original Post
nes8bit
nes8bit
how can I use ChangeRenderTarget to render a mirror. I understand the concept of multiple passes, but the only thing I could find about ChangeRenderTarget is in the DX7SDK and nvidia''s page. Are there any tutorials that I could have missed?
Esap1
Esap1
If you were using a portal engine, you could easily make a mirror
Lars W.
Lars W.
Hi

There are two ways, from which i know, without a Portal Engine.
The first one is to Render the Scene from the Position of the Mirror, and Render that Image to an Texture, which you have to Apply to the Mirror Object (A very Slow Method i think).
The other way is to use the Stencil Buffer. Render Your Scene completely, then render the Mirror to the to Stencil Buffer ( You can render it to the Framebuffer too if you wan''t partial reflection ). Then Mirror all Objects in your Scene, and render only where the Stencil Bits are set.
If you wan''t partial reflection, you have to render to a different Target, and Blend Both Images together.

hope that helps
Lars
nes8bit
nes8bit
I think I have a portal engine or at least a type of portal engine. My main question was about ChangeRenderTarget(D3D). I already know about the pseudo style of rendering mirrors. I want something more in depth.
Lars W.
Lars W.
Ok

You wan''t something Specific :
I think you have everything Setup in Direct3D

LPDIRECTDRAWSURFACE7 aDirectDrawSurface;

DDSURFACEDESC2 ddsd;
ddsd.dwSize=sizeof(ddsd);
ddsd.dwFlags=DDSD_CAPS/DDSD_WIDTH/DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps=DDSCAPS_3DDEVICE / DDSCAPS_OFFSCREENPLAIN;// NO TEXTURE !!!
...

Create the Surface...

Very IMPORTANT
If your main Rendertarget uses an ZBuffer, you have to attach one to the aDirectDrawsurface
too, or the Rendering to the new Target will fail.

D3DDevice->SetRenderTarget(aDirectDrawSurface,0);

D3DVIEPORT7 vp;
vp.dwX=0;
vp.dwY=0;
vp.dwWidth=256; // if you wan''t to render a 256x256 Texture
vp.dwHeight=256;

D3DDevice->SetViewport(&vp);

Now you can render from the View of your Mirror looking into the Direction,
a Ray would be reflected, when it comes from the normal camera and hits the Mirror.

yourTextureSurface->Blt(NULL,aDirectDrawSurface,NULL,DDBLT_WAIT,NULL);

D3DDevice->SetRenderTarget(NormalRenderSurface,0);
vp.dwWidth=x-resolution; // your normal Resolution
vp.dwHeight=y-resolution;

D3DDevice->SetViewport(&vp);

No Start rendering your normal Stuff, and aply yourTextureSurface to the MirrorSurface.
Also you should do Errorchecking on all the functions, and look if i did nothing wrong or
forget something important (maybe some others could look trough it too).
I hope that is in depth enough, for Mirrors with ChangeRenderTarget

Lars
nes8bit
nes8bit
Cool, just what I wanted. I''ll try to implement it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.