Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TheLazyEngineer · Aug 31, 2020 at 12:36 AM · shaderraycastinggpudirectx

Using the DirectX Raytracing API in Unity

I'm trying to find examples / info on how to build custom shaders using the DirectX Raytracing API in unity.


This presentation:


(slides) https://on-demand.gputechconf.com/siggraph/2019/pdf/sig940-getting-started-with-directx-ray-tracing-in-unity.pdf

(video) https://developer.nvidia.com/siggraph/2019/video/sig940-vid


shows exactly what I want to accomplish : use the DirectX API to handle my custom raytracing methods. However, there are not enough details, and it seems like it may be a little out of data now based on the documentation that is available in Unity:


https://docs.unity3d.com/ScriptReference/Experimental.Rendering.RayTracingAccelerationStructure.html


So, here's where my understanding is, and please correct me if I'm wrong (I probably am)!


1)

I need to write a Ray Generation shader by creating a .raytrace shader. This is easy ( I think ). It can be dispatched like a compute shader from the c# side in Unity.

2)

Because the direction of my rays will change continuously as it moves through space searching for an intersection, I need to take more of a ray marching approach with a small step size. So, from the Ray Generation shader, I will call TraceRay() function from the DirectX API on the initially created ray with a small tMax parameter.

3)

Since I am ray marching to find an intersection, and updating the direction of the ray at each step, I need to spawn a new ray on every miss - so I need a custom Miss shader that accompanies my Ray Generation shader (same file?). The miss shader will calculate the new ray direction and origin and call TraceRay() again. So this is a recursive process, and the Miss shader will be calculated MANY times until some max distance traveled by the ray has been reached or until we encounter a hit!

4)

In order to tests for a hit, I need an Intersection shader. Since I will be using meshes in my scene - with mesh renderers, I believe Unity will automatically manage the Acceleration Structure by adding the game objects with a mesh renderer to the structure in order to be tested for intersection. And so I don't think I need to make my own custom intersection shader or manually manage the Acceleration structure. But I'm confused on how exactly I use the RayTracingAccelerationStructure in Unity - the documentation is not clear to me. Can someone clear this up?

5)

When an intersection is encountered, a Hit shader will be called (I don't need to worry about AnyHit shaders I don't think, so we'll ignore those for now). Basically, I just want this shader to return the mesh texture at the intersected UV coordinate. I believe for this I just need to add a Hit shader that does this as a sub shader in the mesh's material, right?

6)

From there I can graphics.Blit the texture that the raytracing writes to (?)


I would really like to see a full unity example that implements these steps like I've laid out. It would be really helpful! Also, if I am misunderstanding something, please let me know.

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

280 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Performance of looping compute shader in Update() 2 Answers

Making a custom shader use GPU Instancing? 1 Answer

Shader Sprites/Default shader is not supported on this GPU iPad 8th Gen iOS 14.5 0 Answers

Read float values from RGBAFloat texture 1 Answer

DirectX 12 Native Plugin: synchronise render-to-screen 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges