Calculating Normals in a Scriptable Rendering Pipeline Using a Shader Graph How this is handled depends on the type of rendering pipeline being used (scriptable vs. The normal calculated above will be in world-space and depending on your shader and renderer setup in Unity, it will most likely need to be in tangent space. There’s one small issue with this, however. Normal = normalize ( cross ( ddy ( worldPosition ), ddx ( worldPosition ) ) ) The key to doing this is to use the partial-derivative shader functions ddx and ddy: The benefit of this approach is that the per-vertex normals are no longer needed which makes for optimal vertex sharing and memory savings. polygon), then there is a fairly inexpensive way to calculate them at runtime in a pixel shader. If you don’t mind having normals calculated per triangle (vs. Calculating Face Normals in a Fragment Shader This will result in slower runtime performance and an increase in the amount of memory required to store the mesh for rendering. However, when flat shading is applied, the center vertex can no longer be shared as each adjacent quad requires it to have a different normal. When smooth shading is used, the middle vertex in the mesh shown above can be shared by each of the adjacent triangles which results in a fairly substantial memory savings as well as a performance boost as the GPU will likely only need to process the vertex once. The more important issue with using per-vertex normals to achieve flat shading is its memory and performance penalties. It should be possible to fix this issue by accounting for the normal in the ambient occlusion shader, but neither Blender nor Unity do this currently. The image on the right shows the undesired results after enabling ambient occlusion. The image on the left shows the desired rendering of a 2x2 grid of quads with only the vertex in the middle lowered. While this might render as desired at first, the bad news is that the non-coplanar triangles can cause problems once additional effects such as screen-space ambient occlusion are enabled. The good news is that the per-vertex normals will still be assigned to the calculated normal of the original polygon. Since GPUs and most rendering engines work with triangles, these polygons will be converted (arbitrarily) to triangles during export. The first issue with this approach is that polygons with more than three edges are not always truly “flat” – meaning that a polygon’s vertices may not all lie on the same plane. “Shade Smooth.” Selecting “Shade Flat” will result in the model being exported with per-vertex normals that are aligned to the normal of their polygon. For example, Blender makes this easy with options on its right-click menu for “Shade Flat” vs. The simplest way to achieve flat shading is to specify that the faces should be rendered that way in whatever tool is used to model them. In this article I’ll cover ways for achieving this look more optimally in Unity using its scriptable and standard rendering pipelines. Unfortunately, the simplest, most common approach to achieving this look is far from optimal. I really like the flat-shaded, low-poly style especially when combined with nice lighting.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |