Fast Custom Textures?

I’m fairly new to panda and wanted to know the best way to generate a custom texture. Our project is going to have perlin noise generated textures so they need to be created in realtime.

Currently I have code that looks like this:

#create white texture with alpha channel test
def createTextureTest(width, height):
    p = PNMImage(width, height)
    p.addAlpha()
    for y in range(p.getYSize()):
       for x in range(p.getXSize()):
         p.setXel(x, y, 1.0, 1.0, 1.0)
         p.setAlpha(x, y, 1.0)
        
    t = Texture()
    t.load(p)
    return t

Am I in the ball park here? This works fine, but it’s not exactly setting the world on fire as far as speed is concerned.

In C I would access the pixel data directly, is there a way todo that in the Python side of Panda? Better still, is there a way to go setImageData(data)?

Or should I be looking to alter the Panda source?

PS. If there is another thread on this I couldn’t find it, feel free to point me in the right direction :slight_smile:

I’m not sure python is fast enough for pixel manipulations. But I am impressed that you got that far. None of that is documented in the manual.

What are you using this perlin noise for? If it’s for clouds, I’d say the way to do it is to have a single, premade perlin noise texture stored as a JPG, and load it. Then, use a Cg shader to add it to scaled versions of itself to generate multiple octaves. I’ve tried this — it works well.

If you really need to generate textures on the fly, you probably do need to write some CXX subroutines. Not exactly easy, but some of the guys on here have figured out how to do it — in particular, you might want to look at Hugh Perkins’ “libfractalspline” stuff (do a forum search).

  • Josh

Thanks for the reply Josh.

The perlin noise textures will be used in a universe generator, and they will be for anything from planet surfaces, clouds to the nebula glow in the skybox so they really need to be generated on the fly.

I have worked extensively with a c++ project that embedded python so writing a extension or adding functionality to panda wont be a problem, but I didnt want to rewrite code that was already present.

It already looks like we will need C code to put in the adaptive mesh code for planets anyway.

I’m off to check out libfractalspline now.

Cheers!

^^^ That was me if you didnt guess… must of logged me out.