armory3d / armory

3D Engine with Blender Integration
https://armory3d.org
zlib License
3.07k stars 315 forks source link

LOD’s not working as expected on plane’s or grid’s? #1278

Open rossoe opened 5 years ago

rossoe commented 5 years ago

SHORT DESCRIPTION:

Having opened the example - LOD blend file I created both a Plane and a Grid But running Krom (Armory Player) I cannot seem to get materials against the various LOD's to cycle through their different states - as set up in properties.

EXPECTED RESULT:

As you move the camera away from Grid or Plane, the LOD & associated materials will cycle through whatever I've set against the object.

ACTUAL RESULT:

Objects like Monkey, Cube and Sphere work fine and switch through the various LOD’s & different materials applied as you move away. However the Plane and Grid does not change it’s material (colour)? It appears to only show in Krom the material from the last LOD for any given plane or grid?

image

STEPS TO REPRODUCE:

Steps:

  1. Create plane or grid
  2. Auto generate 2 LOD's tick 'Material Lod'
  3. Create material for original object - set colour
  4. Create materials for associated LOD's - set different colours
  5. Run Krom (Armory Player)

TECHNICAL SPECIFICATIONS:

What version(s) of the following did you try: Blender: 2.8beta Armory: 0.7.0 (recent git) Operating system: Win 10 Graphics card & driver: GTX960 latest Nvidia

TEST FILE TO REPRODUCE:

https://1drv.ms/u/s!AjCedBZJ5Eh4jBAwxl0N1G9Cuvd-

paxetgloria commented 5 years ago

Hi @rossoe, Miro here, I had a look at your file and it seems that it's mainly happening because of the fact those planes and grids have dimension Z = 0. I did a dirty trick and added a single vertex to each grid LOD's mesh and shifted it 2 meters above grid mesh, this way it becomes "volume"(dimensionZ=2) and LODing starts working. Untitled-1

MoritzBrueckner commented 4 years ago

I think the issue is caused by iron.MeshObject.computeScreenSize(): https://github.com/armory3d/iron/blob/dd61dd852ac9995e1fba9e48c8110f906e6abca7/Sources/iron/object/MeshObject.hx#L342

public inline function computeScreenSize(camera: CameraObject) {
    // Approx..
    // var rp = camera.renderPath;
    // var screenVolume = rp.currentW * rp.currentH;
    var tr = transform;
    var volume = tr.dim.x * tr.dim.y * tr.dim.z;
    screenSize = volume * (1.0 / cameraDistance);
    screenSize = screenSize > 1.0 ? 1.0 : screenSize;
}

If at least one dimension equals 0, the volume is 0, thus the objects screenSize is 0 too. This is used at https://github.com/armory3d/iron/blob/master/Sources/iron/object/MeshObject.hx#L244.

Is there any advantage of using the screenSize for LOD over the distance of the object? It is more accurate if the "origin" of the visible mesh is not at the origin position of the object, but that could probably be achieved by calculating the center of the visible mesh and using that for distance calculation?