Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: 1 [2] 3 4
  Print  
Author Topic: Hurtle: the ballistic RTS (physics RTS game)  (Read 63279 times)
nicolas
Community Member
*
Posts: 172


« Reply #20 on: March 03, 2010, 07:46:41 AM »

OK, shadows...

I've given it a try but it doesn't work 100% as it should. Two problems:

1) my terrain (which is a TVMesh, not a TVLandscape!) has its grass texture tiled 40*40 over its surface. Obviously, I'd want the shadow (lightmap) texture to be 1*1. I can't find how to set the UV coordinates for that texture.

2) I've made a new camera and a rendersurface. I've set the new camera to isometric. However, I think my render isn't isometric. Trees far to the side are drawn more sideways, trees close to the centre more from the top. I think I'm doing something wrong with assigning the camera to the scene for the main render and the other camera to the rendersurface for the shadows.

Here's the code.

Generate both camera's:

Code:
'   Create the camera.
    Set Camera = New TVCamera
    Set Camera = Scene.GetCamera
    Camera.SetViewFrustum 45, 700, 0.1
    Randomize
    Camera.SetPosition 150 * (Rnd - 0.5), 30, 150 * (Rnd - 0.5)
    Camera.SetRotation 45, -45, 0
   
'   Create the shadows rendering camera and rendersurface.
    Set TVRenderSurface = New TVRenderSurface
    Set TVRenderSurface = Scene.CreateRenderSurface(1024, 1024, False)
    Set ShadowCam = New TVCamera
    Set ShadowCam = TVRenderSurface.GetCamera
    TVRenderSurface.SetBackgroundColor TVGlobals.RGBA(1, 1, 1, 1)
    ShadowCam.SetViewIsometric 1, 1000, 1
    ShadowCam.SetCustomAspectRatio 380.94 / 386.56
    ShadowCam.SetViewFrustum 90, 1000, 1
    ShadowCam.SetPosition 0, 380.94, 0
    ShadowCam.SetRotation 90, 0, 0

There is no other code apart from this to assign cameras. I have a gut feeling there should be some though... Smiley

Render shadows and apply texture to terrain mesh:
Code:
'   Render the shadows
    TVRenderSurface.StartRender False
    For i = 1 To 1000
        mTree(i).Render
    Next i
    TVRenderSurface.EndRender
    mTerrain.SetTextureEx 1, TVRenderSurface.GetTexture
Logged
nicolas
Community Member
*
Posts: 172


« Reply #21 on: March 03, 2010, 08:17:39 AM »

OK, I think I solved one of the problems:

-calling setviewfrustum after setviewisometric kills isometric...  Embarrassed

Now I've got a perfect shadows texture. What I've done (because my trees are hardly visible from straight above due to their semi-billboard geometry) is render the minimesh shadows as I have them now onto the rendersurface. That means I don't have to render the minimesh shadows every render cycle anymore, and need to update their position only whenever updating the shadows rendersurface.

The tiling problem remains.
« Last Edit: March 03, 2010, 08:31:00 AM by nicolas » Logged
asia
Customers
Community Member
*****
Posts: 183


« Reply #22 on: March 03, 2010, 08:38:37 AM »

TVMeshes have (atleast?) two set of UV coordinate. One is used for the diffuse texture the other set for the other possible textures (Normalmap, Lightmap and son on).
They call it "stages". I do not know if you can have more than two UV sets. But for your case two is enough.
If you have a tvmesh play with the TV Modelview using a dummy texure as a placeolder of your "future" shadowmap (lightmap). Look under the model properties (bottom left of the ModelView window).
Ciao

PS
TIPS:
It is not compulsory to use the same mehes for the shadows.
Have a look to the tutorial:
http://wiki.truevision3d.com/tutorialsarticlesandexamples/create_simple_projected_actor_shadows
« Last Edit: March 03, 2010, 08:45:58 AM by asia » Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
Aki
Customers
Community Member
*****
Posts: 84


« Reply #23 on: March 03, 2010, 08:45:58 AM »

What asia said. Also, there should be a landscape command involving expanding the texture across the terrain, which should do it for you. There's a lot of information about TVLandscape on the wiki/forums.

Also, if you get any depth problems with your shadow rendering stage (IE - shadow overlap) make sure you are using alpha blending, alpha testing (0<), and setting the Y coordinate to something unique per shadow (or random).
Logged

nicolas
Community Member
*
Posts: 172


« Reply #24 on: March 03, 2010, 10:00:55 AM »

Aki, I'm not using a TVLandscape.

I'll try the suggestions. Thanks for the input!
Logged
nicolas
Community Member
*
Posts: 172


« Reply #25 on: March 03, 2010, 10:24:23 AM »

Haven't found yet how to access the second UV coordinates of a tvmesh through code, but there's a more important thing to note.

This approach resulted in a 5FPS decrease compared to just rendering the minimeshes every cycle on the scene like I did before.

My method is to have a VB timer that renders the shadow minimeshes isometrically onto the rendersurface every 10 seconds and use that result as lightmap for the terrain TVM. The shadow minimeshes aren't rendered in the main loop.

Why would this cause the FPS to drop?
-The mere fact that a VB timer is running?
-The rendersurface itself, even though it is only called once every 10 seconds?
-the fact that my 1000 shadows minimeshes have no alpha culling anymore, even though they are only rendered once every 10 seconds?
-maybe something wrong with my camera assigning, causing some double render weardness or something?

Strange...
Logged
nicolas
Community Member
*
Posts: 172


« Reply #26 on: March 03, 2010, 10:37:37 AM »

Maybe I should also consider shifting to TVLandscape for the terrain. It has some nice options such as getheight. And splatting and easy texture stretching...
Logged
Shadowsong
Customers
Community Member
*****
Posts: 328


« Reply #27 on: March 03, 2010, 10:42:47 AM »

Just simply NEVER use a VB timer!!

You should do any kind of timing with your main loop.
Have a counter-variable which gets increased every frame and gets compared to your event time.

This is always the safe way to go since you can control when the timer is inreased or the event is fired. Using a VB timer makes it asynchronous from your main loop which causes trouble guaranteed.
Logged
nicolas
Community Member
*
Posts: 172


« Reply #28 on: March 03, 2010, 11:16:29 AM »

OK, I'll change that. But would it also explain the large drop in FPS?
Logged
asia
Customers
Community Member
*****
Posts: 183


« Reply #29 on: March 03, 2010, 12:59:36 PM »

We can not help if you do not show your render loop and maybe your debug file...  Roll Eyes
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
nicolas
Community Member
*
Posts: 172


« Reply #30 on: March 03, 2010, 02:45:03 PM »

I'll let it rest for tonight. I decided I won't go down the TVLandscape route (takes too many changes throughout my code), so it'll have to be done with a TVMesh. Shouldn't be that difficult, the only thing left to tackle there is setting UV coordinates for its lightmap.

So the problem now is why the rendersurface method causes the FPS to drop rather than increase. I'll try it again  tomorrow and post the relevant code.

Thanks for the help everyone. These shadows and some optimising on the trees are the last things TV3D related that need to be done before I can start with the main program logic. I won't be needing much TV3D after that, except for maybe some code in the moving/pathfinding section. But that's for (much later).
Logged
nicolas
Community Member
*
Posts: 172


« Reply #31 on: March 03, 2010, 05:29:10 PM »

couldn't control myself... Grin

Anyway, shadowing principle works now! Seems to give about 5 FPS improvement.

But it's not finished yet: I still need to find how to set the lightmap UV's of a tvmesh...
Logged
nicolas
Community Member
*
Posts: 172


« Reply #32 on: March 04, 2010, 05:43:10 AM »

I switched to TVLandscape anyway. I think it can give me some nice functions for the future.

For current functions, I don't use getheight but do a collision ray when placing objects. Works fine. But anyway, shadows.

I've got the same problem at the moment: I set the grass texture using settexture and settexturescale. If I then set the lightmap using settextureex, it is tiled like the grass...
Logged
Aki
Customers
Community Member
*****
Posts: 84


« Reply #33 on: March 04, 2010, 06:52:38 AM »

I believe you're looking for the ExpandTexture command. Or ExpandSplattingTexture. The function params are pretty self explanatory, other than the stage - that's the texture number you pick when you use SetTextureEx.
Logged

asia
Customers
Community Member
*****
Posts: 183


« Reply #34 on: March 04, 2010, 07:20:12 AM »

I think the lightmap should be made on a chunk base with
land.SetCustomLightmap textureID,chunkID
This could be a problem at the begining but if you think better you can place your shadow camera on top of each chunk and produce a render surface for each chunk.
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
nicolas
Community Member
*
Posts: 172


« Reply #35 on: March 04, 2010, 10:19:46 AM »

hmmmm I think I should simply drop this method. It only works well if you can really make a shader from it, get directly into the TV pipeline.

At the moment, the situation is that updating shadow minimeshes every cycle is 5 FPS faster than updating a rendersurface every second...

The only disadvantage of the minimesh method is some artifacts: when close to a steep terrain slope, the shadow disappears where it goes through the slope. This is because the shadow is a 3D object, not a texture, so it doesn't follow changes in the slope of the terrain.
Logged
Aki
Customers
Community Member
*****
Posts: 84


« Reply #36 on: March 04, 2010, 02:47:38 PM »

If rendering minimeshes every second is slower than a rendersurface, you have a dangerous shortage of VRAM or are doing something incorrectly. Try changing the rendersurface to 128x128 and R5G6R5. Is it faster now?

If not, you're doing something wrong. I use a method very similar to this which updates every frame rather than per second and it barely slows me down.

You're right though, using a shader would definitely ease things.

To prevent some shadow artifacts, maybe try getting landscape height for all 4 corners of the shadow plane rather than the center, and adjusting the vertices accordingly. Or better yet, subdivide the plane and check the height at each position.
Logged

nicolas
Community Member
*
Posts: 172


« Reply #37 on: March 05, 2010, 04:00:36 AM »

VRAM? This laptop is the kind that used disc space as video memory (and my disc is full...).  Lips sealed

Anyway, the shadows using the first method are very fast (they have alpha culling, so only a few are rendered) and very pretty. At 128*128, they'd get very blurry.

I'll leave it like this and continue with the rest of the program.

The thing now runs at 30+FPS on a terrible laptop (1.66GHz Core2 Dell D820 with 2GB RAM and no video card worth mentioning...) so it's OK. Smiley

Quote
To prevent some shadow artifacts, maybe try getting landscape height for all 4 corners of the shadow plane rather than the center, and adjusting the vertices accordingly. Or better yet, subdivide the plane and check the height at each position.
Sound good, but would require some extra work and calculations per cycle. I'll save it for later, if I feel the need for a final touch. Wink

This method still wouldn't solve all artifacts though: at peaks in the terrain, it still might pierce through the shadow. Piercing through slopes would be solved though. So I'll leave it as is for now. The game now looks quite fine indeed, if I may so myself. Smiley
« Last Edit: March 05, 2010, 05:16:48 AM by nicolas » Logged
Aki
Customers
Community Member
*****
Posts: 84


« Reply #38 on: March 05, 2010, 03:50:28 PM »

Great. Remember, all these calculations don't need to be performed every second, and the GetHeight check is MUCH faster than a raycast - so if you aren't using it already, make sure you do now.

Also, the idea of the 128x128 was just to test if the memory consumed by the render surface was slowing you down. Obviously you'd have to tweak it after testing. But if you've found a technique that works - stick with that!
Logged

nicolas
Community Member
*
Posts: 172


« Reply #39 on: March 08, 2010, 06:52:22 AM »

I'm using the raycasts at init, which hence doesn't really matter. I'm changing the rest to GetHeight tonight. Most of it is already changed, only the camera terrain following code not yet. Shouldn't be any problem.
Logged
Pages: 1 [2] 3 4
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks