Search Unity

AR app (Shadow Problem) I have a problem to Creating Shadow using Vuforia

Discussion in 'Vuforia' started by sweetan, Mar 30, 2018.

  1. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    Hi,
    I have created Some AR app using Vuforia Marker SDK. I was tried to create a shadow but It's Not worked well.
    My problem Was :
    When I zoom in the camera that time shadow will appear I tried AR camera zoom out my camera Shadow disappear.
    Unity version: 2017.3.0 P2
    Vuforia Version: 7.1.30
    Help me to Solve this problem.
    I have attached my Quality settings below
    Thanks & Regards
    Sweetan.M
     

    Attached Files:

    • sc.png
      sc.png
      File size:
      56.9 KB
      Views:
      777
  2. weliketoparty

    weliketoparty

    Joined:
    Aug 17, 2011
    Posts:
    124
    You need to increase the Shadow Distance on the Quality settings depending on how far the marker will be placed. Vuforia take control of your camera based on the marker position. The camera might be very far from the marker and your graphic, this means the unit is not anymore 1unit=1meter. This will reflect on the shadow not being visible.

    I also suggest you to check how far the camera is from you marker using something like that. Code not tested

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class TestDistance : MonoBehaviour {
    7.  
    8.     [SerializeField]
    9.     [Tooltip("Drag your Vuforia marker here, inside the inspector")]
    10.     private Transform marker;
    11.     [SerializeField]
    12.     [Tooltip("Drag your camera here, inside the inspector")]
    13.     private Transform camera;
    14.     [SerializeField]
    15.     [Tooltip("If TRUE, it automatically sets the Shadow Distance on the QualitySettings. Although it's not recomended")]
    16.     private bool setShadowDistanceAutomatically;
    17.  
    18.     void Update (){
    19.  
    20.         var distanceBetweenMarkerAndCamera = Vector3.Distance(marker.position , camera.position);
    21.         var currentShadowQuality = QualitySettings.shadowDistance;
    22.         var isShadowDistanceSmaller = (currentShadowQuality < distanceBetweenMarkerAndCamera);
    23.         Debug.Log("The Distance Between Marker and Camera is: " + distanceBetweenMarkerAndCamera.ToString("F0"));
    24.  
    25.         if (isShadowDistanceSmaller) {
    26.             Debug.Log("The Shadow Distance is smaller than the distance between the camera and marker.");
    27.             if (setShadowDistanceAutomatically){
    28.                 int newShadowDistance = (int)distanceBetweenMarkerAndCamera + 10;
    29.                 Debug.Log("Automatically set the shadow distance to " + newShadowDistance);
    30.                 QualitySettings.shadowDistance = newShadowDistance;
    31.             }
    32.         }
    33.     }
    34. }
    35.  
     
    sweetan likes this.
  3. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    Hi weliketoparty
    Thanks for your replay ...
    Your script was worked very well...Thank you so much.....:):):):):):):)
    Finally, I got the shadow on my AR app
     
  4. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    Vuforia-Strasza likes this.
  5. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    It's worked thank you so much. And I have another problem too How to smooth a shadow (Now it's pixelated)