Developing a city builder terrain engine

Once you enable the Shader Generator, that limit of 4 stages magically vanishes.

Still not getting it to work. :frowning:

Running 1.7.0, tested on Linux and Windows 7 - identical results.

I confirmed (I believe) that the Shader Generator is on. I have render.setShaderAuto() near the top of the script, and it’s been there from the beginning. If I comment it out I only get the first 4 texture stages.

Here is my code (at the moment):

import direct.directbase.DirectStart
from pandac.PandaModules import Vec4
from pandac.PandaModules import TextureStage
from pandac.PandaModules import GeoMipTerrain
from pandac.PandaModules import AmbientLight


render.setShaderAuto()


# add ambient light
ambient = Vec4(0.34, 0.3, 0.3, 1)
alight = AmbientLight('alight')
alight.setColor(ambient)
alnp = render.attachNewNode(alight)
render.setLight(alnp)


# Set up the GeoMipTerrain
terrain = GeoMipTerrain("genTerrain")
terrain.setHeightfield("generatedheight.png")

 
# Set terrain properties
terrain.setBlockSize(32)
terrain.setFactor(100)
terrain.setNear(40)
terrain.setFar(100)
terrain.setFocalPoint(base.camera)
 
# Store the root NodePath for convenience
root = terrain.getRoot()
root.reparentTo(render)
root.setSz(50)

# Generate it.
terrain.generate()



# Step 1: alpha maps - first two
ts = TextureStage("stage-basicalpha")
ts.setSort(00)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture("alpha2.png", "alpha4.png"))
ts.setSavedResult(True)

# Step 2: first texture - rocks go on everything
ts = TextureStage("stage-first")
ts.setSort(10)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture("rock.jpg"))
root.setTexScale(ts, 64, 64)


# Step 3: second texture grass go on alpha2
ts = TextureStage("stage-second")
ts.setSort(20)
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor,
                                             TextureStage.CSPrevious, TextureStage.COSrcColor,
                                             TextureStage.CSLastSavedResult, TextureStage.COSrcColor)
root.setTexture(ts, loader.loadTexture("grass.jpg"))
root.setTexScale(ts, 32, 32)


# Step 4: full map texture is blended with everything
ts = TextureStage("stage-global")
ts.setSort(30)
ts.setCombineRgb(TextureStage.CMModulate, TextureStage.CSPrevious, TextureStage.COSrcColor,
                                          TextureStage.CSTexture, TextureStage.COSrcColor)
ts.setRgbScale(2)
root.setTexture(ts, loader.loadTexture("generatedtex.png"))
#ts.setSavedResult(True)


## Step 5: third texture - road goes on alpha4
ts = TextureStage("stage-third")
ts.setSort(40)
root.setTexture(ts, loader.loadTexture("road.jpg"))
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor,
                                             TextureStage.CSPrevious, TextureStage.COSrcColor,
                                             TextureStage.CSLastSavedResult, TextureStage.COSrcAlpha)

root.setTexScale(ts, 128, 128)
ts.setSavedResult(True)


#Step 6: apply the wood texture to the entire terrain
ts = TextureStage("stage-wood")
ts.setSort(50)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture("wood.jpg"))
root.setTexScale(ts, 64, 64)


#Step 7: Using an alpha map set texture to either previous wood texture or last saved texture state
ts = TextureStage("stage-woodalpha")
ts.setSort(60)
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSPrevious, TextureStage.COSrcColor,
                                             TextureStage.CSLastSavedResult, TextureStage.COSrcColor,
                                             TextureStage.CSTexture, TextureStage.COSrcColor)
root.setTexture(ts, loader.loadTexture("alpha5.png"))


run()

If I comment out steps 6 and 7, it works as expected, basically the same as the example code. If I comment out step 5 and uncomment ts.setSavedResult(True) from step 4 then that texture works as expected. If I run it as is then nothing from steps 5, 6, or 7 show and I get the following errors:

:gobj(error): created-shader: (20) : error C5102: output semantic attribute “TEXCOORD” has too big of a numeric index (8)
:gobj(error): Shader encountered an error.
:gobj(error): created-shader: (20) : error C5102: output semantic attribute “TEXCOORD” has too big of a numeric index (8)
:gobj(error): created-shader: (20) : error C5041: cannot locate suitable resource to bind parameter “l_eye_normal”

Interestingly enough, at least to me, if I comment out the render.setShaderAuto() line I get the same visual results, but no error.

To fix those errors, try putting “basic-shaders-only #f” in Config.prc

No joy, same thing. In fact, my Windows 7 box was already set to #f.

FWIW, my Windows box is an ION nettop (nVidia 9400M gpu) and my Linux box is running an nVidia GTS250. I don’t think there is a hardware issue.

This thread seems to be going in a different direction from the original, should I start a new one?

I just accidentally stumbled across a “solution” to my problem. Not sure if it’s a bug or what. In the process of breaking out the various parts of my code into classes in separate files, I happened to run the script with the ambient light section commented out. Much to my surprise, not only did I not get the errors I posted above, but all the textures I had defined showed up correctly. Can anyone explain why the following lines of code do not allow me to add extra textures to my geoMipTerrain?

ambient = Vec4(0.34, 0.3, 0.3, 1)
alight = AmbientLight(‘alight’)
alight.setColor(ambient)
alnp = render.attachNewNode(alight)
render.setLight(alnp)

FWIW, leaving “from pandac.PandaModules import AmbientLight” in the script is fine.

Has anyone been able to find a solution for this?