Projected Texture Shadows a fatal flaw :(

Started by
3 comments, last by gcard28 16 years, 10 months ago
I have projected shadows running in my engine.... but they are dog slow..... Here is what I do, each item that is shadowed has it's own render target texture, so I switch from one render target to the next to draw the shadows for each character that is visible. This is KILLING and I mean KILLING my framerate. I was thinking that well have one render target texture that all the shadowed entities render to. Each entity renders to a section of this large render target. Now here comes my question. I am using DirectX9 and I have absolutely no idea how to do this. Is it even possible? Say I have a 512x512 texture and each shadowed entry uses 128x128 textures. That means I can have 16 entities stored in this one render texture.... The thing is how do I render into a subsection of this large texture? I would GREATLY appreciate any help anyone can give me. Perhaps some simple sample code or pointers to information or even if it is even possible. Many thanks to anyone kind enough to give some assistance
Advertisement
You propably want to use IDirect3DDevice9::SetViewport(). Have a look into the DX documentation to see how to use it.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
You shouldn't think of it as how many objects you can fit into a shadow texture, but rather how big of an AREA you can fit into the shadow texture. It shouldn't matter what objects are there. Simply set up the viewport to grab a given area around the camera and render those objects into the shadow texture. Any that lie outside of that can either not be shadowed, or you can look into Perspective Shadow Maps, Cascading Shadow Maps, Light Space Shadow Maps, etc..
Author Freeworld3Dhttp://www.freeworld3d.org
But from what I gather he's not using shadow maps, but projected shadow textures, which are somewhat different. As in Halflife2, each oject casts an independent shadow. While the efficiency of a method like this is questionable, the OP wants to know how to pack multiple renders onto a single surface.

This is a useful method for other things as well like imposters. Here is some sample code from my tree imposter code that does this..its renders 256 128*128 views of trees into a a 1024*4096 surface:

nFrame=i+(treetype*8);	viewport_imp.X = DWORD( (nFrame % 8 ) * 128 );viewport_imp.Y = DWORD( (nFrame / 16 ) *128 );viewport_imp.Width = 128;viewport_imp.Height = 128;viewport_imp.MinZ = 0.0f;viewport_imp.MaxZ = 1.0f;//set viewportpd3ddev->SetViewport(&viewport_imp);
Hi yes,

Thank you for everyones help. I wasn't aware you could resize the viewport to anything other than the full dimensions of the render target.

I know there are better ways of doing shadows than projected textures, but this is the method I started with and it is not possible for me to start from scratch for shadows.

But thanks for the suggestion of setting the viewport.

Many thanks to everyone

This topic is closed to new replies.

Advertisement