Game Development Community

Black lines at brush borders

by Ryan Mounts · in Constructor · 02/20/2008 (8:52 am) · 30 replies

Does anyone know what causes the black lines between touching brushes? They vanish as you get closer to them. The red arrows just point out a few of about a dozen examples visible in this image alone. Unfortunately these black lines destroy the illusion that a flat wall is one solid piece of geometry.

www.geocities.com/rmounts79/DIF_lines.jpg
Page «Previous 1 2
#1
02/21/2008 (12:36 pm)
That looks like lightmaps. They probably have mipmaps being created automatically for them - this would cause this error.
#2
02/22/2008 (9:27 am)
Hmmm... I use "SetInteriorRenderMode(11)" to make the DIF "self-illuminated", so even though the lightmaps are generated, they shouldn't be blended with the textures at render time... I think. All the lighting is baked into the textures.
#3
02/22/2008 (10:59 am)
Lighting is not baked into the textures; BUT generated into a lightmap texture of its own.

Check your texture set, and be sure you are not useing PNG with an alpha channel. Also (most unlikely) be sure your textures are true ^2 X/Y, I have seen 255x255 textures work correctly, with odd borders that are fixed with changing to 256x256.
#4
02/22/2008 (11:11 am)
Sorry, I guess I wasn't very clear... I baked the lighting into my DIF textures in 3dsmax (notice the color bleeding under the eaves from the grass) and intentionally disabled lightmaps with "SetInteriorRenderMode(11)" which just renders the DIF with no shading whatsoever as a kind of fast and dirty self-illumination. Since the lighting is in my textures, I don't need lightmaps. With that said, I don't think the lightmaps are causing the black lines, unless there is something about SetInteriorRenderMode() that I don't know about.
#5
02/22/2008 (2:42 pm)
Looking at the code, SetInteriorRenderMode(11) renders base textures + "null surfaces". I think you just want SetInteriorRenderMode(6).
Anyway, Most likely your textures have black on the edges. Then when the mipmap is created, it averages in the black border when it creates the smaller image. Try disabling mipmaps, and I bet it goes away.
#6
02/22/2008 (6:36 pm)
Ah, I see. I was wondering how you got such sharp shadow lines. SO im guessing your textures are JPG? As Jaimi mentioned it could be mipmaps but some odd things could happen running without mips'.

Are the 'lines' located at brush edges? Are the textures scaled in any odd way?
#7
02/25/2008 (7:16 am)
@ Jaimi

Thanks for the good info. Yeah, I agree that mipmapping is the culprit. It's actually pretty obvious now that I think about it... you can see how the lines get worse the further they are from the camera. In my texture (shown below), each polygon is surrounded by black. When rendering to texture, each poly is padded by 2 pixels by default, but apparently this is not enough. I'll try padding more. Maybe trilinear filtering would help too. Is there a simple way to completely disable mipmaps without modifying the code (for testing purposes)? I used "setOpenGLInteriorMipReduction(5)" to lock in mip level 5 at close viewing distances, and it was clear that the black was being averaged into the edges.

www.geocities.com/rmounts79/duplex_texture.jpg
@ Caylo

They're actually PNG. The whole building is covered by about nine 1024x1024 png's with V-Ray global illumination baked in using "Render to Texture".
#8
02/26/2008 (11:41 pm)
How about useing a SELECT COLOR function from a paint program, and adding a BLUR to the black? It should smear the 'texture' part edges into the black space.
#9
02/27/2008 (6:31 am)
3dsmax goes a step further than that... it pads the texture out (copies the edge pixels) a variable number of pixels into the black around each polygon's UV coordinates. The pic above has a padding of 2 pixels. So about mip level 2, you'll start seeing the black leak in. I bumped up the padding to 6, and the black lines don't start to appear until you're a reasonable distance away, and it's not very noticeable. But adding more padding means losing texture space for real texture information, so there's a big trade-off.

Really the only reason for mapping things this way was to get the global illumination into Torque. I'm looking into the lightmap generation code (and making very slow progress), to hopefully learn how to simply render out a lightmap in 3dsmax and still map regular textures the usual way. Any thoughts on this task would be appreciated!!! :)
#10
03/11/2008 (12:07 pm)
Okay, I fixed it! :) This is a much better solution... instead of baking all the lighting and texture info into one or more very large textures, like above, i modified map2dif_plus to give me the ability to "bake" my advanced lighting into the DIF lightmap. Now I can texture my DIF in the normal manner with smaller, tileable textures, thus avoiding the black lines above caused by mipmapping. Here's a test scene...

www.geocities.com/rmounts79/Baked.jpg
Lightmap

www.geocities.com/rmounts79/BakedLM.jpg
#11
03/11/2008 (2:01 pm)
Nice.. very nice.. very nice in deed..
#12
03/17/2008 (12:06 pm)
Very interesting Ryan!

I have been trying to get 'better ligtning' into the engine by baking textures in 3DS Max myself. The difference from your approach is that I used *.dts's using the polysoup resource instead of *.dif's. I encountered the same problem you did, having too large textures in the end (trying to keep the resolution as high as possible).

Since I'm no programmer I couldn't figure out how to add support for an extra UV-channel in the *.dts exporter/format (channel 1 - tile:able textures, channel 2 - low res lightmap) so I ended up scrapping this approach.

I understand if you don't just want to 'give away' your new map2dif_plus...but can you point me in the right direction of getting to use the 3DS Max generated lightmap into the *.dif?

Question;

Do you model in 3DS Max - thus getting the UV coords from there...?! (I have seen some plugs to 3DS Max that can export to *.map with the UV coords intact...but I guess this is just ONE channel?!)
#13
03/17/2008 (1:14 pm)
Tobias,

I have absolutely no problem sharing my modified map2dif_plus. I'm always glad if my personal little side projects can be of some help to the community. This tool sounds like what you need, but right now it would not be of much use to you. Here's why... the advanced lighting gets baked into the DIF lightmap, but when placed in-game and you relight the scene, the Torque sun gets added to the baked lightmap. This isn't what we want. To get the image above, I just didn't relight the scene after adding my DIF, but this is not very practical. :) So one of my next projects is to modify the engine slightly to allow you to selectively disable the sun for certain interiors. Upfront I don't think this should be very hard, but programming is really just a hobby, so easy things take a while for me sometimes. But since there seems to be some interest, I'll post it as a resource when it gets finished (hopefully like a week or so), and I'll shoot you an email.

Yes, I use 3dsmax to model and map my interiors. I released a couple of free resources a while back that let you export your 3dsmax scene directly to Constructor. Hopefully, you'll find these helpful.

Max2Ctor (You should make a note of Petteri's comment)
Tutorial
#14
03/17/2008 (4:02 pm)
@Ryan -

I'm interested too, this could be neat. Maybe we could build the functionality into the internal exporter (maybe even load the lightmaps into constructor to see them in real time...)
#15
03/17/2008 (5:04 pm)
Ryan...

Tried to model in Max to check how the texture coords look exported into Constructor (used your csx-exporter).

niva3d.com/temp/csx_export.jpg
What do you think? Missing something here?

(Even though my texture looks a little bit distorted in Max, it still looks even worse in Constructor. Seems like the 'straight, planar' projection makes seams between the faces...)
#16
03/17/2008 (8:52 pm)
@Tobias

That's actually not a problem with the exporter... it's a limitation of the dif/map format. It's kinda difficult to explain, but basically to preserve the texture mapping perfectly from 3dsmax to Constructor (and ultimately Torque), each polygon must map linearly from world space into texture space. This means you can only only move, rotate, scale, and skew polygons in texture space. Your mesh is an example of nonlinear mapping, hence the texture warping across the polygons. The dif format cannot preserve this. Maybe to help explain this more visually, create a plain sphere and a geosphere side by side in 3dsmax (turn the sides down to a reasonable number). Place the same texture on both and leave max's default spherical mapping. Notice that the plain sphere will exhibit some texture warping just like your tube above. Export the scene to Constructor and notice the results. The plain sphere will look different just like your Constructor tube above. That's because the quads were nonlinearly (spherically) mapped into texture space. But notice that the geosphere looks correct. This is because the geosphere is composed of tri's, and tri's ALWAYS map linearly into texture space. I was disappointed to learn this too, but we have to know the limitations of our tools and representations, and learn to work around them. (I know I said something about twisting tree roots in the tutorial, but I didn't realize at the time that there would be inherent texture seams. A busy texture can hide them fairly well, though :)

@ Jaimi

That's exactly what I was thinking! I left the existing functionality of map2dif_plus completely untouched, and simply augmented it by adding a couple of new flags to harness the new behavior. That should make it fairly simple to integrate, I would think. Like I mentioned above, though, some engine code needs to be changed to actually take advantage of this in-game. I'll keep you updated. And all your hard work is very much appreciated!
#17
03/20/2008 (11:14 am)
For anybody who's interested in the lightmap baking for interiors, here's a little update. First a pic. :)

www.geocities.com/rmounts79/Baked_Mod.jpg
You can see in the world editor inspector pane that I added a "disableSun" flag to the interior class. This allows me to selectively turn off the sun for interiors that have their lighting baked, while still casting a shadow on the terrain. It took some time, but I was also able to leave the ability to place Torque lights in the scene and have their lighting affect the baked lightmap properly. Notice the Torque light near the wooden box and how it casts a shadow from the blue guy. This opens up some interesting possibilities... for example, instead of baking all the advanced lighting into a texture in 3dsmax, you could bake only the indirect light. Then ingame you could have Torque lights casting the direct light so that it would affect the players and cast shadows from them. Combining the direct light with the baked indirect light should give a workable global illumination solution. I would like to add one more thing before I release this, and that's an ambient override for interiors. This would be useful if you wanted to bake ambient skylight into your lightmap (to get nice ambient occlusion). Then ingame you could set that interiors ambient override to (0,0,0) because the ambient light is already in the base lightmap, and the sun would provide the direct light and shadowing.
#18
03/20/2008 (5:10 pm)
I really like how far you've managed to take this!

Had a peak at the TGEA 1.7 Beta and it still lacks the ability for lightmaps in *.dts's - the polysoup-meshes can just recieve dynamic shadows e.g. from the player (though it will be an AWESOME update when it's released)...but what you've done here is great.
Also like your approach to have it quite "customizable" - so you can choose to disable sun, or just choose to bake ambient occl. and still let TGEA sun affect/shadow the *.dif.

Some question (bare with a none-coder);

If you bake just AO into the "outside-generated-lightmap" and let TGEA calc. shadows from sun/other lights - does this mean it's a "3-pass-thingy" - tiled textures, outside-AO-map and finally TGEA's lightmap on top of this...or?!

And in your pic above - approx. how high is the tiled texture resolution in relation to the non-tiled lightmap?

Anyway I totally love this...and can't wait to test this myself later on. Just awesome IMO!
#19
03/21/2008 (9:46 am)
@Tobias

Hey, I really appreciate the support. This is my first time to actually touch the engine code, so it's definitely cool to slowly see something taking shape here. Hopefully this is the right answer, :) I don't know all the underlying mechanics, but I wouldn't call this a multi-pass effect. When you relight the scene, Torque calculates the lighting for each surface of an interior with respect to each light source that is in range (including the sun) and merges that lighting with that interior's base lightmap. So that all happens "offline." Now I'm not sure how this gets rendered in realtime, whether the tiled textures are getting modulated by the lightmaps before being drawn, or if everything gets drawn unlit and then the lighting is drawn to another buffer and they get multiplied together. But this tool doesn't change the render pipeline at all, so there's no performance change. As for the texture resolution, those are all 512x512. You can render your lightmap texture in 3dsmax any size you want, but it'll get converted to multiple 256x256 lightmaps in the dif. I think the one above has 3. Also, I should tell you that all this has been done in TGE. I have TGEA too but decided to learn TGE first to get a better understanding of the engine code. Once I get it all working in TGE, I'll see if I can get it working in TGEA.

@Jaimi

I just realized that you were talking about maybe integrating this into the internal exporter, not just another map2dif option. That would be really stinkin' cool, but I have no idea how difficult it would be... I'd probably code it slightly differently if that approach was taken. Would I be able to have access to the source code, or would that be something that you'd have to do yourself? Also, here's something that would be really beneficial to users like me that would like advanced control of their interiors... if Constructor could read and write normals to and from the csx file. That way I could manually set my normals in 3dsmax. I've just never gotten the light_smoothing thing to work the way I would expect. Would that be feasible?
#20
03/25/2008 (7:43 am)
Here's another little update. I'm basically done with the fundamental things I wanted to accomplish. Of course there's room for more tweaks and options, but I think it's pretty much ready to be released. I need to get a small tutorial together and make some minor adjustments, but Lord willing, it'll be ready sometime this week. Here are some pics showing off some different lightmap uses.

www.geocities.com/rmounts79/Cornell1.jpg
www.geocities.com/rmounts79/Cornell2.jpg
www.geocities.com/rmounts79/Cornell3.jpg
Page «Previous 1 2