Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | player0815 |
hi iam new and trying around with godot <3
at the moment i try to create a basic terrain generator e.g. tile or voxel based.
For generating the mesh i use SurfaceTool. That works very well for now and i can create a tile-plane (with an easy for-loop).
At the moment i create every tile as its own surface with a specific material and add it to the SurfaceTool. So i can generate e.g. a “Minecraft”-like surface.
Now i would like using shaders to make some cross-fade effects with neighbor textures.
For testing i have written a small shader who uses 2 textures - the main texture from the tile and a second one who represents the texture for a neighbor tile.
//import Textures
uniform sampler2D tex1: hint_albedo;
uniform sampler2D tex2: hint_black;
void fragment() {
// get pixel color
vec3 vTex1 = texture(tex1, UV).rgb;
vec3 vTex2 = texture(tex2, UV).rgb;
// merge & draw
float c = 1.0 * UV.x * UV.x; // west-east "curve"
vec3 m = mix(vTex1, vTex2, c);
ALBEDO = m; // draw
}
i know that i can set the texture parameter with “material.set_shader_param()” and i tried something like this:
var ter = SurfaceTool.new()
var myMesh = Mesh.new()
func cube_face_top_full(offset = Vector3(0,0,0), material = matDirt, neighborTex):
# positions
var xr = offset.x + 1 + grid_offset
var y = offset.y + 1 + grid_offset
var zf = offset.z + 1 + grid_offset
# [etc...]
ter.begin(VisualServer.PRIMITIVE_TRIANGLES)
# NOT WORKING HERE... <---------------
#material.set_shader_param("tex2", load(neighborTex))
ter.set_material(material)
# triangle 1
ter.add_uv(Vector2(1,1))
ter.add_vertex(Vector3(xr,y,zf))
# [etc...]
ter.generate_normals()
myMesh = ter.commit(myMesh)
And this is were iam stuck
How can i tell the shader wich texture should be used?
My knowlegde of shaders and 3d-meshes is very basic but can anyone give me a hint how i can solve this problem?
sry for my bad english^^
thx a lot!