unexpected shadow effect while using lightmaps

Software: Away3D 4.x

Mike Samuel, Newbie
Posted: 28 July 2012 11:57 PM   Total Posts: 30

Hello,

me again, having some problems. I do not really know how or what to call it, nor how to describe it in words, so here are a series of images and some explanation on my setup. (Please see the attached image, it has 6 parts)

General setup:
- Light is fixed, does not move at all. (see code below for setup)
- The wall pattern is created using a single normal map, applied via UV.
- Each mesh has its own, unique light map applied for shadows.
- The two meshes making up one wall are perfectly aligned in Blender.
  There is no cap at all, in any direction between the top and bottom mesh

I. Just a screen of the complete model, to show why I need the two meshes.
II. Removed everything but one wall (two meshes).
  Normal and light maps are still applied to each mesh
  In this camera angle, one can see a “shadow” on the bottom mesh all
  across its top edge. (Yellow rectangle)
III. Turning the camera towards a more perpendicular posting to the wall
  The “shadow line” starts to disappear towards the back.
IV. disappear even more
V. Perpendicular view of the wall, zoomed in. There is no edge, nothing.
VI. Same shot as # II., but Normal maps removed on both.
  Bottom mesh only has light map applied.
  It seems to me it has to do with the light map of the bottom mesh.

I am guessing the top mesh shows the same effect, but it is black due to wanted shadow, so that doesn’t matter.

The light map itself is completely 0xffffff on the edge, I checked.

Maybe this is a lengthy description of a well known effect I just haven’t heard of. Then I’m sorry. How do I fix it??

Here is some setup code used in the project.
I can post more if needed, but I can not post all the code, nor the project. If required, I can make a simple project showing just the effect and post that.

_sunLight = new DirectionalLight( );// -0.4, -0.6, -0.95);
_sunLight.position = new Vector3D(111);
_sunLight.direction = new Vector3D(-1,-.5,-1);
_sunLight.color 0xffffff;
_sunLight.castsShadows false;
_sunLight.ambient 0.7;
_sunLight.diffuse 0.9;
_sunLight.specular 0.3;

var 
camera:Camera3D = new Camera3D();
camera.500;
camera.0;

_camTarget = new ObjectContainer3D();
_camTarget.0;
_camTarget.50;
_camTarget.0
_cameraController 
= new HoverController(_view.camera_camTarget, -120, -5, -600);

//Materials are created using settings
var matTex:TextureMaterial = new TextureMaterial(new BitmapTexture(bitmapIn));
matTex.alphaBlending false;
matTex.bothSides false;
matTex.lightPicker _lightPicker;
matTex.gloss 20;
matTex.ambientColor 0xffffff;
matTex.ambient 0.5;
matTex.specular 0.5

So ya, long story, anything I can do to make this line disappear?

Regards

PS: The front wall has the same effect, just towards the other side.

 

   

Richard Olsson, Administrator
Posted: 29 July 2012 09:32 AM   Total Posts: 1192   [ # 1 ]

Are you not using runtime shadows at all? This looks like some sort of precision error. If that’s the case, it’s going to be hard to get rid of without working around the problem.

How does the UV map look for both the top and the bottom mesh in the wall? Could it be a case of the dark part of the texture “leaking” into the bottom due to interpolation? Try toggling mipmap and smoothing on/off on your material to see if that makes a difference.

Why do you need the two meshes? Can’t you just use a single mesh and have two separate colors in separate regions using a texture?

 

   

Mike Samuel, Newbie
Posted: 29 July 2012 03:01 PM   Total Posts: 30   [ # 2 ]

uh, I understand about half of what you just posted here Richard.

1.) Do I use runtime shadows?
- I think not. There is one light only, its drowShadow prop set to false
- I do not assign any shadow methods anywhere.
- What else do I have to do to ensure there are no shadows?

2.) How does the UV map looks like.
- I don’t know, I import the UV coordinates with the model from Blender.
- Within Blender, after I UV-unwrap I make sure all vertices are within the texture. ie of the sidewall, since it is a rectangle, I manually enter the 4 vertices coordinates as (0,0), (0,512), (1024,0) (1024,512).
- I don’t know what else to do, or how to check in away3d if the UV stuff is correct. I just import it via 3ds, that’s all I know so far.

3.) mipmap.
- If I turn it to false, the “shadow effect” is gone, but it creates an other effect. (see attachment: you can see does “curve pattern”. I remember something about them being a normal effect due to the vertical lines of the texture, but I do not remember the name of it.
- so yes, turning off mipmap gets ride of the shadow, but the overall texture quality goes downhill.
- I tried turning it off just on the bottom, but own can clearly see the difference.
4.) smooth =false
- makes the shadow sharp, rectangular in shape, more noticeable

5.) why the two meshes?
Well, that’s why I included image # I. in the first attachment, but I guess I never never really explained it. There are controls on the side to switch individual colors for individual parts. So in case of the wall, you can choose white for your main color, but red for the bottom, smaller part.
So everything the user can choose individually, Trims, Door frames, window frames, etc, are in fact individual meshes in my model.

I guess I could create, one texture for each combination, but with 10 - 20 colors to choose from I end up creating 200-400 texture images and I need some extra code to handle them.
So if I must, I can simplify my model to have a single mesh / wall. But the code complexity and file size will go up.

If there is a third option, I’m all yours.

I also tried with just the bottom part of the mesh alone, no top part at all and the shadow effect still appears. So I guess it has nothing to do with the top mesh, nothing “slipping over” or so.

Ya, that’s about it , I have no idea what I can test about the interpolation thing.

Regards

 

 

   

Richard Olsson, Administrator
Posted: 29 July 2012 03:37 PM   Total Posts: 1192   [ # 3 ]

Ok, then we know what’s causing the error at least. I’d like to see the UV unwraps. Could you take a screen grab of the blender Image/UV editor for both of wall parts? I’m thinking that increasing the margins between textures could potentially get rid of the problem (by avoiding accidentally interpolating from the darker pixels.)

I would still consider using just a single mesh though, and work around the problem that way. You don’t have to create textures for each combination, as you could just redraw the texture whenever the user changes the option, using BitmapData.draw(). Draw the two patterns onto the same BitmapData and then just assign that to the bitmapData property of the BitmapTexture before calling invalidateContent().

This will trigger the image to be re-uploaded to the GPU, which comes at a slight overhead cost. That would be a problem if you did it every frame or so, but doing it just as a response to the user selecting an image through the interface should not be a problem.

Using fewer meshes will result in fewer draw calls, which will increase performance, especially on mobile devices.

 

   

Mike Samuel, Newbie
Posted: 29 July 2012 04:02 PM   Total Posts: 30   [ # 4 ]

as for the screenshots, here they are, I hope this is what you are looking for.

Let me say this again. The UV unwrap from blender had a different shape, I manually adjusted them to the outer edges of the images to, originally fit my texture. I am just using the same UV coordinates with the light maps. Since Blender “backs” the shadows into the UV map, I figured that should always fit. That’s all I know so far. Maybe that’s my problem, I have no idea.

As for the drawing directly to a single Bitmap. I think you, or someone else mentioned that on a previews post. I will look into that this afternoon.
I kinda like the idea, not just would it simplify the model, reduce meshes and reduce the number of texture images. But I could also have different heights, one foot, two foot ...
So ya, I have to look into that.

I’m just a noob, and I come from a pure coding background. I create single objects, but them into lists, and grab then when needed. I just copied that idea to the 3D model, I guess it is time to deviate from that idea.

Thanx for all the help, I really learn a lot from your posts

 

   

Mike Samuel, Newbie
Posted: 29 July 2012 04:46 PM   Total Posts: 30   [ # 5 ]

I think I just found a fix to the problem. You said:

I’m thinking that increasing the margins between textures could potentially get rid of the problem (by avoiding accidentally interpolating from the darker pixels.)

While I am not 100% sure what this means, I went ahead and extended the white area in my lighmap file outside the UV rectangle. I never noticed, but since I use png for the lighmaps, everything outside the UV chap is transparent. Once white, the effect is gone.

Switching to jpg fixes it as well, but I guess that’s the same effect, transparent is replaced with white.

I guess the point here is to do what you suggest and have a few extra pixel as margin. Lesson learned.

Still gonna check out drawing the texture directly in code, I like the idea.

 

 

   

Richard Olsson, Administrator
Posted: 29 July 2012 08:17 PM   Total Posts: 1192   [ # 6 ]

Yeah, that’s basically what I meant. You should be able to solve the problem by just increasing the margin in the Blender light-baking settings. If you set it to 4-5 pixels, there should be enough margin around the borders of the UV unwrapped mesh to accommodate any smoothing that happens during interpolation of the mipmapped texture.

 

   

Shegl, Sr. Member
Posted: 29 July 2012 08:53 PM   Total Posts: 134   [ # 7 ]

Yes. Current mipmap(and MipMapGenerator in away3d too) system crappy. Better dont even try to use mipmap if you have lower when 256x256 texture resolution.. Also mipmap bug with textureProjection.. You can particulary fix it by modifieng MipMapGenerator code and using..

The problem with using matrix scaling is that it doesn’t do any antialiasing or smoothing..

So code below:

var image:Image = new Image();
image.load(new Bitmap(sourceBitmapDataPixelSnapping.NEVERtrue));

var 
scaledWidth:uint sourceBitmapData.width scale;
var 
scaledHeight:uint sourceBitmapData.height scale;

image.content.width scaledWidth;
image.content.height scaledHeight;

var 
scaledBitmapData:BitmapData = new BitmapData(scaledWidthscaledHeight);
scaledBitmapData.draw(image.content); 

image null

will produce much better downscaled picture ^_^. You can check it out and see the difference below this 2 ways..

P.S. Class Image is http://help.adobe.com/en_US/FlashPlatform/...

 

   

Richard Olsson, Administrator
Posted: 29 July 2012 09:21 PM   Total Posts: 1192   [ # 8 ]

@Shegl:
I’m sorry to hear that you think that Away3D is crappy. Please help improve it’s crappyness by filing issue reports when you find things that you think are problematic.

Obviously, we can’t have Away3D rely on Spark classes, but even still, I’m not sure I understand your concerns exactly.

You seem to be saying that the way that MipMapGenerator currently works results in scaling happening without the use of smoothing. That’s not true, because the smoothing parameter in BitmapData.draw() in MipMapGenerator is set to true, so smoothing does happen.

Regardless though, the problem in this thread doesn’t come from a lack of smoothing, but rather from the fact that there is smoothing going on, and thus that at smaller mipmaps the pixel that is sampled from the texture will have been interpolated between the white and the black parts of the texture.

Correct me if I’m wrong, but does the code you suggest even scale down the image at all? Setting the width and height of image.content (and thus modifying it’s transform matrix) should have no effect when you invoke draw() because any transformations of the source objects are ignored, as described in the documentation for BitmapData.draw():

The source display object does not use any of its applied transformations for this call. It is treated as it exists in the library or file, with no matrix transform, no color transform, and no blend mode. To draw a display object (such as a movie clip) by using its own transform properties, you can copy its transform property object to the transform property of the Bitmap object that uses the BitmapData object.

Still, if you have any documentation, or for example screenshots, that could motivate the change that you’re suggesting, please do share them and we will consider modifying the mip-map generation in any way that we deem an improvement. The best place to share such suggestions would be through the GitHub issue tracker at: http://github.com/away3d/away3d-core-fp11/issues

Thanks!

 

   

Shegl, Sr. Member
Posted: 29 July 2012 10:07 PM   Total Posts: 134   [ # 9 ]

And again im about stage3d mipmap is crappy.. Not away3d.. And in mipmap generator which uses draw() with matrix is worther then using static Image class.. Here are 2 images with matrix downscaled by (50%) and Away3D(MipMapGenerator);

on second scaled picture if you open it with any image editor you will see what edges are smoothed too with Smoothing with draw matrix + smooth true;

I dunno why.. But if use Image the downscaled pictures look a bit better when using as mipmap.. Also… I havent access to SSL or !=80 web port..

 

   

Mike Samuel, Newbie
Posted: 29 July 2012 10:57 PM   Total Posts: 30   [ # 10 ]

@Richard: Ya, now I know what that setting is for, and more importantly, why one would bake with a margin. Thanx, learned a lot today.

As for the mipmap thing, I can ready it, but that’s pretty much all I can do. I leave it to you two to discuss that, it’s way over my head

Regards,

Mike

 

   

Richard Olsson, Administrator
Posted: 30 July 2012 06:35 AM   Total Posts: 1192   [ # 11 ]

@Shegl
I’m struggling to understand you, because it sounds like you’re saying that smoothing is required for mipmaps to look good, but when I look at your screenshots it looks like you think smoothing is actually bad.

Please, if you want to help, implement what you feel is a better way of generating mipmaps, without relying on Flex/Spark (e.g. using Bitmap instead of Image) and provide screenshots of it actually in use in a 3D scene. Create a new thread or file a feature request at GitHub.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X