Texture Projection - setNear()?


I’m making a planet, and I would like anything above a certain height to be a stony texture instead of a grassy texture.

This is more difficult with a sphere than with a plane, so I thought for a while, and eventually came up with the idea to project a texture from the centre of the planet.

        rockProjector = render.attachNewNode(LensNode('rockProj'))
        rockLens = PerspectiveLens()
        #Ground level is about 2000
        rockLens.setNearFar(2100, 3000)
        #To cover half the planet, I will make another one for the other half
        rockProjector.setHpr(0, 0, 0)
        rockTexture = loader.loadTexture('models/blue_cracks.jpg')
        ts = TextureStage('rockTs')
        self.planetBR.projectTexture(ts, rockTexture, rockProjector)

To make the mountains only mountainous above a certain height, I added the setNearFar, though this does nothing. Even if I set the NearFar to 30000, 40000 (much greater than the radius of my planet), it still makes the planet rocky everywhere.

So my question is: Does setNearFar work with projectTexture()?

Also, in the panda API it says

void Lens::set_far(float far_distance);

Description: Defines the position of the far plane (or cylinder, sphere, whatever). Points farther from the lens than this may not be rendered.

How do I set the far plane to be a sphere. I think this would be better for limiting the view onto a spherical shape?


The near and far planes are used to artificially limit the geometry that is sent to the graphics card, and to make the depth buffer a finite numeric range, but these are not involved in texture projection, which extends infinitely.

The near plane is always a plane when you are using a PerspectiveLens, or any lens that can be used for hardware rendering or hardware texture projection. It is a sphere in the the case of a FisheyeLens, and a cylinder in the case of a CylindricalLens. You cannot use these more exotic-shaped lenses in projectTexture(), but there is another interface called ProjectionScreen, which can use these lenses to compute texture coordinate on the CPU, instead of in the graphics hardware. Unlike projectTexture(), which generates the UV’s on-the-fly and the UV’s disappear when you turn off the effect, ProjectionScreen will permanently modify your geometry to store the UV’s on its vertices. The interface is also a little unusual, but I think there are some examples in the forum.

It still doesn’t respect the near plane, however. (And what kind of texture coordinates would you expect it to generate outside the near plane if it did? Zero? There’s still texture data at (0,0). There’s no texture coordinates that mean “no texture should be applied here”.)


Ah, so I’ll have to find another way to do it, or just apply the textures to the actual geometry in blender.