sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Info] Ambient Occlusion -> Simple Rays

    Scheduled Pinned Locked Moved Plugins
    66 Posts 22 Posters 75.5k Views 22 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      @qpik said:

      plane = [face.vertices[0].position, face.normal]

      You can use face.plane instead

      @qpik said:

      This could be optimized by passing pre-sorted face array (based on results from previous tests) instead of browsing entities array, but I doubt it would speed it up much.
      What do you think?

      hmm... If you only iterate the entities collection once then it won't help to pre-process to filter out only faces. Infact, that would mean more iterations. But if you need to iterate the face multiple times, then you will save time on pre-filtering.

      @qpik said:

      I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.

      Isn't that the same thing?

      @qpik said:

      I quickly wrote this, but it worked MUCH slower than original method.

      You're writing a ruby method to be faster than a C method - that C method must be doing a lot of extra processing in order to be able to out-perform it in Ruby.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • Q Offline
        qpik
        last edited by

        @thomthom said:

        You can use face.plane instead

        Somehow I didn't notice that one in the API πŸ˜„

        @thomthom said:

        hmm... If you only iterate the entities collection once then it won't help to pre-process to filter out only faces. Infact, that would mean more iterations. But if you need to iterate the face multiple times, then you will save time on pre-filtering.

        I meant to sort the collection before proceeding to the next testing point. The faces that got hit before might as well be the first to get hit by rays cast from adjacent point.

        @thomthom said:

        @qpik said:

        I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.

        Isn't that the same thing?

        I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

        @thomthom said:

        @qpik said:

        I quickly wrote this, but it worked MUCH slower than original method.

        You're writing a ruby method to be faster than a C method - that C method must be doing a lot of extra processing in order to be able to out-perform it in Ruby.

        That is certainly true. That is why I managed to connect with a DLL using Win32api.call (BTW thanks to TBD for his SUDLL example).
        Now I'm on my way to moving everything to C. I hope this will finally give a speed boost.

        I'm looking into Ruby-OpenGL as well for another approach.
        Here is an example - http://forums.sketchucation.com/viewtopic.php?f=180&t=20893&p=209966#p209966

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @qpik said:

          I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

          that would be very odd. if it did produce a full array before returning I think it should return the full array.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Q Offline
            qpik
            last edited by

            But then how would it find out the closest intersection?

            ps. I write all this out of my head, I'm not familiar with 3d algorithms.

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomasz
              last edited by

              @qpik said:

              I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

              I think it does break after first positive hit. Make sure you check if the object is not hidden or on a hidden layer, otherwise your rays will stop too early when hidden layer present in a model.

              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

              1 Reply Last reply Reply Quote 0
              • Q Offline
                qpik
                last edited by

                Yeah, but how would the method know if the first hit is the closest?
                It could be for example some distant face that got hit first, because it was first in the collection.

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  Did you ever find any improvements that could be made?

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • Q Offline
                    qpik
                    last edited by

                    I planned writing new method in C and calling it via Win32api... but I never find time and enough determination to do it. I wish somebody else did it instead πŸ˜„, someone who knows C, unlike me.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      I'm also an C ignorant... 😞

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        KiraNL
                        last edited by

                        Any chance this ever might come out which works for round shapes?
                        Love to use this as subtile shadows over the textures, sort of lighting baking.

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          seikun
                          last edited by

                          how can i download the plug-in

                          1 Reply Last reply Reply Quote 0
                          • GaieusG Offline
                            Gaieus
                            last edited by

                            It's attached to the first post of the topic. But it is not yet tested on SU version 9 - so it may not work for you (unless you made a typo when registering in which case, could you correct it, please?).
                            πŸ˜‰

                            Gai...

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              tomasz
                              last edited by

                              Hi Kuba,

                              Nice to see another Polish architect in action as a programmer. πŸ˜„
                              I am getting more and more comfortable with C++, but I do not expect to be able to help you within next few months.
                              I won't forget you effort and if I will find time, I will see whether I can help you with the raytest issue.

                              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                              1 Reply Last reply Reply Quote 0
                              • Dan RathbunD Offline
                                Dan Rathbun
                                last edited by

                                This "plugin" (using the term liberally,) has been NOMINATED for QUARANTINE.

                                see: [Candidate] Quarantine: Ambient Occlusion by qpik

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • Dan RathbunD Offline
                                  Dan Rathbun
                                  last edited by

                                  NOTICE: Preliminary Overhaul of the SimpleRays plugin !

                                  Developers' forum: [Plugin] Qpik::SimpleRays OVERHAUL

                                  I did this overhaul so we can remove SimpleRays from the Quarantine List

                                  Jakub, where are you ?

                                  ❓

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • Q Offline
                                    qpik
                                    last edited by

                                    I'm back πŸ˜„

                                    1 Reply Last reply Reply Quote 0
                                    • jiminy-billy-bobJ Offline
                                      jiminy-billy-bob
                                      last edited by

                                      http://i.imgur.com/Sd7uce4.jpg

                                      25% off Skatter for SketchUcation Premium Members

                                      1 Reply Last reply Reply Quote 0
                                      • TomPendergrassT Offline
                                        TomPendergrass
                                        last edited by

                                        Hello SketchUcators!

                                        I have a lot of interest in this topic. While modeling in Sketchup can be bliss, creating impressive visual displays without a full blown renderer is very difficult. Being a game developer hobbyist, this limitation keeps me in Blender for most of my game related art.

                                        Anyways, I was curious about raytest and what it's quirks were. As was stated earlier in this thread, limiting the raytest's scanning distance could be the solution to faster raycasting. Unfortunately, the ruby API doesn't offer this option; I suppose all rays are infinite (or my theory is the raytests are to the bounds of the scene.)

                                        I decided to do a test: I made a ruby method > raytest_repeating(ray, repeatCount) and cast a ray along the y axis 10,000 times. With no obstructions, it completed it's process on average around 0.15 seconds. Introducing two cubes in separate groups to intersect with, the same method took about 0.68 seconds on average. Here's the interesting part. I placed 2000 groups along the y axis and ran the same method again. This process took ~938 seconds to complete! Keeping the same cubes in the scene and moving all but two of them out of the ray path dropped the calculation back down to the 0.68 average!

                                        In conclusion, raytest must be spending time on all objects the ray interesects, even though it only returns the closest object. It's no wonder your occlusion process drops to a crawl in dense scenes, since I assume you're casting hemispherical rays into 'infinite space', colliding with EVERYTHING along the way! I believe a possible solution to your problem is to find the faces that are in the range of a raytest (IE, nearby faces that actually effect the shading) and to dynamically hide the rest of your scene as needed. Since the raytest can ignore hidden objects, it should speed up the overall process considerably. I ran one final test with the 2000 cubes, hiding all but 2 of them. While the process was slower, 10,000 rays came back in 5.2 seconds, which is far better than 938!

                                        I hope my findings can assist you on this wonderful creation of yours!

                                        -Thomas Pendergrass

                                        1 Reply Last reply Reply Quote 0
                                        • Q Offline
                                          qpik
                                          last edited by

                                          Thanks, good to know that.
                                          But what would be the method to define relevant shading objects, an object's area to sphere-at-the object-distance area ratio?

                                          1 Reply Last reply Reply Quote 0
                                          • TomPendergrassT Offline
                                            TomPendergrass
                                            last edited by

                                            Hey qpik,

                                            I know it's been a whole year, I didn't notice that you had posted back on the forum. You're right, you'd need to do a check of what is in your range, and hide everything else. I actually made a script for this way back when, but it remains to be purely experimental. What I did was accept a point in space and created a square bounding box, since bounding spheres aren't really a thing. From that I can iterate through the scene and hide any group that isn't touching my bounding box by using the .contains? method (.contains in versions before 2015 returned invalid results sometimes).

                                            Assuming a dense scene is constructed of small groups, you could do this .contains check for every x amount of rays you cast and hide the irrelevant geometry. It's a patchy fix to a clunky raycast system, but it may fit all of your needs. If you're still interested in this topic, let me know and I'll dust off the old code and post it here.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 1 / 4
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement