Results 1 to 14 of 14

Thread: Cast Ray test - noob Q

  1. #1

    Cast Ray test - noob Q

    I'm not experienced with the ray casting sort of nodes, but would like to be... so here's a quick Q for a project I'm working on now:

    I need to cast a ray in a specific direction that simply reports back if it hit something, or didn't (i.e. hits the background). How?

    The application is a rain/wetness shader that is currently slope-based; it currently "wets" all surfaces facing up, including those that are under something that should keep it from getting wet.

    I can think of several ways to do this conceptually, including the use of a raytraced light where we test for the surfaces that it hits; the shadows would take care of the areas that are covered by other areas. (I'd like this one because I could then use a dome/area light to feather the "wet" areas). But how it works, no ideas.

  2. #2
    Goes bump in the night RebelHill's Avatar
    Join Date
    Nov 2003
    Location
    jersey
    Posts
    5,766
    Teh ray trace node could help you out here... lets you "project" the surface of one object onto another (thus u could create a "sky" poly, and trace from it to the ground)... or ray cast, which fires off rays and reports 1 if it hits something, or 0 if it doesnt. Either of these would let you create a "mask" for your ground surface based on tracing... and as for blurring, you couls further use this mask to mask in/out a procedural to give you broken up edges... or additionally use the DP blue node, etc, etc.

    If you're sued to how the whole nodal system works... just have a play around, and try em out... their use should reveal itself quickly enough with a bit of experimentation.
    LSR Surface and Rendering Tuts.
    RHiggit Rigging and Animation Tools
    RHA Animation Tutorials
    RHR Rigging Tutorials
    RHN Nodal Tutorials
    YT Vids Tuts for all

  3. #3
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    RayCast and RayTrace return distance (Length output) from Ray Origin in Ray Direction (both node parameters) to geometry that has been hit, which can be any value between 0.0 and infinity.
    Otherwise it's returning -1 which means that nothing has been hit, and ray went to sky.
    I am showing how to use this in mine tutorials "How to Control Reflections"
    http://www.youtube.com/watch?v=WjvUxRnNcak
    http://www.youtube.com/watch?v=nP425jM1oGM

  4. #4
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    What a great idea!

    Here you go....


  5. #5
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    Use RayCast, it'll render faster. You don't need surfacing for this kind of job.

  6. #6
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    Quote Originally Posted by Sensei View Post
    Use RayCast, it'll render faster. You don't need surfacing for this kind of job.
    Is that the difference between the two? Thanks.

    Edit :- Just tested it (not that I don't believe you) and it's about 30% quicker!
    Last edited by XswampyX; 05-28-2013 at 02:02 PM.

  7. #7
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    Ray cast is only processing kd-tree, and finding triangle that's the closest to origin in given direction.
    Ray tracing is above plus surfacing, returning result from image map textures, procedural textures, nodes, probably recursive called reflections, refractions, sss, etc. etc.
    How faster is cast method depends on used in scene materials and recursion limit. In really complex scenes might be thousands times faster.

  8. #8
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    Quote Originally Posted by XswampyX View Post
    Edit :- Just tested it (not that I don't believe you) and it's about 30% quicker!
    If you would have SSS, dielectric materials on some objects, or other heavy surfacing techniques, it would be much higher, I guess.

  9. #9
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    Yep I can see that. Thanks again.

  10. #10
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    Works also for a rain grunge texture.


  11. #11
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    I noticed something wrong with your setup- you should better normalize direction prior plugging it to RayCast/RayTrace nodes.
    It's unclear whether they (nodes) normalize vector prior using.
    Actually it would be slowing them down a bit if they would normalize every vector, whether it needs or not.
    Internal version of ray casting function absolutely requires normalized direction vector.

    Bump vectors are from definition not normalized. They're premultiplied by Bump Amount.

    Normalized vector means that length of vector is equal 1.0. You can check whether vector is normalized by f.e. Math > Vector > Length. It should be 1.0.
    So simple check is plug vector to Math > Vector > Length, then to Diffuse Shading (and nothing else plugged to others). If result is absolute white 1,1,1 then vector was normalized.

  12. #12
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    Thanks Sensei, I think I've got it nailed now. The normalize function didn't make any difference to the shader (this time), but it's nice to know how it should work.


  13. #13
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,897
    If you multiply vector by f.e. 1000, Math > Vector > Scale = 1000, and use such as direction for RayCast node you will see there is difference in result in comparison to not multiplied. It means RayCast/RayTrace are not normalizing direction normal vector and this must be done by user.

  14. #14
    Super Member XswampyX's Avatar
    Join Date
    Aug 2010
    Location
    Kernow
    Posts
    2,076
    Ok. I have put it in there.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •