Skip to content

Strange light behavior with different far plane values of orthographic camera #4473

@kirusfg

Description

@kirusfg

Bevy version

latest (8630b19)

Operating system & version

OS: Artix Linux x86_64
Linux Kernel: 5.17.2-zen2-1-zen
GPU: NVIDIA GeForce 920MX
Nvidia driver: 510.60.02-1

What you did

Loaded a glTF scene with an orthographic camera and a point light in it:

use bevy::prelude::*;


fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn_scene(asset_server.load("ortho10.gltf#Scene0"));
}


fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

To test and experiment with this, edit the zfar field of the camera in the file provided:

ortho10.gtlf
{
    "asset" : {
        "generator" : "Khronos glTF Blender I/O v1.8.19",
        "version" : "2.0"
    },
    "extensionsUsed" : [
        "KHR_lights_punctual"
    ],
    "extensionsRequired" : [
        "KHR_lights_punctual"
    ],
    "extensions" : {
        "KHR_lights_punctual" : {
            "lights" : [
                {
                    "color" : [
                        1,
                        1,
                        1
                    ],
                    "intensity" : 1000,
                    "type" : "point",
                    "name" : "Light.001"
                }
            ]
        }
    },
    "scene" : 0,
    "scenes" : [
        {
            "name" : "Scene",
            "nodes" : [
                0,
                3,
                6,
                7
            ]
        }
    ],
    "nodes" : [
        {
            "mesh" : 0,
            "name" : "Cube",
            "translation" : [
                0,
                1,
                0
            ]
        },
        {
            "extensions" : {
                "KHR_lights_punctual" : {
                    "light" : 0
                }
            },
            "name" : "Light_Orientation_Orientation",
            "rotation" : [
                -0.7071067690849304,
                0,
                0,
                0.7071067690849304
            ]
        },
        {
            "children" : [
                1
            ],
            "name" : "Light_Orientation"
        },
        {
            "children" : [
                2
            ],
            "name" : "Light",
            "rotation" : [
                0.16907575726509094,
                0.7558803558349609,
                -0.27217137813568115,
                0.570947527885437
            ],
            "translation" : [
                4.076245307922363,
                5.903861999511719,
                -1.0054539442062378
            ]
        },
        {
            "camera" : 0,
            "name" : "Camera_Orientation_Orientation",
            "rotation" : [
                -0.7071067690849304,
                0,
                0,
                0.7071067690849304
            ]
        },
        {
            "children" : [
                4
            ],
            "name" : "Camera_Orientation"
        },
        {
            "children" : [
                5
            ],
            "name" : "Camera",
            "rotation" : [
                0.40501639246940613,
                0.4532789885997772,
                -0.24283890426158905,
                0.7559954524040222
            ],
            "translation" : [
                7.977607727050781,
                6.902405738830566,
                4.161380290985107
            ]
        },
        {
            "mesh" : 1,
            "name" : "Plane",
            "scale" : [
                10.624591827392578,
                10.624591827392578,
                10.624591827392578
            ]
        }
    ],
    "cameras" : [
        {
            "name" : "Camera.001",
            "orthographic" : {
                "xmag" : 10,
                "ymag" : 10,
                "zfar" : 100,
                "znear" : 0.10000000149011612
            },
            "type" : "orthographic"
        }
    ],
    "materials" : [
        {
            "doubleSided" : true,
            "name" : "Material.001",
            "pbrMetallicRoughness" : {
                "baseColorFactor" : [
                    0.057456985116004944,
                    0.0665164664387703,
                    0.8000000715255737,
                    1
                ],
                "metallicFactor" : 0,
                "roughnessFactor" : 0.4000000059604645
            }
        },
        {
            "doubleSided" : true,
            "name" : "Material.002",
            "pbrMetallicRoughness" : {
                "baseColorFactor" : [
                    0.8000000715255737,
                    0.2788206934928894,
                    0.2428315132856369,
                    1
                ],
                "metallicFactor" : 0,
                "roughnessFactor" : 0.5
            }
        }
    ],
    "meshes" : [
        {
            "name" : "Cube.001",
            "primitives" : [
                {
                    "attributes" : {
                        "POSITION" : 0,
                        "NORMAL" : 1,
                        "TEXCOORD_0" : 2
                    },
                    "indices" : 3,
                    "material" : 0
                }
            ]
        },
        {
            "name" : "Plane",
            "primitives" : [
                {
                    "attributes" : {
                        "POSITION" : 4,
                        "NORMAL" : 5,
                        "TEXCOORD_0" : 6
                    },
                    "indices" : 7,
                    "material" : 1
                }
            ]
        }
    ],
    "accessors" : [
        {
            "bufferView" : 0,
            "componentType" : 5126,
            "count" : 24,
            "max" : [
                1,
                1,
                1
            ],
            "min" : [
                -1,
                -1,
                -1
            ],
            "type" : "VEC3"
        },
        {
            "bufferView" : 1,
            "componentType" : 5126,
            "count" : 24,
            "type" : "VEC3"
        },
        {
            "bufferView" : 2,
            "componentType" : 5126,
            "count" : 24,
            "type" : "VEC2"
        },
        {
            "bufferView" : 3,
            "componentType" : 5123,
            "count" : 36,
            "type" : "SCALAR"
        },
        {
            "bufferView" : 4,
            "componentType" : 5126,
            "count" : 4,
            "max" : [
                1,
                0,
                1
            ],
            "min" : [
                -1,
                0,
                -1
            ],
            "type" : "VEC3"
        },
        {
            "bufferView" : 5,
            "componentType" : 5126,
            "count" : 4,
            "type" : "VEC3"
        },
        {
            "bufferView" : 6,
            "componentType" : 5126,
            "count" : 4,
            "type" : "VEC2"
        },
        {
            "bufferView" : 7,
            "componentType" : 5123,
            "count" : 6,
            "type" : "SCALAR"
        }
    ],
    "bufferViews" : [
        {
            "buffer" : 0,
            "byteLength" : 288,
            "byteOffset" : 0
        },
        {
            "buffer" : 0,
            "byteLength" : 288,
            "byteOffset" : 288
        },
        {
            "buffer" : 0,
            "byteLength" : 192,
            "byteOffset" : 576
        },
        {
            "buffer" : 0,
            "byteLength" : 72,
            "byteOffset" : 768
        },
        {
            "buffer" : 0,
            "byteLength" : 48,
            "byteOffset" : 840
        },
        {
            "buffer" : 0,
            "byteLength" : 48,
            "byteOffset" : 888
        },
        {
            "buffer" : 0,
            "byteLength" : 32,
            "byteOffset" : 936
        },
        {
            "buffer" : 0,
            "byteLength" : 12,
            "byteOffset" : 968
        }
    ],
    "buffers" : [
        {
            "byteLength" : 980,
            "uri" : "data:application/octet-stream;base64,AACAPwAAgD8AAIC/AACAPwAAgD8AAIC/AACAPwAAgD8AAIC/AACAPwAAgL8AAIC/AACAPwAAgL8AAIC/AACAPwAAgL8AAIC/AACAPwAAgD8AAIA/AACAPwAAgD8AAIA/AACAPwAAgD8AAIA/AACAPwAAgL8AAIA/AACAPwAAgL8AAIA/AACAPwAAgL8AAIA/AACAvwAAgD8AAIC/AACAvwAAgD8AAIC/AACAvwAAgD8AAIC/AACAvwAAgL8AAIC/AACAvwAAgL8AAIC/AACAvwAAgL8AAIC/AACAvwAAgD8AAIA/AACAvwAAgD8AAIA/AACAvwAAgD8AAIA/AACAvwAAgL8AAIA/AACAvwAAgL8AAIA/AACAvwAAgL8AAIA/AAAAAAAAAAAAAIC/AAAAAAAAgD8AAACAAACAPwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIC/AACAPwAAAAAAAACAAAAAAAAAAAAAAIA/AAAAAAAAgD8AAACAAACAPwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIA/AACAPwAAAAAAAACAAACAvwAAAAAAAACAAAAAAAAAAAAAAIC/AAAAAAAAgD8AAACAAACAvwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIC/AACAvwAAAAAAAACAAAAAAAAAAAAAAIA/AAAAAAAAgD8AAACAAACAvwAAAAAAAACAAAAAAAAAgL8AAACAAAAAAAAAAAAAAIA/AAAgPwAAAD8AACA/AAAAPwAAID8AAAA/AADAPgAAAD8AAMA+AAAAPwAAwD4AAAA/AAAgPwAAgD4AACA/AACAPgAAID8AAIA+AADAPgAAgD4AAMA+AACAPgAAwD4AAIA+AAAgPwAAQD8AACA/AABAPwAAYD8AAAA/AADAPgAAQD8AAAA+AAAAPwAAwD4AAEA/AAAgPwAAgD8AACA/AAAAAAAAYD8AAIA+AADAPgAAgD8AAAA+AACAPgAAwD4AAAAAAQAOABQAAQAUAAcACgAGABMACgATABcAFQASAAwAFQAMAA8AEAADAAkAEAAJABYABQACAAgABQAIAAsAEQANAAAAEQAAAAQAAACAvwAAAAAAAIA/AACAPwAAAAAAAIA/AACAvwAAAAAAAIC/AACAPwAAAAAAAIC/AAAAAAAAgD8AAACAAAAAAAAAgD8AAACAAAAAAAAAgD8AAACAAAAAAAAAgD8AAACAAAAAAAAAgD8AAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAEAAwAAAAMAAgA="
        }
    ]
}

What you expected to happen

Proper lighting

What actually happened

Lighting behaving strangely on different far settings of the orthographic camera set in Blender:

30

30

50

50

100

100

1000

1000

Additional Information

Note that at a 1000, the lighted parts of the scene are not visible in a 16:9 window and I had to stretch it. In #4005, the light was being "cutoff" because the far value was not loaded from glTF, and by default, it was being set to 0. Same thing is happening here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions