I then render a quad with that texture applied to it to the frame buffer, using a pixel shader which applies the Sobel filter. When the toggle for the Sobel filtering is turned on, the scene is no longer directly rendered to the frame buffer and is instead rendered to a texture (basic post-processing stuff). Having sussed out the Sobel filter and got it working, I thought I might as well use it for edge detection as well. This is what I do to calculate the normals and light the terrain accordingly. Running a Sobel filter over a heightmap will actually generate a normal map for the resulting displacement mesh. The Sobel operator essentially calculates the areas where the intensity of an image changes, and as such it can be used for edge-detection algorithms in image processing (more on this later). This is where the Sobel operator or Sobel filter comes in. It's all well and good adding vertices to a mesh, but if you can't calculate their normals you won't be able to light it properly. I did that too, which I'll talk about in my next post. the tessellation factor sent from the hull shader to the tessellator stage) non-uniformly, perhaps based on proximity to the player or camera. They can also be done through the domain shader after tessellation, as I've done here, since the domain shader is essentially just a vertex shader for vertices created through tessellation.Īn even more interesting concept is changing the level of tessellation (i.e. I said earlier that the heightmap vertex displacements could be done through the vertex shader. Similarly to the height multiplier, I made the tessellation factor a dynamic value that changes based on user input, which is then passed to the shader as part of a cbuffer. This means that at the maximum tessellation factor I have a 1-to-1 map between heightmap pixel values and vertices in the mesh. The reason I made the base terrain mesh a 4x4 block of quads instead of just a single one is so that at the maximum tessellation I have a 256x256 mesh, which just so happens to be the dimensions of my heightmap. The maximum tessellation factor in DirectX11 is 64, meaning that at most one edge can become 64. One of the really interesting features of DirectX11 is the additions of the hull and domain shaders to allow for tessellation that is, adding triangles to a mesh dynamically on the GPU to avoid the overhead of pushing them into the graphics pipeline from the CPU. The mesh itself is made up of just a 5x5 grid of vertices, giving 16 quads as shown in the top middle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |