# How can I use shaders in Unity to write a scientific computing program?

I want to write a GPU shallow water code on Unity3D. For sure, performance matters a lot. I've done this before using DirectX and C++. But for a couple of reasons I want to redo it in Unity3D.

I have some hands on experiences with Unity3D, but I have no idea how I can write GPGPU codes, like what I did in DirectX.

In DirectX I am using textures as my data structure for the properties of water cells (height, x-velocity, y-velocity, etc.) and HLSL shaders as my parallel computational functions (kernels).

Furthermore, I prefer my code to be [near] cross-platform. Is it possible to do something similar in Unity3D using OpenGL?

I am an engineer, and not a game developer, so please keep it simple ...

• Can you clarify whether you're looking for help with writing the shaders themselves in Unity's somewhat idiosyncratic format? Or setting up the chain of operations/render passes that you want to perform with those shaders (eg. First use buffer X and Y to compute intermediate result buffer Z, then use Z and X to generate the next frame's Y, then...)? If there are specific aspects of Unity that you're stuck on, letting us know what they are will help get more targeted & relevant answers. – DMGregory Nov 17 '15 at 13:21

In Unity you can do with shaders pretty much everything you could do with DirectX or other Framework/APIs as long as you use the shader for stuff like surface materials or post processing. Vertex and surface shaders are written in HLSL/Cg but are wrapped in ShaderLab code. I don't know how much that impairs your cross-plattform requirement, but since Unity supports a broad spectrum of target platforms, it should suffice.

Shader "foo/bar" {