#Why isn't my collision shape matching my shader displacement

1 messages · Page 1 of 1 (latest)

jovial nacelle
#

So, I've got this shader:

shader_type spatial;

uniform sampler2D height_map;
uniform float amplification = 1.0;

void vertex() {
    float height = texture(height_map, UV).r * amplification;
    VERTEX.y += height;
}


void fragment() {
    /*NORMAL = normalize(cross(dFdyCoarse(VERTEX), dFdxCoarse(VERTEX)));
    TANGENT = normalize(cross(NORMAL, VIEW_MATRIX[2].xyz));
    BINORMAL = normalize(cross(NORMAL, TANGENT));*/

    ALBEDO = vec3(0.3, 0.3, 0.1);
}

And I generate a heightmap based of the same noise map:

HeightMapShape3D heightMapShape = new();

Image noiseImage = _noise.GetImage();
noiseImage.Convert(Image.Format.Rf);

int width = noiseImage.GetWidth();
int height = noiseImage.GetHeight();

heightMapShape.UpdateMapDataFromImage(noiseImage, 0, _amplification);

var shapeScale = new Vector3(_size / (float) width, 1.0f, _size / (float)height);
_collisionShape.SetScale(shapeScale);
_collisionShape.SetShape(heightMapShape);

I can assure it is the same noise texture as it is set as a shader parameter

private Shader _shader = ResourceLoader.Load<Shader>("uid://cqmw3jjm305qi");

... 
  ShaderMaterial material = new();

  material.Shader = _shader;
  material.SetShaderParameter("height_map", _noise);
  material.SetShaderParameter("amplification", _amplification);

  _mesh.SetMaterial(material);
...

But as can be seen on the picture, while the size is correct, the shape doesn't match the displacement. I appreciate any help!

#

I've added some normal recalculation to enhance the visibility

warm haven
#

The collision mesh has many more triangles than the visual one. Reduce map_width and map_depth to closer match the plane's divisions

jovial nacelle