I’m trying to apply a shader for multitexturing to a node generated by a HeightfieldTesselator and having no luck.
It works to some (very very small) degree, the highest part of terrain is brown, middle is green and lowest is grey. However, there is no texture detail at all, just these 3 colors.
I know the shader works, because when I apply it to a model it works perfectly.
Here is my code:
self.hf = HeightfieldTesselator("Terrain")
self.hf.setHeightfield(Filename("data/terrain.png"))
self.hf.setHorizontalScale(HORIZONTALSCALE)
self.hf.setVerticalScale(VERTICALSCALE)
self.tex0 = loader.loadTexture('data/dirt.png')
self.tex1 = loader.loadTexture('data/fungus.png')
self.tex2 = loader.loadTexture('data/grass.png')
self.ts0 = TextureStage('dirt')
self.ts1 = TextureStage('fungus')
self.ts2 = TextureStage('grass')
render.setShaderInput( 'fog', Vec4( 0.16, 0.32, 0.36, 0.0002 ) )
render.setShaderInput( 'lightvec', Vec4( 1, 0, 1, 0 ) )
# THIS WORKS PERFECTLY
np = loader.loadModel('data/terrain.bam.pz')
np.reparentTo(render)
np.setPos( 0, 0, 0 )
np.setShader(loader.loadShader("shaders/terrain.sha"))
np.setTexture(self.ts0, self.tex0)
np.setTexture(self.ts1, self.tex1)
np.setTexture(self.ts2, self.tex2)
np.setShaderInput('terrain', Vec4( 46, 66, 0, 0 ))
# This is broken?
self.hf.setFocalPoint(camera.getX(), -camera.getY())
node = self.hf.generate()
node.reparentTo(render)
node.setPos(0, 0, 0)
node.setShader(loader.loadShader("shaders/terrain.sha"))
node.setTexture(self.ts0, self.tex0)
node.setTexture(self.ts1, self.tex1)
node.setTexture(self.ts2, self.tex2)
node.setShaderInput('terrain', Vec4( 46, 66, 0, 0 ))
Oh and btw it doesn’t matter if I load model or heightfield first. The model always works, heightfield never does
Can anyone shed a light?
I’m thinking that I need to generate texture coords for the heigthfield or something like that.
I however did try something like this:
node.setTexGen( TextureStage.getDefault( ), TexGenAttrib.MWorldPosition )
node.setTexScale( TextureStage.getDefault( ), 1.0, 1.0 )
With no luck. Maybe the params are not right… I’m not sure how they work