Search Unity

Question Toggling raytracing in a script?

Discussion in 'High Definition Render Pipeline' started by AIProgrammer, Jan 16, 2024.

  1. AIProgrammer

    AIProgrammer

    Joined:
    Jun 14, 2021
    Posts:
    2
    I've set up HDRP and created an HDRP asset with all the settings I want (using set-up guide recommended ones) and I would like to be able to toggle RT using a boolean. How would I do this?
     
  2. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    765
    Best way would be to have two HDRP asset (one with Real time ray tracing ON and the other OFF). And then you can easily switch at runtime between quality setting using SetQualityLevel.

    upload_2024-1-17_8-38-3.png

    You can also do it per camera if you'd like by using custom frame settings. Those can also be modified at runtime following this example from documentation.

    upload_2024-1-17_8-37-0.png

    Cheers.
     
  3. Jack_Martison

    Jack_Martison

    Joined:
    Jun 24, 2018
    Posts:
    143
    But what about switching between DX11 and 12? For example, I want more performance gain with DX12 and RT, I can switch only in player settings, meaning I can only have separated builds with DX11 and 12?
     
  4. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    765
    you can put both DX11 / DX12 in your windows graphics APIs settings and then launch the exec using arguments.
    So like -force-d3d12 for dx12.. etc. So you'll still need to "relaunch" the exec for switching but you can keep one build.
     
    Remy_Unity and Jack_Martison like this.