0 votes

Hi

I'm trying to create simple ground generator for my game but I have problem with shading of generated geometries.

I this code I have used two methods (ImmediateGeometry and MeshInstance with SurfaceTool) and in both situation problem looks the same. Third object on screen is MeshInstance with "New PlaneMesh" and it's working ok. All of the objects (except blue ground) have the same shader.

This "procedural" meshes are gray and they not casting any shadows. Why, what can I do with that?

Best!

func test():
randomize()

# ImmediateGeometry
var im = scene.get_node('ImmediateGeometry')
im.clear()
im.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP, null)
for x_num in 10:
    var x = x_num*2
    var v1 = Vector3(0+x, 0, rand_range(-0.25, 0.25))
    var v3 = Vector3(1+x, 2, rand_range(-0.25, 0.25))
    im.add_vertex(v1)
    im.add_vertex(v3)
im.set_normal(Vector3(0, 0, 1))
im.set_color(Color(1, 1, 1))
im.end()

# MeshInstance - bb
var bb = scene.get_node('bb')
var surf = SurfaceTool.new()
var msh = Mesh.new()
surf.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for x_num in 10:
    var x = x_num*2
    var v1 = Vector3(0+x, 0, rand_range(-0.25, 0.25))
    var v3 = Vector3(1+x, 2, rand_range(-0.25, 0.25))
    surf.add_vertex(v1)
    surf.add_vertex(v3)
surf.generate_normals()
surf.commit(msh)

bb.set_mesh(msh)

enter image description here

in Engine by (227 points)

One issue with the code for the immediate geometry is that you need to set the normals and the color for every vertex. It may be possible to set them once in the beginning and not set them again if they don't change, but in any case you need to call set_normal and set_color before you call add_vertex.

1 Answer

0 votes

Have you added a material in the inspector? That's where properties like color or shadow casting are set.

by (1,120 points)

Yes, material are added to booth meshes. But your solution from comment above works flawlessly! Thanks!

Of course it's working using ImmediateGeometry, second option "MeshInstance with SurfaceTool" hasn't option set_normal() but there are command generate_normals() what I have used in code above but it's not working :(

But thanks for help with ImmediateGeometry you are great :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.