sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

Model shadow on ARSceneView

Open pablojoseoroz opened this issue 1 year ago • 5 comments

Any example to show a model shadow? I try with LightNode, adding PlaneNode below ModelNode, setting isShadowCaster and isShadowReceiver, changing scenes lightEstimation, adding custom LightNode to scene... But never appears model shadow :-(

fun addModelNodeLocalOnHit(context: Context, hitResult: HitResult, model: String) {
        sceneView.modelLoader.loadModelAsync("models/$model") {
            it?.let {
                val parent = createAnchorNode(hitResult)
                ModelNode(
                    modelInstance = it.instance,
                    parent = parent,
                    centerOrigin = Position(y = -1f),
                    scaleToUnits = 0.004f
                ).apply {
                    //isEditable = true
                    isShadowCaster = true
                    isShadowReceiver = false
                }.also {
                    PlaneNode(
                        getEngine(),
                        size = Size(0.5f, 0.1f, .5f),
                        center = Position(y = -.5f),
                        materialInstance = MaterialLoader(getEngine(), context)
                            .createColorMaterial(Color(1f, 1f, 1f, 1f), 0f, 0f, 0f),
                        parent = it
                    ).apply {
                        isShadowCaster = false
                        isShadowReceiver = true
                    }
                }
                addChilNodeToScene(parent)
}

Thanks!

pablojoseoroz avatar Nov 17 '23 11:11 pablojoseoroz

I've never gotten shadows to work either.

ryust avatar Feb 06 '24 22:02 ryust

Did you find a solution for adding the shadow?

natasam avatar Feb 24 '24 20:02 natasam

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 25 '24 05:05 github-actions[bot]

@pablojoseoroz try to use the following material for the PlaneNode and ensure ModelNode is between directional light and plane.

4.2.29 Lighting: shadowMultiplier

material {
    name : GroundShadow,
    blending : transparent,
    shadingModel : unlit,
    shadowMultiplier : true
}

fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);
        material.baseColor = vec4(0.0, 0.0, 0.0, 0.5); // 0.5 is strength of the shadow. Change it or modify to use parameter.
    }
}

also check if shadows are enabled in the view

engine.createView().apply {
   setShadowingEnabled(true)
}

Dreiko avatar May 30 '24 16:05 Dreiko