So I’m trying to optimize/rationalize my terrain system. I have discovered that to render my textures correctly, I must call
twice. I don’t know why, but if I only call it once, renderings using multiple textures in the shader get all mangled as if the textures were swapped or not yet loaded.
I have tried:
and it does not help.
I’m also trying to thread it, or at least avoid calling
when its running in realtime, but thats not working very well, so I’m trying to figure out whats going on without threading first. Ignore the illogical unfinished threading related stuff in this code. Heres the code:
yes, I’m needlessly copying to ram, and copying the texture too (both of which are unnecessary), but those are because of bugs which I’ll address later. One thing at a time for now please.
def renderMap(self, rawTile, inputMaps, shader, threaded=False): # Resolution of texture/buffer to be rendered size=int(round(tileMapSize*shader.resolutionScale+shader.addPixels)) #we get a handle to the default window mainWindow=base.win #we now get buffer thats going to hold the texture of our new scene buff=mainWindow.makeTextureBuffer('MapBuff',size,size,Texture(),True) #now we have to setup a new scene graph to make this scene altRender=NodePath("new render") #this takes care of setting up ther camera properly altCam=base.makeCamera(buff) oLens = OrthographicLens() margin=texMargin(size) oLens.setFilmSize(1+margin*2, 1+margin*2) altCam.node().setLens(oLens) altCam.reparentTo(altRender) altCam.setPos(.5,-1,.5) c=CardMaker("MapCardMaker") c.setUvRange(0-margin,1+margin,0-margin,1+margin) c.setFrame(0-margin,1+margin,0-margin,1+margin) mapCard=NodePath(c.generate()) mapCard.reparentTo(altRender) mapCard.setPos(0,0,0) mapCard.setShader(shader.shader) mapCard.setShaderInput("offset",rawTile.x,rawTile.y,0,0) mapCard.setShaderInput("scale",rawTile.scale,0,0,0) for m in inputMaps: texStage=TextureStage(m.name+"stage") mapCard.setTexture(texStage,m.tex) for p in shader.shaderTex: mapCard.setTexture(*p) """ Here the texture is aauctually generated For some unknowen reason, both calls to: base.graphicsEngine.renderFrame() are needed or there are issues when using multiple textures. """ def waitAFrame(): if threaded: i = self.frameCount while self.frameCount == i: print i Thread.considerYield() else: base.graphicsEngine.renderFrame() #buff.setSort(-100) tex = buff.getTexture() waitAFrame() #buff.setOneShot(True) waitAFrame() buff.setActive(False) tex = tex.makeCopy() base.graphicsEngine.removeWindow(buff) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) mapCard.remove() return Map(shader.name,tex)
Now if I can get these last few issues resolved, you all will get endless, seamless (I think I fixed both texture and mesh seams, including texture interpolation on the edge pixels), procedural terrain using geomipterrain tiles (with brute force enabled, because its much faster, smoother, and I have my own cool LOD system. Ya, I’ll make that more logical later) generated as needed in the background. You want that right? So fix my stuff
If it would be helpful, I can upload the latest complete version of the project so you can run it. It is in somewhat of a messy mid debugging state at the moment though.