Search Unity

[RELEASED] RealSunAR - Sun and shadows matching the real world on your AR project

Discussion in 'Assets and Asset Store' started by A_Savvidis, Jun 15, 2019.

  1. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    RealSunAR.jpg
    Real sun & shadows for your AR project
    that match the real Sun!


    STORE URL: https://assetstore.unity.com/packages/slug/148713
    Version 2.10
    ---------------------
    Made to work for all AR SDKs/Toolkits!

    What does RealSunAR™ do?
    It creates & rotates a directional sun at the same place as the real Sun. In other words it's currently the only way to give illumination & shadows on your AR objects that match those of the real sun!

    Hasn't google released something like that?
    In a few words... No. Google's light estimate is only good for interior scenes. You can find more about this here.
    and you can download the comparison app using this link.

    Is there a demo?
    Yes. You can download an android .apk file to install on your ARCore compatible android phone. Use this link to download.

    Is it hard to use?
    Just drag and drop one script on a root gameobject and you are done!
    You don't have to think about it. I've also included tooltips on everything.
    Version 2.00 now comes with a debugging mode for all you statistics maniacs out there.

    Features
    • Made to be super easy, everything is automated
    • Includes tool to simplify switching the lights from sun to internal and vice versa
    • My own algorithm for smoothing compass values
    • An internal compass drift detector
    • Sun updates as time passes
    • Countless sail-safe mechanisms under the hood
    • Tips & warnings appear on the inspector or the console (optional)
    • The Sun's intensity as well as it's color will change at altitudes near Horizon
    • The shadow's strength is automatically set according to the local weather!
    • Regularly Updated
    • Open source
    • Constant top quality support

    How does it do that?
    Basically, it uses the phone's GPS and Compass to figure out where you are and where you are looking then it uses my own algorithm to position the sun taking account all that, as well as June/December solstice and comes with a ShadowCatcher material that acts as a plain ground that shows shadows. Also, it takes into account other elements such as:
    • Weather (Through the OpenWeatherMap API)
    • The device's tilt (compass tends to get reversed when looking over 90 degrees)
    • If the phone was shaking around (compass stability)
    • If the camera is indeed starting generating it's own rotation coordinates

    Will it work for me?
    Still sceptical? You can use this free tool (Unity package file) to verify that it does work under your AR SDK & hardware!

    Where was it tested?
    It's been tested & verified in:
    • Greece
    • Germany
    • UK
    • USA

    Verified compatibility with Unity versions
    • 2019.3.0b4
    • 2019.2.6
    • 2019.1.8
    • 2019.1.7
    • 2019.1.5
    • 2018.4.9
    • 2018.4.2
    • 2018.4.0 (I submitted the plug-in using this version)
    • 2017.4.32
    • 2017.4.29
    • 2017.4.28
    RealSunAR works in both Mono & IL2CPP scripting backends.

    Is it 100% accurate?
    Simply put, that's impossible. It all comes down to the compass accuracy as well at the camera rotation value your AR SDK/Toolkit produces. And phone's compasses do drift a bit all the time. Expect a +/-15 degrees error in most cases. The good news is that this is not enough to ruin the experience but don't take my word for it, download the demo app and see for yourself.

    Support
    If you need to ask anything/need help or have suggestions just email me or write on the support forum. Thank you.
    Forum
    Android ARCore demo
    Manual (PDF)
    Developer's LinkedIn
    • Email: RealSunAR@gmail.com

    Please remember to RATE & REVIEW
    Thank you!
    STORE URL: https://assetstore.unity.com/packages/slug/148713
     
    Last edited: Feb 20, 2020
  2. nigel-moore

    nigel-moore

    Joined:
    Aug 28, 2012
    Posts:
    26
    Hi, I am having some issues with your plugin where the shadows don't match the sun direction in the real world, even in your demo apk. Strangely when I tested the demo yesterday before buying your plugin it appeared to be working correctly, however today I get different shadow directions depending upon which direction I am facing when I initialise the app. Also in my scene I allow the user to rotate the AR object but this also rotates the direction of the shadows. Quite confused by this behaviour, have you any ideas what might be going on?
     
  3. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Hi there nigel-moor. Thank you for reaching out. Yes I have an idea of what's going on.
    Most of the time this is caused due to poor compass reading. Try doing that typical "8" type of motion on the device.
    However I currently coding the update to the plugin that should feature compass drift detection, meaning that each 5 seconds the plug in will check to see if there was a drift more that +/- 10-15 degrees and kick in the calculations from the start.

    Now about that other issue: "Also in my scene I allow the user to rotate the AR object but this also rotates the direction of the shadows".

    I do recommend placing the RealSunAR gameobject at the root of the hierarchy, did you by any chance placed it as a child of that AR object? That would explain such behavior.
     
  4. ibompuis

    ibompuis

    Joined:
    Sep 13, 2012
    Posts:
    100
  5. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
  6. algida74

    algida74

    Joined:
    Dec 3, 2019
    Posts:
    1
    Hi,
    is it working without ground detection?
    I use a gps based 3d model position (for a building) and there isn't ground recognition.
    can i just use a plane under the model with the transparent shadow catcher shader?
    thanx for your time
     
  7. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    It doesn't require gps detection.
    It does require:
    GPS
    Compass
    A proper Camera.y rotation value (if the device rotates the y rotation should rotate properly)

    In 2 days I will begin drafting a test script to help people figure out of RealSunAR works or not as a Unity C# script. and also 2-3 other changes in the next update.
     
  8. vinzer_x

    vinzer_x

    Joined:
    Apr 2, 2013
    Posts:
    7
    Hi, is it possible to bypass GPS usage and input specific location coordinates? I plan to use your plug-in in a simulation instead of AR. Thanks for your time!
     
  9. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    You don't need my plugin for that. There are websites such as this which can give you the info you are looking for.
     
  10. dokterdok

    dokterdok

    Joined:
    Dec 17, 2019
    Posts:
    3
    Hi Antonis, great plugin, thank you for making it!
    I'm very new to using Unity so please forgive me if I ask dumb questions.

    After a little bit of testing, I ran into those minor issues. Perhaps you have a workaround to point me to? I have an app where I make animated objects appear in AR.

    - When my gameobjects walk around and turn (e.g. walking to the left), their shadow turn with them. Ideally I'd like the lighting/shadow to keep their initial angles.
    - Making multiple gameobjects appear makes them over exposed, as if an extra sun was each time added to the scene. Can this be avoided?
    - Once the sun shadow angle is calculated for one gameobject, if would be great if new gameobjects instantly received the same shadow configuration without needing to wait a few seconds.

    Thanks for any help!
     
  11. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    There are no dump questions friend. Keep digging and keep learning each day! Knowledge never ends!

    Now about the issue... from what I can see from your descriptions is that you used more than one instance of the RealSunAR script when you only needed to use only one copy of it no matter how many object you have on your screen.
    One thing that could cause that if you have things not being destroy when loading new scenes etc.

    I got to go out for a few minutes. If you can't fix it with what I wrote email me so we can solve it by emails or web-chats. Whatever suits you! And after that please remember to rate my plugin!

    Thank you and by the way, the new version is 95% done already, it will soon come out.
     
    Last edited: Jan 15, 2020
    dokterdok likes this.
  12. dokterdok

    dokterdok

    Joined:
    Dec 17, 2019
    Posts:
    3
    Thank you for the quick feedback! You nailed it.
    I was indeed using the script many times over as I had it wrongly attached to a non-root GameObject that I kept instantiating. To fix this, I simply created an empty root GameObject in my scene for the RealSunAR script.
    Looking forward for the next update!
     
  13. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    So glad to hear that! Please remember to rate my plugin it means a lot to me! Thank you
     
  14. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Wow ! This is really cool and very very handy solution. Thx !:)
     
  15. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Thank you a lot for your kind words! I would really appreciate it if you could take a moment and rate my work. In a few days I'm pushing my update with the following changes:

    ADDED: Android will now request coarse location permission so that the end user doesn't have to enable it manually.
    ADDED: Setting to interpolate sun intensity according to it's altitude angle.
    ADDED: Setting to interpolate sun color according to it's altitude angle.
    ADDED: help url button on RealSunAR's gameobject component now links to the pdf manual.
    CHANGED: Location canvas is now deactivated instead of destroyed
    IMPROVED: Script inspector now hides the fields that are not to be used according to user choices.
    IMPROVED: Script tooltips.
     
    dokterdok likes this.
  16. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    RealSun 2.10 is out!
    (changes since version 2.00)

    -ADDED: Android will now request coarse location permission so that the end user doesn't have to enable it manually.
    -ADDED: Inspector Setting to interpolate sun intensity according to it's altitude angle.
    -ADDED: Inspector Setting to interpolate sun color according to it's altitude angle.
    -ADDED: Inspector Setting that keeps the GPS service on after RealSunAR starts (maybe your own scripts demand GPS services too)
    -ADDED: Inspector help URL button on RealSunAR's gameobject component now links to the PDF manual.
    -ADDED: Script to exchange RealSunAR light to artificial light and vice versa.
    -ADDED: Singleton design doesn't allow more than one instances of RealSunAR (kudos to "dokterdok" for finding that bug)
    -FIX: RealSunAR would not fire up timed orbit recalculation in some cares
    -CHANGED: Location canvas is now deactivated instead of destroyed
    -IMPROVED: Script inspector now hides the properties that are not to be used according to other inspector settings.
    -IMPROVED: Script tool-tips.
    -IMPROVED: Minor GPS energy save improvement.
    -MANUAL: Improvements.

    Please remember to rate my plugin!
     
    dokterdok likes this.
  17. CherryEngine

    CherryEngine

    Joined:
    Sep 10, 2015
    Posts:
    19
    Hi Antonis,
    Thanks for making it that great plugin! But I think I've found a bug - works on iOS (tested on iPhone 8 plus and XS max)
    openweathermap
    You are starting IEnumerator GetRequest() in Start without checking if GPS coordinates are working -
    So every time you got cloudiness of lat=0, long=0
    you can check that by sending "URL" to text field - before you get the answer!

    Fix - StartCoroutine, not in Start but when you will get GPS data.

    Best,
    Tom
     
  18. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Thank you for your interest and your kind words fellow developer!

    That is a bit weird as the

            while (!gotGPSlock)
    {
    yield return new WaitForEndOfFrame(); // just wait here till we sort out where we are!
    }


    part found in IEnumerator GetRequest() exists for that purpose. So that the plugin asks for weather data only after it locks to GPS. Unless I understood something wrong from your message.

    I'm already doing some updates to that plugin and I'm thinking of doing some major refactoring too. I'll keep that in mind but please send any more info if you can/have.
     
  19. TomZubr

    TomZubr

    Joined:
    Nov 4, 2020
    Posts:
    3
    Is there a way to input my own lat long coordinates so the sun with appear in the correct place without enabling the GPS?
     
    A_Savvidis likes this.
  20. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Now that's a good question! The short answer is no but I can push it in a quick update next week if you need this. Just let me know.
     
    TomZubr likes this.
  21. TomZubr

    TomZubr

    Joined:
    Nov 4, 2020
    Posts:
    3
    Hi again, From my testing I dont think that is required but thank you for the fast response. In turn I would like to ask another question. I live in the UK and have been testing it but the shadows are slightly longer than i'd expect. Ive taken a look through the manual that comes with it and have fiddled with the variables within the inspector but cant seem to find the source. What would your initial thoughts on that be?

    I also have another question(Sorry for the bombardment). With the app I am developing it can only be used in one location and must be calibrated by a stationary object in that location meaning they are always going to be in the same place looking the same way. In this instance I don't require a compass. Can i detach the compass functionality and only use the already known bearing that i have once the scene is placed thus no longer requiring the access of the compass?

    Thank you ever so much for your attention and time thus far, any assistance in these minor problems would be perfect :)
     
    Last edited: May 28, 2021
  22. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Hi there Tom. There are so many reasons for slightly longer shadows. First of all the plane detection usually is a few cm above the actual ground, second of all compasses always drift a bit and third my algorithm is not astronomy grade or anything like that. It's a very close approximation and does work fine, I tested it in London myself back when travel was allowed and it seemed realistic enough (didn't measure the shadow of "The Shard" though!!!).

    As for the 2nd question... a quick way to fix it is set the compass quality method to simple instead of superb and then go to those lines and change those to
    line179-180: comment those out so that they don't run at all

    Code (CSharp):
    1.         //Input.compass.enabled = true;
    2.         //Input.compensateSensors = true;
    line 185 & 208: comment those out
    Code (CSharp):
    1. //float nullVariable = Input.compass.trueHeading;
    line 249
    Code (CSharp):
    1. float myOffset = (compassReadout == compassQuality.Superb) ? CameraToCompassAverage(measuringCompass) : mainCamera.rotation.eulerAngles.y - Input.compass.trueHeading;`
    Here all you have to do is remove the "Input.compass.trueHeading" and substitute it with a variable holding the heading your stationary phone is facing at.
    line 317: same thing as 249
    line 418 change it to :
    Code (CSharp):
    1. if (gotGPSlock)
    lines 526-532: comment those out so that they don't run at all
    Those should be fine. Let me know how it goes.
     
    TomZubr likes this.
  23. TomZubr

    TomZubr

    Joined:
    Nov 4, 2020
    Posts:
    3
    Hello,

    So I have gone away and attempted these changes. Once I had removed all of the compass related code you provided shadows would not appear. I am connected to the internet and have location services active, when I reverse the changes the shadows appear again so I have a feeling its going to take more tweaking. For context all I have within a plane tracking prefab is a stick standing vertically with a plane below it with the shadows shader attached.

    Although I am submitting these problems I by no means have any problems with the asset it is a brilliant approximation and would be perfect in almost all projects except in the strange context I am using.

    If you could look into inputting my own latitude and longitude and having a way of avoiding using compass to draw a basic approximated shadow. Thanks again for your help
     
  24. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    I'm sorry about that. It seems I missed something as I was going through my code. However since I'm currently on vacation I will be able to respond about 10 days after today.
     
  25. Harald_Heide

    Harald_Heide

    Joined:
    Jul 22, 2015
    Posts:
    81
    Could this be easily modified to work with xr pico4 seethrough? Also is urp supported? Thx
     
  26. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Hmmm @Harald_Heide I can't think of a reason for it not to work with pico as long as pico gives compass readings (does it?). As for URP. email me at info@synthercat.com and I'll send you a shader for that.
     
  27. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
  28. IF_test

    IF_test

    Joined:
    Feb 27, 2017
    Posts:
    13
    @A_Savvidis i want to get real position of sun and real shadows of 3d objects placed on google map for my webgl app. these shadow will be later used to calculate its area and exclude its are from main drawing area on map.
     
  29. tengkutruxr

    tengkutruxr

    Joined:
    Dec 28, 2022
    Posts:
    2
    Hi, May I know if this plugin work for unity 2021.3 LTS? I am targeting for mobile AR android/ios
     
  30. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    I am sorry but you cannot use the current version of my plugin for that purpose as it uses the compass of the device for its calculation so it cannot actually be used for a 2d calculation.
     
  31. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    Hello there Tengku! As I haven't recently updated my plugin I cannot confirm it works on that version but I will do that soon, and I will let you know how it goes. I will also send you a new shader so that you can utilize it with the URP. I think I will have an answer by tomorrow.
     
  32. christophe_unity

    christophe_unity

    Joined:
    Jan 18, 2023
    Posts:
    3
    Hi Antonis,

    I bought your plugin a few month ago and it's really cool and work very well on my AR scenes!
    I am trying to use it with the google geospatial API though and am running into issues with it. I think that the sun initializes but I can't see it on my objects that are anchored to the scene. I thought that the sun being too far from the objects was a problem so I anchored it at the same location but same problem here.
    Have you tried it with Google geospatial API by any chance?

    Thanks!

    Chris