setNormalMap on a quad

Hello,

I can’t get setNormalMap to work.

from panda3d.core import loadPrcFileData
loadPrcFileData("", "show-frame-rate-meter 1")
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from panda3d.core import *

cardmaker= CardMaker( 'cardmaker' )
card= cardmaker.generate( )
cardNP= render.attachNewNode( card )
sphernormmap= loader.loadTexture( 'sphere.png' )
cardNP.setNormalMap( sphernormmap )

plight= PointLight( 'plight' )
plightNP= render.attachNewNode( plight )
plightNP.setPos( -10, 0, -10 )
plight.setAttenuation( Point3( 0.01, 0.01, 0.01 ) )
render.setLight( plightNP )

base.cam.setPos( 0, -5, 0 )
run( )

The light should be coming from the lower left, but it is coming from directly ahead.

When applying normal maps, whether via a shader or via setNormalMap(), you always need to have a model with tangents and binormals defined (in addition to UV’s). The tangents and binormals are necessary to define the coordinate space of the normals.

The CardMaker doesn’t create a card with tangents and binormals. Try this egg file instead:

<CoordinateSystem> { Z-Up }

<VertexPool> vpool {
  <Vertex> 0 {
    0 0 0
    <UV> {
      0 0
      <Tangent> { 1 0 0 }
      <Binormal> { 0 0 1 }
    }
    <Normal> { 0 -1 0 }
    <RGBA> { 1 1 1 1 }
  }
  <Vertex> 1 {
    0 0 1
    <UV> {
      0 1
      <Tangent> { 1 0 0 }
      <Binormal> { 0 0 1 }
    }
    <Normal> { 0 -1 0 }
    <RGBA> { 1 1 1 1 }
  }
  <Vertex> 2 {
    1 0 0
    <UV> {
      1 0
      <Tangent> { 1 0 0 }
      <Binormal> { 0 0 1 }
    }
    <Normal> { 0 -1 0 }
    <RGBA> { 1 1 1 1 }
  }
  <Vertex> 3 {
    1 0 1
    <UV> {
      1 1
      <Tangent> { 1 0 0 }
      <Binormal> { 0 0 1 }
    }
    <Normal> { 0 -1 0 }
    <RGBA> { 1 1 1 1 }
  }
}
<Polygon> {
  <VertexRef> { 1 0 3 <Ref> { vpool } }
}
<Polygon> {
  <VertexRef> { 3 0 2 <Ref> { vpool } }
}

That egg file is actually somewhat pleasing; just it detracts from the “one-liner” advantages of a single-file program. Not that I’ve gotten the vertex data and tried to learn to create those extra arrays procedurally.

I attempted the strategy from the driving scene with an AlphaTestAttrib to give the texture some transparent regions. Failure!

Any pointers?

Hmm, I don’t think the TextureStages created by NodePath::set_normal_map() make any particular effort to preserve the alpha channel. (Not that it’s obvious which alpha channel you’d want to preserve, either–the one in the normal map? Or the original vertices, or some other texture?)

You might have to lay down your own TextureStages that do exactly what you want to do with the rgb and alpha channels. You can follow the example of NodePath::set_normal_map() (but you’ll have to read the C++ code in the source).

David

Hum. You don’t happen to have an egg of a dodecahedron, do you?

This resource is similar.

cpan.uwinnipeg.ca/htdocs/Math-Po … ra.pm.html

I nabbed the tetrahedron pretty easily; it just needed its “=>” changed to “:”'s. It’s just the vertices, not normals or anything.