Search Unity

GPU Raytracing: Accessing Materials in a Compute Shader

Discussion in 'Shaders' started by lumoconnor, Oct 19, 2018.

  1. lumoconnor

    lumoconnor

    Joined:
    Jan 17, 2016
    Posts:
    27
    Hey everyone. I'm currently working on a GPU Raytracing Renderer, implemented using a Compute Shader.

    So far I have managed to pass all the geometry in the scene across to the shader using a custom mesh structure, allowing me to perform raycasts on the scene geometry.

    I now need access to the Materials/Textures in the scene, in order to retrieve colour information where the rays intersect geometry. Are the Materials/Textures stored as some global property that is accessible from a Compute Shader? Or will I need to pass this data to the Compute Shader manually?

    Thanks in advance for your help!

    [Here's what it looks like so far - a world of mirror like surfaces reflecting a sky texture]

    gpu_raytracer_so_far.PNG
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    You'll need to pass all of the necessary information to the compute shader yourself.
     
  3. lumoconnor

    lumoconnor

    Joined:
    Jan 17, 2016
    Posts:
    27
    Cool, thanks!

    Further to my original question then - any ideas the best way to pass, and access, an arbitrary set of textures in a compute shader? Looked into using a structured buffer but it seems as though each texture would have to be the same size.