I'm using HLSL Shader Model 5.0. I'm using a Texture2D with the vertex positions for a mesh. In the Shader I'm trying to displace patchepositions along the normal of the patches I'd like to actualize the new position to the texture out of the shader, so the next patch is using the modified value. There is the Load function for loading values out of the texture, but is there a function to store values back into the texture? I didn't find anything. How do you guys managing similar problems? thx
3 Answers
In Direct3D 11.1 you can use unordered access views (UAVs) for read-writable textures in all shader stages. So you can add an RWTexture2D
to your vertex shader and use it to store values as the vertices are shaded. However, this functionality isn't available in Direct3D 11.0 or earlier, and 11.1 is only available on Windows 8.0 or higher.
If you're limited to Direct3D 11.0, you could implement your displacement operation using a pixel shader and doing a standard full-screen pass on the texture containing the positions. Another possibility (though likely slower) is using a compute shader. In either case, you would do this as a pre-pass before actually drawing the displaced mesh.
-
-
\$\begingroup\$ @SeanMiddleditch I believe that only adds an 11.1 reference device. This page linked from that update says "Feature level 11.1 hardware support is not available (through the platform update)... On Windows 7 with the platform update, D3D11CreateDevice always returns a feature level of 11.0 or lower, except for with a reference device that can be used to test an 11.1 code path on Windows 7." \$\endgroup\$ Nov 22, 2013 at 3:00
-
\$\begingroup\$ always nice to read from you :) what do you mean by full-screen pass? \$\endgroup\$– JinxiNov 22, 2013 at 9:42
You cannot moddify textures in the pixelshader that way, the only way to do that is to render to a texture.
Direct compute offers you the possibility to read and write data to a texture on demand. you could achive your diserd effect by having a Direct compute pass.
Here is a good link to msdn about compute shaders
Since it's vertex data you want to store somewhere you also have the option of using stream out from either the vertex or geometry shader.