Giter Club home page Giter Club logo

unrealcomputeshaderexample's Introduction

This project is a minimal example for using compute shaders in the Unreal Engine.

The main thing to implement is a way to pass/bind our GPU buffers to the compute shader. We do this by subclassing a FGlobalShader, in our example our subclass is named FComputeShaderDeclaration. FComputeShaderDeclaration in ComputeShaderTestComponent.h is how we bind our buffers from our Unreal classes to the compute shader. You write one of these for each of your compute shaders.

UComputeShaderTestComponent in ComputeShaderTestComponent.h contains the structured-buffer and unordered-access-views (UAVs) that we bind to the compute shader. We setup and bind to our compute shader in TickComponent, on the render command queue.

UDrawPositionsComponent in ComputeShaderTestComponent.h draws the positions from the UComputeShaderTestComponent using an UInstancedStaticMeshComponent (ISMC).

I couldn't figure out how to bind the compute shader to the ISMCs internal buffers. So, we are doing unnecessary copying back to the CPU and back to the GPU. I also copy from a FVector array to a FTransform array, that's a little ugly.

The compute shader is super basic, it just modulates positions with a sine function.

Gotchas

  • The LoadingPhase in the uproject file needs to be PostConfigInit
  • You must let Unreal know where to find your shader directly. I set this in the game mode in the module interface in ComputeShaderExample.h

unrealcomputeshaderexample's People

Contributors

timdecode avatar ltorrao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.