Flickering projected normal map

I’m assessing the possibility to project a normal map composed in an offscreen buffer onto a terrain and I’m having some problems with it.

The first thing is flickering.
When the texture is projected to a MModulate texture stage it all looks ok, but when I change the stage to MNormal it behaves really strange. It flickers between a correct version and something… well something (see screenshot below)



The buffer viewer shows a correct image all the time. Any ideas what’s wrong and how it can be fixed?

The second problem is a black border visible on the first screen.
I’ve set the border color to a neutral hue and set the wrap mode to WMBorderColor

        altBuffer.getTexture().setWrapU(Texture.WMBorderColor)
        altBuffer.getTexture().setWrapV(Texture.WMBorderColor)
        altBuffer.getTexture().setBorderColor(VBase4(0.5, 0.5, 1, 1)) 

How can I get rid of it?

Here’s a (bit sloppy) demo of what I’m trying to do. If anyone can help, pleas do.
sendspace.com/file/4aelqz

W-S-A-D to move, mouse3 to start/stop camera rotation.

What’s your Panda version?

Assuming you have vsync enabled and your screenshot is not tearing, at first glance, that looks like z-fighting. Do you have multiple planes overlapping each other?

Running version 1.8.0, windows xp, anchient hardware.

I have multiple overlaping planes, but only in the buffer viewed part of the scene and these planes have some depth sort values set.
The plane that is the target of the projection is just one big quad.
When using the same setup but projecting into a MModulate TextureStage there are no visible artefacts. I don’t think it’s a z-fight problem.

The flickering is kind of wierd. On my pc, the code runs at 20-30 fps, but this flickering is not that fast, also it switches from these two states visible on the screen only when the camera, or the character moves (the projector node moves with the character). Testing some sort values for my tasks did not change anything.

Also when I try to project this onto a GeoMipMapTerrain it flickers from wrong blocks to none at all.

I feel there’s some sort of bug, or projecting normal maps is just something you can’t do.

I think that running the sample I’ve posted and looking at its code will provide more info then I can give you.

There must be something wrong with my code, I just can’t find what.

I’ve removed all my tasks and it’s still the same.
I’ve tried to project any normal map texture, not one composed in a buffer - still the same.

The strangest thing is that when I replace an actor with a blank NodePath, then the projected normal map has no effect at all.

At the same time a color texture (diffuse/modulate, call it what you will) composed the same way, and projected the very same way as the normal map texture works A-OK.

I’ve also tested something simpler and to be honest I can’t reproduce the errors I’m seeing.
Help?

So, the error was not in my code… it was in my model, it just lacked tangent and binormals (even thou I’ve run egg-trans -tbnall). The other error was in my head - I’ve tried to project the normal map onto a geo-mip-mapped terrain, as with the former it lacks normals.