# ImmediateGeometry and procedural meshes shading problem

Attention Topic was automatically imported from the old Question2Answer platform.

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.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.generate_normals()
surf.commit(msh)

bb.set_mesh(msh)
``````

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`.

Warlaan | 2018-04-04 08:01

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