![]() Tessellation and triangulation can mean complicated, fancy things to people who are mathematicians and computer scientists studying complicated, fancy things like computational geometry. This is where tessellation and triangulation come in handy! The algorithms I’m going to be showing in this tutorial break up the polys that make up a mesh without changing the shape of the mesh. We may need to break up polygons with lots of verticies into triangles, a necessary step before handing it to the renderer or prepare a mesh for a warp like stellation or extrusion to ensure that it’ll have lots of small details. Sometimes, we want to add detail to a mesh without changing its shape. These 2 function are commented out in the CustomTessellation file, you should copy them over to a new shader you make with tessellation :) Shader Code with comments (You need both!):ĬustomTessellation.DISCLAIMER #1: Code presented here is pseudocode that does NOT necessarily reflect production Limit Theory code.ĭISCLAIMER #2: This tutorial assumes you have at least basic knowledge of 3D geometry and related math. hlsl to the shader itself so it's a bit clearer where the per-shader parts are. Note: I moved the second vertex function, and the domain from the. The fragment program doesn't change, I've just added (Varyings IN) so we can use the UV map. In this second vertex function, we can finally use the tessellated vertices properly, set up here as a noise texture displacing over the whole mesh Fragment Note how the usual _WorldSpaceCameraPos is replaced by GetCameraPositionWS() Domainįinally we go through the domain program, which goes through the second vertex function. It's set up to fade over distance from the camera. TessellationĪfter that we do the actual tessellation in patchConstantFunction, as described above the hull program. The hull program needs all these parts to know what to do. This is the function declared in #pragma vertex (TessellationVertexProgram) Hull The mesh data of the original vertex struct Instead of : POSITION, notice how it says INTERNALTESSPOS The links at the bottom do a better job of explaining the process, I don't want to copy what they say so please check them out. Very roughly : Take the original vertices, gather data to divide them, divide them, pass divided vertices on again, colorize. Vertex > Hull > Domain + Second Vertex > Fragment So to add in tessellation we need 3 more functions. The appdata struct is called Attributes, and the v2f struct is called Varyings. There's a " RenderPipeline" = " UniversalRenderPipeline" tag It's the equivalent of a vertex/fragment shader you might know from legacy, but a few things are different. ![]() Lets start with the most simple unlit URP code shader from the Unity documentation The Shader code and HLSL file you need are linked at the bottom The setup is actually very similar to the built-in/legacy tessellation but if you're like me and only used it in combination with surface shaders it's a bit more work than that. In this post I'm going over the most basic tessellated shader in URP. ![]() ![]() Here's the new CustomTessellation.hlsl file : Pastebin LinkĪnd the new BasicTessellation shader file to go with it, a little cleaner : Pastebin Link If you look in CustomTessellation.hlsl, there are 2 more options commented out, for edge length based tessellation (Can get very dense) and the same with culling, which works in theory but I dont know how to properly test that I've added all the options from the Built-in version Tessellation.cginc to the CustomTessellation.hlsl
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |