Hello i try to have multi texturing in shaderterrain with use alpha map (for apply texture in zone)
With geomip it’s work but with shaderterrain alphamap is not applied
this is my code :
from pandac.PandaModules import GeoMipTerrain
from pandac.PandaModules import TextureStage
from panda3d.core import ShaderTerrainMesh, Shader, load_prc_file_data
class myTerrainClass:
def __init__(self):
self.tssort = 0
def buildterrain(self, heightmap, tername):
# Construct the terrain
self.terrain_node = ShaderTerrainMesh()
# Set a heightfield, the heightfield should be a 16-bit png and
# have a quadratic size of a power of two.
self.terrain_node.heightfield = loader.loadTexture("heightfield.png")
# Set the target triangle width. For a value of 10.0 for example,
# the terrain will attempt to make every triangle 10 pixels wide on screen.
self.terrain_node.target_triangle_width = 10.0
# Generate the terrain
self.terrain_node.generate()
# Attach the terrain to the main scene and set its scale. With no scale
# set, the terrain ranges from (0, 0, 0) to (1, 1, 1)
self.terrain = render.attach_new_node(self.terrain_node)
self.terrain.set_scale(1024, 1024, 100)
self.terrain.set_pos(-512, -512, -70.0)
# Set a shader on the terrain. The ShaderTerrainMesh only works with
# an applied shader. You can use the shaders used here in your own application
terrain_shader = Shader.load(Shader.SL_GLSL, "terrain.vert.glsl", "terrain.frag.glsl")
self.terrain.set_shader(terrain_shader)
self.terrain.set_shader_input("camera", base.camera)
# Store the root NodePath for convenience
root = self.terrain
root.reparentTo(render)
root.setSz(75)
def addterraintex(self, tex, stage):
self.tssort += 1
root = self.terrain
# Step 4: full map texture is blended with everything
ts = TextureStage(stage)
ts.setSort(self.tssort)
ts.setCombineRgb(TextureStage.CMModulate, TextureStage.CSPrevious, TextureStage.COSrcColor,
TextureStage.CSTexture, TextureStage.COSrcColor)
ts.setRgbScale(2)
root.setTexture(ts, loader.loadTexture(tex))
ts.setSavedResult(True)
def addalphatex(self, alphamap, tex, scale, stage):
self.tssort += 1
root = self.terrain
#apply the texture to the entire terrain
ts = TextureStage(stage)
ts.setSort(self.tssort)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture(tex))
root.setTexScale(ts, scale, scale)
self.tssort += 1
#Use an alpha map set texture to either previous texture or last saved texture
ts = TextureStage(stage + "alpha")
ts.setSort(self.tssort)
root.setTexture(ts, loader.loadTexture(alphamap))
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSPrevious, TextureStage.COSrcColor,
TextureStage.CSLastSavedResult, TextureStage.COSrcColor,
TextureStage.CSTexture, TextureStage.COSrcColor)
ts.setSavedResult(True)
# Add a task to keep updating the terrain
def myupdateTerrainTask(self, task):
self.terrain.update()
return task.cont
import direct.directbase.DirectStart
from pandac.PandaModules import Vec4
from pandac.PandaModules import TextureStage
from pandac.PandaModules import GeoMipTerrain
from pandac.PandaModules import AmbientLight
# Required for matrix calculations
load_prc_file_data("", "gl-coordinate-system default")
render.setShaderAuto()
myterrain = myTerrainClass()
myterrain.buildterrain("heightfield.png", "myterrain")
myterrain.addalphatex("rock_alpha.png", "Rock.png", 64, "stage-grass1")
run()
with geomip terrain it’s work and i have this output :
but with shadder terrain i have this :
i have not white carre
this is my rock texture and my alpha texture