ScreenSpaceToWorldSpace but Z is a value from the Depth render target?

Ines Hilz
Ines Hilz Posts: 38 🔥

Hi all :)
I'm working with the city landmarker right now and have to find a way to spawn objects on the building fasades of London.
I managed to get a depth render target and screen space normals, and i know that i can place objects in the world with this little script:

//@input SceneObject TestSphere
//@input Component.Camera camera

var event = script.createEvent("TouchStartEvent");
    var touchedPos = eventData.getTouchPosition();
    var objPos =, 40.0)

I wonder if i can somehow use my normals/depth texture data instead of hard coding the distance in where i place the TestSphere?

Best Answer

  • Max
    Max Posts: 26 🔥
    #2 Answer ✓

    Yes! Using the Depth Texture controls, you can request the depth at a certain screen position.

    This will print the depth of the Depth Texture at the center of the screen (which has a screen position of 0.5, 0.5)

    //@input Asset.Texture depthTexture
    var depth = script.depthTexture.control.getDepth(new vec2(0.5, 0.5)); // distance (world units / cm)

    And another example: this will print the depth at the position where you tap on the screen

    //@input Asset.Texture depthTexture
    function onTap(args){
        var screenPosition = args.getTapPosition();
        var depth = script.depthTexture.control.getDepth(screenPosition); // distance (world units / cm)
    var onTapEvent = script.createEvent('TapEvent');